From cf43f93284dccbae7d54c32b12d2ff400e1af357 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Wed, 6 Sep 2017 15:52:05 -0400 Subject: [PATCH] Address feedback review --- ...s-null-or-undefined.js => trap-is-null.js} | 28 ++++++++----- ...ng.js => trap-is-undefined-no-property.js} | 20 ++++++++-- .../Proxy/apply/trap-is-undefined.js | 37 ++++++++++++++++++ .../construct/call-parameters-new-target.js | 20 +++++----- ...s-null-or-undefined.js => trap-is-null.js} | 25 ++++++++---- ...ng.js => trap-is-undefined-no-property.js} | 6 ++- ...rap-is-undefined-proto-from-ctor-realm.js} | 0 .../Proxy/construct/trap-is-undefined.js | 39 +++++++++++++++++++ 8 files changed, 145 insertions(+), 30 deletions(-) rename test/built-ins/Proxy/apply/{trap-is-null-or-undefined.js => trap-is-null.js} (50%) rename test/built-ins/Proxy/apply/{trap-is-missing.js => trap-is-undefined-no-property.js} (55%) create mode 100644 test/built-ins/Proxy/apply/trap-is-undefined.js rename test/built-ins/Proxy/construct/{trap-is-null-or-undefined.js => trap-is-null.js} (55%) rename test/built-ins/Proxy/construct/{trap-is-missing.js => trap-is-undefined-no-property.js} (80%) rename test/built-ins/Proxy/construct/{trap-is-missing-proto-from-ctor-realm.js => trap-is-undefined-proto-from-ctor-realm.js} (100%) create mode 100644 test/built-ins/Proxy/construct/trap-is-undefined.js diff --git a/test/built-ins/Proxy/apply/trap-is-null-or-undefined.js b/test/built-ins/Proxy/apply/trap-is-null.js similarity index 50% rename from test/built-ins/Proxy/apply/trap-is-null-or-undefined.js rename to test/built-ins/Proxy/apply/trap-is-null.js index a0414b71aa..126ad24103 100644 --- a/test/built-ins/Proxy/apply/trap-is-null-or-undefined.js +++ b/test/built-ins/Proxy/apply/trap-is-null.js @@ -1,27 +1,37 @@ // Copyright (C) 2015 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- es6id: 9.5.13 esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist description: > - If trap is null or undefined, propagate the call to the target object. + If the apply trap value is null, propagate the call to the target object. info: > [[Call]] (thisArgument, argumentsList) - 7. If trap is undefined, then Return Call(target, thisArgument, - argumentsList). + ... + 5. Let trap be ? GetMethod(handler, "apply"). + 6. If trap is undefined, then + a. Return ? Call(target, thisArgument, argumentsList). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... ---*/ +var calls = 0; + function target(a, b) { - assert.sameValue(this, ctx); - return a + b; + assert.sameValue(this, ctx); + calls += 1; + return a + b; } var ctx = {}; var p = new Proxy(target, {apply: null}); var res = p.call(ctx, 1, 2); assert.sameValue(res, 3, "`apply` trap is `null`"); - -p = new Proxy(target, {apply: undefined}); -res = p.call(ctx, 3, 4); -assert.sameValue(res, 7, "`apply` trap is `undefined`"); +assert.sameValue(calls, 1, "target is called once"); diff --git a/test/built-ins/Proxy/apply/trap-is-missing.js b/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js similarity index 55% rename from test/built-ins/Proxy/apply/trap-is-missing.js rename to test/built-ins/Proxy/apply/trap-is-undefined-no-property.js index 935ea21e4a..6ee47cfa3b 100644 --- a/test/built-ins/Proxy/apply/trap-is-missing.js +++ b/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js @@ -1,19 +1,32 @@ // Copyright (C) 2015 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- es6id: 9.5.13 esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist description: > - If trap is null or undefined, propagate the call to the target object. + If trap is not set, propagate the call to the target object. info: > [[Call]] (thisArgument, argumentsList) - 7. If trap is undefined, then Return Call(target, thisArgument, - argumentsList). + ... + 5. Let trap be ? GetMethod(handler, "apply"). + 6. If trap is undefined, then + a. Return ? Call(target, thisArgument, argumentsList). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... ---*/ +var calls = 0; + function target(a, b) { assert.sameValue(this, ctx); + calls += 1; return a + b; } @@ -21,3 +34,4 @@ var ctx = {}; var p = new Proxy(target, {}); var res = p.call(ctx, 1, 2); assert.sameValue(res, 3, "`apply` trap is missing"); +assert.sameValue(calls, 1, "target is called once"); diff --git a/test/built-ins/Proxy/apply/trap-is-undefined.js b/test/built-ins/Proxy/apply/trap-is-undefined.js new file mode 100644 index 0000000000..819fb95632 --- /dev/null +++ b/test/built-ins/Proxy/apply/trap-is-undefined.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 9.5.13 +esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist +description: > + If the apply trap value is undefined, propagate the call to the target object. +info: > + [[Call]] (thisArgument, argumentsList) + + ... + 5. Let trap be ? GetMethod(handler, "apply"). + 6. If trap is undefined, then + a. Return ? Call(target, thisArgument, argumentsList). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... +---*/ + +var calls = 0; + +function target(a, b) { + assert.sameValue(this, ctx); + calls += 1; + return a + b; +} + +var ctx = {}; +var p = new Proxy(target, {apply: undefined}); +var res = p.call(ctx, 1, 2); +assert.sameValue(res, 3, "`apply` trap is `null`"); +assert.sameValue(calls, 1, "target is called once"); diff --git a/test/built-ins/Proxy/construct/call-parameters-new-target.js b/test/built-ins/Proxy/construct/call-parameters-new-target.js index 35dcbb532d..e9a3ff1d9b 100644 --- a/test/built-ins/Proxy/construct/call-parameters-new-target.js +++ b/test/built-ins/Proxy/construct/call-parameters-new-target.js @@ -18,18 +18,18 @@ function Target() {} function NewTarget() {} var handler = { - construct: function(_Target, args, _NewTarget) { - assert.sameValue(this, handler, "trap context is the handler object"); - assert.sameValue(_Target, Target, "first parameter is the target object"); - assert.sameValue(args.length, 2, "arguments list contains all construct arguments"); + construct: function(target, args, newTarget) { + assert.sameValue(this, handler, "trap context is the handler object"); + assert.sameValue(target, Target, "first parameter is the target object"); + assert.sameValue(args.length, 2, "arguments list contains all construct arguments"); - var a = args[0]; - var b = args[1]; - assert.sameValue(a, 1, "arguments list has first construct argument"); - assert.sameValue(b, 2, "arguments list has second construct argument"); - assert.sameValue(_NewTarget, NewTarget, "newTarget is passed as the third parameter"); + var a = args[0]; + var b = args[1]; + assert.sameValue(a, 1, "arguments list has first construct argument"); + assert.sameValue(b, 2, "arguments list has second construct argument"); + assert.sameValue(newTarget, NewTarget, "newTarget is passed as the third parameter"); - return {sum: a + b}; + return {sum: a + b}; }, }; diff --git a/test/built-ins/Proxy/construct/trap-is-null-or-undefined.js b/test/built-ins/Proxy/construct/trap-is-null.js similarity index 55% rename from test/built-ins/Proxy/construct/trap-is-null-or-undefined.js rename to test/built-ins/Proxy/construct/trap-is-null.js index dbb126117b..f3249af7e1 100644 --- a/test/built-ins/Proxy/construct/trap-is-null-or-undefined.js +++ b/test/built-ins/Proxy/construct/trap-is-null.js @@ -1,28 +1,39 @@ // Copyright (C) 2015 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. + /*--- es6id: 9.5.14 esid: sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget description: > - If trap is null or undefined, propagate the construct to the target object. + If the construct trap value is null, propagate the construct to the target object. info: > [[Construct]] (argumentsList, newTarget) - 7. If trap is undefined, then - b. Return Construct(target, argumentsList, newTarget). + ... + 5. Let trap be ? GetMethod(handler, "construct"). + 6. If trap is undefined, then + a. Assert: target has a [[Construct]] internal method. + b. Return ? Construct(target, argumentsList, newTarget). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... features: [Reflect.construct] ---*/ +var calls = 0; + function NewTarget() {} function Target(a, b) { assert.sameValue(new.target, NewTarget); + calls += 1; return {sum: a + b}; } var P = new Proxy(Target, {construct: null}); var obj = Reflect.construct(P, [3, 4], NewTarget); assert.sameValue(obj.sum, 7, "`construct` trap is `null`"); - -P = new Proxy(Target, {construct: undefined}); -obj = Reflect.construct(P, [5, 6], NewTarget); -assert.sameValue(obj.sum, 11, "`construct` trap is `undefined`"); +assert.sameValue(calls, 1, "target is called once"); diff --git a/test/built-ins/Proxy/construct/trap-is-missing.js b/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js similarity index 80% rename from test/built-ins/Proxy/construct/trap-is-missing.js rename to test/built-ins/Proxy/construct/trap-is-undefined-no-property.js index 2ba279826f..368b2999c2 100644 --- a/test/built-ins/Proxy/construct/trap-is-missing.js +++ b/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js @@ -4,7 +4,7 @@ es6id: 9.5.14 esid: sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget description: > - If trap is null or undefined, propagate the construct to the target object. + If the construct trap is not set, propagate the construct to the target object. info: > [[Construct]] (argumentsList, newTarget) @@ -13,12 +13,16 @@ info: > features: [Reflect.construct] ---*/ +var calls = 0; + function NewTarget() {} function Target(a, b) { assert.sameValue(new.target, NewTarget); + calls += 1; return {sum: a + b}; } var P = new Proxy(Target, {}); var obj = Reflect.construct(P, [1, 2], NewTarget); assert.sameValue(obj.sum, 3, "`construct` trap is missing"); +assert.sameValue(calls, 1, "target is called once"); diff --git a/test/built-ins/Proxy/construct/trap-is-missing-proto-from-ctor-realm.js b/test/built-ins/Proxy/construct/trap-is-undefined-proto-from-ctor-realm.js similarity index 100% rename from test/built-ins/Proxy/construct/trap-is-missing-proto-from-ctor-realm.js rename to test/built-ins/Proxy/construct/trap-is-undefined-proto-from-ctor-realm.js diff --git a/test/built-ins/Proxy/construct/trap-is-undefined.js b/test/built-ins/Proxy/construct/trap-is-undefined.js new file mode 100644 index 0000000000..35852a6e2d --- /dev/null +++ b/test/built-ins/Proxy/construct/trap-is-undefined.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 9.5.14 +esid: sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget +description: > + If the construct trap value is undefined, propagate the construct to the target object. +info: > + [[Construct]] (argumentsList, newTarget) + + ... + 5. Let trap be ? GetMethod(handler, "construct"). + 6. If trap is undefined, then + a. Assert: target has a [[Construct]] internal method. + b. Return ? Construct(target, argumentsList, newTarget). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... +features: [Reflect.construct] +---*/ + +var calls = 0; + +function NewTarget() {} +function Target(a, b) { + assert.sameValue(new.target, NewTarget); + calls += 1; + return {sum: a + b}; +} + +var P = new Proxy(Target, {construct: undefined}); +var obj = Reflect.construct(P, [3, 4], NewTarget); +assert.sameValue(obj.sum, 7, "`construct` trap is `undefined`"); +assert.sameValue(calls, 1, "target is called once");