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 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "v8.h" | 8 #include "v8.h" |
9 | 9 |
10 #include "accessors.h" | 10 #include "accessors.h" |
(...skipping 9741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9752 // No callback set and code generation disallowed. | 9752 // No callback set and code generation disallowed. |
9753 return false; | 9753 return false; |
9754 } else { | 9754 } else { |
9755 // Callback set. Let it decide if code generation is allowed. | 9755 // Callback set. Let it decide if code generation is allowed. |
9756 VMState<EXTERNAL> state(isolate); | 9756 VMState<EXTERNAL> state(isolate); |
9757 return callback(v8::Utils::ToLocal(context)); | 9757 return callback(v8::Utils::ToLocal(context)); |
9758 } | 9758 } |
9759 } | 9759 } |
9760 | 9760 |
9761 | 9761 |
9762 // Walk up the stack expecting: | |
9763 // - Runtime_CompileString | |
9764 // - JSFunction callee (eval, Function constructor, etc) | |
9765 // - call() (maybe) | |
9766 // - apply() (maybe) | |
9767 // - bind() (maybe) | |
9768 // - JSFunction caller (maybe) | |
9769 // | |
9770 // return true if the caller has the same security token as the callee | |
9771 // or if an exit frame was hit, in which case allow it through, as it could | |
9772 // have come through the api. | |
9773 static bool TokensMatchForCompileString(Isolate* isolate) { | |
9774 MaybeHandle<JSFunction> callee; | |
9775 bool exit_handled = true; | |
9776 bool tokens_match = true; | |
9777 bool done = false; | |
9778 for (StackFrameIterator it(isolate); !it.done() && !done; it.Advance()) { | |
9779 StackFrame* raw_frame = it.frame(); | |
9780 if (!raw_frame->is_java_script()) { | |
9781 if (raw_frame->is_exit()) exit_handled = false; | |
9782 continue; | |
9783 } | |
9784 JavaScriptFrame* outer_frame = JavaScriptFrame::cast(raw_frame); | |
9785 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | |
9786 outer_frame->Summarize(&frames); | |
9787 for (int i = frames.length() - 1; i >= 0 && !done; --i) { | |
9788 FrameSummary& frame = frames[i]; | |
9789 Handle<JSFunction> fun = frame.function(); | |
9790 // Capture the callee function. | |
9791 if (callee.is_null()) { | |
9792 callee = fun; | |
9793 exit_handled = true; | |
9794 continue; | |
9795 } | |
9796 // Exit condition. | |
9797 Handle<Context> context = handle(callee.ToHandleChecked()->context()); | |
Toon Verwaest
2014/06/11 12:28:44
remove " = handle"
| |
9798 if (!fun->context()->HasSameSecurityTokenAs(*context)) { | |
9799 tokens_match = false; | |
9800 done = true; | |
9801 continue; | |
9802 } | |
9803 // Skip bound functions in correct origin. | |
9804 if (fun->shared()->bound()) { | |
9805 exit_handled = true; | |
9806 continue; | |
9807 } | |
9808 done = true; | |
9809 } | |
9810 } | |
9811 return !exit_handled || tokens_match; | |
9812 } | |
9813 | |
9814 | |
9762 RUNTIME_FUNCTION(Runtime_CompileString) { | 9815 RUNTIME_FUNCTION(Runtime_CompileString) { |
9763 HandleScope scope(isolate); | 9816 HandleScope scope(isolate); |
9764 ASSERT(args.length() == 2); | 9817 ASSERT(args.length() == 2); |
9765 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 9818 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
9766 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); | 9819 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); |
9767 | 9820 |
9768 // Extract native context. | 9821 // Extract native context. |
9769 Handle<Context> context(isolate->context()->native_context()); | 9822 Handle<Context> context(isolate->context()->native_context()); |
9770 | 9823 |
9824 // Filter cross security context calls. | |
9825 if (!TokensMatchForCompileString(isolate)) { | |
9826 return isolate->heap()->undefined_value(); | |
9827 } | |
9828 | |
9771 // Check if native context allows code generation from | 9829 // Check if native context allows code generation from |
9772 // strings. Throw an exception if it doesn't. | 9830 // strings. Throw an exception if it doesn't. |
9773 if (context->allow_code_gen_from_strings()->IsFalse() && | 9831 if (context->allow_code_gen_from_strings()->IsFalse() && |
9774 !CodeGenerationFromStringsAllowed(isolate, context)) { | 9832 !CodeGenerationFromStringsAllowed(isolate, context)) { |
9775 Handle<Object> error_message = | 9833 Handle<Object> error_message = |
9776 context->ErrorMessageForCodeGenerationFromStrings(); | 9834 context->ErrorMessageForCodeGenerationFromStrings(); |
9777 return isolate->Throw(*isolate->factory()->NewEvalError( | 9835 return isolate->Throw(*isolate->factory()->NewEvalError( |
9778 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); | 9836 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); |
9779 } | 9837 } |
9780 | 9838 |
(...skipping 5337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15118 } | 15176 } |
15119 return NULL; | 15177 return NULL; |
15120 } | 15178 } |
15121 | 15179 |
15122 | 15180 |
15123 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15181 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15124 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15182 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15125 } | 15183 } |
15126 | 15184 |
15127 } } // namespace v8::internal | 15185 } } // namespace v8::internal |
OLD | NEW |