| OLD | NEW |
| 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_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
| 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 3559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3570 __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 3570 __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3571 | 3571 |
| 3572 __ bind(&exit); | 3572 __ bind(&exit); |
| 3573 __ AssertSmi(eax); | 3573 __ AssertSmi(eax); |
| 3574 context()->Plug(eax); | 3574 context()->Plug(eax); |
| 3575 } | 3575 } |
| 3576 | 3576 |
| 3577 | 3577 |
| 3578 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { | 3578 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3579 ZoneList<Expression*>* args = expr->arguments(); | 3579 ZoneList<Expression*>* args = expr->arguments(); |
| 3580 DCHECK(args->length() == 1); | 3580 DCHECK_EQ(1, args->length()); |
| 3581 Label done, null, function, non_function_constructor; | 3581 Label done, null, function, function_constructor; |
| 3582 | 3582 |
| 3583 VisitForAccumulatorValue(args->at(0)); | 3583 VisitForAccumulatorValue(args->at(0)); |
| 3584 | 3584 |
| 3585 // If the object is a smi, we return null. | 3585 // If the object is a smi, we return null. |
| 3586 __ JumpIfSmi(eax, &null); | 3586 __ JumpIfSmi(eax, &null, Label::kNear); |
| 3587 | 3587 |
| 3588 // Check that the object is a JS object but take special care of JS | 3588 // If the object is not a receiver, we return null. |
| 3589 // functions to make sure they have 'Function' as their class. | 3589 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); |
| 3590 // Assume that there are only two callable types, and one of them is at | 3590 __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, eax); |
| 3591 // either end of the type range for JS object types. Saves extra comparisons. | 3591 __ j(below, &null, Label::kNear); |
| 3592 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | |
| 3593 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); | |
| 3594 // Map is now in eax. | |
| 3595 __ j(below, &null); | |
| 3596 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == | |
| 3597 FIRST_SPEC_OBJECT_TYPE + 1); | |
| 3598 __ j(equal, &function); | |
| 3599 | 3592 |
| 3600 __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); | 3593 // According to ES5 section 15 Standard Built-in ECMAScript Objects, the |
| 3601 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == | 3594 // [[Class]] of builtin objects is "Function" if a [[Call]] internal |
| 3602 LAST_SPEC_OBJECT_TYPE - 1); | 3595 // method is present. |
| 3603 __ j(equal, &function); | 3596 __ test_b(FieldOperand(eax, Map::kBitFieldOffset), 1 << Map::kIsCallable); |
| 3604 // Assume that there is no larger type. | 3597 __ j(not_zero, &function, Label::kNear); |
| 3605 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); | |
| 3606 | 3598 |
| 3607 // Check if the constructor in the map is a JS function. | 3599 // Check if the constructor in the map is a JS function. |
| 3608 __ GetMapConstructor(eax, eax, ebx); | 3600 __ GetMapConstructor(eax, eax, ebx); |
| 3609 __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); | 3601 __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); |
| 3610 __ j(not_equal, &non_function_constructor); | 3602 __ j(equal, &function_constructor, Label::kNear); |
| 3611 | 3603 |
| 3604 // Objects with a non-function constructor have class 'Object'. |
| 3605 __ LoadRoot(eax, Heap::kObject_stringRootIndex); |
| 3606 __ jmp(&done, Label::kNear); |
| 3607 |
| 3608 // Non-JS objects have class null. |
| 3609 __ bind(&null); |
| 3610 __ LoadRoot(eax, Heap::kNullValueRootIndex); |
| 3611 __ jmp(&done, Label::kNear); |
| 3612 |
| 3613 // Functions have class 'Function'. |
| 3614 __ bind(&function); |
| 3615 __ LoadRoot(eax, Heap::kFunction_stringRootIndex); |
| 3616 __ jmp(&done, Label::kNear); |
| 3617 |
| 3618 __ bind(&function_constructor); |
| 3612 // eax now contains the constructor function. Grab the | 3619 // eax now contains the constructor function. Grab the |
| 3613 // instance class name from there. | 3620 // instance class name from there. |
| 3614 __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); | 3621 __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 3615 __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); | 3622 __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3616 __ jmp(&done); | |
| 3617 | |
| 3618 // Functions have class 'Function'. | |
| 3619 __ bind(&function); | |
| 3620 __ mov(eax, isolate()->factory()->Function_string()); | |
| 3621 __ jmp(&done); | |
| 3622 | |
| 3623 // Objects with a non-function constructor have class 'Object'. | |
| 3624 __ bind(&non_function_constructor); | |
| 3625 __ mov(eax, isolate()->factory()->Object_string()); | |
| 3626 __ jmp(&done); | |
| 3627 | |
| 3628 // Non-JS objects have class null. | |
| 3629 __ bind(&null); | |
| 3630 __ mov(eax, isolate()->factory()->null_value()); | |
| 3631 | 3623 |
| 3632 // All done. | 3624 // All done. |
| 3633 __ bind(&done); | 3625 __ bind(&done); |
| 3634 | 3626 |
| 3635 context()->Plug(eax); | 3627 context()->Plug(eax); |
| 3636 } | 3628 } |
| 3637 | 3629 |
| 3638 | 3630 |
| 3639 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { | 3631 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3640 ZoneList<Expression*>* args = expr->arguments(); | 3632 ZoneList<Expression*>* args = expr->arguments(); |
| (...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5231 Assembler::target_address_at(call_target_address, | 5223 Assembler::target_address_at(call_target_address, |
| 5232 unoptimized_code)); | 5224 unoptimized_code)); |
| 5233 return OSR_AFTER_STACK_CHECK; | 5225 return OSR_AFTER_STACK_CHECK; |
| 5234 } | 5226 } |
| 5235 | 5227 |
| 5236 | 5228 |
| 5237 } // namespace internal | 5229 } // namespace internal |
| 5238 } // namespace v8 | 5230 } // namespace v8 |
| 5239 | 5231 |
| 5240 #endif // V8_TARGET_ARCH_IA32 | 5232 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |