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

Side by Side Diff: Source/bindings/core/v8/V8ScriptRunner.cpp

Issue 648423003: Enforce ScriptForbiddenScope and make it non-fatal. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Getting ambitious Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 18 matching lines...) Expand all
29 #include "bindings/core/v8/ScriptSourceCode.h" 29 #include "bindings/core/v8/ScriptSourceCode.h"
30 #include "bindings/core/v8/ScriptStreamer.h" 30 #include "bindings/core/v8/ScriptStreamer.h"
31 #include "bindings/core/v8/V8Binding.h" 31 #include "bindings/core/v8/V8Binding.h"
32 #include "bindings/core/v8/V8GCController.h" 32 #include "bindings/core/v8/V8GCController.h"
33 #include "bindings/core/v8/V8RecursionScope.h" 33 #include "bindings/core/v8/V8RecursionScope.h"
34 #include "bindings/core/v8/V8ThrowException.h" 34 #include "bindings/core/v8/V8ThrowException.h"
35 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
36 #include "core/fetch/CachedMetadata.h" 36 #include "core/fetch/CachedMetadata.h"
37 #include "core/fetch/ScriptResource.h" 37 #include "core/fetch/ScriptResource.h"
38 #include "platform/TraceEvent.h" 38 #include "platform/TraceEvent.h"
39 #include "wtf/OwnPtr.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 namespace { 43 namespace {
43 44
44 // In order to make sure all pending messages to be processed in 45 // In order to make sure all pending messages to be processed in
45 // v8::Function::Call, we don't call handleMaxRecursionDepthExceeded 46 // v8::Function::Call, we don't call handleMaxRecursionDepthExceeded
46 // directly. Instead, we create a v8::Function of 47 // directly. Instead, we create a v8::Function of
47 // throwStackOverflowException and call it. 48 // throwStackOverflowException and call it.
48 void throwStackOverflowException(const v8::FunctionCallbackInfo<v8::Value>& info ) 49 void throwStackOverflowException(const v8::FunctionCallbackInfo<v8::Value>& info )
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName()))); 169 TRACE_EVENT1("v8", "v8.run", "fileName", TRACE_STR_COPY(*v8::String::Utf8Val ue(script->GetUnboundScript()->GetScriptName())));
169 170
170 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 171 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth)
171 return throwStackOverflowExceptionIfNeeded(isolate); 172 return throwStackOverflowExceptionIfNeeded(isolate);
172 173
173 RELEASE_ASSERT(!context->isIteratingOverObservers()); 174 RELEASE_ASSERT(!context->isIteratingOverObservers());
174 175
175 // Run the script and keep track of the current recursion depth. 176 // Run the script and keep track of the current recursion depth.
176 v8::Local<v8::Value> result; 177 v8::Local<v8::Value> result;
177 { 178 {
178 V8RecursionScope recursionScope(isolate); 179 OwnPtr<V8RecursionScope> recursionScope = V8RecursionScope::create(isola te);
180 if (!recursionScope)
181 return v8::Undefined(isolate);
182
179 result = script->Run(); 183 result = script->Run();
180 } 184 }
181 185
182 if (result.IsEmpty()) 186 if (result.IsEmpty())
183 return v8::Local<v8::Value>(); 187 return v8::Local<v8::Value>();
184 188
185 crashIfV8IsDead(); 189 crashIfV8IsDead();
186 return result; 190 return result;
187 } 191 }
188 192
(...skipping 24 matching lines...) Expand all
213 v8::Local<v8::Value> V8ScriptRunner::callFunction(v8::Handle<v8::Function> funct ion, ExecutionContext* context, v8::Handle<v8::Value> receiver, int argc, v8::Ha ndle<v8::Value> args[], v8::Isolate* isolate) 217 v8::Local<v8::Value> V8ScriptRunner::callFunction(v8::Handle<v8::Function> funct ion, ExecutionContext* context, v8::Handle<v8::Value> receiver, int argc, v8::Ha ndle<v8::Value> args[], v8::Isolate* isolate)
214 { 218 {
215 TRACE_EVENT0("v8", "v8.callFunction"); 219 TRACE_EVENT0("v8", "v8.callFunction");
216 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 220 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
217 221
218 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) 222 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth)
219 return throwStackOverflowExceptionIfNeeded(isolate); 223 return throwStackOverflowExceptionIfNeeded(isolate);
220 224
221 RELEASE_ASSERT(!context->isIteratingOverObservers()); 225 RELEASE_ASSERT(!context->isIteratingOverObservers());
222 226
223 V8RecursionScope recursionScope(isolate); 227 OwnPtr<V8RecursionScope> recursionScope = V8RecursionScope::create(isolate);
228 if (!recursionScope)
229 return v8::Undefined(isolate);
224 v8::Local<v8::Value> result = function->Call(receiver, argc, args); 230 v8::Local<v8::Value> result = function->Call(receiver, argc, args);
225 crashIfV8IsDead(); 231 crashIfV8IsDead();
226 return result; 232 return result;
227 } 233 }
228 234
229 v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio n> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> arg s[], v8::Isolate* isolate) 235 v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio n> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> arg s[], v8::Isolate* isolate)
230 { 236 {
231 TRACE_EVENT0("v8", "v8.callFunction"); 237 TRACE_EVENT0("v8", "v8.callFunction");
232 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 238 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
233 V8RecursionScope::MicrotaskSuppression recursionScope(isolate); 239 V8RecursionScope::MicrotaskSuppression recursionScope(isolate);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 V8RecursionScope::MicrotaskSuppression scope(isolate); 272 V8RecursionScope::MicrotaskSuppression scope(isolate);
267 v8::Local<v8::Object> result = function->NewInstance(argc, argv); 273 v8::Local<v8::Object> result = function->NewInstance(argc, argv);
268 crashIfV8IsDead(); 274 crashIfV8IsDead();
269 return result; 275 return result;
270 } 276 }
271 277
272 v8::Local<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Isolate* i solate, v8::Handle<v8::Function> function, ExecutionContext* context, int argc, v8::Handle<v8::Value> argv[]) 278 v8::Local<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Isolate* i solate, v8::Handle<v8::Function> function, ExecutionContext* context, int argc, v8::Handle<v8::Value> argv[])
273 { 279 {
274 TRACE_EVENT0("v8", "v8.newInstance"); 280 TRACE_EVENT0("v8", "v8.newInstance");
275 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); 281 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
276 V8RecursionScope scope(isolate); 282 OwnPtr<V8RecursionScope> scope = V8RecursionScope::create(isolate);
283 if (!scope)
284 return v8::Local<v8::Object>();
277 v8::Local<v8::Object> result = function->NewInstance(argc, argv); 285 v8::Local<v8::Object> result = function->NewInstance(argc, argv);
278 crashIfV8IsDead(); 286 crashIfV8IsDead();
279 return result; 287 return result;
280 } 288 }
281 289
282 unsigned V8ScriptRunner::tagForParserCache() 290 unsigned V8ScriptRunner::tagForParserCache()
283 { 291 {
284 return StringHash::hash(v8::V8::GetVersion()) * 2; 292 return StringHash::hash(v8::V8::GetVersion()) * 2;
285 } 293 }
286 294
287 unsigned V8ScriptRunner::tagForCodeCache() 295 unsigned V8ScriptRunner::tagForCodeCache()
288 { 296 {
289 return StringHash::hash(v8::V8::GetVersion()) * 2 + 1; 297 return StringHash::hash(v8::V8::GetVersion()) * 2 + 1;
290 } 298 }
291 299
292 } // namespace blink 300 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698