Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/runtime.cc

Issue 9155011: Inline fast case of CodeGenerationFromStringsAllowed (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 9355 matching lines...) Expand 10 before | Expand all | Expand 10 after
9366 // Syntax error or stack overflow in scanner. 9366 // Syntax error or stack overflow in scanner.
9367 ASSERT(isolate->has_pending_exception()); 9367 ASSERT(isolate->has_pending_exception());
9368 return Failure::Exception(); 9368 return Failure::Exception();
9369 } 9369 }
9370 return *result; 9370 return *result;
9371 } 9371 }
9372 9372
9373 9373
9374 bool CodeGenerationFromStringsAllowed(Isolate* isolate, 9374 bool CodeGenerationFromStringsAllowed(Isolate* isolate,
9375 Handle<Context> context) { 9375 Handle<Context> context) {
9376 if (context->allow_code_gen_from_strings()->IsFalse()) { 9376 ASSERT(context->allow_code_gen_from_strings()->IsFalse());
9377 // Check with callback if set. 9377 // Check with callback if set.
9378 AllowCodeGenerationFromStringsCallback callback = 9378 AllowCodeGenerationFromStringsCallback callback =
9379 isolate->allow_code_gen_callback(); 9379 isolate->allow_code_gen_callback();
9380 if (callback == NULL) { 9380 if (callback == NULL) {
9381 // No callback set and code generation disallowed. 9381 // No callback set and code generation disallowed.
9382 return false; 9382 return false;
9383 } else { 9383 } else {
9384 // Callback set. Let it decide if code generation is allowed. 9384 // Callback set. Let it decide if code generation is allowed.
9385 VMState state(isolate, EXTERNAL); 9385 VMState state(isolate, EXTERNAL);
9386 return callback(v8::Utils::ToLocal(context)); 9386 return callback(v8::Utils::ToLocal(context));
9387 }
9388 } 9387 }
9389 return true;
9390 } 9388 }
9391 9389
9392 9390
9393 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { 9391 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) {
9394 HandleScope scope(isolate); 9392 HandleScope scope(isolate);
9395 ASSERT_EQ(1, args.length()); 9393 ASSERT_EQ(1, args.length());
9396 CONVERT_ARG_CHECKED(String, source, 0); 9394 CONVERT_ARG_CHECKED(String, source, 0);
9397 9395
9398 // Extract global context. 9396 // Extract global context.
9399 Handle<Context> context(isolate->context()->global_context()); 9397 Handle<Context> context(isolate->context()->global_context());
9400 9398
9401 // Check if global context allows code generation from 9399 // Check if global context allows code generation from
9402 // strings. Throw an exception if it doesn't. 9400 // strings. Throw an exception if it doesn't.
9403 if (!CodeGenerationFromStringsAllowed(isolate, context)) { 9401 if (context->allow_code_gen_from_strings()->IsFalse() &&
9402 !CodeGenerationFromStringsAllowed(isolate, context)) {
9404 return isolate->Throw(*isolate->factory()->NewError( 9403 return isolate->Throw(*isolate->factory()->NewError(
9405 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); 9404 "code_gen_from_strings", HandleVector<Object>(NULL, 0)));
9406 } 9405 }
9407 9406
9408 // Compile source string in the global context. 9407 // Compile source string in the global context.
9409 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 9408 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
9410 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); 9409 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition);
9411 if (shared.is_null()) return Failure::Exception(); 9410 if (shared.is_null()) return Failure::Exception();
9412 Handle<JSFunction> fun = 9411 Handle<JSFunction> fun =
9413 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, 9412 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
9414 context, 9413 context,
9415 NOT_TENURED); 9414 NOT_TENURED);
9416 return *fun; 9415 return *fun;
9417 } 9416 }
9418 9417
9419 9418
9420 static ObjectPair CompileGlobalEval(Isolate* isolate, 9419 static ObjectPair CompileGlobalEval(Isolate* isolate,
9421 Handle<String> source, 9420 Handle<String> source,
9422 Handle<Object> receiver, 9421 Handle<Object> receiver,
9423 LanguageMode language_mode, 9422 LanguageMode language_mode,
9424 int scope_position) { 9423 int scope_position) {
9425 Handle<Context> context = Handle<Context>(isolate->context()); 9424 Handle<Context> context = Handle<Context>(isolate->context());
9426 Handle<Context> global_context = Handle<Context>(context->global_context()); 9425 Handle<Context> global_context = Handle<Context>(context->global_context());
9427 9426
9428 // Check if global context allows code generation from 9427 // Check if global context allows code generation from
9429 // strings. Throw an exception if it doesn't. 9428 // strings. Throw an exception if it doesn't.
9430 if (!CodeGenerationFromStringsAllowed(isolate, global_context)) { 9429 if (global_context->allow_code_gen_from_strings()->IsFalse() &&
9430 !CodeGenerationFromStringsAllowed(isolate, global_context)) {
9431 isolate->Throw(*isolate->factory()->NewError( 9431 isolate->Throw(*isolate->factory()->NewError(
9432 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); 9432 "code_gen_from_strings", HandleVector<Object>(NULL, 0)));
9433 return MakePair(Failure::Exception(), NULL); 9433 return MakePair(Failure::Exception(), NULL);
9434 } 9434 }
9435 9435
9436 // Deal with a normal eval call with a string argument. Compile it 9436 // Deal with a normal eval call with a string argument. Compile it
9437 // and return the compiled function bound in the local context. 9437 // and return the compiled function bound in the local context.
9438 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 9438 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
9439 source, 9439 source,
9440 Handle<Context>(isolate->context()), 9440 Handle<Context>(isolate->context()),
(...skipping 4107 matching lines...) Expand 10 before | Expand all | Expand 10 after
13548 } else { 13548 } else {
13549 // Handle last resort GC and make sure to allow future allocations 13549 // Handle last resort GC and make sure to allow future allocations
13550 // to grow the heap without causing GCs (if possible). 13550 // to grow the heap without causing GCs (if possible).
13551 isolate->counters()->gc_last_resort_from_js()->Increment(); 13551 isolate->counters()->gc_last_resort_from_js()->Increment();
13552 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13552 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13553 } 13553 }
13554 } 13554 }
13555 13555
13556 13556
13557 } } // namespace v8::internal 13557 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698