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

Side by Side Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 1307943013: [es5] Class of object is "Function" if object has [[Call]]. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Jakobs comments. 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/codegen.h" 9 #include "src/codegen.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 3545 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 __ movp(rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset)); 3556 __ movp(rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset));
3557 3557
3558 __ bind(&exit); 3558 __ bind(&exit);
3559 __ AssertSmi(rax); 3559 __ AssertSmi(rax);
3560 context()->Plug(rax); 3560 context()->Plug(rax);
3561 } 3561 }
3562 3562
3563 3563
3564 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { 3564 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) {
3565 ZoneList<Expression*>* args = expr->arguments(); 3565 ZoneList<Expression*>* args = expr->arguments();
3566 DCHECK(args->length() == 1); 3566 DCHECK_EQ(1, args->length());
3567 Label done, null, function, non_function_constructor; 3567 Label done, null, function, function_constructor;
3568 3568
3569 VisitForAccumulatorValue(args->at(0)); 3569 VisitForAccumulatorValue(args->at(0));
3570 3570
3571 // If the object is a smi, we return null. 3571 // If the object is a smi, we return null.
3572 __ JumpIfSmi(rax, &null); 3572 __ JumpIfSmi(rax, &null, Label::kNear);
3573 3573
3574 // Check that the object is a JS object but take special care of JS 3574 // If the object is not a receiver, we return null.
3575 // functions to make sure they have 'Function' as their class. 3575 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
3576 // Assume that there are only two callable types, and one of them is at 3576 __ CmpObjectType(rax, FIRST_JS_RECEIVER_TYPE, rax);
3577 // either end of the type range for JS object types. Saves extra comparisons. 3577 __ j(below, &null, Label::kNear);
3578 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2);
3579 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax);
3580 // Map is now in rax.
3581 __ j(below, &null);
3582 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE ==
3583 FIRST_SPEC_OBJECT_TYPE + 1);
3584 __ j(equal, &function);
3585 3578
3586 __ CmpInstanceType(rax, LAST_SPEC_OBJECT_TYPE); 3579 // According to ES5 section 15 Standard Built-in ECMAScript Objects, the
3587 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == 3580 // [[Class]] of builtin objects is "Function" if a [[Call]] internal
3588 LAST_SPEC_OBJECT_TYPE - 1); 3581 // method is present.
3589 __ j(equal, &function); 3582 __ testb(FieldOperand(rax, Map::kBitFieldOffset),
3590 // Assume that there is no larger type. 3583 Immediate(1 << Map::kIsCallable));
3591 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); 3584 __ j(not_zero, &function, Label::kNear);
3592 3585
3593 // Check if the constructor in the map is a JS function. 3586 // Check if the constructor in the map is a JS function.
3594 __ GetMapConstructor(rax, rax, rbx); 3587 __ GetMapConstructor(rax, rax, rbx);
3595 __ CmpInstanceType(rbx, JS_FUNCTION_TYPE); 3588 __ CmpInstanceType(rbx, JS_FUNCTION_TYPE);
3596 __ j(not_equal, &non_function_constructor); 3589 __ j(equal, &function_constructor, Label::kNear);
3597 3590
3591 // Objects with a non-function constructor have class 'Object'.
3592 __ LoadRoot(rax, Heap::kObject_stringRootIndex);
3593 __ jmp(&done, Label::kNear);
3594
3595 // Non-JS objects have class null.
3596 __ bind(&null);
3597 __ LoadRoot(rax, Heap::kNullValueRootIndex);
3598 __ jmp(&done, Label::kNear);
3599
3600 // Functions have class 'Function'.
3601 __ bind(&function);
3602 __ LoadRoot(rax, Heap::kFunction_stringRootIndex);
3603 __ jmp(&done, Label::kNear);
3604
3605 __ bind(&function_constructor);
3598 // rax now contains the constructor function. Grab the 3606 // rax now contains the constructor function. Grab the
3599 // instance class name from there. 3607 // instance class name from there.
3600 __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); 3608 __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset));
3601 __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); 3609 __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset));
3602 __ jmp(&done);
3603
3604 // Functions have class 'Function'.
3605 __ bind(&function);
3606 __ Move(rax, isolate()->factory()->Function_string());
3607 __ jmp(&done);
3608
3609 // Objects with a non-function constructor have class 'Object'.
3610 __ bind(&non_function_constructor);
3611 __ Move(rax, isolate()->factory()->Object_string());
3612 __ jmp(&done);
3613
3614 // Non-JS objects have class null.
3615 __ bind(&null);
3616 __ LoadRoot(rax, Heap::kNullValueRootIndex);
3617 3610
3618 // All done. 3611 // All done.
3619 __ bind(&done); 3612 __ bind(&done);
3620 3613
3621 context()->Plug(rax); 3614 context()->Plug(rax);
3622 } 3615 }
3623 3616
3624 3617
3625 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { 3618 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) {
3626 ZoneList<Expression*>* args = expr->arguments(); 3619 ZoneList<Expression*>* args = expr->arguments();
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after
5242 Assembler::target_address_at(call_target_address, 5235 Assembler::target_address_at(call_target_address,
5243 unoptimized_code)); 5236 unoptimized_code));
5244 return OSR_AFTER_STACK_CHECK; 5237 return OSR_AFTER_STACK_CHECK;
5245 } 5238 }
5246 5239
5247 5240
5248 } // namespace internal 5241 } // namespace internal
5249 } // namespace v8 5242 } // namespace v8
5250 5243
5251 #endif // V8_TARGET_ARCH_X64 5244 #endif // V8_TARGET_ARCH_X64
OLDNEW
« 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