Skip to content

Commit

Permalink
Reflect.{apply, construct} should not allow a primitive as argument…
Browse files Browse the repository at this point in the history
…s object
  • Loading branch information
zloirock committed Jul 17, 2016
1 parent 16001de commit 34d5d0b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions modules/es6.reflect.apply.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// 26.1.1 Reflect.apply(target, thisArgument, argumentsList)
var $export = require('./$.export')
, _apply = Function.apply;
var $export = require('./$.export')
, _apply = Function.apply
, anObject = require('./$.an-object');

$export($export.S, 'Reflect', {
apply: function apply(target, thisArgument, argumentsList){
return _apply.call(target, thisArgument, argumentsList);
return _apply.call(target, thisArgument, anObject(argumentsList));
}
});
3 changes: 2 additions & 1 deletion modules/es6.reflect.construct.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ $export($export.S + $export.F * require('./$.fails')(function(){
}), 'Reflect', {
construct: function construct(Target, args /*, newTarget*/){
aFunction(Target);
anObject(args);
var newTarget = arguments.length < 3 ? Target : aFunction(arguments[2]);
if(Target == newTarget){
// w/o altered newTarget, optimization for 0-4 arguments
if(args != undefined)switch(anObject(args).length){
switch(args.length){
case 0: return new Target;
case 1: return new Target(args[0]);
case 2: return new Target(args[0], args[1]);
Expand Down
2 changes: 1 addition & 1 deletion tests/commonjs.ls
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ for P in <[.. ../library]>
ok \next of require("#P/fn/number/iterator") 42
ok \isNaN of require("#P/fn/number")
ok require("#P/fn/reflect/apply")(((a, b)-> a + b), null, [1, 2]) is 3
ok require("#P/fn/reflect/construct")(-> @a = 2).a is 2
ok require("#P/fn/reflect/construct")((-> @a = 2), []).a is 2
require("#P/fn/reflect/define-property")(O = {}, \a {value: 42})
ok O.a is 42
ok require("#P/fn/reflect/delete-property") {q: 1}, \q
Expand Down

0 comments on commit 34d5d0b

Please sign in to comment.