OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); | 258 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); |
259 ScriptOriginOptions options(script->origin_options()); | 259 ScriptOriginOptions options(script->origin_options()); |
260 v8::ScriptOrigin origin( | 260 v8::ScriptOrigin origin( |
261 Utils::ToLocal(scriptName), | 261 Utils::ToLocal(scriptName), |
262 v8::Integer::New(v8_isolate, script->line_offset()), | 262 v8::Integer::New(v8_isolate, script->line_offset()), |
263 v8::Integer::New(v8_isolate, script->column_offset()), | 263 v8::Integer::New(v8_isolate, script->column_offset()), |
264 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()), | 264 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()), |
265 v8::Integer::New(v8_isolate, script->id()), | 265 v8::Integer::New(v8_isolate, script->id()), |
266 Utils::ToLocal(source_map_url), | 266 Utils::ToLocal(source_map_url), |
267 v8::Boolean::New(v8_isolate, options.IsOpaque()), | 267 v8::Boolean::New(v8_isolate, options.IsOpaque()), |
268 v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM)); | 268 v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM), |
| 269 v8::Boolean::New(v8_isolate, options.IsModule())); |
269 return origin; | 270 return origin; |
270 } | 271 } |
271 | 272 |
272 | 273 |
273 // --- E x c e p t i o n B e h a v i o r --- | 274 // --- E x c e p t i o n B e h a v i o r --- |
274 | 275 |
275 | 276 |
276 void i::FatalProcessOutOfMemory(const char* location) { | 277 void i::FatalProcessOutOfMemory(const char* location) { |
277 i::V8::FatalProcessOutOfMemory(location, false); | 278 i::V8::FatalProcessOutOfMemory(location, false); |
278 } | 279 } |
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 // It's an API error to call Evaluate before Instantiate. | 2076 // It's an API error to call Evaluate before Instantiate. |
2076 CHECK(self->instantiated()); | 2077 CHECK(self->instantiated()); |
2077 | 2078 |
2078 Local<Value> result; | 2079 Local<Value> result; |
2079 has_pending_exception = !ToLocal(i::Module::Evaluate(self), &result); | 2080 has_pending_exception = !ToLocal(i::Module::Evaluate(self), &result); |
2080 RETURN_ON_FAILED_EXECUTION(Value); | 2081 RETURN_ON_FAILED_EXECUTION(Value); |
2081 RETURN_ESCAPED(result); | 2082 RETURN_ESCAPED(result); |
2082 } | 2083 } |
2083 | 2084 |
2084 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal( | 2085 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal( |
2085 Isolate* v8_isolate, Source* source, CompileOptions options, | 2086 Isolate* v8_isolate, Source* source, CompileOptions options) { |
2086 bool is_module) { | |
2087 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 2087 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
2088 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound, | 2088 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound, |
2089 UnboundScript); | 2089 UnboundScript); |
2090 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); | 2090 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); |
2091 | 2091 |
2092 // Don't try to produce any kind of cache when the debugger is loaded. | 2092 // Don't try to produce any kind of cache when the debugger is loaded. |
2093 if (isolate->debug()->is_loaded() && | 2093 if (isolate->debug()->is_loaded() && |
2094 (options == kProduceParserCache || options == kProduceCodeCache)) { | 2094 (options == kProduceParserCache || options == kProduceCodeCache)) { |
2095 options = kNoCompileOptions; | 2095 options = kNoCompileOptions; |
2096 } | 2096 } |
(...skipping 24 matching lines...) Expand all Loading... |
2121 if (!source->resource_column_offset.IsEmpty()) { | 2121 if (!source->resource_column_offset.IsEmpty()) { |
2122 column_offset = | 2122 column_offset = |
2123 static_cast<int>(source->resource_column_offset->Value()); | 2123 static_cast<int>(source->resource_column_offset->Value()); |
2124 } | 2124 } |
2125 if (!source->source_map_url.IsEmpty()) { | 2125 if (!source->source_map_url.IsEmpty()) { |
2126 source_map_url = Utils::OpenHandle(*(source->source_map_url)); | 2126 source_map_url = Utils::OpenHandle(*(source->source_map_url)); |
2127 } | 2127 } |
2128 result = i::Compiler::GetSharedFunctionInfoForScript( | 2128 result = i::Compiler::GetSharedFunctionInfoForScript( |
2129 str, name_obj, line_offset, column_offset, source->resource_options, | 2129 str, name_obj, line_offset, column_offset, source->resource_options, |
2130 source_map_url, isolate->native_context(), NULL, &script_data, options, | 2130 source_map_url, isolate->native_context(), NULL, &script_data, options, |
2131 i::NOT_NATIVES_CODE, is_module); | 2131 i::NOT_NATIVES_CODE); |
2132 has_pending_exception = result.is_null(); | 2132 has_pending_exception = result.is_null(); |
2133 if (has_pending_exception && script_data != NULL) { | 2133 if (has_pending_exception && script_data != NULL) { |
2134 // This case won't happen during normal operation; we have compiled | 2134 // This case won't happen during normal operation; we have compiled |
2135 // successfully and produced cached data, and but the second compilation | 2135 // successfully and produced cached data, and but the second compilation |
2136 // of the same source code fails. | 2136 // of the same source code fails. |
2137 delete script_data; | 2137 delete script_data; |
2138 script_data = NULL; | 2138 script_data = NULL; |
2139 } | 2139 } |
2140 RETURN_ON_FAILED_EXECUTION(UnboundScript); | 2140 RETURN_ON_FAILED_EXECUTION(UnboundScript); |
2141 | 2141 |
2142 if ((options == kProduceParserCache || options == kProduceCodeCache) && | 2142 if ((options == kProduceParserCache || options == kProduceCodeCache) && |
2143 script_data != NULL) { | 2143 script_data != NULL) { |
2144 // script_data now contains the data that was generated. source will | 2144 // script_data now contains the data that was generated. source will |
2145 // take the ownership. | 2145 // take the ownership. |
2146 source->cached_data = new CachedData( | 2146 source->cached_data = new CachedData( |
2147 script_data->data(), script_data->length(), CachedData::BufferOwned); | 2147 script_data->data(), script_data->length(), CachedData::BufferOwned); |
2148 script_data->ReleaseDataOwnership(); | 2148 script_data->ReleaseDataOwnership(); |
2149 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) { | 2149 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) { |
2150 source->cached_data->rejected = script_data->rejected(); | 2150 source->cached_data->rejected = script_data->rejected(); |
2151 } | 2151 } |
2152 delete script_data; | 2152 delete script_data; |
2153 } | 2153 } |
2154 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); | 2154 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); |
2155 } | 2155 } |
2156 | 2156 |
2157 | 2157 |
2158 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript( | 2158 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript( |
2159 Isolate* v8_isolate, Source* source, CompileOptions options) { | 2159 Isolate* v8_isolate, Source* source, CompileOptions options) { |
2160 return CompileUnboundInternal(v8_isolate, source, options, false); | 2160 DCHECK(!source->GetResourceOptions().IsModule()); |
| 2161 return CompileUnboundInternal(v8_isolate, source, options); |
2161 } | 2162 } |
2162 | 2163 |
2163 | 2164 |
2164 Local<UnboundScript> ScriptCompiler::CompileUnbound(Isolate* v8_isolate, | 2165 Local<UnboundScript> ScriptCompiler::CompileUnbound(Isolate* v8_isolate, |
2165 Source* source, | 2166 Source* source, |
2166 CompileOptions options) { | 2167 CompileOptions options) { |
2167 RETURN_TO_LOCAL_UNCHECKED( | 2168 DCHECK(!source->GetResourceOptions().IsModule()); |
2168 CompileUnboundInternal(v8_isolate, source, options, false), | 2169 RETURN_TO_LOCAL_UNCHECKED(CompileUnboundInternal(v8_isolate, source, options), |
2169 UnboundScript); | 2170 UnboundScript); |
2170 } | 2171 } |
2171 | 2172 |
2172 | 2173 |
2173 MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context, | 2174 MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context, |
2174 Source* source, | 2175 Source* source, |
2175 CompileOptions options) { | 2176 CompileOptions options) { |
| 2177 DCHECK(!source->GetResourceOptions().IsModule()); |
2176 auto isolate = context->GetIsolate(); | 2178 auto isolate = context->GetIsolate(); |
2177 auto maybe = CompileUnboundInternal(isolate, source, options, false); | 2179 auto maybe = CompileUnboundInternal(isolate, source, options); |
2178 Local<UnboundScript> result; | 2180 Local<UnboundScript> result; |
2179 if (!maybe.ToLocal(&result)) return MaybeLocal<Script>(); | 2181 if (!maybe.ToLocal(&result)) return MaybeLocal<Script>(); |
2180 v8::Context::Scope scope(context); | 2182 v8::Context::Scope scope(context); |
2181 return result->BindToCurrentContext(); | 2183 return result->BindToCurrentContext(); |
2182 } | 2184 } |
2183 | 2185 |
2184 | 2186 |
2185 Local<Script> ScriptCompiler::Compile( | 2187 Local<Script> ScriptCompiler::Compile( |
2186 Isolate* v8_isolate, | 2188 Isolate* v8_isolate, |
2187 Source* source, | 2189 Source* source, |
2188 CompileOptions options) { | 2190 CompileOptions options) { |
2189 auto context = v8_isolate->GetCurrentContext(); | 2191 auto context = v8_isolate->GetCurrentContext(); |
2190 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); | 2192 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); |
2191 } | 2193 } |
2192 | 2194 |
2193 MaybeLocal<Module> ScriptCompiler::CompileModule(Isolate* isolate, | 2195 MaybeLocal<Module> ScriptCompiler::CompileModule(Isolate* isolate, |
2194 Source* source) { | 2196 Source* source) { |
2195 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2197 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
2196 | 2198 |
2197 auto maybe = CompileUnboundInternal(isolate, source, kNoCompileOptions, true); | 2199 DCHECK(source->GetResourceOptions().IsModule()); |
| 2200 auto maybe = CompileUnboundInternal(isolate, source, kNoCompileOptions); |
2198 Local<UnboundScript> unbound; | 2201 Local<UnboundScript> unbound; |
2199 if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>(); | 2202 if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>(); |
2200 | 2203 |
2201 i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound); | 2204 i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound); |
2202 return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared)); | 2205 return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared)); |
2203 } | 2206 } |
2204 | 2207 |
2205 | 2208 |
2206 class IsIdentifierHelper { | 2209 class IsIdentifierHelper { |
2207 public: | 2210 public: |
(...skipping 7055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9263 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9266 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
9264 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); | 9267 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); |
9265 i::ScriptData* script_data = NULL; | 9268 i::ScriptData* script_data = NULL; |
9266 i::Handle<i::String> str = Utils::OpenHandle(*source); | 9269 i::Handle<i::String> str = Utils::OpenHandle(*source); |
9267 i::Handle<i::SharedFunctionInfo> result; | 9270 i::Handle<i::SharedFunctionInfo> result; |
9268 { | 9271 { |
9269 ScriptOriginOptions origin_options; | 9272 ScriptOriginOptions origin_options; |
9270 result = i::Compiler::GetSharedFunctionInfoForScript( | 9273 result = i::Compiler::GetSharedFunctionInfoForScript( |
9271 str, i::Handle<i::Object>(), 0, 0, origin_options, | 9274 str, i::Handle<i::Object>(), 0, 0, origin_options, |
9272 i::Handle<i::Object>(), isolate->native_context(), NULL, &script_data, | 9275 i::Handle<i::Object>(), isolate->native_context(), NULL, &script_data, |
9273 ScriptCompiler::kNoCompileOptions, i::INSPECTOR_CODE, false); | 9276 ScriptCompiler::kNoCompileOptions, i::INSPECTOR_CODE); |
9274 has_pending_exception = result.is_null(); | 9277 has_pending_exception = result.is_null(); |
9275 RETURN_ON_FAILED_EXECUTION(UnboundScript); | 9278 RETURN_ON_FAILED_EXECUTION(UnboundScript); |
9276 } | 9279 } |
9277 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); | 9280 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); |
9278 } | 9281 } |
9279 | 9282 |
9280 Local<String> CpuProfileNode::GetFunctionName() const { | 9283 Local<String> CpuProfileNode::GetFunctionName() const { |
9281 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); | 9284 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
9282 i::Isolate* isolate = node->isolate(); | 9285 i::Isolate* isolate = node->isolate(); |
9283 const i::CodeEntry* entry = node->entry(); | 9286 const i::CodeEntry* entry = node->entry(); |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9957 Address callback_address = | 9960 Address callback_address = |
9958 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9961 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9959 VMState<EXTERNAL> state(isolate); | 9962 VMState<EXTERNAL> state(isolate); |
9960 ExternalCallbackScope call_scope(isolate, callback_address); | 9963 ExternalCallbackScope call_scope(isolate, callback_address); |
9961 callback(info); | 9964 callback(info); |
9962 } | 9965 } |
9963 | 9966 |
9964 | 9967 |
9965 } // namespace internal | 9968 } // namespace internal |
9966 } // namespace v8 | 9969 } // namespace v8 |
OLD | NEW |