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

Side by Side Diff: src/accessors.cc

Issue 6713059: Function.caller when caller is a strict function. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 9 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 | « no previous file | src/messages.js » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 ReadOnlySetAccessor, 820 ReadOnlySetAccessor,
821 0 821 0
822 }; 822 };
823 823
824 824
825 // 825 //
826 // Accessors::FunctionCaller 826 // Accessors::FunctionCaller
827 // 827 //
828 828
829 829
830 static MaybeObject* CheckNonStrictCallerOrThrow(
831 Isolate* isolate,
832 JSFunction* caller) {
833 DisableAssertNoAllocation enable_allocation;
834 if (caller->shared()->strict_mode()) {
835 return isolate->Throw(
836 *isolate->factory()->NewTypeError("strict_caller",
837 HandleVector<Object>(NULL, 0)));
838 }
839 return caller;
840 }
841
842
830 MaybeObject* Accessors::FunctionGetCaller(Object* object, void*) { 843 MaybeObject* Accessors::FunctionGetCaller(Object* object, void*) {
831 Isolate* isolate = Isolate::Current(); 844 Isolate* isolate = Isolate::Current();
832 HandleScope scope(isolate); 845 HandleScope scope(isolate);
833 AssertNoAllocation no_alloc; 846 AssertNoAllocation no_alloc;
834 bool found_it = false; 847 bool found_it = false;
835 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); 848 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it);
836 if (!found_it) return isolate->heap()->undefined_value(); 849 if (!found_it) return isolate->heap()->undefined_value();
837 Handle<JSFunction> function(holder, isolate); 850 Handle<JSFunction> function(holder, isolate);
838 851
839 List<JSFunction*> functions(2); 852 List<JSFunction*> functions(2);
840 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) { 853 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) {
841 JavaScriptFrame* frame = it.frame(); 854 JavaScriptFrame* frame = it.frame();
842 frame->GetFunctions(&functions); 855 frame->GetFunctions(&functions);
843 for (int i = functions.length() - 1; i >= 0; i--) { 856 for (int i = functions.length() - 1; i >= 0; i--) {
844 if (functions[i] == *function) { 857 if (functions[i] == *function) {
845 // Once we have found the frame, we need to go to the caller 858 // Once we have found the frame, we need to go to the caller
846 // frame. This may require skipping through a number of top-level 859 // frame. This may require skipping through a number of top-level
847 // frames, e.g. frames for scripts not functions. 860 // frames, e.g. frames for scripts not functions.
848 if (i > 0) { 861 if (i > 0) {
849 ASSERT(!functions[i - 1]->shared()->is_toplevel()); 862 ASSERT(!functions[i - 1]->shared()->is_toplevel());
850 return functions[i - 1]; 863 return CheckNonStrictCallerOrThrow(isolate, functions[i - 1]);
851 } else { 864 } else {
852 for (it.Advance(); !it.done(); it.Advance()) { 865 for (it.Advance(); !it.done(); it.Advance()) {
853 frame = it.frame(); 866 frame = it.frame();
854 functions.Rewind(0); 867 functions.Rewind(0);
855 frame->GetFunctions(&functions); 868 frame->GetFunctions(&functions);
856 if (!functions.last()->shared()->is_toplevel()) { 869 if (!functions.last()->shared()->is_toplevel()) {
857 return functions.last(); 870 return CheckNonStrictCallerOrThrow(isolate, functions.last());
858 } 871 }
859 ASSERT(functions.length() == 1); 872 ASSERT(functions.length() == 1);
860 } 873 }
861 if (it.done()) return isolate->heap()->null_value(); 874 if (it.done()) return isolate->heap()->null_value();
862 break; 875 break;
863 } 876 }
864 } 877 }
865 } 878 }
866 functions.Rewind(0); 879 functions.Rewind(0);
867 } 880 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 } 915 }
903 916
904 917
905 const AccessorDescriptor Accessors::ObjectPrototype = { 918 const AccessorDescriptor Accessors::ObjectPrototype = {
906 ObjectGetPrototype, 919 ObjectGetPrototype,
907 ObjectSetPrototype, 920 ObjectSetPrototype,
908 0 921 0
909 }; 922 };
910 923
911 } } // namespace v8::internal 924 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698