From 4e2f2e83c5d4060b4663ed1299cc5fe5e43eb880 Mon Sep 17 00:00:00 2001 From: conectado Date: Sun, 7 Oct 2018 15:20:11 -0300 Subject: [PATCH 1/4] test: add test for a vm indexed property Adds a single test for a vm with an indexed property. --- test/parallel/test-vm-context-property-forwarding.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/parallel/test-vm-context-property-forwarding.js b/test/parallel/test-vm-context-property-forwarding.js index eca34e9b0987ec..d94e686c39744d 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -32,3 +32,9 @@ assert.strictEqual(vm.runInContext('x;', ctx), 3); vm.runInContext('y = 4;', ctx); assert.strictEqual(sandbox.y, 4); assert.strictEqual(ctx.y, 4); + +const x = vm.createContext({ get a() { return 5; } }); + +assert.strictEqual(x.a, 5); +delete x.a; +assert.strictEqual(x.a, undefined); From a815617c0742ba6e189b2a90292760bf9130c969 Mon Sep 17 00:00:00 2001 From: conectado Date: Sun, 7 Oct 2018 17:34:04 -0300 Subject: [PATCH 2/4] test: improves indexed properties test by comparing object descriptors --- test/parallel/test-vm-context-property-forwarding.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-vm-context-property-forwarding.js b/test/parallel/test-vm-context-property-forwarding.js index d94e686c39744d..98772d97b392b3 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -33,8 +33,12 @@ vm.runInContext('y = 4;', ctx); assert.strictEqual(sandbox.y, 4); assert.strictEqual(ctx.y, 4); -const x = vm.createContext({ get a() { return 5; } }); +const x = { get a() { return 5; } }; +const pd_expected = Object.getOwnPropertyDescriptor(x, 'a'); +const ctx2 = vm.createContext(x); +const pd_actual = Object.getOwnPropertyDescriptor(ctx2, 'a'); -assert.strictEqual(x.a, 5); -delete x.a; -assert.strictEqual(x.a, undefined); +assert.deepStrictEqual(pd_actual, pd_expected); +assert.strictEqual(ctx2.a, 5); +delete ctx2.a; +assert.strictEqual(ctx2.a, undefined); From 7171a49a10b1abb9cd3781356623ba8178aa2eb0 Mon Sep 17 00:00:00 2001 From: conectado Date: Sun, 7 Oct 2018 18:33:29 -0300 Subject: [PATCH 3/4] update make it explicit that we are accessing an indexed property --- test/parallel/test-vm-context-property-forwarding.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-vm-context-property-forwarding.js b/test/parallel/test-vm-context-property-forwarding.js index 98772d97b392b3..b7a9c54e3f84d9 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -33,12 +33,12 @@ vm.runInContext('y = 4;', ctx); assert.strictEqual(sandbox.y, 4); assert.strictEqual(ctx.y, 4); -const x = { get a() { return 5; } }; -const pd_expected = Object.getOwnPropertyDescriptor(x, 'a'); +const x = { get 1() { return 5; } }; +const pd_expected = Object.getOwnPropertyDescriptor(x, 1); const ctx2 = vm.createContext(x); -const pd_actual = Object.getOwnPropertyDescriptor(ctx2, 'a'); +const pd_actual = Object.getOwnPropertyDescriptor(ctx2, 1); assert.deepStrictEqual(pd_actual, pd_expected); -assert.strictEqual(ctx2.a, 5); -delete ctx2.a; -assert.strictEqual(ctx2.a, undefined); +assert.strictEqual(ctx2[1], 5); +delete ctx2[1]; +assert.strictEqual(ctx2[1], undefined); From c2fd550b5ed7a1ed8652929d389c8adcbcd6eeff Mon Sep 17 00:00:00 2001 From: conectado Date: Sun, 7 Oct 2018 23:39:24 -0300 Subject: [PATCH 4/4] test: add comment explaining components tested --- test/parallel/test-vm-context-property-forwarding.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-vm-context-property-forwarding.js b/test/parallel/test-vm-context-property-forwarding.js index b7a9c54e3f84d9..800a9fa2438988 100644 --- a/test/parallel/test-vm-context-property-forwarding.js +++ b/test/parallel/test-vm-context-property-forwarding.js @@ -33,6 +33,7 @@ vm.runInContext('y = 4;', ctx); assert.strictEqual(sandbox.y, 4); assert.strictEqual(ctx.y, 4); +// Test `IndexedPropertyGetterCallback` and `IndexedPropertyDeleterCallback` const x = { get 1() { return 5; } }; const pd_expected = Object.getOwnPropertyDescriptor(x, 1); const ctx2 = vm.createContext(x);