Skip to content

Commit

Permalink
Reflect.apply should not allow primitive as the third argument, close
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 27, 2016
1 parent 1cb3f6b commit 184047d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
8 changes: 5 additions & 3 deletions library/modules/es6.reflect.apply.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 26.1.1 Reflect.apply(target, thisArgument, argumentsList)
var $export = require('./_export')
, _apply = Function.apply;
var $export = require('./_export')
, aFunction = require('./_a-function')
, anObject = require('./_an-object')
, _apply = Function.apply;

$export($export.S, 'Reflect', {
apply: function apply(target, thisArgument, argumentsList){
return _apply.call(target, thisArgument, argumentsList);
return _apply.call(aFunction(target), thisArgument, anObject(argumentsList));
}
});
8 changes: 5 additions & 3 deletions modules/es6.reflect.apply.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 26.1.1 Reflect.apply(target, thisArgument, argumentsList)
var $export = require('./_export')
, _apply = Function.apply;
var $export = require('./_export')
, aFunction = require('./_a-function')
, anObject = require('./_an-object')
, _apply = Function.apply;

$export($export.S, 'Reflect', {
apply: function apply(target, thisArgument, argumentsList){
return _apply.call(target, thisArgument, argumentsList);
return _apply.call(aFunction(target), thisArgument, anObject(argumentsList));
}
});
8 changes: 7 additions & 1 deletion tests/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/library.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/library/es6.reflect.apply.ls
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ test 'Reflect.apply' (assert)!->
C = (a, b, c)-> a + b + c
C.apply = 42
assert.strictEqual apply(C, null, <[foo bar baz]>), \foobarbaz, 'works with redefined apply'
assert.throws (!-> apply 42, null, []), TypeError, 'throws on primitive'
assert.throws (!-> apply 42, null, []), TypeError, 'throws on primitive'
assert.throws (!-> apply (!->), null), TypeError, 'throws without third argument'
assert.throws (!-> apply (!->), null, \123), TypeError, 'throws on primitive as third argument'
8 changes: 7 additions & 1 deletion tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/tests/es6.reflect.apply.ls
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ test 'Reflect.apply' (assert)!->
C = (a, b, c)-> a + b + c
C.apply = 42
assert.strictEqual apply(C, null, <[foo bar baz]>), \foobarbaz, 'works with redefined apply'
assert.throws (!-> apply 42, null, []), TypeError, 'throws on primitive'
assert.throws (!-> apply 42, null, []), TypeError, 'throws on primitive as first argument'
assert.throws (!-> apply (!->), null), TypeError, 'throws without third argument'
assert.throws (!-> apply (!->), null, \123), TypeError, 'throws on primitive as third argument'

0 comments on commit 184047d

Please sign in to comment.