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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 if (callback == NULL) { | 298 if (callback == NULL) { |
299 // No callback set and code generation disallowed. | 299 // No callback set and code generation disallowed. |
300 return false; | 300 return false; |
301 } else { | 301 } else { |
302 // Callback set. Let it decide if code generation is allowed. | 302 // Callback set. Let it decide if code generation is allowed. |
303 VMState<EXTERNAL> state(isolate); | 303 VMState<EXTERNAL> state(isolate); |
304 return callback(v8::Utils::ToLocal(context)); | 304 return callback(v8::Utils::ToLocal(context)); |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 | |
309 static Object* CompileGlobalEval(Isolate* isolate, Handle<String> source, | 308 static Object* CompileGlobalEval(Isolate* isolate, Handle<String> source, |
310 Handle<SharedFunctionInfo> outer_info, | 309 Handle<SharedFunctionInfo> outer_info, |
311 LanguageMode language_mode, | 310 LanguageMode language_mode, |
312 int scope_position) { | 311 int eval_scope_position, int eval_position) { |
313 Handle<Context> context = Handle<Context>(isolate->context()); | 312 Handle<Context> context = Handle<Context>(isolate->context()); |
314 Handle<Context> native_context = Handle<Context>(context->native_context()); | 313 Handle<Context> native_context = Handle<Context>(context->native_context()); |
315 | 314 |
316 // Check if native context allows code generation from | 315 // Check if native context allows code generation from |
317 // strings. Throw an exception if it doesn't. | 316 // strings. Throw an exception if it doesn't. |
318 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 317 if (native_context->allow_code_gen_from_strings()->IsFalse() && |
319 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 318 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
320 Handle<Object> error_message = | 319 Handle<Object> error_message = |
321 native_context->ErrorMessageForCodeGenerationFromStrings(); | 320 native_context->ErrorMessageForCodeGenerationFromStrings(); |
322 Handle<Object> error; | 321 Handle<Object> error; |
323 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( | 322 MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError( |
324 MessageTemplate::kCodeGenFromStrings, error_message); | 323 MessageTemplate::kCodeGenFromStrings, error_message); |
325 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); | 324 if (maybe_error.ToHandle(&error)) isolate->Throw(*error); |
326 return isolate->heap()->exception(); | 325 return isolate->heap()->exception(); |
327 } | 326 } |
328 | 327 |
329 // Deal with a normal eval call with a string argument. Compile it | 328 // Deal with a normal eval call with a string argument. Compile it |
330 // and return the compiled function bound in the local context. | 329 // and return the compiled function bound in the local context. |
331 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; | 330 static const ParseRestriction restriction = NO_PARSE_RESTRICTION; |
332 Handle<JSFunction> compiled; | 331 Handle<JSFunction> compiled; |
333 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 332 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
334 isolate, compiled, | 333 isolate, compiled, Compiler::GetFunctionFromEval( |
335 Compiler::GetFunctionFromEval(source, outer_info, context, language_mode, | 334 source, outer_info, context, language_mode, |
336 restriction, scope_position), | 335 restriction, eval_scope_position, eval_position), |
337 isolate->heap()->exception()); | 336 isolate->heap()->exception()); |
338 return *compiled; | 337 return *compiled; |
339 } | 338 } |
340 | 339 |
341 | 340 |
342 RUNTIME_FUNCTION(Runtime_ResolvePossiblyDirectEval) { | 341 RUNTIME_FUNCTION(Runtime_ResolvePossiblyDirectEval) { |
343 HandleScope scope(isolate); | 342 HandleScope scope(isolate); |
344 DCHECK(args.length() == 5); | 343 DCHECK(args.length() == 6); |
345 | 344 |
346 Handle<Object> callee = args.at<Object>(0); | 345 Handle<Object> callee = args.at<Object>(0); |
347 | 346 |
348 // If "eval" didn't refer to the original GlobalEval, it's not a | 347 // If "eval" didn't refer to the original GlobalEval, it's not a |
349 // direct call to eval. | 348 // direct call to eval. |
350 // (And even if it is, but the first argument isn't a string, just let | 349 // (And even if it is, but the first argument isn't a string, just let |
351 // execution default to an indirect call to eval, which will also return | 350 // execution default to an indirect call to eval, which will also return |
352 // the first argument without doing anything). | 351 // the first argument without doing anything). |
353 if (*callee != isolate->native_context()->global_eval_fun() || | 352 if (*callee != isolate->native_context()->global_eval_fun() || |
354 !args[1]->IsString()) { | 353 !args[1]->IsString()) { |
355 return *callee; | 354 return *callee; |
356 } | 355 } |
357 | 356 |
358 DCHECK(args[3]->IsSmi()); | 357 DCHECK(args[3]->IsSmi()); |
359 DCHECK(is_valid_language_mode(args.smi_at(3))); | 358 DCHECK(is_valid_language_mode(args.smi_at(3))); |
360 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); | 359 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); |
361 DCHECK(args[4]->IsSmi()); | 360 DCHECK(args[4]->IsSmi()); |
362 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), | 361 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), |
363 isolate); | 362 isolate); |
364 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, | 363 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, |
365 language_mode, args.smi_at(4)); | 364 language_mode, args.smi_at(4), args.smi_at(5)); |
366 } | 365 } |
367 } // namespace internal | 366 } // namespace internal |
368 } // namespace v8 | 367 } // namespace v8 |
OLD | NEW |