| 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/ExecutionContext.h" | 32 #include "core/dom/ExecutionContext.h" |
| 33 #include "core/fetch/CachedMetadata.h" | 33 #include "core/fetch/CachedMetadata.h" |
| 34 #include "core/fetch/ScriptResource.h" | 34 #include "core/fetch/ScriptResource.h" |
| 35 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 PassOwnPtr<v8::ScriptData> V8ScriptRunner::precompileScript(v8::Handle<v8::Strin
g> code, ScriptResource* resource) | 39 PassOwnPtr<v8::ScriptData> V8ScriptRunner::precompileScript(v8::Handle<v8::Strin
g> code, ScriptResource* resource) |
| 40 { | 40 { |
| 41 TRACE_EVENT0("v8", "v8.compile"); | 41 TRACE_EVENT0("v8", "v8.compile"); |
| 42 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Compile"); | 42 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Compile"); |
| 43 // A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from | 43 // A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from |
| 44 // the ScriptResource. If the format changes, this ID should be changed too. | 44 // the ScriptResource. If the format changes, this ID should be changed too. |
| 45 static const unsigned dataTypeID = 0xECC13BD7; | 45 static const unsigned dataTypeID = 0xECC13BD7; |
| 46 | 46 |
| 47 // Very small scripts are not worth the effort to preparse. | 47 // Very small scripts are not worth the effort to preparse. |
| 48 static const int minPreparseLength = 1024; | 48 static const int minPreparseLength = 1024; |
| 49 | 49 |
| 50 if (!resource || code->Length() < minPreparseLength) | 50 if (!resource || code->Length() < minPreparseLength) |
| 51 return nullptr; | 51 return nullptr; |
| 52 | 52 |
| 53 CachedMetadata* cachedMetadata = resource->cachedMetadata(dataTypeID); | 53 CachedMetadata* cachedMetadata = resource->cachedMetadata(dataTypeID); |
| 54 if (cachedMetadata) | 54 if (cachedMetadata) |
| 55 return adoptPtr(v8::ScriptData::New(cachedMetadata->data(), cachedMetada
ta->size())); | 55 return adoptPtr(v8::ScriptData::New(cachedMetadata->data(), cachedMetada
ta->size())); |
| 56 | 56 |
| 57 OwnPtr<v8::ScriptData> scriptData = adoptPtr(v8::ScriptData::PreCompile(code
)); | 57 OwnPtr<v8::ScriptData> scriptData = adoptPtr(v8::ScriptData::PreCompile(code
)); |
| 58 if (!scriptData) | 58 if (!scriptData) |
| 59 return nullptr; | 59 return nullptr; |
| 60 | 60 |
| 61 resource->setCachedMetadata(dataTypeID, scriptData->Data(), scriptData->Leng
th()); | 61 resource->setCachedMetadata(dataTypeID, scriptData->Data(), scriptData->Leng
th()); |
| 62 | 62 |
| 63 return scriptData.release(); | 63 return scriptData.release(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 v8::Local<v8::Script> V8ScriptRunner::compileScript(v8::Handle<v8::String> code,
const String& fileName, const TextPosition& scriptStartPosition, v8::ScriptData
* scriptData, v8::Isolate* isolate, AccessControlStatus corsStatus) | 66 v8::Local<v8::Script> V8ScriptRunner::compileScript(v8::Handle<v8::String> code,
const String& fileName, const TextPosition& scriptStartPosition, v8::ScriptData
* scriptData, v8::Isolate* isolate, AccessControlStatus corsStatus) |
| 67 { | 67 { |
| 68 TRACE_EVENT0("v8", "v8.compile"); | 68 TRACE_EVENT0("v8", "v8.compile"); |
| 69 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Compile"); | 69 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Compile"); |
| 70 v8::Handle<v8::String> name = v8String(isolate, fileName); | 70 v8::Handle<v8::String> name = v8String(isolate, fileName); |
| 71 v8::Handle<v8::Integer> line = v8::Integer::New(isolate, scriptStartPosition
.m_line.zeroBasedInt()); | 71 v8::Handle<v8::Integer> line = v8::Integer::New(isolate, scriptStartPosition
.m_line.zeroBasedInt()); |
| 72 v8::Handle<v8::Integer> column = v8::Integer::New(isolate, scriptStartPositi
on.m_column.zeroBasedInt()); | 72 v8::Handle<v8::Integer> column = v8::Integer::New(isolate, scriptStartPositi
on.m_column.zeroBasedInt()); |
| 73 v8::Handle<v8::Boolean> isSharedCrossOrigin = corsStatus == SharableCrossOri
gin ? v8::True(isolate) : v8::False(isolate); | 73 v8::Handle<v8::Boolean> isSharedCrossOrigin = corsStatus == SharableCrossOri
gin ? v8::True(isolate) : v8::False(isolate); |
| 74 v8::ScriptOrigin origin(name, line, column, isSharedCrossOrigin); | 74 v8::ScriptOrigin origin(name, line, column, isSharedCrossOrigin); |
| 75 return v8::Script::Compile(code, &origin, scriptData); | 75 return v8::Script::Compile(code, &origin, scriptData); |
| 76 } | 76 } |
| 77 | 77 |
| 78 v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Handle<v8::Script> sc
ript, ExecutionContext* context, v8::Isolate* isolate) | 78 v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Handle<v8::Script> sc
ript, ExecutionContext* context, v8::Isolate* isolate) |
| 79 { | 79 { |
| 80 TRACE_EVENT0("v8", "v8.run"); | 80 TRACE_EVENT0("v8", "v8.run"); |
| 81 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 81 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 82 if (script.IsEmpty()) | 82 if (script.IsEmpty()) |
| 83 return v8::Local<v8::Value>(); | 83 return v8::Local<v8::Value>(); |
| 84 | 84 |
| 85 if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth) | 85 if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth) |
| 86 return handleMaxRecursionDepthExceeded(isolate); | 86 return handleMaxRecursionDepthExceeded(isolate); |
| 87 | 87 |
| 88 if (handleOutOfMemory()) | 88 if (handleOutOfMemory()) |
| 89 return v8::Local<v8::Value>(); | 89 return v8::Local<v8::Value>(); |
| 90 | 90 |
| 91 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 91 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 if (result.IsEmpty()) | 103 if (result.IsEmpty()) |
| 104 return v8::Local<v8::Value>(); | 104 return v8::Local<v8::Value>(); |
| 105 | 105 |
| 106 crashIfV8IsDead(); | 106 crashIfV8IsDead(); |
| 107 return result; | 107 return result; |
| 108 } | 108 } |
| 109 | 109 |
| 110 v8::Local<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle<v8::
String> source, v8::Isolate* isolate, const String& fileName, const TextPosition
& scriptStartPosition, v8::ScriptData* scriptData) | 110 v8::Local<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle<v8::
String> source, v8::Isolate* isolate, const String& fileName, const TextPosition
& scriptStartPosition, v8::ScriptData* scriptData) |
| 111 { | 111 { |
| 112 TRACE_EVENT0("v8", "v8.run"); | 112 TRACE_EVENT0("v8", "v8.run"); |
| 113 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 113 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 114 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, fileNa
me, scriptStartPosition, scriptData, isolate); | 114 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, fileNa
me, scriptStartPosition, scriptData, isolate); |
| 115 if (script.IsEmpty()) | 115 if (script.IsEmpty()) |
| 116 return v8::Local<v8::Value>(); | 116 return v8::Local<v8::Value>(); |
| 117 | 117 |
| 118 V8RecursionScope::MicrotaskSuppression recursionScope; | 118 V8RecursionScope::MicrotaskSuppression recursionScope; |
| 119 v8::Local<v8::Value> result = script->Run(); | 119 v8::Local<v8::Value> result = script->Run(); |
| 120 crashIfV8IsDead(); | 120 crashIfV8IsDead(); |
| 121 return result; | 121 return result; |
| 122 } | 122 } |
| 123 | 123 |
| 124 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> info[], v8::Isolate* isolate) | 124 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> info[], v8::Isolate* isolate) |
| 125 { | 125 { |
| 126 TRACE_EVENT0("v8", "v8.callFunction"); | 126 TRACE_EVENT0("v8", "v8.callFunction"); |
| 127 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 127 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 128 | 128 |
| 129 if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth) | 129 if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth) |
| 130 return handleMaxRecursionDepthExceeded(isolate); | 130 return handleMaxRecursionDepthExceeded(isolate); |
| 131 | 131 |
| 132 RELEASE_ASSERT(!context->isIteratingOverObservers()); | 132 RELEASE_ASSERT(!context->isIteratingOverObservers()); |
| 133 | 133 |
| 134 V8RecursionScope recursionScope(context); | 134 V8RecursionScope recursionScope(context); |
| 135 v8::Local<v8::Value> result = function->Call(receiver, argc, info); | 135 v8::Local<v8::Value> result = function->Call(receiver, argc, info); |
| 136 crashIfV8IsDead(); | 136 crashIfV8IsDead(); |
| 137 return result; | 137 return result; |
| 138 } | 138 } |
| 139 | 139 |
| 140 v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio
n> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> inf
o[], v8::Isolate* isolate) | 140 v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio
n> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> inf
o[], v8::Isolate* isolate) |
| 141 { | 141 { |
| 142 TRACE_EVENT0("v8", "v8.callFunction"); | 142 TRACE_EVENT0("v8", "v8.callFunction"); |
| 143 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 143 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 144 V8RecursionScope::MicrotaskSuppression recursionScope; | 144 V8RecursionScope::MicrotaskSuppression recursionScope; |
| 145 v8::Local<v8::Value> result = function->Call(receiver, argc, info); | 145 v8::Local<v8::Value> result = function->Call(receiver, argc, info); |
| 146 crashIfV8IsDead(); | 146 crashIfV8IsDead(); |
| 147 return result; | 147 return result; |
| 148 } | 148 } |
| 149 | 149 |
| 150 v8::Local<v8::Value> V8ScriptRunner::callAsFunction(v8::Handle<v8::Object> objec
t, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) | 150 v8::Local<v8::Value> V8ScriptRunner::callAsFunction(v8::Handle<v8::Object> objec
t, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) |
| 151 { | 151 { |
| 152 TRACE_EVENT0("v8", "v8.callFunction"); | 152 TRACE_EVENT0("v8", "v8.callFunction"); |
| 153 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 153 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 154 | 154 |
| 155 V8RecursionScope::MicrotaskSuppression recursionScope; | 155 V8RecursionScope::MicrotaskSuppression recursionScope; |
| 156 v8::Local<v8::Value> result = object->CallAsFunction(receiver, argc, info); | 156 v8::Local<v8::Value> result = object->CallAsFunction(receiver, argc, info); |
| 157 crashIfV8IsDead(); | 157 crashIfV8IsDead(); |
| 158 return result; | 158 return result; |
| 159 } | 159 } |
| 160 | 160 |
| 161 v8::Local<v8::Value> V8ScriptRunner::callAsConstructor(v8::Handle<v8::Object> ob
ject, int argc, v8::Handle<v8::Value> info[]) | 161 v8::Local<v8::Value> V8ScriptRunner::callAsConstructor(v8::Handle<v8::Object> ob
ject, int argc, v8::Handle<v8::Value> info[]) |
| 162 { | 162 { |
| 163 TRACE_EVENT0("v8", "v8.callFunction"); | 163 TRACE_EVENT0("v8", "v8.callFunction"); |
| 164 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 164 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 165 | 165 |
| 166 V8RecursionScope::MicrotaskSuppression recursionScope; | 166 V8RecursionScope::MicrotaskSuppression recursionScope; |
| 167 v8::Local<v8::Value> result = object->CallAsConstructor(argc, info); | 167 v8::Local<v8::Value> result = object->CallAsConstructor(argc, info); |
| 168 crashIfV8IsDead(); | 168 crashIfV8IsDead(); |
| 169 return result; | 169 return result; |
| 170 } | 170 } |
| 171 | 171 |
| 172 v8::Local<v8::Object> V8ScriptRunner::instantiateObject(v8::Handle<v8::ObjectTem
plate> objectTemplate) | 172 v8::Local<v8::Object> V8ScriptRunner::instantiateObject(v8::Handle<v8::ObjectTem
plate> objectTemplate) |
| 173 { | 173 { |
| 174 TRACE_EVENT0("v8", "v8.newInstance"); | 174 TRACE_EVENT0("v8", "v8.newInstance"); |
| 175 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 175 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 176 | 176 |
| 177 V8RecursionScope::MicrotaskSuppression scope; | 177 V8RecursionScope::MicrotaskSuppression scope; |
| 178 v8::Local<v8::Object> result = objectTemplate->NewInstance(); | 178 v8::Local<v8::Object> result = objectTemplate->NewInstance(); |
| 179 crashIfV8IsDead(); | 179 crashIfV8IsDead(); |
| 180 return result; | 180 return result; |
| 181 } | 181 } |
| 182 | 182 |
| 183 v8::Local<v8::Object> V8ScriptRunner::instantiateObject(v8::Handle<v8::Function>
function, int argc, v8::Handle<v8::Value> argv[]) | 183 v8::Local<v8::Object> V8ScriptRunner::instantiateObject(v8::Handle<v8::Function>
function, int argc, v8::Handle<v8::Value> argv[]) |
| 184 { | 184 { |
| 185 TRACE_EVENT0("v8", "v8.newInstance"); | 185 TRACE_EVENT0("v8", "v8.newInstance"); |
| 186 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 186 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 187 | 187 |
| 188 V8RecursionScope::MicrotaskSuppression scope; | 188 V8RecursionScope::MicrotaskSuppression scope; |
| 189 v8::Local<v8::Object> result = function->NewInstance(argc, argv); | 189 v8::Local<v8::Object> result = function->NewInstance(argc, argv); |
| 190 crashIfV8IsDead(); | 190 crashIfV8IsDead(); |
| 191 return result; | 191 return result; |
| 192 } | 192 } |
| 193 | 193 |
| 194 v8::Local<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Handle<v8:
:Function> function, ExecutionContext* context, int argc, v8::Handle<v8::Value>
argv[]) | 194 v8::Local<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Handle<v8:
:Function> function, ExecutionContext* context, int argc, v8::Handle<v8::Value>
argv[]) |
| 195 { | 195 { |
| 196 TRACE_EVENT0("v8", "v8.newInstance"); | 196 TRACE_EVENT0("v8", "v8.newInstance"); |
| 197 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution"); | 197 TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Execution"); |
| 198 V8RecursionScope scope(context); | 198 V8RecursionScope scope(context); |
| 199 v8::Local<v8::Object> result = function->NewInstance(argc, argv); | 199 v8::Local<v8::Object> result = function->NewInstance(argc, argv); |
| 200 crashIfV8IsDead(); | 200 crashIfV8IsDead(); |
| 201 return result; | 201 return result; |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace WebCore | 204 } // namespace WebCore |
| OLD | NEW |