Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 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/ScriptForbiddenScope.h" | |
| 38 #include "platform/TraceEvent.h" | 39 #include "platform/TraceEvent.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. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 { |
| 179 if (ScriptForbiddenScope::isScriptForbidden()) | |
| 180 return v8::Undefined(isolate); | |
|
haraken
2014/10/14 05:55:29
v8::Undefined(isolate) => return v8::Local<v8::Val
dcheng
2014/10/14 06:42:08
Done.
| |
| 178 V8RecursionScope recursionScope(isolate); | 181 V8RecursionScope recursionScope(isolate); |
| 179 result = script->Run(); | 182 result = script->Run(); |
| 180 } | 183 } |
| 181 | 184 |
| 182 if (result.IsEmpty()) | 185 if (result.IsEmpty()) |
| 183 return v8::Local<v8::Value>(); | 186 return v8::Local<v8::Value>(); |
| 184 | 187 |
| 185 crashIfV8IsDead(); | 188 crashIfV8IsDead(); |
| 186 return result; | 189 return result; |
| 187 } | 190 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 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) | 216 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 { | 217 { |
| 215 TRACE_EVENT0("v8", "v8.callFunction"); | 218 TRACE_EVENT0("v8", "v8.callFunction"); |
| 216 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 219 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 217 | 220 |
| 218 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) | 221 if (V8RecursionScope::recursionLevel(isolate) >= kMaxRecursionDepth) |
| 219 return throwStackOverflowExceptionIfNeeded(isolate); | 222 return throwStackOverflowExceptionIfNeeded(isolate); |
| 220 | 223 |
| 221 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 224 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| 222 | 225 |
| 226 if (ScriptForbiddenScope::isScriptForbidden()) | |
| 227 return v8::Undefined(isolate); | |
|
haraken
2014/10/14 05:55:29
v8::Undefined(isolate) => return v8::Local<v8::Val
dcheng
2014/10/14 06:42:08
Done.
| |
| 223 V8RecursionScope recursionScope(isolate); | 228 V8RecursionScope recursionScope(isolate); |
| 224 v8::Local<v8::Value> result = function->Call(receiver, argc, args); | 229 v8::Local<v8::Value> result = function->Call(receiver, argc, args); |
| 225 crashIfV8IsDead(); | 230 crashIfV8IsDead(); |
| 226 return result; | 231 return result; |
| 227 } | 232 } |
| 228 | 233 |
| 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) | 234 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 { | 235 { |
| 231 TRACE_EVENT0("v8", "v8.callFunction"); | 236 TRACE_EVENT0("v8", "v8.callFunction"); |
| 232 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 237 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 V8RecursionScope::MicrotaskSuppression scope(isolate); | 271 V8RecursionScope::MicrotaskSuppression scope(isolate); |
| 267 v8::Local<v8::Object> result = function->NewInstance(argc, argv); | 272 v8::Local<v8::Object> result = function->NewInstance(argc, argv); |
| 268 crashIfV8IsDead(); | 273 crashIfV8IsDead(); |
| 269 return result; | 274 return result; |
| 270 } | 275 } |
| 271 | 276 |
| 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[]) | 277 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 { | 278 { |
| 274 TRACE_EVENT0("v8", "v8.newInstance"); | 279 TRACE_EVENT0("v8", "v8.newInstance"); |
| 275 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 280 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
| 281 if (ScriptForbiddenScope::isScriptForbidden()) | |
| 282 return v8::Local<v8::Object>(); | |
| 276 V8RecursionScope scope(isolate); | 283 V8RecursionScope scope(isolate); |
| 277 v8::Local<v8::Object> result = function->NewInstance(argc, argv); | 284 v8::Local<v8::Object> result = function->NewInstance(argc, argv); |
| 278 crashIfV8IsDead(); | 285 crashIfV8IsDead(); |
| 279 return result; | 286 return result; |
| 280 } | 287 } |
| 281 | 288 |
| 282 unsigned V8ScriptRunner::tagForParserCache() | 289 unsigned V8ScriptRunner::tagForParserCache() |
| 283 { | 290 { |
| 284 return StringHash::hash(v8::V8::GetVersion()) * 2; | 291 return StringHash::hash(v8::V8::GetVersion()) * 2; |
| 285 } | 292 } |
| 286 | 293 |
| 287 unsigned V8ScriptRunner::tagForCodeCache() | 294 unsigned V8ScriptRunner::tagForCodeCache() |
| 288 { | 295 { |
| 289 return StringHash::hash(v8::V8::GetVersion()) * 2 + 1; | 296 return StringHash::hash(v8::V8::GetVersion()) * 2 + 1; |
| 290 } | 297 } |
| 291 | 298 |
| 292 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |