UNPKG

ember-legacy-class-transform

Version:
1,436 lines (1,201 loc) 253 kB
define('@glimmer/runtime', ['exports', '@glimmer/util', '@glimmer/reference', '@glimmer/wire-format'], function (exports, _glimmer_util, _glimmer_reference, WireFormat) { 'use strict'; function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Registers * * For the most part, these follows MIPS naming conventions, however the * register numbers are different. */ (function (Register) { // $0 or $pc (program counter): pointer into `program` for the next insturction; -1 means exit Register[Register["pc"] = 0] = "pc"; // $1 or $ra (return address): pointer into `program` for the return Register[Register["ra"] = 1] = "ra"; // $2 or $fp (frame pointer): pointer into the `evalStack` for the base of the stack Register[Register["fp"] = 2] = "fp"; // $3 or $sp (stack pointer): pointer into the `evalStack` for the top of the stack Register[Register["sp"] = 3] = "sp"; // $4-$5 or $s0-$s1 (saved): callee saved general-purpose registers Register[Register["s0"] = 4] = "s0"; Register[Register["s1"] = 5] = "s1"; // $6-$7 or $t0-$t1 (temporaries): caller saved general-purpose registers Register[Register["t0"] = 6] = "t0"; Register[Register["t1"] = 7] = "t1"; })(exports.Register || (exports.Register = {})); function debugSlice(env, start, end) { } var AppendOpcodes = function () { function AppendOpcodes() { _classCallCheck(this, AppendOpcodes); this.evaluateOpcode = _glimmer_util.fillNulls(72 /* Size */).slice(); } AppendOpcodes.prototype.add = function add(name, evaluate) { this.evaluateOpcode[name] = evaluate; }; AppendOpcodes.prototype.evaluate = function evaluate(vm, opcode, type) { var func = this.evaluateOpcode[type]; func(vm, opcode); }; return AppendOpcodes; }(); var APPEND_OPCODES = new AppendOpcodes(); var AbstractOpcode = function () { function AbstractOpcode() { _classCallCheck(this, AbstractOpcode); _glimmer_util.initializeGuid(this); } AbstractOpcode.prototype.toJSON = function toJSON() { return { guid: this._guid, type: this.type }; }; return AbstractOpcode; }(); var UpdatingOpcode = function (_AbstractOpcode) { _inherits(UpdatingOpcode, _AbstractOpcode); function UpdatingOpcode() { _classCallCheck(this, UpdatingOpcode); var _this = _possibleConstructorReturn(this, _AbstractOpcode.apply(this, arguments)); _this.next = null; _this.prev = null; return _this; } return UpdatingOpcode; }(AbstractOpcode); function _defaults$1(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn$1(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits$1(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults$1(subClass, superClass); } var PrimitiveReference = function (_ConstReference) { _inherits$1(PrimitiveReference, _ConstReference); function PrimitiveReference(value) { _classCallCheck$1(this, PrimitiveReference); return _possibleConstructorReturn$1(this, _ConstReference.call(this, value)); } PrimitiveReference.create = function create(value) { if (value === undefined) { return UNDEFINED_REFERENCE; } else if (value === null) { return NULL_REFERENCE; } else if (value === true) { return TRUE_REFERENCE; } else if (value === false) { return FALSE_REFERENCE; } else if (typeof value === 'number') { return new ValueReference(value); } else { return new StringReference(value); } }; PrimitiveReference.prototype.get = function get(_key) { return UNDEFINED_REFERENCE; }; return PrimitiveReference; }(_glimmer_reference.ConstReference); var StringReference = function (_PrimitiveReference) { _inherits$1(StringReference, _PrimitiveReference); function StringReference() { _classCallCheck$1(this, StringReference); var _this2 = _possibleConstructorReturn$1(this, _PrimitiveReference.apply(this, arguments)); _this2.lengthReference = null; return _this2; } StringReference.prototype.get = function get(key) { if (key === 'length') { var lengthReference = this.lengthReference; if (lengthReference === null) { lengthReference = this.lengthReference = new ValueReference(this.inner.length); } return lengthReference; } else { return _PrimitiveReference.prototype.get.call(this, key); } }; return StringReference; }(PrimitiveReference); var ValueReference = function (_PrimitiveReference2) { _inherits$1(ValueReference, _PrimitiveReference2); function ValueReference(value) { _classCallCheck$1(this, ValueReference); return _possibleConstructorReturn$1(this, _PrimitiveReference2.call(this, value)); } return ValueReference; }(PrimitiveReference); var UNDEFINED_REFERENCE = new ValueReference(undefined); var NULL_REFERENCE = new ValueReference(null); var TRUE_REFERENCE = new ValueReference(true); var FALSE_REFERENCE = new ValueReference(false); var ConditionalReference = function () { function ConditionalReference(inner) { _classCallCheck$1(this, ConditionalReference); this.inner = inner; this.tag = inner.tag; } ConditionalReference.prototype.value = function value() { return this.toBool(this.inner.value()); }; ConditionalReference.prototype.toBool = function toBool(value) { return !!value; }; return ConditionalReference; }(); function _defaults$2(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn$2(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits$2(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults$2(subClass, superClass); } var ConcatReference = function (_CachedReference) { _inherits$2(ConcatReference, _CachedReference); function ConcatReference(parts) { _classCallCheck$2(this, ConcatReference); var _this = _possibleConstructorReturn$2(this, _CachedReference.call(this)); _this.parts = parts; _this.tag = _glimmer_reference.combineTagged(parts); return _this; } ConcatReference.prototype.compute = function compute() { var parts = new Array(); for (var i = 0; i < this.parts.length; i++) { var value = this.parts[i].value(); if (value !== null && value !== undefined) { parts[i] = castToString(value); } } if (parts.length > 0) { return parts.join(''); } return null; }; return ConcatReference; }(_glimmer_reference.CachedReference); function castToString(value) { if (typeof value.toString !== 'function') { return ''; } return String(value); } APPEND_OPCODES.add(1 /* Helper */, function (vm, _ref) { var _helper = _ref.op1; var stack = vm.stack; var helper = vm.constants.getFunction(_helper); var args = stack.pop(); var value = helper(vm, args); args.clear(); vm.stack.push(value); }); APPEND_OPCODES.add(2 /* Function */, function (vm, _ref2) { var _function = _ref2.op1; var func = vm.constants.getFunction(_function); vm.stack.push(func(vm)); }); APPEND_OPCODES.add(5 /* GetVariable */, function (vm, _ref3) { var symbol = _ref3.op1; var expr = vm.referenceForSymbol(symbol); vm.stack.push(expr); }); APPEND_OPCODES.add(4 /* SetVariable */, function (vm, _ref4) { var symbol = _ref4.op1; var expr = vm.stack.pop(); vm.scope().bindSymbol(symbol, expr); }); APPEND_OPCODES.add(70 /* ResolveMaybeLocal */, function (vm, _ref5) { var _name = _ref5.op1; var name = vm.constants.getString(_name); var locals = vm.scope().getPartialMap(); var ref = locals[name]; if (ref === undefined) { ref = vm.getSelf().get(name); } vm.stack.push(ref); }); APPEND_OPCODES.add(19 /* RootScope */, function (vm, _ref6) { var symbols = _ref6.op1, bindCallerScope = _ref6.op2; vm.pushRootScope(symbols, !!bindCallerScope); }); APPEND_OPCODES.add(6 /* GetProperty */, function (vm, _ref7) { var _key = _ref7.op1; var key = vm.constants.getString(_key); var expr = vm.stack.pop(); vm.stack.push(expr.get(key)); }); APPEND_OPCODES.add(7 /* PushBlock */, function (vm, _ref8) { var _block = _ref8.op1; var block = _block ? vm.constants.getBlock(_block) : null; vm.stack.push(block); }); APPEND_OPCODES.add(8 /* GetBlock */, function (vm, _ref9) { var _block = _ref9.op1; vm.stack.push(vm.scope().getBlock(_block)); }); APPEND_OPCODES.add(9 /* HasBlock */, function (vm, _ref10) { var _block = _ref10.op1; var hasBlock = !!vm.scope().getBlock(_block); vm.stack.push(hasBlock ? TRUE_REFERENCE : FALSE_REFERENCE); }); APPEND_OPCODES.add(10 /* HasBlockParams */, function (vm, _ref11) { var _block = _ref11.op1; var block = vm.scope().getBlock(_block); var hasBlockParams = block && block.symbolTable.parameters.length; vm.stack.push(hasBlockParams ? TRUE_REFERENCE : FALSE_REFERENCE); }); APPEND_OPCODES.add(11 /* Concat */, function (vm, _ref12) { var count = _ref12.op1; var out = []; for (var i = count; i > 0; i--) { out.push(vm.stack.pop()); } vm.stack.push(new ConcatReference(out.reverse())); }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Arguments = function () { function Arguments() { _classCallCheck$4(this, Arguments); this.stack = null; this.positional = new PositionalArguments(); this.named = new NamedArguments(); } Arguments.prototype.empty = function empty() { this.setup(null, true); return this; }; Arguments.prototype.setup = function setup(stack, synthetic) { this.stack = stack; var names = stack.fromTop(0); var namedCount = names.length; var positionalCount = stack.fromTop(namedCount + 1); var start = positionalCount + namedCount + 2; var positional = this.positional; positional.setup(stack, start, positionalCount); var named = this.named; named.setup(stack, namedCount, names, synthetic); }; Arguments.prototype.at = function at(pos) { return this.positional.at(pos); }; Arguments.prototype.get = function get(name) { return this.named.get(name); }; Arguments.prototype.capture = function capture() { return { tag: this.tag, length: this.length, positional: this.positional.capture(), named: this.named.capture() }; }; Arguments.prototype.clear = function clear() { var stack = this.stack, length = this.length; stack.pop(length + 2); }; _createClass(Arguments, [{ key: 'tag', get: function () { return _glimmer_reference.combineTagged([this.positional, this.named]); } }, { key: 'length', get: function () { return this.positional.length + this.named.length; } }]); return Arguments; }(); var PositionalArguments = function () { function PositionalArguments() { _classCallCheck$4(this, PositionalArguments); this.length = 0; this.stack = null; this.start = 0; this._tag = null; this._references = null; } PositionalArguments.prototype.setup = function setup(stack, start, length) { this.stack = stack; this.start = start; this.length = length; this._tag = null; this._references = null; }; PositionalArguments.prototype.at = function at(position) { var start = this.start, length = this.length; if (position < 0 || position >= length) { return UNDEFINED_REFERENCE; } // stack: pos1, pos2, pos3, named1, named2 // start: 4 (top - 4) // // at(0) === pos1 === top - start // at(1) === pos2 === top - (start - 1) // at(2) === pos3 === top - (start - 2) var fromTop = start - position - 1; return this.stack.fromTop(fromTop); }; PositionalArguments.prototype.capture = function capture() { return new CapturedPositionalArguments(this.tag, this.references); }; _createClass(PositionalArguments, [{ key: 'tag', get: function () { var tag = this._tag; if (!tag) { tag = this._tag = _glimmer_reference.combineTagged(this.references); } return tag; } }, { key: 'references', get: function () { var references = this._references; if (!references) { var length = this.length; references = this._references = new Array(length); for (var i = 0; i < length; i++) { references[i] = this.at(i); } } return references; } }]); return PositionalArguments; }(); var CapturedPositionalArguments = function () { function CapturedPositionalArguments(tag, references) { var length = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : references.length; _classCallCheck$4(this, CapturedPositionalArguments); this.tag = tag; this.references = references; this.length = length; } CapturedPositionalArguments.prototype.at = function at(position) { return this.references[position]; }; CapturedPositionalArguments.prototype.value = function value() { return this.references.map(this.valueOf); }; CapturedPositionalArguments.prototype.get = function get(name) { var references = this.references, length = this.length; if (name === 'length') { return PrimitiveReference.create(length); } else { var idx = parseInt(name, 10); if (idx < 0 || idx >= length) { return UNDEFINED_REFERENCE; } else { return references[idx]; } } }; CapturedPositionalArguments.prototype.valueOf = function valueOf(reference) { return reference.value(); }; return CapturedPositionalArguments; }(); var NamedArguments = function () { function NamedArguments() { _classCallCheck$4(this, NamedArguments); this.length = 0; this._tag = null; this._references = null; this._names = null; this._realNames = _glimmer_util.EMPTY_ARRAY; } NamedArguments.prototype.setup = function setup(stack, length, names, synthetic) { this.stack = stack; this.length = length; this._tag = null; this._references = null; if (synthetic) { this._names = names; this._realNames = _glimmer_util.EMPTY_ARRAY; } else { this._names = null; this._realNames = names; } }; NamedArguments.prototype.has = function has(name) { return this.names.indexOf(name) !== -1; }; NamedArguments.prototype.get = function get(name) { var names = this.names, length = this.length; var idx = names.indexOf(name); if (idx === -1) { return UNDEFINED_REFERENCE; } // stack: pos1, pos2, pos3, named1, named2 // start: 4 (top - 4) // namedDict: { named1: 1, named2: 0 }; // // get('named1') === named1 === top - (start - 1) // get('named2') === named2 === top - start var fromTop = length - idx; return this.stack.fromTop(fromTop); }; NamedArguments.prototype.capture = function capture() { return new CapturedNamedArguments(this.tag, this.names, this.references); }; NamedArguments.prototype.sliceName = function sliceName(name) { return name.slice(1); }; _createClass(NamedArguments, [{ key: 'tag', get: function () { return _glimmer_reference.combineTagged(this.references); } }, { key: 'names', get: function () { var names = this._names; if (!names) { names = this._names = this._realNames.map(this.sliceName); } return names; } }, { key: 'references', get: function () { var references = this._references; if (!references) { var names = this.names, length = this.length; references = this._references = []; for (var i = 0; i < length; i++) { references[i] = this.get(names[i]); } } return references; } }]); return NamedArguments; }(); var CapturedNamedArguments = function () { function CapturedNamedArguments(tag, names, references) { _classCallCheck$4(this, CapturedNamedArguments); this.tag = tag; this.names = names; this.references = references; this.length = names.length; this._map = null; } CapturedNamedArguments.prototype.has = function has(name) { return this.names.indexOf(name) !== -1; }; CapturedNamedArguments.prototype.get = function get(name) { var names = this.names, references = this.references; var idx = names.indexOf(name); if (idx === -1) { return UNDEFINED_REFERENCE; } else { return references[idx]; } }; CapturedNamedArguments.prototype.value = function value() { var names = this.names, references = this.references; var out = _glimmer_util.dict(); for (var i = 0; i < names.length; i++) { var name = names[i]; out[name] = references[i].value(); } return out; }; _createClass(CapturedNamedArguments, [{ key: 'map', get: function () { var map$$1 = this._map; if (!map$$1) { var names = this.names, references = this.references; map$$1 = this._map = _glimmer_util.dict(); for (var i = 0; i < names.length; i++) { var name = names[i]; map$$1[name] = references[i]; } } return map$$1; } }]); return CapturedNamedArguments; }(); var ARGS = new Arguments(); function _defaults$5(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn$5(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits$5(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults$5(subClass, superClass); } APPEND_OPCODES.add(20 /* ChildScope */, function (vm) { return vm.pushChildScope(); }); APPEND_OPCODES.add(21 /* PopScope */, function (vm) { return vm.popScope(); }); APPEND_OPCODES.add(39 /* PushDynamicScope */, function (vm) { return vm.pushDynamicScope(); }); APPEND_OPCODES.add(40 /* PopDynamicScope */, function (vm) { return vm.popDynamicScope(); }); APPEND_OPCODES.add(12 /* Immediate */, function (vm, _ref) { var number = _ref.op1; vm.stack.push(number); }); APPEND_OPCODES.add(13 /* Constant */, function (vm, _ref2) { var other = _ref2.op1; vm.stack.push(vm.constants.getOther(other)); }); APPEND_OPCODES.add(14 /* PrimitiveReference */, function (vm, _ref3) { var primitive = _ref3.op1; var stack = vm.stack; var flag = (primitive & 3 << 30) >>> 30; var value = primitive & ~(3 << 30); switch (flag) { case 0: stack.push(PrimitiveReference.create(value)); break; case 1: stack.push(PrimitiveReference.create(vm.constants.getFloat(value))); break; case 2: stack.push(PrimitiveReference.create(vm.constants.getString(value))); break; case 3: switch (value) { case 0: stack.push(FALSE_REFERENCE); break; case 1: stack.push(TRUE_REFERENCE); break; case 2: stack.push(NULL_REFERENCE); break; case 3: stack.push(UNDEFINED_REFERENCE); break; } break; } }); APPEND_OPCODES.add(15 /* Dup */, function (vm, _ref4) { var register = _ref4.op1, offset = _ref4.op2; var position = vm.fetchValue(register) - offset; vm.stack.dup(position); }); APPEND_OPCODES.add(16 /* Pop */, function (vm, _ref5) { var count = _ref5.op1; return vm.stack.pop(count); }); APPEND_OPCODES.add(17 /* Load */, function (vm, _ref6) { var register = _ref6.op1; return vm.load(register); }); APPEND_OPCODES.add(18 /* Fetch */, function (vm, _ref7) { var register = _ref7.op1; return vm.fetch(register); }); APPEND_OPCODES.add(38 /* BindDynamicScope */, function (vm, _ref8) { var _names = _ref8.op1; var names = vm.constants.getArray(_names); vm.bindDynamicScope(names); }); APPEND_OPCODES.add(47 /* PushFrame */, function (vm) { return vm.pushFrame(); }); APPEND_OPCODES.add(48 /* PopFrame */, function (vm) { return vm.popFrame(); }); APPEND_OPCODES.add(49 /* Enter */, function (vm, _ref9) { var args = _ref9.op1; return vm.enter(args); }); APPEND_OPCODES.add(50 /* Exit */, function (vm) { return vm.exit(); }); APPEND_OPCODES.add(41 /* CompileDynamicBlock */, function (vm) { var stack = vm.stack; var block = stack.pop(); stack.push(block ? block.compileDynamic(vm.env) : null); }); APPEND_OPCODES.add(42 /* InvokeStatic */, function (vm, _ref10) { var _block = _ref10.op1; var block = vm.constants.getBlock(_block); var compiled = block.compileStatic(vm.env); vm.call(compiled.handle); }); APPEND_OPCODES.add(43 /* InvokeDynamic */, function (vm, _ref11) { var _invoker = _ref11.op1; var invoker = vm.constants.getOther(_invoker); var block = vm.stack.pop(); invoker.invoke(vm, block); }); APPEND_OPCODES.add(44 /* Jump */, function (vm, _ref12) { var target = _ref12.op1; return vm.goto(target); }); APPEND_OPCODES.add(45 /* JumpIf */, function (vm, _ref13) { var target = _ref13.op1; var reference = vm.stack.pop(); if (_glimmer_reference.isConst(reference)) { if (reference.value()) { vm.goto(target); } } else { var cache = new _glimmer_reference.ReferenceCache(reference); if (cache.peek()) { vm.goto(target); } vm.updateWith(new Assert(cache)); } }); APPEND_OPCODES.add(46 /* JumpUnless */, function (vm, _ref14) { var target = _ref14.op1; var reference = vm.stack.pop(); if (_glimmer_reference.isConst(reference)) { if (!reference.value()) { vm.goto(target); } } else { var cache = new _glimmer_reference.ReferenceCache(reference); if (!cache.peek()) { vm.goto(target); } vm.updateWith(new Assert(cache)); } }); APPEND_OPCODES.add(22 /* Return */, function (vm) { return vm.return(); }); APPEND_OPCODES.add(23 /* ReturnTo */, function (vm, _ref15) { var relative = _ref15.op1; vm.returnTo(relative); }); var ConstTest = function (ref, _env) { return new _glimmer_reference.ConstReference(!!ref.value()); }; var SimpleTest = function (ref, _env) { return ref; }; var EnvironmentTest = function (ref, env) { return env.toConditionalReference(ref); }; APPEND_OPCODES.add(51 /* Test */, function (vm, _ref16) { var _func = _ref16.op1; var stack = vm.stack; var operand = stack.pop(); var func = vm.constants.getFunction(_func); stack.push(func(operand, vm.env)); }); var Assert = function (_UpdatingOpcode) { _inherits$5(Assert, _UpdatingOpcode); function Assert(cache) { _classCallCheck$6(this, Assert); var _this = _possibleConstructorReturn$5(this, _UpdatingOpcode.call(this)); _this.type = 'assert'; _this.tag = cache.tag; _this.cache = cache; return _this; } Assert.prototype.evaluate = function evaluate(vm) { var cache = this.cache; if (_glimmer_reference.isModified(cache.revalidate())) { vm.throw(); } }; Assert.prototype.toJSON = function toJSON() { var type = this.type, _guid = this._guid, cache = this.cache; var expected = void 0; try { expected = JSON.stringify(cache.peek()); } catch (e) { expected = String(cache.peek()); } return { args: [], details: { expected: expected }, guid: _guid, type: type }; }; return Assert; }(UpdatingOpcode); var JumpIfNotModifiedOpcode = function (_UpdatingOpcode2) { _inherits$5(JumpIfNotModifiedOpcode, _UpdatingOpcode2); function JumpIfNotModifiedOpcode(tag, target) { _classCallCheck$6(this, JumpIfNotModifiedOpcode); var _this2 = _possibleConstructorReturn$5(this, _UpdatingOpcode2.call(this)); _this2.target = target; _this2.type = 'jump-if-not-modified'; _this2.tag = tag; _this2.lastRevision = tag.value(); return _this2; } JumpIfNotModifiedOpcode.prototype.evaluate = function evaluate(vm) { var tag = this.tag, target = this.target, lastRevision = this.lastRevision; if (!vm.alwaysRevalidate && tag.validate(lastRevision)) { vm.goto(target); } }; JumpIfNotModifiedOpcode.prototype.didModify = function didModify() { this.lastRevision = this.tag.value(); }; JumpIfNotModifiedOpcode.prototype.toJSON = function toJSON() { return { args: [JSON.stringify(this.target.inspect())], guid: this._guid, type: this.type }; }; return JumpIfNotModifiedOpcode; }(UpdatingOpcode); var DidModifyOpcode = function (_UpdatingOpcode3) { _inherits$5(DidModifyOpcode, _UpdatingOpcode3); function DidModifyOpcode(target) { _classCallCheck$6(this, DidModifyOpcode); var _this3 = _possibleConstructorReturn$5(this, _UpdatingOpcode3.call(this)); _this3.target = target; _this3.type = 'did-modify'; _this3.tag = _glimmer_reference.CONSTANT_TAG; return _this3; } DidModifyOpcode.prototype.evaluate = function evaluate() { this.target.didModify(); }; return DidModifyOpcode; }(UpdatingOpcode); var LabelOpcode = function () { function LabelOpcode(label) { _classCallCheck$6(this, LabelOpcode); this.tag = _glimmer_reference.CONSTANT_TAG; this.type = 'label'; this.label = null; this.prev = null; this.next = null; _glimmer_util.initializeGuid(this); this.label = label; } LabelOpcode.prototype.evaluate = function evaluate() {}; LabelOpcode.prototype.inspect = function inspect$$1() { return this.label + ' [' + this._guid + ']'; }; LabelOpcode.prototype.toJSON = function toJSON() { return { args: [JSON.stringify(this.inspect())], guid: this._guid, type: this.type }; }; return LabelOpcode; }(); function _defaults$4(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _possibleConstructorReturn$4(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits$4(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults$4(subClass, superClass); } function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } APPEND_OPCODES.add(24 /* Text */, function (vm, _ref) { var text = _ref.op1; vm.elements().appendText(vm.constants.getString(text)); }); APPEND_OPCODES.add(25 /* Comment */, function (vm, _ref2) { var text = _ref2.op1; vm.elements().appendComment(vm.constants.getString(text)); }); APPEND_OPCODES.add(27 /* OpenElement */, function (vm, _ref3) { var tag = _ref3.op1; vm.elements().openElement(vm.constants.getString(tag)); }); APPEND_OPCODES.add(28 /* OpenElementWithOperations */, function (vm, _ref4) { var tag = _ref4.op1; var tagName = vm.constants.getString(tag); var operations = vm.stack.pop(); vm.elements().openElement(tagName, operations); }); APPEND_OPCODES.add(29 /* OpenDynamicElement */, function (vm) { var operations = vm.stack.pop(); var tagName = vm.stack.pop().value(); vm.elements().openElement(tagName, operations); }); APPEND_OPCODES.add(36 /* PushRemoteElement */, function (vm) { var elementRef = vm.stack.pop(); var nextSiblingRef = vm.stack.pop(); var element = void 0; var nextSibling = void 0; if (_glimmer_reference.isConst(elementRef)) { element = elementRef.value(); } else { var cache = new _glimmer_reference.ReferenceCache(elementRef); element = cache.peek(); vm.updateWith(new Assert(cache)); } if (_glimmer_reference.isConst(nextSiblingRef)) { nextSibling = nextSiblingRef.value(); } else { var _cache = new _glimmer_reference.ReferenceCache(nextSiblingRef); nextSibling = _cache.peek(); vm.updateWith(new Assert(_cache)); } vm.elements().pushRemoteElement(element, nextSibling); }); APPEND_OPCODES.add(37 /* PopRemoteElement */, function (vm) { return vm.elements().popRemoteElement(); }); var ClassList = function () { function ClassList() { _classCallCheck$5(this, ClassList); this.list = null; this.isConst = true; } ClassList.prototype.append = function append(reference) { var list = this.list, isConst$$1 = this.isConst; if (list === null) list = this.list = []; list.push(reference); this.isConst = isConst$$1 && _glimmer_reference.isConst(reference); }; ClassList.prototype.toReference = function toReference() { var list = this.list, isConst$$1 = this.isConst; if (!list) return NULL_REFERENCE; if (isConst$$1) return PrimitiveReference.create(toClassName(list)); return new ClassListReference(list); }; return ClassList; }(); var ClassListReference = function (_CachedReference) { _inherits$4(ClassListReference, _CachedReference); function ClassListReference(list) { _classCallCheck$5(this, ClassListReference); var _this = _possibleConstructorReturn$4(this, _CachedReference.call(this)); _this.list = []; _this.tag = _glimmer_reference.combineTagged(list); _this.list = list; return _this; } ClassListReference.prototype.compute = function compute() { return toClassName(this.list); }; return ClassListReference; }(_glimmer_reference.CachedReference); function toClassName(list) { var ret = []; for (var i = 0; i < list.length; i++) { var value = list[i].value(); if (value !== false && value !== null && value !== undefined) ret.push(value); } return ret.length === 0 ? null : ret.join(' '); } var SimpleElementOperations = function () { function SimpleElementOperations(env) { _classCallCheck$5(this, SimpleElementOperations); this.env = env; this.opcodes = null; this.classList = null; } SimpleElementOperations.prototype.addStaticAttribute = function addStaticAttribute(element, name, value) { if (name === 'class') { this.addClass(PrimitiveReference.create(value)); } else { this.env.getAppendOperations().setAttribute(element, name, value); } }; SimpleElementOperations.prototype.addStaticAttributeNS = function addStaticAttributeNS(element, namespace, name, value) { this.env.getAppendOperations().setAttribute(element, name, value, namespace); }; SimpleElementOperations.prototype.addDynamicAttribute = function addDynamicAttribute(element, name, reference, isTrusting) { if (name === 'class') { this.addClass(reference); } else { var attributeManager = this.env.attributeFor(element, name, isTrusting); var attribute = new DynamicAttribute(element, attributeManager, name, reference); this.addAttribute(attribute); } }; SimpleElementOperations.prototype.addDynamicAttributeNS = function addDynamicAttributeNS(element, namespace, name, reference, isTrusting) { var attributeManager = this.env.attributeFor(element, name, isTrusting, namespace); var nsAttribute = new DynamicAttribute(element, attributeManager, name, reference, namespace); this.addAttribute(nsAttribute); }; SimpleElementOperations.prototype.flush = function flush(element, vm) { var env = vm.env; var opcodes = this.opcodes, classList = this.classList; for (var i = 0; opcodes && i < opcodes.length; i++) { vm.updateWith(opcodes[i]); } if (classList) { var attributeManager = env.attributeFor(element, 'class', false); var attribute = new DynamicAttribute(element, attributeManager, 'class', classList.toReference()); var opcode = attribute.flush(env); if (opcode) { vm.updateWith(opcode); } } this.opcodes = null; this.classList = null; }; SimpleElementOperations.prototype.addClass = function addClass(reference) { var classList = this.classList; if (!classList) { classList = this.classList = new ClassList(); } classList.append(reference); }; SimpleElementOperations.prototype.addAttribute = function addAttribute(attribute) { var opcode = attribute.flush(this.env); if (opcode) { var opcodes = this.opcodes; if (!opcodes) { opcodes = this.opcodes = []; } opcodes.push(opcode); } }; return SimpleElementOperations; }(); var ComponentElementOperations = function () { function ComponentElementOperations(env) { _classCallCheck$5(this, ComponentElementOperations); this.env = env; this.attributeNames = null; this.attributes = null; this.classList = null; } ComponentElementOperations.prototype.addStaticAttribute = function addStaticAttribute(element, name, value) { if (name === 'class') { this.addClass(PrimitiveReference.create(value)); } else if (this.shouldAddAttribute(name)) { this.addAttribute(name, new StaticAttribute(element, name, value)); } }; ComponentElementOperations.prototype.addStaticAttributeNS = function addStaticAttributeNS(element, namespace, name, value) { if (this.shouldAddAttribute(name)) { this.addAttribute(name, new StaticAttribute(element, name, value, namespace)); } }; ComponentElementOperations.prototype.addDynamicAttribute = function addDynamicAttribute(element, name, reference, isTrusting) { if (name === 'class') { this.addClass(reference); } else if (this.shouldAddAttribute(name)) { var attributeManager = this.env.attributeFor(element, name, isTrusting); var attribute = new DynamicAttribute(element, attributeManager, name, reference); this.addAttribute(name, attribute); } }; ComponentElementOperations.prototype.addDynamicAttributeNS = function addDynamicAttributeNS(element, namespace, name, reference, isTrusting) { if (this.shouldAddAttribute(name)) { var attributeManager = this.env.attributeFor(element, name, isTrusting, namespace); var nsAttribute = new DynamicAttribute(element, attributeManager, name, reference, namespace); this.addAttribute(name, nsAttribute); } }; ComponentElementOperations.prototype.flush = function flush(element, vm) { var env = this.env; var attributes = this.attributes, classList = this.classList; for (var i = 0; attributes && i < attributes.length; i++) { var opcode = attributes[i].flush(env); if (opcode) { vm.updateWith(opcode); } } if (classList) { var attributeManager = env.attributeFor(element, 'class', false); var attribute = new DynamicAttribute(element, attributeManager, 'class', classList.toReference()); var _opcode = attribute.flush(env); if (_opcode) { vm.updateWith(_opcode); } } }; ComponentElementOperations.prototype.shouldAddAttribute = function shouldAddAttribute(name) { return !this.attributeNames || this.attributeNames.indexOf(name) === -1; }; ComponentElementOperations.prototype.addClass = function addClass(reference) { var classList = this.classList; if (!classList) { classList = this.classList = new ClassList(); } classList.append(reference); }; ComponentElementOperations.prototype.addAttribute = function addAttribute(name, attribute) { var attributeNames = this.attributeNames, attributes = this.attributes; if (!attributeNames) { attributeNames = this.attributeNames = []; attributes = this.attributes = []; } attributeNames.push(name); attributes.push(attribute); }; return ComponentElementOperations; }(); APPEND_OPCODES.add(33 /* FlushElement */, function (vm) { var stack = vm.elements(); var action = 'FlushElementOpcode#evaluate'; stack.expectOperations(action).flush(stack.expectConstructing(action), vm); stack.flushElement(); }); APPEND_OPCODES.add(34 /* CloseElement */, function (vm) { return vm.elements().closeElement(); }); APPEND_OPCODES.add(30 /* StaticAttr */, function (vm, _ref5) { var _name = _ref5.op1, _value = _ref5.op2, _namespace = _ref5.op3; var name = vm.constants.getString(_name); var value = vm.constants.getString(_value); if (_namespace) { var namespace = vm.constants.getString(_namespace); vm.elements().setStaticAttributeNS(namespace, name, value); } else { vm.elements().setStaticAttribute(name, value); } }); APPEND_OPCODES.add(35 /* Modifier */, function (vm, _ref6) { var _manager = _ref6.op1; var manager = vm.constants.getOther(_manager); var stack = vm.stack; var args = stack.pop(); var tag = args.tag; var _vm$elements = vm.elements(), element = _vm$elements.constructing, updateOperations = _vm$elements.updateOperations; var dynamicScope = vm.dynamicScope(); var modifier = manager.create(element, args, dynamicScope, updateOperations); args.clear(); vm.env.scheduleInstallModifier(modifier, manager); var destructor = manager.getDestructor(modifier); if (destructor) { vm.newDestroyable(destructor); } vm.updateWith(new UpdateModifierOpcode(tag, manager, modifier)); }); var UpdateModifierOpcode = function (_UpdatingOpcode) { _inherits$4(UpdateModifierOpcode, _UpdatingOpcode); function UpdateModifierOpcode(tag, manager, modifier) { _classCallCheck$5(this, UpdateModifierOpcode); var _this2 = _possibleConstructorReturn$4(this, _UpdatingOpcode.call(this)); _this2.tag = tag; _this2.manager = manager; _this2.modifier = modifier; _this2.type = 'update-modifier'; _this2.lastUpdated = tag.value(); return _this2; } UpdateModifierOpcode.prototype.evaluate = function evaluate(vm) { var manager = this.manager, modifier = this.modifier, tag = this.tag, lastUpdated = this.lastUpdated; if (!tag.validate(lastUpdated)) { vm.env.scheduleUpdateModifier(modifier, manager); this.lastUpdated = tag.value(); } }; UpdateModifierOpcode.prototype.toJSON = function toJSON() { return { guid: this._guid, type: this.type }; }; return UpdateModifierOpcode; }(UpdatingOpcode); var StaticAttribute = function () { function StaticAttribute(element, name, value, namespace) { _classCallCheck$5(this, StaticAttribute); this.element = element; this.name = name; this.value = value; this.namespace = namespace; } StaticAttribute.prototype.flush = function flush(env) { env.getAppendOperations().setAttribute(this.element, this.name, this.value, this.namespace); return null; }; return StaticAttribute; }(); var DynamicAttribute = function () { function DynamicAttribute(element, attributeManager, name, reference, namespace) { _classCallCheck$5(this, DynamicAttribute); this.element = element; this.attributeManager = attributeManager; this.name = name; this.reference = reference; this.namespace = namespace; this.cache = null; this.tag = reference.tag; } DynamicAttribute.prototype.patch = function patch(env) { var element = this.element, cache = this.cache; var value = cache.revalidate(); if (_glimmer_reference.isModified(value)) { this.attributeManager.updateAttribute(env, element, value, this.namespace); } }; DynamicAttribute.prototype.flush = function flush(env) { var reference = this.reference, element = this.element; if (_glimmer_reference.isConst(reference)) { var value = reference.value(); this.attributeManager.setAttribute(env, element, value, this.namespace); return null; } else { var cache = this.cache = new _glimmer_reference.ReferenceCache(reference); var _value2 = cache.peek(); this.attributeManager.setAttribute(env, element, _value2, this.namespace); return new PatchElementOpcode(this); } }; DynamicAttribute.prototype.toJSON = function toJSON() { var element = this.element, namespace = this.namespace, name = this.name, cache = this.cache; var formattedElement = formatElement(element); var lastValue = cache.peek(); if (namespace) { return { element: formattedElement, lastValue: lastValue, name: name, namespace: namespace, type: 'attribute' }; } return { element: formattedElement, lastValue: lastValue, name: name, namespace: namespace === undefined ? null : namespace, type: 'attribute' }; }; return DynamicAttribute; }(); function formatElement(element) { return JSON.stringify('<' + element.tagName.toLowerCase() + ' />'); } APPEND_OPCODES.add(32 /* DynamicAttrNS */, function (vm, _ref7) { var _name = _ref7.op1, _namespace = _ref7.op2, trusting = _ref7.op3; var name = vm.constants.getString(_name); var namespace = vm.constants.getString(_namespace); var reference = vm.stack.pop(); vm.elements().setDynamicAttributeNS(namespace, name, reference, !!trusting); }); APPEND_OPCODES.add(31 /* DynamicAttr */, function (vm, _ref8) { var _name = _ref8.op1, trusting = _ref8.op2; var name = vm.constants.getString(_name); var reference = vm.stack.pop(); vm.elements().setDynamicAttribute(name, reference, !!trusting)