Chromium Code Reviews| 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/v8.h" | 5 #include "src/v8.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.h" | 10 #include "src/frames.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 script->set_line_offset(Smi::FromInt(-line_num)); | 387 script->set_line_offset(Smi::FromInt(-line_num)); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 return *fun; | 390 return *fun; |
| 391 } | 391 } |
| 392 | 392 |
| 393 | 393 |
| 394 static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source, | 394 static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source, |
| 395 Handle<SharedFunctionInfo> outer_info, | 395 Handle<SharedFunctionInfo> outer_info, |
| 396 Handle<Object> receiver, | 396 Handle<Object> receiver, |
| 397 StrictMode strict_mode, | 397 LanguageMode language_mode, |
| 398 int scope_position) { | 398 int scope_position) { |
| 399 Handle<Context> context = Handle<Context>(isolate->context()); | 399 Handle<Context> context = Handle<Context>(isolate->context()); |
| 400 Handle<Context> native_context = Handle<Context>(context->native_context()); | 400 Handle<Context> native_context = Handle<Context>(context->native_context()); |
| 401 | 401 |
| 402 // Check if native context allows code generation from | 402 // Check if native context allows code generation from |
| 403 // strings. Throw an exception if it doesn't. | 403 // strings. Throw an exception if it doesn't. |
| 404 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 404 if (native_context->allow_code_gen_from_strings()->IsFalse() && |
| 405 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 405 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
| 406 Handle<Object> error_message = | 406 Handle<Object> error_message = |
| 407 native_context->ErrorMessageForCodeGenerationFromStrings(); | 407 native_context->ErrorMessageForCodeGenerationFromStrings(); |
| 408 Handle<Object> error; | 408 Handle<Object> error; |
| 409 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( | 409 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( |
| 410 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)); | 410 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)); |
| 411 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); | 411 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); |
| 412 return MakePair(isolate->heap()->exception(), NULL); | 412 return MakePair(isolate->heap()->exception(), NULL); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Deal with a normal eval call with a string argument. Compile it | 415 // Deal with a normal eval call with a string argument. Compile it |
| 416 // and return the compiled function bound in the local context. | 416 // and return the compiled function bound in the local context. |
| 417 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; | 417 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; |
| 418 Handle<JSFunction> compiled; | 418 Handle<JSFunction> compiled; |
| 419 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 419 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 420 isolate, compiled, | 420 isolate, compiled, |
| 421 Compiler::GetFunctionFromEval(source, outer_info, context, strict_mode, | 421 Compiler::GetFunctionFromEval(source, outer_info, context, language_mode, |
| 422 restriction, scope_position), | 422 restriction, scope_position), |
| 423 MakePair(isolate->heap()->exception(), NULL)); | 423 MakePair(isolate->heap()->exception(), NULL)); |
| 424 return MakePair(*compiled, *receiver); | 424 return MakePair(*compiled, *receiver); |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ResolvePossiblyDirectEval) { | 428 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ResolvePossiblyDirectEval) { |
| 429 HandleScope scope(isolate); | 429 HandleScope scope(isolate); |
| 430 DCHECK(args.length() == 6); | 430 DCHECK(args.length() == 6); |
| 431 | 431 |
| 432 Handle<Object> callee = args.at<Object>(0); | 432 Handle<Object> callee = args.at<Object>(0); |
| 433 | 433 |
| 434 // If "eval" didn't refer to the original GlobalEval, it's not a | 434 // If "eval" didn't refer to the original GlobalEval, it's not a |
| 435 // direct call to eval. | 435 // direct call to eval. |
| 436 // (And even if it is, but the first argument isn't a string, just let | 436 // (And even if it is, but the first argument isn't a string, just let |
| 437 // execution default to an indirect call to eval, which will also return | 437 // execution default to an indirect call to eval, which will also return |
| 438 // the first argument without doing anything). | 438 // the first argument without doing anything). |
| 439 if (*callee != isolate->native_context()->global_eval_fun() || | 439 if (*callee != isolate->native_context()->global_eval_fun() || |
| 440 !args[1]->IsString()) { | 440 !args[1]->IsString()) { |
| 441 return MakePair(*callee, isolate->heap()->undefined_value()); | 441 return MakePair(*callee, isolate->heap()->undefined_value()); |
| 442 } | 442 } |
| 443 | 443 |
| 444 DCHECK(args[4]->IsSmi()); | 444 DCHECK(args[4]->IsSmi()); |
| 445 DCHECK(args.smi_at(4) == SLOPPY || args.smi_at(4) == STRICT); | 445 STATIC_ASSERT(LANGUAGE_END == 2); |
| 446 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(4)); | 446 DCHECK(args.smi_at(4) == STRICT || args.smi_at(4) == SLOPPY); |
|
rossberg
2015/02/03 12:26:20
Could use predicate here as well.
marja
2015/02/03 14:45:02
Done.
| |
| 447 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(4)); | |
| 447 DCHECK(args[5]->IsSmi()); | 448 DCHECK(args[5]->IsSmi()); |
| 448 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), | 449 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), |
| 449 isolate); | 450 isolate); |
| 450 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, | 451 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, |
| 451 args.at<Object>(3), strict_mode, args.smi_at(5)); | 452 args.at<Object>(3), language_mode, args.smi_at(5)); |
| 452 } | 453 } |
| 453 } | 454 } |
| 454 } // namespace v8::internal | 455 } // namespace v8::internal |
| OLD | NEW |