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_X87 | 5 #if V8_TARGET_ARCH_X87 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 } | 1509 } |
1510 | 1510 |
1511 | 1511 |
1512 // static | 1512 // static |
1513 void Builtins::Generate_Call(MacroAssembler* masm) { | 1513 void Builtins::Generate_Call(MacroAssembler* masm) { |
1514 // ----------- S t a t e ------------- | 1514 // ----------- S t a t e ------------- |
1515 // -- eax : the number of arguments (not including the receiver) | 1515 // -- eax : the number of arguments (not including the receiver) |
1516 // -- edi : the target to call (can be any Object). | 1516 // -- edi : the target to call (can be any Object). |
1517 // ----------------------------------- | 1517 // ----------------------------------- |
1518 | 1518 |
1519 Label non_smi, non_function; | 1519 Label non_callable, non_function, non_smi; |
1520 __ JumpIfSmi(edi, &non_function); | 1520 __ JumpIfSmi(edi, &non_callable); |
1521 __ bind(&non_smi); | 1521 __ bind(&non_smi); |
1522 __ CmpObjectType(edi, JS_FUNCTION_TYPE, edx); | 1522 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
1523 __ j(equal, masm->isolate()->builtins()->CallFunction(), | 1523 __ j(equal, masm->isolate()->builtins()->CallFunction(), |
1524 RelocInfo::CODE_TARGET); | 1524 RelocInfo::CODE_TARGET); |
1525 __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); | 1525 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
1526 __ j(not_equal, &non_function); | 1526 __ j(not_equal, &non_function); |
1527 | 1527 |
1528 // 1. Call to function proxy. | 1528 // 1. Call to function proxy. |
1529 // TODO(neis): This doesn't match the ES6 spec for [[Call]] on proxies. | 1529 // TODO(neis): This doesn't match the ES6 spec for [[Call]] on proxies. |
1530 __ mov(edi, FieldOperand(edi, JSFunctionProxy::kCallTrapOffset)); | 1530 __ mov(edi, FieldOperand(edi, JSFunctionProxy::kCallTrapOffset)); |
1531 __ AssertNotSmi(edi); | 1531 __ AssertNotSmi(edi); |
1532 __ jmp(&non_smi); | 1532 __ jmp(&non_smi); |
1533 | 1533 |
1534 // 2. Call to something else, which might have a [[Call]] internal method (if | 1534 // 2. Call to something else, which might have a [[Call]] internal method (if |
1535 // not we raise an exception). | 1535 // not we raise an exception). |
1536 __ bind(&non_function); | 1536 __ bind(&non_function); |
1537 // TODO(bmeurer): I wonder why we prefer to have slow API calls? This could | 1537 // Check if target has a [[Call]] internal method. |
1538 // be awesome instead; i.e. a trivial improvement would be to call into the | 1538 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), 1 << Map::kIsCallable); |
1539 // runtime and just deal with the API function there instead of returning a | 1539 __ j(zero, &non_callable, Label::kNear); |
1540 // delegate from a runtime call that just jumps back to the runtime once | |
1541 // called. Or, bonus points, call directly into the C API function here, as | |
1542 // we do in some Crankshaft fast cases. | |
1543 // Overwrite the original receiver with the (original) target. | 1540 // Overwrite the original receiver with the (original) target. |
1544 __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); | 1541 __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); |
| 1542 // Let the "call_as_function_delegate" take care of the rest. |
| 1543 __ LoadGlobalFunction(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, edi); |
| 1544 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); |
| 1545 |
| 1546 // 3. Call to something that is not callable. |
| 1547 __ bind(&non_callable); |
1545 { | 1548 { |
1546 // Determine the delegate for the target (if any). | |
1547 FrameScope scope(masm, StackFrame::INTERNAL); | 1549 FrameScope scope(masm, StackFrame::INTERNAL); |
1548 __ SmiTag(eax); | |
1549 __ Push(eax); | |
1550 __ Push(edi); | 1550 __ Push(edi); |
1551 __ CallRuntime(Runtime::kGetFunctionDelegate, 1); | 1551 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
1552 __ mov(edi, eax); | |
1553 __ Pop(eax); | |
1554 __ SmiUntag(eax); | |
1555 } | 1552 } |
1556 // The delegate is always a regular function. | |
1557 __ AssertFunction(edi); | |
1558 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); | |
1559 } | 1553 } |
1560 | 1554 |
1561 | 1555 |
1562 // static | 1556 // static |
1563 void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { | 1557 void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { |
1564 // ----------- S t a t e ------------- | 1558 // ----------- S t a t e ------------- |
1565 // -- eax : the number of arguments (not including the receiver) | 1559 // -- eax : the number of arguments (not including the receiver) |
1566 // -- edx : the original constructor (checked to be a JSFunction) | 1560 // -- edx : the original constructor (checked to be a JSFunction) |
1567 // -- edi : the constructor to call (checked to be a JSFunction) | 1561 // -- edi : the constructor to call (checked to be a JSFunction) |
1568 // ----------------------------------- | 1562 // ----------------------------------- |
(...skipping 15 matching lines...) Expand all Loading... |
1584 | 1578 |
1585 // static | 1579 // static |
1586 void Builtins::Generate_Construct(MacroAssembler* masm) { | 1580 void Builtins::Generate_Construct(MacroAssembler* masm) { |
1587 // ----------- S t a t e ------------- | 1581 // ----------- S t a t e ------------- |
1588 // -- eax : the number of arguments (not including the receiver) | 1582 // -- eax : the number of arguments (not including the receiver) |
1589 // -- edx : the original constructor (either the same as the constructor or | 1583 // -- edx : the original constructor (either the same as the constructor or |
1590 // the JSFunction on which new was invoked initially) | 1584 // the JSFunction on which new was invoked initially) |
1591 // -- edi : the constructor to call (can be any Object) | 1585 // -- edi : the constructor to call (can be any Object) |
1592 // ----------------------------------- | 1586 // ----------------------------------- |
1593 | 1587 |
1594 Label slow; | 1588 Label non_callable, non_function; |
1595 __ JumpIfSmi(edi, &slow, Label::kNear); | 1589 __ JumpIfSmi(edi, &non_callable); |
1596 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 1590 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
1597 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), | 1591 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
1598 RelocInfo::CODE_TARGET); | 1592 RelocInfo::CODE_TARGET); |
1599 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); | 1593 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
1600 __ j(not_equal, &slow, Label::kNear); | 1594 __ j(not_equal, &non_function, Label::kNear); |
1601 | 1595 |
| 1596 // 1. Construct of function proxy. |
1602 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. | 1597 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. |
1603 __ mov(edi, FieldOperand(edi, JSFunctionProxy::kConstructTrapOffset)); | 1598 __ mov(edi, FieldOperand(edi, JSFunctionProxy::kConstructTrapOffset)); |
1604 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | 1599 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); |
1605 | 1600 |
1606 __ bind(&slow); | 1601 // 2. Construct of something else, which might have a [[Construct]] internal |
| 1602 // method (if not we raise an exception). |
| 1603 __ bind(&non_function); |
| 1604 // Check if target has a [[Call]] internal method. |
| 1605 // TODO(bmeurer): This shoud use IsConstructor once available. |
| 1606 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), 1 << Map::kIsCallable); |
| 1607 __ j(zero, &non_callable, Label::kNear); |
| 1608 // Overwrite the original receiver with the (original) target. |
| 1609 __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); |
| 1610 // Let the "call_as_constructor_delegate" take care of the rest. |
| 1611 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi); |
| 1612 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); |
| 1613 |
| 1614 // 3. Construct of something that is not callable. |
| 1615 __ bind(&non_callable); |
1607 { | 1616 { |
1608 // Determine the delegate for the target (if any). | |
1609 FrameScope scope(masm, StackFrame::INTERNAL); | 1617 FrameScope scope(masm, StackFrame::INTERNAL); |
1610 __ SmiTag(eax); | |
1611 __ Push(eax); | |
1612 __ Push(edi); | 1618 __ Push(edi); |
1613 __ CallRuntime(Runtime::kGetConstructorDelegate, 1); | 1619 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
1614 __ mov(edi, eax); | |
1615 __ Pop(eax); | |
1616 __ SmiUntag(eax); | |
1617 } | 1620 } |
1618 // The delegate is always a regular function. | |
1619 __ AssertFunction(edi); | |
1620 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); | |
1621 } | 1621 } |
1622 | 1622 |
1623 | 1623 |
1624 // static | 1624 // static |
1625 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { | 1625 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { |
1626 // ----------- S t a t e ------------- | 1626 // ----------- S t a t e ------------- |
1627 // -- eax : the number of arguments (not including the receiver) | 1627 // -- eax : the number of arguments (not including the receiver) |
1628 // -- ebx : the address of the first argument to be pushed. Subsequent | 1628 // -- ebx : the address of the first argument to be pushed. Subsequent |
1629 // arguments should be consecutive above this, in the same order as | 1629 // arguments should be consecutive above this, in the same order as |
1630 // they are to be pushed onto the stack. | 1630 // they are to be pushed onto the stack. |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 | 1837 |
1838 __ bind(&ok); | 1838 __ bind(&ok); |
1839 __ ret(0); | 1839 __ ret(0); |
1840 } | 1840 } |
1841 | 1841 |
1842 #undef __ | 1842 #undef __ |
1843 } // namespace internal | 1843 } // namespace internal |
1844 } // namespace v8 | 1844 } // namespace v8 |
1845 | 1845 |
1846 #endif // V8_TARGET_ARCH_X87 | 1846 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |