Commit 37567c42 authored by sandholm@chromium.org's avatar sandholm@chromium.org

Introduce NUMBER_IS_FINITE macro to avoid ToNumber() conversion.

Review URL: http://codereview.chromium.org/5977006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6111 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 716e6282
...@@ -1000,7 +1000,7 @@ function DateToISOString() { ...@@ -1000,7 +1000,7 @@ function DateToISOString() {
function DateToJSON(key) { function DateToJSON(key) {
var o = ToObject(this); var o = ToObject(this);
var tv = DefaultNumber(o); var tv = DefaultNumber(o);
if (IS_NUMBER(tv) && !$isFinite(tv)) { if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) {
return null; return null;
} }
return o.toISOString(); return o.toISOString();
......
...@@ -27,11 +27,6 @@ ...@@ -27,11 +27,6 @@
var $JSON = global.JSON; var $JSON = global.JSON;
function ParseJSONUnfiltered(text) {
var s = $String(text);
return %ParseJson(s);
}
function Revive(holder, name, reviver) { function Revive(holder, name, reviver) {
var val = holder[name]; var val = holder[name];
if (IS_OBJECT(val)) { if (IS_OBJECT(val)) {
...@@ -58,7 +53,7 @@ function Revive(holder, name, reviver) { ...@@ -58,7 +53,7 @@ function Revive(holder, name, reviver) {
} }
function JSONParse(text, reviver) { function JSONParse(text, reviver) {
var unfiltered = ParseJSONUnfiltered(text); var unfiltered = %ParseJson(TO_STRING_INLINE(text));
if (IS_FUNCTION(reviver)) { if (IS_FUNCTION(reviver)) {
return Revive({'': unfiltered}, '', reviver); return Revive({'': unfiltered}, '', reviver);
} else { } else {
...@@ -158,7 +153,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) { ...@@ -158,7 +153,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
if (IS_STRING(value)) { if (IS_STRING(value)) {
return %QuoteJSONString(value); return %QuoteJSONString(value);
} else if (IS_NUMBER(value)) { } else if (IS_NUMBER(value)) {
return $isFinite(value) ? $String(value) : "null"; return NUMBER_IS_FINITE(value) ? $String(value) : "null";
} else if (IS_BOOLEAN(value)) { } else if (IS_BOOLEAN(value)) {
return value ? "true" : "false"; return value ? "true" : "false";
} else if (IS_NULL(value)) { } else if (IS_NULL(value)) {
...@@ -169,7 +164,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) { ...@@ -169,7 +164,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
return SerializeArray(value, replacer, stack, indent, gap); return SerializeArray(value, replacer, stack, indent, gap);
} else if (IS_NUMBER_WRAPPER(value)) { } else if (IS_NUMBER_WRAPPER(value)) {
value = ToNumber(value); value = ToNumber(value);
return $isFinite(value) ? ToString(value) : "null"; return NUMBER_IS_FINITE(value) ? ToString(value) : "null";
} else if (IS_STRING_WRAPPER(value)) { } else if (IS_STRING_WRAPPER(value)) {
return %QuoteJSONString(ToString(value)); return %QuoteJSONString(ToString(value));
} else if (IS_BOOLEAN_WRAPPER(value)) { } else if (IS_BOOLEAN_WRAPPER(value)) {
...@@ -244,7 +239,7 @@ function BasicJSONSerialize(key, holder, stack, builder) { ...@@ -244,7 +239,7 @@ function BasicJSONSerialize(key, holder, stack, builder) {
if (IS_STRING(value)) { if (IS_STRING(value)) {
builder.push(%QuoteJSONString(value)); builder.push(%QuoteJSONString(value));
} else if (IS_NUMBER(value)) { } else if (IS_NUMBER(value)) {
builder.push(($isFinite(value) ? %_NumberToString(value) : "null")); builder.push(NUMBER_IS_FINITE(value) ? %_NumberToString(value) : "null");
} else if (IS_BOOLEAN(value)) { } else if (IS_BOOLEAN(value)) {
builder.push(value ? "true" : "false"); builder.push(value ? "true" : "false");
} else if (IS_NULL(value)) { } else if (IS_NULL(value)) {
...@@ -254,7 +249,7 @@ function BasicJSONSerialize(key, holder, stack, builder) { ...@@ -254,7 +249,7 @@ function BasicJSONSerialize(key, holder, stack, builder) {
// Unwrap value if necessary // Unwrap value if necessary
if (IS_NUMBER_WRAPPER(value)) { if (IS_NUMBER_WRAPPER(value)) {
value = ToNumber(value); value = ToNumber(value);
builder.push(($isFinite(value) ? %_NumberToString(value) : "null")); builder.push(NUMBER_IS_FINITE(value) ? %_NumberToString(value) : "null");
} else if (IS_STRING_WRAPPER(value)) { } else if (IS_STRING_WRAPPER(value)) {
builder.push(%QuoteJSONString(ToString(value))); builder.push(%QuoteJSONString(ToString(value)));
} else if (IS_BOOLEAN_WRAPPER(value)) { } else if (IS_BOOLEAN_WRAPPER(value)) {
......
...@@ -120,6 +120,7 @@ macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg)); ...@@ -120,6 +120,7 @@ macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once. # Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || arg - arg == 0);
macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg))); macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToInteger(ToNumber(arg)));
macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg))); macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(ToNumber(arg)));
macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0)); macro TO_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));
......
...@@ -2369,7 +2369,7 @@ function NumberToJSON_(value) { ...@@ -2369,7 +2369,7 @@ function NumberToJSON_(value) {
if (isNaN(value)) { if (isNaN(value)) {
return 'NaN'; return 'NaN';
} }
if (!isFinite(value)) { if (!NUMBER_IS_FINITE(value)) {
if (value > 0) { if (value > 0) {
return 'Infinity'; return 'Infinity';
} else { } else {
......
...@@ -127,7 +127,7 @@ function StringLastIndexOf(pat /* position */) { // length == 1 ...@@ -127,7 +127,7 @@ function StringLastIndexOf(pat /* position */) { // length == 1
var index = subLength - patLength; var index = subLength - patLength;
if (%_ArgumentsLength() > 1) { if (%_ArgumentsLength() > 1) {
var position = ToNumber(%_Arguments(1)); var position = ToNumber(%_Arguments(1));
if (!$isNaN(position)) { if (!NUMBER_IS_NAN(position)) {
position = TO_INTEGER(position); position = TO_INTEGER(position);
if (position < 0) { if (position < 0) {
position = 0; position = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment