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

Side by Side Diff: src/ia32/builtins-ia32.cc

Issue 7062007: Avoid calling ToObject on JSFunction receiver arguments for Function.call and Function.apply. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add static asserts. Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/arm/builtins-arm.cc ('k') | src/mips/builtins-mips.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 1 << SharedFunctionInfo::kStrictModeBitWithinByte); 599 1 << SharedFunctionInfo::kStrictModeBitWithinByte);
600 __ j(not_equal, &shift_arguments); 600 __ j(not_equal, &shift_arguments);
601 601
602 // Do not transform the receiver for natives (shared already in ebx). 602 // Do not transform the receiver for natives (shared already in ebx).
603 __ test_b(FieldOperand(ebx, SharedFunctionInfo::kES5NativeByteOffset), 603 __ test_b(FieldOperand(ebx, SharedFunctionInfo::kES5NativeByteOffset),
604 1 << SharedFunctionInfo::kES5NativeBitWithinByte); 604 1 << SharedFunctionInfo::kES5NativeBitWithinByte);
605 __ j(not_equal, &shift_arguments); 605 __ j(not_equal, &shift_arguments);
606 606
607 // Compute the receiver in non-strict mode. 607 // Compute the receiver in non-strict mode.
608 __ mov(ebx, Operand(esp, eax, times_4, 0)); // First argument. 608 __ mov(ebx, Operand(esp, eax, times_4, 0)); // First argument.
609
610 // Call ToObject on the receiver if it is not an object, or use the
611 // global object if it is null or undefined.
609 __ test(ebx, Immediate(kSmiTagMask)); 612 __ test(ebx, Immediate(kSmiTagMask));
610 __ j(zero, &convert_to_object); 613 __ j(zero, &convert_to_object);
611
612 __ cmp(ebx, factory->null_value()); 614 __ cmp(ebx, factory->null_value());
613 __ j(equal, &use_global_receiver); 615 __ j(equal, &use_global_receiver);
614 __ cmp(ebx, factory->undefined_value()); 616 __ cmp(ebx, factory->undefined_value());
615 __ j(equal, &use_global_receiver); 617 __ j(equal, &use_global_receiver);
616 618 STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE);
617 // We don't use IsObjectJSObjectType here because we jump on success. 619 STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
618 __ mov(ecx, FieldOperand(ebx, HeapObject::kMapOffset)); 620 __ CmpObjectType(ebx, FIRST_JS_OBJECT_TYPE, ecx);
619 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); 621 __ j(above_equal, &shift_arguments);
620 __ sub(Operand(ecx), Immediate(FIRST_JS_OBJECT_TYPE));
621 __ cmp(ecx, LAST_JS_OBJECT_TYPE - FIRST_JS_OBJECT_TYPE);
622 __ j(below_equal, &shift_arguments);
623 622
624 __ bind(&convert_to_object); 623 __ bind(&convert_to_object);
625 __ EnterInternalFrame(); // In order to preserve argument count. 624 __ EnterInternalFrame(); // In order to preserve argument count.
626 __ SmiTag(eax); 625 __ SmiTag(eax);
627 __ push(eax); 626 __ push(eax);
628 627
629 __ push(ebx); 628 __ push(ebx);
630 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); 629 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
631 __ mov(ebx, eax); 630 __ mov(ebx, eax);
632 631
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 __ j(not_equal, &push_receiver); 760 __ j(not_equal, &push_receiver);
762 761
763 Factory* factory = masm->isolate()->factory(); 762 Factory* factory = masm->isolate()->factory();
764 763
765 // Do not transform the receiver for natives (shared already in ecx). 764 // Do not transform the receiver for natives (shared already in ecx).
766 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kES5NativeByteOffset), 765 __ test_b(FieldOperand(ecx, SharedFunctionInfo::kES5NativeByteOffset),
767 1 << SharedFunctionInfo::kES5NativeBitWithinByte); 766 1 << SharedFunctionInfo::kES5NativeBitWithinByte);
768 __ j(not_equal, &push_receiver); 767 __ j(not_equal, &push_receiver);
769 768
770 // Compute the receiver in non-strict mode. 769 // Compute the receiver in non-strict mode.
770 // Call ToObject on the receiver if it is not an object, or use the
771 // global object if it is null or undefined.
771 __ test(ebx, Immediate(kSmiTagMask)); 772 __ test(ebx, Immediate(kSmiTagMask));
772 __ j(zero, &call_to_object); 773 __ j(zero, &call_to_object);
773 __ cmp(ebx, factory->null_value()); 774 __ cmp(ebx, factory->null_value());
774 __ j(equal, &use_global_receiver); 775 __ j(equal, &use_global_receiver);
775 __ cmp(ebx, factory->undefined_value()); 776 __ cmp(ebx, factory->undefined_value());
776 __ j(equal, &use_global_receiver); 777 __ j(equal, &use_global_receiver);
778 STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE);
779 STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
780 __ CmpObjectType(ebx, FIRST_JS_OBJECT_TYPE, ecx);
781 __ j(above_equal, &push_receiver);
777 782
778 // If given receiver is already a JavaScript object then there's no
779 // reason for converting it.
780 // We don't use IsObjectJSObjectType here because we jump on success.
781 __ mov(ecx, FieldOperand(ebx, HeapObject::kMapOffset));
782 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
783 __ sub(Operand(ecx), Immediate(FIRST_JS_OBJECT_TYPE));
784 __ cmp(ecx, LAST_JS_OBJECT_TYPE - FIRST_JS_OBJECT_TYPE);
785 __ j(below_equal, &push_receiver);
786
787 // Convert the receiver to an object.
788 __ bind(&call_to_object); 783 __ bind(&call_to_object);
789 __ push(ebx); 784 __ push(ebx);
790 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); 785 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
791 __ mov(ebx, Operand(eax)); 786 __ mov(ebx, Operand(eax));
792 __ jmp(&push_receiver); 787 __ jmp(&push_receiver);
793 788
794 // Use the current global receiver object as the receiver. 789 // Use the current global receiver object as the receiver.
795 __ bind(&use_global_receiver); 790 __ bind(&use_global_receiver);
796 const int kGlobalOffset = 791 const int kGlobalOffset =
797 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; 792 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); 1593 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR);
1599 generator.Generate(); 1594 generator.Generate();
1600 } 1595 }
1601 1596
1602 1597
1603 #undef __ 1598 #undef __
1604 } 1599 }
1605 } // namespace v8::internal 1600 } // namespace v8::internal
1606 1601
1607 #endif // V8_TARGET_ARCH_IA32 1602 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/arm/builtins-arm.cc ('k') | src/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698