Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
- index f6f6486..bcbc891 100644
- --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
- +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
- @@ -353,6 +353,7 @@ APPEND_OPCODES.add(Op.GetComponentSelf, (vm, { op1: _state }) => {
- let { definition, state } = check(vm.fetchValue(_state), CheckComponentInstance);
- let { manager } = definition;
- + console.log(manager, state, manager.getSelf(state));
- vm.stack.push(manager.getSelf(state));
- });
- diff --git a/packages/@glimmer/runtime/lib/vm/gbox.ts b/packages/@glimmer/runtime/lib/vm/gbox.ts
- index 8f5b288..b559282 100644
- --- a/packages/@glimmer/runtime/lib/vm/gbox.ts
- +++ b/packages/@glimmer/runtime/lib/vm/gbox.ts
- @@ -10,7 +10,7 @@
- import { assert } from '@glimmer/util';
- import { DEBUG } from '@glimmer/local-debug-flags';
- import { WasmLowLevelVM } from '@glimmer/low-level';
- -import { isConst } from '@glimmer/reference';
- +import { isConst, ConstReference } from '@glimmer/reference';
- import { ComponentInstance } from "../compiled/opcodes/component";
- import {
- ComponentDefinition,
- @@ -72,6 +72,14 @@ export class Context {
- }
- encode(a: any): number {
- + if (a instanceof ConstReference) {
- + console.log('encode', a);
- + return this.encodeRaw(a.value()) | Flag.CONST_REF;
- + }
- + return this.encodeRaw(a);
- + }
- +
- + private encodeRaw(a: any): number {
- switch (typeof a) {
- case 'number':
- if (a as number % 1 === 0)
- @@ -93,13 +101,23 @@ export class Context {
- }
- decode(a: number): any {
- + const ret = this.decodeRaw(a);
- + if (this.isConstReference(a) ) {
- + let r = new ConstReference(ret);
- + console.log('decode', r);
- + return r;
- + }
- + return ret;
- + }
- +
- + private decodeRaw(a: number): any {
- switch (a & TAG_MASK) {
- case Tag.NUMBER:
- return a >> FIELD_SIZE;
- case Tag.NEGATIVE:
- return -(a >> FIELD_SIZE);
- case Tag.BOOLEAN_OR_VOID:
- - switch (a) {
- + switch (a & ~Flag.CONST_REF) {
- case Immediates.False:
- return false;
- case Immediates.True:
- @@ -127,7 +145,7 @@ export class Context {
- return this.stack[idx];
- }
- - isConstReference(gbox: number): boolean {
- + private isConstReference(gbox: number): boolean {
- return !!((gbox & FLAG_MASK) === Flag.CONST_REF);
- }
- @@ -143,12 +161,12 @@ export class Context {
- private encodeObject(a: any): number {
- const idx = this.stack.length;
- this.stack.push(a);
- - return this.encodeNumberAndTag(idx, Tag.ANY, isConst(a));
- + return this.encodeNumberAndTag(idx, Tag.ANY);
- }
- - private encodeNumberAndTag(a: number, tag: number, isConst = false): number {
- + private encodeNumberAndTag(a: number, tag: number): number {
- assert(a < (1 << (32 - FIELD_SIZE)), 'number too big');
- - return (a << FIELD_SIZE) | tag | (isConst ? Flag.CONST_REF : 0);
- + return (a << FIELD_SIZE) | tag;
- }
- private decodeComponent(component_idx: number): ComponentInstance {
- diff --git a/packages/@glimmer/runtime/test/gbox-test.ts b/packages/@glimmer/runtime/test/gbox-test.ts
- index 6784f21..f67a1fd 100644
- --- a/packages/@glimmer/runtime/test/gbox-test.ts
- +++ b/packages/@glimmer/runtime/test/gbox-test.ts
- @@ -44,6 +44,7 @@ QUnit.test("serializes JavaScript objects", assert => {
- QUnit.test("annotates ConstReference objects", assert => {
- let ref = new ConstReference(true);
- let gbox = ctx.encode(ref);
- - assert.strictEqual(ctx.decode(gbox), ref);
- - assert.ok(ctx.isConstReference(gbox));
- + let ref2 = ctx.decode(gbox);
- + assert.ok(ref2 instanceof ConstReference);
- + assert.strictEqual(ref2.value(), ref.value());
- });
Add Comment
Please, Sign In to add comment