diff --git a/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js b/test/built-ins/Proxy/apply/trap-is-missing.js similarity index 53% rename from test/built-ins/Proxy/apply/trap-is-undefined-no-property.js rename to test/built-ins/Proxy/apply/trap-is-missing.js index 65f5810b55..935ea21e4a 100644 --- a/test/built-ins/Proxy/apply/trap-is-undefined-no-property.js +++ b/test/built-ins/Proxy/apply/trap-is-missing.js @@ -2,8 +2,9 @@ // 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 undefined, propagate the call to the target object. + If trap is null or undefined, propagate the call to the target object. info: > [[Call]] (thisArgument, argumentsList) @@ -11,9 +12,12 @@ info: > argumentsList). ---*/ -var target = function(a, b) { +function target(a, b) { + assert.sameValue(this, ctx); return a + b; -}; -var p = new Proxy(target, {}); +} -assert.sameValue(p(1, 2), 3); +var ctx = {}; +var p = new Proxy(target, {}); +var res = p.call(ctx, 1, 2); +assert.sameValue(res, 3, "`apply` trap is missing"); diff --git a/test/built-ins/Proxy/apply/trap-is-null-or-undefined.js b/test/built-ins/Proxy/apply/trap-is-null-or-undefined.js new file mode 100644 index 0000000000..a0414b71aa --- /dev/null +++ b/test/built-ins/Proxy/apply/trap-is-null-or-undefined.js @@ -0,0 +1,27 @@ +// 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. +info: > + [[Call]] (thisArgument, argumentsList) + + 7. If trap is undefined, then Return Call(target, thisArgument, + argumentsList). +---*/ + +function target(a, b) { + assert.sameValue(this, ctx); + 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`"); diff --git a/test/built-ins/Proxy/apply/trap-is-undefined.js b/test/built-ins/Proxy/apply/trap-is-undefined.js deleted file mode 100644 index f16cadaa6e..0000000000 --- a/test/built-ins/Proxy/apply/trap-is-undefined.js +++ /dev/null @@ -1,21 +0,0 @@ -// 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 -description: > - If trap is undefined, propagate the call to the target object. -info: > - [[Call]] (thisArgument, argumentsList) - - 7. If trap is undefined, then Return Call(target, thisArgument, - argumentsList). ----*/ - -var target = function(a, b) { - return a + b; -}; -var p = new Proxy(target, { - apply: undefined -}); - -assert.sameValue(p(1, 2), 3); diff --git a/test/built-ins/Proxy/construct/call-parameters-new-target.js b/test/built-ins/Proxy/construct/call-parameters-new-target.js new file mode 100644 index 0000000000..35dcbb532d --- /dev/null +++ b/test/built-ins/Proxy/construct/call-parameters-new-target.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Aleksey Shvayka. 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: > + trap is called with handler object as its context, and parameters are: + target, an array list with the called arguments and the NewTarget +info: > + [[Construct]] (argumentsList, newTarget) + + 9. Let newObj be Call(trap, handler, «target, argArray, newTarget»). +features: [Reflect.construct] +---*/ + +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"); + + 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}; + }, +}; + +var P = new Proxy(Target, handler); +var res = Reflect.construct(P, [1, 2], NewTarget); +assert.sameValue(res.sum, 3); diff --git a/test/built-ins/Proxy/construct/trap-is-undefined-proto-from-ctor-realm.js b/test/built-ins/Proxy/construct/trap-is-missing-proto-from-ctor-realm.js similarity index 97% rename from test/built-ins/Proxy/construct/trap-is-undefined-proto-from-ctor-realm.js rename to test/built-ins/Proxy/construct/trap-is-missing-proto-from-ctor-realm.js index 3fbd4af5b4..5d0ec3f446 100644 --- a/test/built-ins/Proxy/construct/trap-is-undefined-proto-from-ctor-realm.js +++ b/test/built-ins/Proxy/construct/trap-is-missing-proto-from-ctor-realm.js @@ -20,7 +20,7 @@ info: > a. Let realm be ? GetFunctionRealm(constructor). b. Let proto be realm's intrinsic object named intrinsicDefaultProto. [...] -features: [Reflect] +features: [Reflect.construct] ---*/ var other = $262.createRealm().global; diff --git a/test/built-ins/Proxy/construct/trap-is-missing.js b/test/built-ins/Proxy/construct/trap-is-missing.js new file mode 100644 index 0000000000..2ba279826f --- /dev/null +++ b/test/built-ins/Proxy/construct/trap-is-missing.js @@ -0,0 +1,24 @@ +// 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. +info: > + [[Construct]] (argumentsList, newTarget) + + 7. If trap is undefined, then + b. Return Construct(target, argumentsList, newTarget). +features: [Reflect.construct] +---*/ + +function NewTarget() {} +function Target(a, b) { + assert.sameValue(new.target, NewTarget); + 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"); diff --git a/test/built-ins/Proxy/construct/trap-is-null-or-undefined.js b/test/built-ins/Proxy/construct/trap-is-null-or-undefined.js new file mode 100644 index 0000000000..dbb126117b --- /dev/null +++ b/test/built-ins/Proxy/construct/trap-is-null-or-undefined.js @@ -0,0 +1,28 @@ +// 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. +info: > + [[Construct]] (argumentsList, newTarget) + + 7. If trap is undefined, then + b. Return Construct(target, argumentsList, newTarget). +features: [Reflect.construct] +---*/ + +function NewTarget() {} +function Target(a, b) { + assert.sameValue(new.target, NewTarget); + 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`"); diff --git a/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js b/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js deleted file mode 100644 index 57e2c3be2f..0000000000 --- a/test/built-ins/Proxy/construct/trap-is-undefined-no-property.js +++ /dev/null @@ -1,19 +0,0 @@ -// 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 -description: > - If trap is undefined, propagate the construct to the target object. -info: > - [[Construct]] ( argumentsList, newTarget) - - 7. If trap is undefined, then - b. Return Construct(target, argumentsList, newTarget). ----*/ - -function Target(arg) { - this.attr = arg; -} -var P = new Proxy(Target, {}); - -assert.sameValue((new P("foo")).attr, "foo"); diff --git a/test/built-ins/Proxy/construct/trap-is-undefined.js b/test/built-ins/Proxy/construct/trap-is-undefined.js deleted file mode 100644 index fb9a4a2377..0000000000 --- a/test/built-ins/Proxy/construct/trap-is-undefined.js +++ /dev/null @@ -1,21 +0,0 @@ -// 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 -description: > - If trap is undefined, propagate the construct to the target object. -info: > - [[Construct]] ( argumentsList, newTarget) - - 7. If trap is undefined, then - b. Return Construct(target, argumentsList, newTarget). ----*/ - -function Target(arg) { - this.attr = arg; -} -var P = new Proxy(Target, { - construct: undefined -}); - -assert.sameValue((new P("foo")).attr, "foo");