| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 context->ErrorMessageForCodeGenerationFromStrings(); | 362 context->ErrorMessageForCodeGenerationFromStrings(); |
| 363 THROW_NEW_ERROR_RETURN_FAILURE( | 363 THROW_NEW_ERROR_RETURN_FAILURE( |
| 364 isolate, NewEvalError("code_gen_from_strings", | 364 isolate, NewEvalError("code_gen_from_strings", |
| 365 HandleVector<Object>(&error_message, 1))); | 365 HandleVector<Object>(&error_message, 1))); |
| 366 } | 366 } |
| 367 | 367 |
| 368 // Compile source string in the native context. | 368 // Compile source string in the native context. |
| 369 ParseRestriction restriction = function_literal_only | 369 ParseRestriction restriction = function_literal_only |
| 370 ? ONLY_SINGLE_FUNCTION_LITERAL | 370 ? ONLY_SINGLE_FUNCTION_LITERAL |
| 371 : NO_PARSE_RESTRICTION; | 371 : NO_PARSE_RESTRICTION; |
| 372 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); |
| 372 Handle<JSFunction> fun; | 373 Handle<JSFunction> fun; |
| 373 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 374 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 374 isolate, fun, | 375 isolate, fun, |
| 375 Compiler::GetFunctionFromEval(source, context, SLOPPY, restriction, | 376 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY, |
| 376 RelocInfo::kNoPosition)); | 377 restriction, RelocInfo::kNoPosition)); |
| 377 return *fun; | 378 return *fun; |
| 378 } | 379 } |
| 379 | 380 |
| 380 | 381 |
| 381 static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source, | 382 static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source, |
| 383 Handle<SharedFunctionInfo> outer_info, |
| 382 Handle<Object> receiver, | 384 Handle<Object> receiver, |
| 383 StrictMode strict_mode, | 385 StrictMode strict_mode, |
| 384 int scope_position) { | 386 int scope_position) { |
| 385 Handle<Context> context = Handle<Context>(isolate->context()); | 387 Handle<Context> context = Handle<Context>(isolate->context()); |
| 386 Handle<Context> native_context = Handle<Context>(context->native_context()); | 388 Handle<Context> native_context = Handle<Context>(context->native_context()); |
| 387 | 389 |
| 388 // Check if native context allows code generation from | 390 // Check if native context allows code generation from |
| 389 // strings. Throw an exception if it doesn't. | 391 // strings. Throw an exception if it doesn't. |
| 390 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 392 if (native_context->allow_code_gen_from_strings()->IsFalse() && |
| 391 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 393 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
| 392 Handle<Object> error_message = | 394 Handle<Object> error_message = |
| 393 native_context->ErrorMessageForCodeGenerationFromStrings(); | 395 native_context->ErrorMessageForCodeGenerationFromStrings(); |
| 394 Handle<Object> error; | 396 Handle<Object> error; |
| 395 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( | 397 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( |
| 396 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)); | 398 "code_gen_from_strings", HandleVector<Object>(&error_message, 1)); |
| 397 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); | 399 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); |
| 398 return MakePair(isolate->heap()->exception(), NULL); | 400 return MakePair(isolate->heap()->exception(), NULL); |
| 399 } | 401 } |
| 400 | 402 |
| 401 // Deal with a normal eval call with a string argument. Compile it | 403 // Deal with a normal eval call with a string argument. Compile it |
| 402 // and return the compiled function bound in the local context. | 404 // and return the compiled function bound in the local context. |
| 403 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; | 405 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; |
| 404 Handle<JSFunction> compiled; | 406 Handle<JSFunction> compiled; |
| 405 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 407 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 406 isolate, compiled, | 408 isolate, compiled, |
| 407 Compiler::GetFunctionFromEval(source, context, strict_mode, restriction, | 409 Compiler::GetFunctionFromEval(source, outer_info, context, strict_mode, |
| 408 scope_position), | 410 restriction, scope_position), |
| 409 MakePair(isolate->heap()->exception(), NULL)); | 411 MakePair(isolate->heap()->exception(), NULL)); |
| 410 return MakePair(*compiled, *receiver); | 412 return MakePair(*compiled, *receiver); |
| 411 } | 413 } |
| 412 | 414 |
| 413 | 415 |
| 414 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ResolvePossiblyDirectEval) { | 416 RUNTIME_FUNCTION_RETURN_PAIR(Runtime_ResolvePossiblyDirectEval) { |
| 415 HandleScope scope(isolate); | 417 HandleScope scope(isolate); |
| 416 DCHECK(args.length() == 5); | 418 DCHECK(args.length() == 6); |
| 417 | 419 |
| 418 Handle<Object> callee = args.at<Object>(0); | 420 Handle<Object> callee = args.at<Object>(0); |
| 419 | 421 |
| 420 // If "eval" didn't refer to the original GlobalEval, it's not a | 422 // If "eval" didn't refer to the original GlobalEval, it's not a |
| 421 // direct call to eval. | 423 // direct call to eval. |
| 422 // (And even if it is, but the first argument isn't a string, just let | 424 // (And even if it is, but the first argument isn't a string, just let |
| 423 // execution default to an indirect call to eval, which will also return | 425 // execution default to an indirect call to eval, which will also return |
| 424 // the first argument without doing anything). | 426 // the first argument without doing anything). |
| 425 if (*callee != isolate->native_context()->global_eval_fun() || | 427 if (*callee != isolate->native_context()->global_eval_fun() || |
| 426 !args[1]->IsString()) { | 428 !args[1]->IsString()) { |
| 427 return MakePair(*callee, isolate->heap()->undefined_value()); | 429 return MakePair(*callee, isolate->heap()->undefined_value()); |
| 428 } | 430 } |
| 429 | 431 |
| 430 DCHECK(args[3]->IsSmi()); | |
| 431 DCHECK(args.smi_at(3) == SLOPPY || args.smi_at(3) == STRICT); | |
| 432 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(3)); | |
| 433 DCHECK(args[4]->IsSmi()); | 432 DCHECK(args[4]->IsSmi()); |
| 434 return CompileGlobalEval(isolate, args.at<String>(1), args.at<Object>(2), | 433 DCHECK(args.smi_at(4) == SLOPPY || args.smi_at(4) == STRICT); |
| 435 strict_mode, args.smi_at(4)); | 434 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(4)); |
| 435 DCHECK(args[5]->IsSmi()); |
| 436 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), |
| 437 isolate); |
| 438 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, |
| 439 args.at<Object>(3), strict_mode, args.smi_at(5)); |
| 436 } | 440 } |
| 437 } | 441 } |
| 438 } // namespace v8::internal | 442 } // namespace v8::internal |
| OLD | NEW |