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

Unified Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 1306303005: Revert of [es5] Class of object is "Function" if object has [[Call]]. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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 | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/full-codegen/x64/full-codegen-x64.cc
diff --git a/src/full-codegen/x64/full-codegen-x64.cc b/src/full-codegen/x64/full-codegen-x64.cc
index c5ef0916a60e502f1190c86001c661c90790a7f1..a91ccdd02afe4a4bb039333ad3a8de486cffd20e 100644
--- a/src/full-codegen/x64/full-codegen-x64.cc
+++ b/src/full-codegen/x64/full-codegen-x64.cc
@@ -3563,50 +3563,57 @@
void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
- DCHECK_EQ(1, args->length());
- Label done, null, function, function_constructor;
+ DCHECK(args->length() == 1);
+ Label done, null, function, non_function_constructor;
VisitForAccumulatorValue(args->at(0));
// If the object is a smi, we return null.
- __ JumpIfSmi(rax, &null, Label::kNear);
-
- // If the object is not a receiver, we return null.
- STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
- __ CmpObjectType(rax, FIRST_JS_RECEIVER_TYPE, rax);
- __ j(below, &null, Label::kNear);
-
- // According to ES5 section 15 Standard Built-in ECMAScript Objects, the
- // [[Class]] of builtin objects is "Function" if a [[Call]] internal
- // method is present.
- __ testb(FieldOperand(rax, Map::kBitFieldOffset),
- Immediate(1 << Map::kIsCallable));
- __ j(not_zero, &function, Label::kNear);
+ __ JumpIfSmi(rax, &null);
+
+ // Check that the object is a JS object but take special care of JS
+ // functions to make sure they have 'Function' as their class.
+ // Assume that there are only two callable types, and one of them is at
+ // either end of the type range for JS object types. Saves extra comparisons.
+ STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
+ __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax);
+ // Map is now in rax.
+ __ j(below, &null);
+ STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
+ FIRST_SPEC_OBJECT_TYPE + 1);
+ __ j(equal, &function);
+
+ __ CmpInstanceType(rax, LAST_SPEC_OBJECT_TYPE);
+ STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE ==
+ LAST_SPEC_OBJECT_TYPE - 1);
+ __ j(equal, &function);
+ // Assume that there is no larger type.
+ STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1);
// Check if the constructor in the map is a JS function.
__ GetMapConstructor(rax, rax, rbx);
__ CmpInstanceType(rbx, JS_FUNCTION_TYPE);
- __ j(equal, &function_constructor, Label::kNear);
-
- // Objects with a non-function constructor have class 'Object'.
- __ LoadRoot(rax, Heap::kObject_stringRootIndex);
- __ jmp(&done, Label::kNear);
-
- // Non-JS objects have class null.
- __ bind(&null);
- __ LoadRoot(rax, Heap::kNullValueRootIndex);
- __ jmp(&done, Label::kNear);
-
- // Functions have class 'Function'.
- __ bind(&function);
- __ LoadRoot(rax, Heap::kFunction_stringRootIndex);
- __ jmp(&done, Label::kNear);
-
- __ bind(&function_constructor);
+ __ j(not_equal, &non_function_constructor);
+
// rax now contains the constructor function. Grab the
// instance class name from there.
__ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset));
__ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset));
+ __ jmp(&done);
+
+ // Functions have class 'Function'.
+ __ bind(&function);
+ __ Move(rax, isolate()->factory()->Function_string());
+ __ jmp(&done);
+
+ // Objects with a non-function constructor have class 'Object'.
+ __ bind(&non_function_constructor);
+ __ Move(rax, isolate()->factory()->Object_string());
+ __ jmp(&done);
+
+ // Non-JS objects have class null.
+ __ bind(&null);
+ __ LoadRoot(rax, Heap::kNullValueRootIndex);
// All done.
__ bind(&done);
« no previous file with comments | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698