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
This commit is contained in:
sandholm@chromium.org 2010-12-22 13:19:25 +00:00
parent 716e6282e9
commit 37567c42da
5 changed files with 9 additions and 13 deletions

View File

@ -1000,7 +1000,7 @@ function DateToISOString() {
function DateToJSON(key) {
var o = ToObject(this);
var tv = DefaultNumber(o);
if (IS_NUMBER(tv) && !$isFinite(tv)) {
if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) {
return null;
}
return o.toISOString();

View File

@ -27,11 +27,6 @@
var $JSON = global.JSON;
function ParseJSONUnfiltered(text) {
var s = $String(text);
return %ParseJson(s);
}
function Revive(holder, name, reviver) {
var val = holder[name];
if (IS_OBJECT(val)) {
@ -58,7 +53,7 @@ function Revive(holder, name, reviver) {
}
function JSONParse(text, reviver) {
var unfiltered = ParseJSONUnfiltered(text);
var unfiltered = %ParseJson(TO_STRING_INLINE(text));
if (IS_FUNCTION(reviver)) {
return Revive({'': unfiltered}, '', reviver);
} else {
@ -158,7 +153,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
if (IS_STRING(value)) {
return %QuoteJSONString(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)) {
return value ? "true" : "false";
} else if (IS_NULL(value)) {
@ -169,7 +164,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
return SerializeArray(value, replacer, stack, indent, gap);
} else if (IS_NUMBER_WRAPPER(value)) {
value = ToNumber(value);
return $isFinite(value) ? ToString(value) : "null";
return NUMBER_IS_FINITE(value) ? ToString(value) : "null";
} else if (IS_STRING_WRAPPER(value)) {
return %QuoteJSONString(ToString(value));
} else if (IS_BOOLEAN_WRAPPER(value)) {
@ -244,7 +239,7 @@ function BasicJSONSerialize(key, holder, stack, builder) {
if (IS_STRING(value)) {
builder.push(%QuoteJSONString(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)) {
builder.push(value ? "true" : "false");
} else if (IS_NULL(value)) {
@ -254,7 +249,7 @@ function BasicJSONSerialize(key, holder, stack, builder) {
// Unwrap value if necessary
if (IS_NUMBER_WRAPPER(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)) {
builder.push(%QuoteJSONString(ToString(value)));
} else if (IS_BOOLEAN_WRAPPER(value)) {

View File

@ -120,6 +120,7 @@ macro IS_SPEC_OBJECT(arg) = (%_IsSpecObject(arg));
# 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_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || arg - arg == 0);
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_INT32(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : (arg >> 0));

View File

@ -2369,7 +2369,7 @@ function NumberToJSON_(value) {
if (isNaN(value)) {
return 'NaN';
}
if (!isFinite(value)) {
if (!NUMBER_IS_FINITE(value)) {
if (value > 0) {
return 'Infinity';
} else {

View File

@ -127,7 +127,7 @@ function StringLastIndexOf(pat /* position */) { // length == 1
var index = subLength - patLength;
if (%_ArgumentsLength() > 1) {
var position = ToNumber(%_Arguments(1));
if (!$isNaN(position)) {
if (!NUMBER_IS_NAN(position)) {
position = TO_INTEGER(position);
if (position < 0) {
position = 0;