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

Side by Side Diff: src/runtime.cc

Issue 6905167: Implement API to disallow code generation from strings for a context. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix comment Created 9 years, 7 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 | « src/messages.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "global-handles.h" 43 #include "global-handles.h"
44 #include "jsregexp.h" 44 #include "jsregexp.h"
45 #include "liveedit.h" 45 #include "liveedit.h"
46 #include "liveobjectlist-inl.h" 46 #include "liveobjectlist-inl.h"
47 #include "parser.h" 47 #include "parser.h"
48 #include "platform.h" 48 #include "platform.h"
49 #include "runtime.h" 49 #include "runtime.h"
50 #include "runtime-profiler.h" 50 #include "runtime-profiler.h"
51 #include "scopeinfo.h" 51 #include "scopeinfo.h"
52 #include "smart-pointer.h" 52 #include "smart-pointer.h"
53 #include "string-search.h"
53 #include "stub-cache.h" 54 #include "stub-cache.h"
54 #include "v8threads.h" 55 #include "v8threads.h"
55 #include "string-search.h" 56 #include "vm-state-inl.h"
56 57
57 namespace v8 { 58 namespace v8 {
58 namespace internal { 59 namespace internal {
59 60
60 61
61 #define RUNTIME_ASSERT(value) \ 62 #define RUNTIME_ASSERT(value) \
62 if (!(value)) return isolate->ThrowIllegalOperation(); 63 if (!(value)) return isolate->ThrowIllegalOperation();
63 64
64 // Cast the given object to a value of the specified type and store 65 // Cast the given object to a value of the specified type and store
65 // it in a variable with the given name. If the object is not of the 66 // it in a variable with the given name. If the object is not of the
(...skipping 8212 matching lines...) Expand 10 before | Expand all | Expand 10 after
8278 Handle<Object> result = JsonParser::Parse(source); 8279 Handle<Object> result = JsonParser::Parse(source);
8279 if (result.is_null()) { 8280 if (result.is_null()) {
8280 // Syntax error or stack overflow in scanner. 8281 // Syntax error or stack overflow in scanner.
8281 ASSERT(isolate->has_pending_exception()); 8282 ASSERT(isolate->has_pending_exception());
8282 return Failure::Exception(); 8283 return Failure::Exception();
8283 } 8284 }
8284 return *result; 8285 return *result;
8285 } 8286 }
8286 8287
8287 8288
8289 bool CodeGenerationFromStringsAllowed(Isolate* isolate,
8290 Handle<Context> context) {
8291 if (context->allow_code_gen_from_strings()->IsFalse()) {
8292 // Check with callback if set.
8293 AllowCodeGenerationFromStringsCallback callback =
8294 isolate->allow_code_gen_callback();
8295 if (callback == NULL) {
8296 // No callback set and code generation disallowed.
8297 return false;
8298 } else {
8299 // Callback set. Let it decide if code generation is allowed.
8300 VMState state(isolate, EXTERNAL);
8301 return callback(v8::Utils::ToLocal(context));
8302 }
8303 }
8304 return true;
8305 }
8306
8307
8288 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { 8308 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) {
8289 HandleScope scope(isolate); 8309 HandleScope scope(isolate);
8290 ASSERT_EQ(1, args.length()); 8310 ASSERT_EQ(1, args.length());
8291 CONVERT_ARG_CHECKED(String, source, 0); 8311 CONVERT_ARG_CHECKED(String, source, 0);
8292 8312
8313 // Extract global context.
8314 Handle<Context> context(isolate->context()->global_context());
8315
8316 // Check if global context allows code generation from
8317 // strings. Throw an exception if it doesn't.
8318 if (!CodeGenerationFromStringsAllowed(isolate, context)) {
8319 return isolate->Throw(*isolate->factory()->NewError(
8320 "code_gen_from_strings", HandleVector<Object>(NULL, 0)));
8321 }
8322
8293 // Compile source string in the global context. 8323 // Compile source string in the global context.
8294 Handle<Context> context(isolate->context()->global_context());
8295 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, 8324 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source,
8296 context, 8325 context,
8297 true, 8326 true,
8298 kNonStrictMode); 8327 kNonStrictMode);
8299 if (shared.is_null()) return Failure::Exception(); 8328 if (shared.is_null()) return Failure::Exception();
8300 Handle<JSFunction> fun = 8329 Handle<JSFunction> fun =
8301 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, 8330 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
8302 context, 8331 context,
8303 NOT_TENURED); 8332 NOT_TENURED);
8304 return *fun; 8333 return *fun;
8305 } 8334 }
8306 8335
8307 8336
8308 static ObjectPair CompileGlobalEval(Isolate* isolate, 8337 static ObjectPair CompileGlobalEval(Isolate* isolate,
8309 Handle<String> source, 8338 Handle<String> source,
8310 Handle<Object> receiver, 8339 Handle<Object> receiver,
8311 StrictModeFlag strict_mode) { 8340 StrictModeFlag strict_mode) {
8341 Handle<Context> context = Handle<Context>(isolate->context());
8342 Handle<Context> global_context = Handle<Context>(context->global_context());
8343
8344 // Check if global context allows code generation from
8345 // strings. Throw an exception if it doesn't.
8346 if (!CodeGenerationFromStringsAllowed(isolate, global_context)) {
8347 isolate->Throw(*isolate->factory()->NewError(
8348 "code_gen_from_strings", HandleVector<Object>(NULL, 0)));
8349 return MakePair(Failure::Exception(), NULL);
8350 }
8351
8312 // Deal with a normal eval call with a string argument. Compile it 8352 // Deal with a normal eval call with a string argument. Compile it
8313 // and return the compiled function bound in the local context. 8353 // and return the compiled function bound in the local context.
8314 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 8354 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
8315 source, 8355 source,
8316 Handle<Context>(isolate->context()), 8356 Handle<Context>(isolate->context()),
8317 isolate->context()->IsGlobalContext(), 8357 context->IsGlobalContext(),
8318 strict_mode); 8358 strict_mode);
8319 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); 8359 if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
8320 Handle<JSFunction> compiled = 8360 Handle<JSFunction> compiled =
8321 isolate->factory()->NewFunctionFromSharedFunctionInfo( 8361 isolate->factory()->NewFunctionFromSharedFunctionInfo(
8322 shared, Handle<Context>(isolate->context()), NOT_TENURED); 8362 shared, context, NOT_TENURED);
8323 return MakePair(*compiled, *receiver); 8363 return MakePair(*compiled, *receiver);
8324 } 8364 }
8325 8365
8326 8366
8327 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { 8367 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) {
8328 ASSERT(args.length() == 4); 8368 ASSERT(args.length() == 4);
8329 8369
8330 HandleScope scope(isolate); 8370 HandleScope scope(isolate);
8331 Handle<Object> callee = args.at<Object>(0); 8371 Handle<Object> callee = args.at<Object>(0);
8332 Handle<Object> receiver; // Will be overwritten. 8372 Handle<Object> receiver; // Will be overwritten.
(...skipping 3778 matching lines...) Expand 10 before | Expand all | Expand 10 after
12111 } else { 12151 } else {
12112 // Handle last resort GC and make sure to allow future allocations 12152 // Handle last resort GC and make sure to allow future allocations
12113 // to grow the heap without causing GCs (if possible). 12153 // to grow the heap without causing GCs (if possible).
12114 isolate->counters()->gc_last_resort_from_js()->Increment(); 12154 isolate->counters()->gc_last_resort_from_js()->Increment();
12115 isolate->heap()->CollectAllGarbage(false); 12155 isolate->heap()->CollectAllGarbage(false);
12116 } 12156 }
12117 } 12157 }
12118 12158
12119 12159
12120 } } // namespace v8::internal 12160 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/messages.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698