Reviewers: arv,
Message:
PTAL
Description:
Function#toMethod: check `newHome` before `this`
`Function.prototype.toMethod` should check `newHome` before `this` as
per the spec. V8 currently does it the other way around, resulting in
the wrong error message being thrown.
TEST=mjsunit/harmony
BUG=v8:3749
LOG=Y
Please review this at https://codereview.chromium.org/785303002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+33, -6 lines):
M src/harmony-classes.js
M test/mjsunit/harmony/toMethod.js
Index: src/harmony-classes.js
diff --git a/src/harmony-classes.js b/src/harmony-classes.js
index
b6605a902c3059bef54ad3b0956931fcaf19e1d3..9171bb368308b0e87d07c91020a2e34f86be9938
100644
--- a/src/harmony-classes.js
+++ b/src/harmony-classes.js
@@ -9,18 +9,18 @@
(function() {
+ // ES6 draft 12-06-13, section 19.2.3.5.
function FunctionToMethod(homeObject) {
- if (!IS_SPEC_FUNCTION(this)) {
- throw MakeTypeError('toMethod_non_function',
- [%ToString(this), typeof this]);
-
- }
-
if (!IS_SPEC_OBJECT(homeObject)) {
throw MakeTypeError('toMethod_non_object',
[%ToString(homeObject)]);
}
+ if (!IS_SPEC_FUNCTION(this)) {
+ throw MakeTypeError('toMethod_non_function',
+ [%ToString(this), typeof this]);
+ }
+
return %ToMethod(this, homeObject);
}
Index: test/mjsunit/harmony/toMethod.js
diff --git a/test/mjsunit/harmony/toMethod.js
b/test/mjsunit/harmony/toMethod.js
index
ad51b2ff3809001d159443c731408c86f3f36902..8fa859068bc38269512d7dc30acb3982694a8cf6
100644
--- a/test/mjsunit/harmony/toMethod.js
+++ b/test/mjsunit/harmony/toMethod.js
@@ -46,6 +46,33 @@
assertThrows(function() { sFun.call({}, {}); }, TypeError);
function f(){};
assertThrows(function() { f.toMethod(1); }, TypeError);
+ try {
+ Function.prototype.toMethod.call(null, null);
+ // This must never be reached:
+ assertEquals(true, false);
+ } catch (exception) {
+ assertTrue(exception instanceof TypeError);
+ assertEquals('Function.prototype.toMethod: home object null ' +
+ 'is not an object', exception.message);
+ }
+ try {
+ Function.prototype.toMethod.call(42, null);
+ // This must never be reached:
+ assertEquals(true, false);
+ } catch (exception) {
+ assertTrue(exception instanceof TypeError);
+ assertEquals('Function.prototype.toMethod: home object null ' +
+ 'is not an object', exception.message);
+ }
+ try {
+ Function.prototype.toMethod.call(42, {});
+ // This must never be reached:
+ assertEquals(true, false);
+ } catch (exception) {
+ assertTrue(exception instanceof TypeError);
+ assertEquals('Function.prototype.toMethod was called on 42, which is
a ' +
+ 'number and not a function', exception.message);
+ }
}());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.