Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1039)

Unified Diff: src/runtime.js

Issue 1260273002: Optimize ToNumber and NonNumberToNumber. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index dd776dbc8c354722c692c3580914398e5de26d30..4bc50fd6ec8a49dfbb87787360ec43f4625c0901 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -792,8 +792,7 @@ function ToNumber(x) {
}
if (IS_BOOLEAN(x)) return x ? 1 : 0;
if (IS_UNDEFINED(x)) return NAN;
- if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber);
- if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
+ // Types that can't be converted to number are caught in DefaultNumber.
return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
}
@@ -804,8 +803,7 @@ function NonNumberToNumber(x) {
}
if (IS_BOOLEAN(x)) return x ? 1 : 0;
if (IS_UNDEFINED(x)) return NAN;
- if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber);
- if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
+ // Types that can't be converted to number are caught in DefaultNumber.
return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
}
@@ -944,18 +942,17 @@ function IsConcatSpreadable(O) {
// ECMA-262, section 8.6.2.6, page 28.
function DefaultNumber(x) {
- if (!IS_SYMBOL_WRAPPER(x) && !IS_FLOAT32X4_WRAPPER(x)) {
- var valueOf = x.valueOf;
- if (IS_SPEC_FUNCTION(valueOf)) {
- var v = %_CallFunction(x, valueOf);
- if (IsPrimitive(v)) return v;
- }
-
- var toString = x.toString;
- if (IS_SPEC_FUNCTION(toString)) {
- var s = %_CallFunction(x, toString);
- if (IsPrimitive(s)) return s;
- }
+ var valueOf = x.valueOf;
+ if (IS_SPEC_FUNCTION(valueOf)) {
+ var v = %_CallFunction(x, valueOf);
+ if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber);
+ if (IS_FLOAT32X4(v)) throw MakeTypeError(kSimdToNumber);
+ if (IsPrimitive(v)) return v;
+ }
+ var toString = x.toString;
+ if (IS_SPEC_FUNCTION(toString)) {
+ var s = %_CallFunction(x, toString);
+ if (IsPrimitive(s)) return s;
}
throw MakeTypeError(kCannotConvertToPrimitive);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698