Commit 617bdc34 authored by bak@chromium.org's avatar bak@chromium.org

- Specialized IsClassOf for Number, Boolean, Arguments, and Function.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@520 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc87d51f
......@@ -135,11 +135,13 @@ namespace v8 { namespace internal {
V(Proto_symbol, "__proto__") \
V(StringImpl_symbol, "StringImpl") \
V(arguments_symbol, "arguments") \
V(Arguments_symbol, "Arguments") \
V(arguments_shadow_symbol, ".arguments") \
V(call_symbol, "call") \
V(apply_symbol, "apply") \
V(caller_symbol, "caller") \
V(boolean_symbol, "boolean") \
V(Boolean_symbol, "Boolean") \
V(callee_symbol, "callee") \
V(constructor_symbol, "constructor") \
V(code_symbol, ".code") \
......@@ -151,6 +153,8 @@ namespace v8 { namespace internal {
V(length_symbol, "length") \
V(name_symbol, "name") \
V(number_symbol, "number") \
V(Number_symbol, "Number") \
V(RegExp_symbol, "RegExp") \
V(object_symbol, "object") \
V(prototype_symbol, "prototype") \
V(string_symbol, "string") \
......
......@@ -221,7 +221,7 @@ static Object* Runtime_ClassOf(Arguments args) {
return JSObject::cast(obj)->class_name();
}
inline static Object* IsSpecificClassOf(Arguments args, String* name) {
inline static Object* HasSpecificClassOf(Arguments args, String* name) {
NoHandleAllocation ha;
ASSERT(args.length() == 1);
Object* obj = args[0];
......@@ -231,18 +231,43 @@ inline static Object* IsSpecificClassOf(Arguments args, String* name) {
return Heap::false_value();
}
static Object* Runtime_IsStringClass(Arguments args) {
return IsSpecificClassOf(args, Heap::String_symbol());
static Object* Runtime_HasStringClass(Arguments args) {
return HasSpecificClassOf(args, Heap::String_symbol());
}
static Object* Runtime_IsDateClass(Arguments args) {
return IsSpecificClassOf(args, Heap::Date_symbol());
static Object* Runtime_HasDateClass(Arguments args) {
return HasSpecificClassOf(args, Heap::Date_symbol());
}
static Object* Runtime_IsArrayClass(Arguments args) {
return IsSpecificClassOf(args, Heap::Array_symbol());
static Object* Runtime_HasArrayClass(Arguments args) {
return HasSpecificClassOf(args, Heap::Array_symbol());
}
static Object* Runtime_HasFunctionClass(Arguments args) {
return HasSpecificClassOf(args, Heap::function_class_symbol());
}
static Object* Runtime_HasNumberClass(Arguments args) {
return HasSpecificClassOf(args, Heap::Number_symbol());
}
static Object* Runtime_HasBooleanClass(Arguments args) {
return HasSpecificClassOf(args, Heap::Boolean_symbol());
}
static Object* Runtime_HasArgumentsClass(Arguments args) {
return HasSpecificClassOf(args, Heap::Arguments_symbol());
}
static Object* Runtime_HasRegExpClass(Arguments args) {
return HasSpecificClassOf(args, Heap::RegExp_symbol());
}
......
......@@ -165,9 +165,14 @@ namespace v8 { namespace internal {
F(GetScript, 1) \
\
F(ClassOf, 1) \
F(IsDateClass, 1) \
F(IsStringClass, 1) \
F(IsArrayClass, 1) \
F(HasDateClass, 1) \
F(HasStringClass, 1) \
F(HasArrayClass, 1) \
F(HasFunctionClass, 1) \
F(HasNumberClass, 1) \
F(HasBooleanClass, 1) \
F(HasArgumentsClass, 1) \
F(HasRegExpClass, 1) \
F(SetCode, 2) \
\
F(CreateApiFunction, 1) \
......
......@@ -352,8 +352,8 @@ function APPLY_PREPARE(args) {
// Make sure the arguments list has the right type.
if (args != null &&
%ClassOf(args) != 'Array' &&
%ClassOf(args) != 'Arguments') {
!%HasArrayClass(args) &&
!%HasArgumentsClass(args)) {
throw %MakeTypeError('apply_wrong_args', []);
}
......
......@@ -292,7 +292,7 @@ SetupObject();
function BooleanToString() {
// NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean')
if (!IS_BOOLEAN(this) && !%HasBooleanClass(this))
throw new $TypeError('Boolean.prototype.toString is not generic');
return ToString(%_ValueOf(this));
}
......@@ -301,7 +301,7 @@ function BooleanToString() {
function BooleanValueOf() {
// NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean')
if (!IS_BOOLEAN(this) && !%HasBooleanClass(this))
throw new $TypeError('Boolean.prototype.valueOf is not generic');
return %_ValueOf(this);
}
......@@ -340,7 +340,7 @@ function NumberToString(radix) {
// 'this'. This is not as dictated by ECMA-262.
var number = this;
if (!IS_NUMBER(this)) {
if (%ClassOf(this) !== 'Number')
if (!%HasNumberClass(this))
throw new $TypeError('Number.prototype.toString is not generic');
// Get the value of this number in case it's an object.
number = %_ValueOf(this);
......@@ -370,7 +370,7 @@ function NumberToLocaleString() {
function NumberValueOf() {
// NOTE: Both Number objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
if (!IS_NUMBER(this) && %ClassOf(this) !== 'Number')
if (!IS_NUMBER(this) && !%HasNumberClass(this))
throw new $TypeError('Number.prototype.valueOf is not generic');
return %_ValueOf(this);
}
......@@ -466,7 +466,7 @@ $Function.prototype.constructor = $Function;
function FunctionSourceString(func) {
// NOTE: Both Function objects and values can enter here as
// 'func'. This is not as dictated by ECMA-262.
if (!IS_FUNCTION(func) && %ClassOf(func) != 'Function')
if (!IS_FUNCTION(func) && !%HasFunctionClass(func))
throw new $TypeError('Function.prototype.toString is not generic');
var source = %FunctionGetSourceCode(func);
......
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