OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // No callback set and code generation disallowed. | 345 // No callback set and code generation disallowed. |
346 return false; | 346 return false; |
347 } else { | 347 } else { |
348 // Callback set. Let it decide if code generation is allowed. | 348 // Callback set. Let it decide if code generation is allowed. |
349 VMState<EXTERNAL> state(isolate); | 349 VMState<EXTERNAL> state(isolate); |
350 return callback(v8::Utils::ToLocal(context)); | 350 return callback(v8::Utils::ToLocal(context)); |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 | 354 |
355 // Walk up the stack expecting: | |
356 // - Runtime_CompileString | |
357 // - JSFunction callee (eval, Function constructor, etc) | |
358 // - call() (maybe) | |
359 // - apply() (maybe) | |
360 // - bind() (maybe) | |
361 // - JSFunction caller (maybe) | |
362 // | |
363 // return true if the caller has access to the callee or if an exit frame was | |
364 // hit, in which case allow it through, as it could have come through the api. | |
365 bool HasAccessToContextForCompileString(Isolate* isolate) { | |
366 MaybeHandle<JSFunction> callee; | |
367 bool exit_handled = true; | |
368 bool has_access = true; | |
369 bool done = false; | |
370 for (StackFrameIterator it(isolate); !it.done() && !done; it.Advance()) { | |
371 StackFrame* raw_frame = it.frame(); | |
372 if (!raw_frame->is_java_script()) { | |
373 if (raw_frame->is_exit()) exit_handled = false; | |
374 continue; | |
375 } | |
376 JavaScriptFrame* outer_frame = JavaScriptFrame::cast(raw_frame); | |
377 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | |
378 outer_frame->Summarize(&frames); | |
379 for (int i = frames.length() - 1; i >= 0 && !done; --i) { | |
380 FrameSummary& frame = frames[i]; | |
381 Handle<JSFunction> fun = frame.function(); | |
382 // Capture the callee function. | |
383 if (callee.is_null()) { | |
384 callee = fun; | |
385 exit_handled = true; | |
386 continue; | |
387 } | |
388 // Exit condition. | |
389 Handle<JSObject> callee_global_proxy( | |
390 callee.ToHandleChecked()->context()->global_proxy()); | |
391 if (!isolate->MayAccess(handle(fun->context()), callee_global_proxy)) { | |
392 has_access = false; | |
393 done = true; | |
394 continue; | |
395 } | |
396 // Skip bound functions in correct origin. | |
397 if (fun->shared()->bound()) { | |
398 exit_handled = true; | |
399 continue; | |
400 } | |
401 done = true; | |
402 } | |
403 } | |
404 return !exit_handled || has_access; | |
405 } | |
406 | |
407 | |
408 RUNTIME_FUNCTION(Runtime_CompileString) { | 355 RUNTIME_FUNCTION(Runtime_CompileString) { |
409 HandleScope scope(isolate); | 356 HandleScope scope(isolate); |
410 DCHECK(args.length() == 2); | 357 DCHECK(args.length() == 2); |
411 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 358 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
412 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); | 359 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); |
413 | 360 |
414 // Extract native context. | 361 // Extract native context. |
415 Handle<Context> context(isolate->native_context()); | 362 Handle<Context> context(isolate->native_context()); |
416 | 363 |
417 // Filter cross security context calls. | |
418 if (!HasAccessToContextForCompileString(isolate)) { | |
419 return isolate->heap()->undefined_value(); | |
420 } | |
421 | |
422 // Check if native context allows code generation from | 364 // Check if native context allows code generation from |
423 // strings. Throw an exception if it doesn't. | 365 // strings. Throw an exception if it doesn't. |
424 if (context->allow_code_gen_from_strings()->IsFalse() && | 366 if (context->allow_code_gen_from_strings()->IsFalse() && |
425 !CodeGenerationFromStringsAllowed(isolate, context)) { | 367 !CodeGenerationFromStringsAllowed(isolate, context)) { |
426 Handle<Object> error_message = | 368 Handle<Object> error_message = |
427 context->ErrorMessageForCodeGenerationFromStrings(); | 369 context->ErrorMessageForCodeGenerationFromStrings(); |
428 THROW_NEW_ERROR_RETURN_FAILURE( | 370 THROW_NEW_ERROR_RETURN_FAILURE( |
429 isolate, | 371 isolate, |
430 NewEvalError(MessageTemplate::kCodeGenFromStrings, error_message)); | 372 NewEvalError(MessageTemplate::kCodeGenFromStrings, error_message)); |
431 } | 373 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 DCHECK(is_valid_language_mode(args.smi_at(3))); | 439 DCHECK(is_valid_language_mode(args.smi_at(3))); |
498 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); | 440 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); |
499 DCHECK(args[4]->IsSmi()); | 441 DCHECK(args[4]->IsSmi()); |
500 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), | 442 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), |
501 isolate); | 443 isolate); |
502 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, | 444 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, |
503 language_mode, args.smi_at(4)); | 445 language_mode, args.smi_at(4)); |
504 } | 446 } |
505 } // namespace internal | 447 } // namespace internal |
506 } // namespace v8 | 448 } // namespace v8 |
OLD | NEW |