Commit b9df5aa2 authored by ricow@chromium.org's avatar ricow@chromium.org

Create IS_SPEC_OBJECT macro to simplify javescript code.

v8natives and runtime.js updated to use new macro and simplified when possible.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 94288590
...@@ -112,6 +112,11 @@ macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global'); ...@@ -112,6 +112,11 @@ macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg)); macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
macro FLOOR(arg) = $floor(arg); macro FLOOR(arg) = $floor(arg);
# Macro for ECMAScript 5 queries of the type:
# "Type(O) is object."
# This is the same as being either a function or an object in V8 terminology.
macro IS_SPEC_OBJECT_OR_NULL(arg) = (%_IsObject(arg) || %_IsFunction(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 TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg)); macro TO_INTEGER(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : ToInteger(arg));
......
...@@ -80,10 +80,7 @@ function EQUALS(y) { ...@@ -80,10 +80,7 @@ function EQUALS(y) {
} else { } else {
// x is not a number, boolean, null or undefined. // x is not a number, boolean, null or undefined.
if (y == null) return 1; // not equal if (y == null) return 1; // not equal
if (IS_OBJECT(y)) { if (IS_SPEC_OBJECT_OR_NULL(y)) {
return %_ObjectEquals(x, y) ? 0 : 1;
}
if (IS_FUNCTION(y)) {
return %_ObjectEquals(x, y) ? 0 : 1; return %_ObjectEquals(x, y) ? 0 : 1;
} }
...@@ -344,7 +341,7 @@ function DELETE(key) { ...@@ -344,7 +341,7 @@ function DELETE(key) {
// ECMA-262, section 11.8.7, page 54. // ECMA-262, section 11.8.7, page 54.
function IN(x) { function IN(x) {
if (x == null || (!IS_OBJECT(x) && !IS_FUNCTION(x))) { if (x == null || !IS_SPEC_OBJECT_OR_NULL(x)) {
throw %MakeTypeError('invalid_in_operator_use', [this, x]); throw %MakeTypeError('invalid_in_operator_use', [this, x]);
} }
return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToString(this)); return %_IsNonNegativeSmi(this) ? %HasElement(x, this) : %HasProperty(x, %ToString(this));
...@@ -362,13 +359,13 @@ function INSTANCE_OF(F) { ...@@ -362,13 +359,13 @@ function INSTANCE_OF(F) {
} }
// If V is not an object, return false. // If V is not an object, return false.
if (IS_NULL(V) || (!IS_OBJECT(V) && !IS_FUNCTION(V))) { if (IS_NULL(V) || !IS_SPEC_OBJECT_OR_NULL(V)) {
return 1; return 1;
} }
// Get the prototype of F; if it is not an object, throw an error. // Get the prototype of F; if it is not an object, throw an error.
var O = F.prototype; var O = F.prototype;
if (IS_NULL(O) || (!IS_OBJECT(O) && !IS_FUNCTION(O))) { if (IS_NULL(O) || !IS_SPEC_OBJECT_OR_NULL(O)) {
throw %MakeTypeError('instanceof_nonobject_proto', [O]); throw %MakeTypeError('instanceof_nonobject_proto', [O]);
} }
...@@ -482,7 +479,7 @@ function ToPrimitive(x, hint) { ...@@ -482,7 +479,7 @@ function ToPrimitive(x, hint) {
// Fast case check. // Fast case check.
if (IS_STRING(x)) return x; if (IS_STRING(x)) return x;
// Normal behavior. // Normal behavior.
if (!IS_OBJECT(x) && !IS_FUNCTION(x)) return x; if (!IS_SPEC_OBJECT_OR_NULL(x)) return x;
if (x == null) return x; // check for null, undefined if (x == null) return x; // check for null, undefined
if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x); return (hint == NUMBER_HINT) ? %DefaultNumber(x) : %DefaultString(x);
...@@ -587,7 +584,7 @@ function SameValue(x, y) { ...@@ -587,7 +584,7 @@ function SameValue(x, y) {
// Returns if the given x is a primitive value - not an object or a // Returns if the given x is a primitive value - not an object or a
// function. // function.
function IsPrimitive(x) { function IsPrimitive(x) {
if (!IS_OBJECT(x) && !IS_FUNCTION(x)) { if (!IS_SPEC_OBJECT_OR_NULL(x)) {
return true; return true;
} else { } else {
// Even though the type of null is "object", null is still // Even though the type of null is "object", null is still
......
...@@ -225,7 +225,7 @@ function ObjectHasOwnProperty(V) { ...@@ -225,7 +225,7 @@ function ObjectHasOwnProperty(V) {
// ECMA-262 - 15.2.4.6 // ECMA-262 - 15.2.4.6
function ObjectIsPrototypeOf(V) { function ObjectIsPrototypeOf(V) {
if (!IS_OBJECT(V) && !IS_FUNCTION(V) && !IS_UNDETECTABLE(V)) return false; if (!IS_SPEC_OBJECT_OR_NULL(V) && !IS_UNDETECTABLE(V)) return false;
return %IsInPrototypeChain(this, V); return %IsInPrototypeChain(this, V);
} }
...@@ -233,7 +233,7 @@ function ObjectIsPrototypeOf(V) { ...@@ -233,7 +233,7 @@ function ObjectIsPrototypeOf(V) {
// ECMA-262 - 15.2.4.6 // ECMA-262 - 15.2.4.6
function ObjectPropertyIsEnumerable(V) { function ObjectPropertyIsEnumerable(V) {
if (this == null) return false; if (this == null) return false;
if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; if (!IS_SPEC_OBJECT_OR_NULL(this)) return false;
return %IsPropertyEnumerable(this, ToString(V)); return %IsPropertyEnumerable(this, ToString(V));
} }
...@@ -279,7 +279,7 @@ function ObjectLookupSetter(name) { ...@@ -279,7 +279,7 @@ function ObjectLookupSetter(name) {
function ObjectKeys(obj) { function ObjectKeys(obj) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj)) !IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); throw MakeTypeError("obj_ctor_property_non_object", ["keys"]);
return %LocalKeys(obj); return %LocalKeys(obj);
...@@ -329,7 +329,7 @@ function FromPropertyDescriptor(desc) { ...@@ -329,7 +329,7 @@ function FromPropertyDescriptor(desc) {
// ES5 8.10.5. // ES5 8.10.5.
function ToPropertyDescriptor(obj) { function ToPropertyDescriptor(obj) {
if (!IS_OBJECT(obj)) { if (!IS_SPEC_OBJECT_OR_NULL(obj)) {
throw MakeTypeError("property_desc_object", [obj]); throw MakeTypeError("property_desc_object", [obj]);
} }
var desc = new PropertyDescriptor(); var desc = new PropertyDescriptor();
...@@ -599,7 +599,7 @@ function DefineOwnProperty(obj, p, desc, should_throw) { ...@@ -599,7 +599,7 @@ function DefineOwnProperty(obj, p, desc, should_throw) {
// ES5 section 15.2.3.2. // ES5 section 15.2.3.2.
function ObjectGetPrototypeOf(obj) { function ObjectGetPrototypeOf(obj) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj)) !IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]);
return obj.__proto__; return obj.__proto__;
...@@ -608,7 +608,7 @@ function ObjectGetPrototypeOf(obj) { ...@@ -608,7 +608,7 @@ function ObjectGetPrototypeOf(obj) {
// ES5 section 15.2.3.3 // ES5 section 15.2.3.3
function ObjectGetOwnPropertyDescriptor(obj, p) { function ObjectGetOwnPropertyDescriptor(obj, p) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj)) !IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescriptor"]); throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescriptor"]);
var desc = GetOwnProperty(obj, p); var desc = GetOwnProperty(obj, p);
...@@ -618,7 +618,7 @@ function ObjectGetOwnPropertyDescriptor(obj, p) { ...@@ -618,7 +618,7 @@ function ObjectGetOwnPropertyDescriptor(obj, p) {
// ES5 section 15.2.3.4. // ES5 section 15.2.3.4.
function ObjectGetOwnPropertyNames(obj) { function ObjectGetOwnPropertyNames(obj) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj)) !IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"]); throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"]);
...@@ -660,8 +660,7 @@ function ObjectGetOwnPropertyNames(obj) { ...@@ -660,8 +660,7 @@ function ObjectGetOwnPropertyNames(obj) {
// ES5 section 15.2.3.5. // ES5 section 15.2.3.5.
function ObjectCreate(proto, properties) { function ObjectCreate(proto, properties) {
// IS_OBJECT will return true on null covering that case. if (!IS_SPEC_OBJECT_OR_NULL(proto)) {
if (!IS_OBJECT(proto) && !IS_FUNCTION(proto)) {
throw MakeTypeError("proto_object_or_null", [proto]); throw MakeTypeError("proto_object_or_null", [proto]);
} }
var obj = new $Object(); var obj = new $Object();
...@@ -673,7 +672,7 @@ function ObjectCreate(proto, properties) { ...@@ -673,7 +672,7 @@ function ObjectCreate(proto, properties) {
// ES5 section 15.2.3.6. // ES5 section 15.2.3.6.
function ObjectDefineProperty(obj, p, attributes) { function ObjectDefineProperty(obj, p, attributes) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj)) !IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]);
var name = ToString(p); var name = ToString(p);
...@@ -685,7 +684,7 @@ function ObjectDefineProperty(obj, p, attributes) { ...@@ -685,7 +684,7 @@ function ObjectDefineProperty(obj, p, attributes) {
// ES5 section 15.2.3.7. // ES5 section 15.2.3.7.
function ObjectDefineProperties(obj, properties) { function ObjectDefineProperties(obj, properties) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
!IS_UNDETECTABLE(obj)) !IS_UNDETECTABLE(obj))
throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]);
var props = ToObject(properties); var props = ToObject(properties);
......
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