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/api.cc

Issue 2611643002: [modules] Add an IsModule flag to ScriptOriginOptions. (Closed)
Patch Set: Remove convenience function from API. Created 3 years, 11 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
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.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 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); 276 reinterpret_cast<v8::Isolate*>(script->GetIsolate());
277 ScriptOriginOptions options(script->origin_options()); 277 ScriptOriginOptions options(script->origin_options());
278 v8::ScriptOrigin origin( 278 v8::ScriptOrigin origin(
279 Utils::ToLocal(scriptName), 279 Utils::ToLocal(scriptName),
280 v8::Integer::New(v8_isolate, script->line_offset()), 280 v8::Integer::New(v8_isolate, script->line_offset()),
281 v8::Integer::New(v8_isolate, script->column_offset()), 281 v8::Integer::New(v8_isolate, script->column_offset()),
282 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()), 282 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()),
283 v8::Integer::New(v8_isolate, script->id()), 283 v8::Integer::New(v8_isolate, script->id()),
284 Utils::ToLocal(source_map_url), 284 Utils::ToLocal(source_map_url),
285 v8::Boolean::New(v8_isolate, options.IsOpaque()), 285 v8::Boolean::New(v8_isolate, options.IsOpaque()),
286 v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM)); 286 v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM),
287 v8::Boolean::New(v8_isolate, options.IsModule()));
287 return origin; 288 return origin;
288 } 289 }
289 290
290 291
291 // --- E x c e p t i o n B e h a v i o r --- 292 // --- E x c e p t i o n B e h a v i o r ---
292 293
293 294
294 void i::FatalProcessOutOfMemory(const char* location) { 295 void i::FatalProcessOutOfMemory(const char* location) {
295 i::V8::FatalProcessOutOfMemory(location, false); 296 i::V8::FatalProcessOutOfMemory(location, false);
296 } 297 }
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 // It's an API error to call Evaluate before Instantiate. 2097 // It's an API error to call Evaluate before Instantiate.
2097 CHECK(self->instantiated()); 2098 CHECK(self->instantiated());
2098 2099
2099 Local<Value> result; 2100 Local<Value> result;
2100 has_pending_exception = !ToLocal(i::Module::Evaluate(self), &result); 2101 has_pending_exception = !ToLocal(i::Module::Evaluate(self), &result);
2101 RETURN_ON_FAILED_EXECUTION(Value); 2102 RETURN_ON_FAILED_EXECUTION(Value);
2102 RETURN_ESCAPED(result); 2103 RETURN_ESCAPED(result);
2103 } 2104 }
2104 2105
2105 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal( 2106 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
2106 Isolate* v8_isolate, Source* source, CompileOptions options, 2107 Isolate* v8_isolate, Source* source, CompileOptions options) {
2107 bool is_module) {
2108 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 2108 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2109 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound, 2109 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound,
2110 UnboundScript); 2110 UnboundScript);
2111 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler"); 2111 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
2112 2112
2113 // Don't try to produce any kind of cache when the debugger is loaded. 2113 // Don't try to produce any kind of cache when the debugger is loaded.
2114 if (isolate->debug()->is_loaded() && 2114 if (isolate->debug()->is_loaded() &&
2115 (options == kProduceParserCache || options == kProduceCodeCache)) { 2115 (options == kProduceParserCache || options == kProduceCodeCache)) {
2116 options = kNoCompileOptions; 2116 options = kNoCompileOptions;
2117 } 2117 }
(...skipping 24 matching lines...) Expand all
2142 if (!source->resource_column_offset.IsEmpty()) { 2142 if (!source->resource_column_offset.IsEmpty()) {
2143 column_offset = 2143 column_offset =
2144 static_cast<int>(source->resource_column_offset->Value()); 2144 static_cast<int>(source->resource_column_offset->Value());
2145 } 2145 }
2146 if (!source->source_map_url.IsEmpty()) { 2146 if (!source->source_map_url.IsEmpty()) {
2147 source_map_url = Utils::OpenHandle(*(source->source_map_url)); 2147 source_map_url = Utils::OpenHandle(*(source->source_map_url));
2148 } 2148 }
2149 result = i::Compiler::GetSharedFunctionInfoForScript( 2149 result = i::Compiler::GetSharedFunctionInfoForScript(
2150 str, name_obj, line_offset, column_offset, source->resource_options, 2150 str, name_obj, line_offset, column_offset, source->resource_options,
2151 source_map_url, isolate->native_context(), NULL, &script_data, options, 2151 source_map_url, isolate->native_context(), NULL, &script_data, options,
2152 i::NOT_NATIVES_CODE, is_module); 2152 i::NOT_NATIVES_CODE);
2153 has_pending_exception = result.is_null(); 2153 has_pending_exception = result.is_null();
2154 if (has_pending_exception && script_data != NULL) { 2154 if (has_pending_exception && script_data != NULL) {
2155 // This case won't happen during normal operation; we have compiled 2155 // This case won't happen during normal operation; we have compiled
2156 // successfully and produced cached data, and but the second compilation 2156 // successfully and produced cached data, and but the second compilation
2157 // of the same source code fails. 2157 // of the same source code fails.
2158 delete script_data; 2158 delete script_data;
2159 script_data = NULL; 2159 script_data = NULL;
2160 } 2160 }
2161 RETURN_ON_FAILED_EXECUTION(UnboundScript); 2161 RETURN_ON_FAILED_EXECUTION(UnboundScript);
2162 2162
2163 if ((options == kProduceParserCache || options == kProduceCodeCache) && 2163 if ((options == kProduceParserCache || options == kProduceCodeCache) &&
2164 script_data != NULL) { 2164 script_data != NULL) {
2165 // script_data now contains the data that was generated. source will 2165 // script_data now contains the data that was generated. source will
2166 // take the ownership. 2166 // take the ownership.
2167 source->cached_data = new CachedData( 2167 source->cached_data = new CachedData(
2168 script_data->data(), script_data->length(), CachedData::BufferOwned); 2168 script_data->data(), script_data->length(), CachedData::BufferOwned);
2169 script_data->ReleaseDataOwnership(); 2169 script_data->ReleaseDataOwnership();
2170 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) { 2170 } else if (options == kConsumeParserCache || options == kConsumeCodeCache) {
2171 source->cached_data->rejected = script_data->rejected(); 2171 source->cached_data->rejected = script_data->rejected();
2172 } 2172 }
2173 delete script_data; 2173 delete script_data;
2174 } 2174 }
2175 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); 2175 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
2176 } 2176 }
2177 2177
2178 2178
2179 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript( 2179 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript(
2180 Isolate* v8_isolate, Source* source, CompileOptions options) { 2180 Isolate* v8_isolate, Source* source, CompileOptions options) {
2181 return CompileUnboundInternal(v8_isolate, source, options, false); 2181 DCHECK(!source->GetResourceOptions().IsModule());
2182 return CompileUnboundInternal(v8_isolate, source, options);
2182 } 2183 }
2183 2184
2184 2185
2185 Local<UnboundScript> ScriptCompiler::CompileUnbound(Isolate* v8_isolate, 2186 Local<UnboundScript> ScriptCompiler::CompileUnbound(Isolate* v8_isolate,
2186 Source* source, 2187 Source* source,
2187 CompileOptions options) { 2188 CompileOptions options) {
2188 RETURN_TO_LOCAL_UNCHECKED( 2189 DCHECK(!source->GetResourceOptions().IsModule());
2189 CompileUnboundInternal(v8_isolate, source, options, false), 2190 RETURN_TO_LOCAL_UNCHECKED(CompileUnboundInternal(v8_isolate, source, options),
2190 UnboundScript); 2191 UnboundScript);
2191 } 2192 }
2192 2193
2193 2194
2194 MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context, 2195 MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
2195 Source* source, 2196 Source* source,
2196 CompileOptions options) { 2197 CompileOptions options) {
2198 DCHECK(!source->GetResourceOptions().IsModule());
2197 auto isolate = context->GetIsolate(); 2199 auto isolate = context->GetIsolate();
2198 auto maybe = CompileUnboundInternal(isolate, source, options, false); 2200 auto maybe = CompileUnboundInternal(isolate, source, options);
2199 Local<UnboundScript> result; 2201 Local<UnboundScript> result;
2200 if (!maybe.ToLocal(&result)) return MaybeLocal<Script>(); 2202 if (!maybe.ToLocal(&result)) return MaybeLocal<Script>();
2201 v8::Context::Scope scope(context); 2203 v8::Context::Scope scope(context);
2202 return result->BindToCurrentContext(); 2204 return result->BindToCurrentContext();
2203 } 2205 }
2204 2206
2205 2207
2206 Local<Script> ScriptCompiler::Compile( 2208 Local<Script> ScriptCompiler::Compile(
2207 Isolate* v8_isolate, 2209 Isolate* v8_isolate,
2208 Source* source, 2210 Source* source,
2209 CompileOptions options) { 2211 CompileOptions options) {
2210 auto context = v8_isolate->GetCurrentContext(); 2212 auto context = v8_isolate->GetCurrentContext();
2211 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); 2213 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script);
2212 } 2214 }
2213 2215
2214 MaybeLocal<Module> ScriptCompiler::CompileModule(Isolate* isolate, 2216 MaybeLocal<Module> ScriptCompiler::CompileModule(Isolate* isolate,
2215 Source* source) { 2217 Source* source) {
2216 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 2218 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2217 2219
2218 auto maybe = CompileUnboundInternal(isolate, source, kNoCompileOptions, true); 2220 DCHECK(source->GetResourceOptions().IsModule());
2221 auto maybe = CompileUnboundInternal(isolate, source, kNoCompileOptions);
2219 Local<UnboundScript> unbound; 2222 Local<UnboundScript> unbound;
2220 if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>(); 2223 if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>();
2221 2224
2222 i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound); 2225 i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound);
2223 return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared)); 2226 return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared));
2224 } 2227 }
2225 2228
2226 2229
2227 class IsIdentifierHelper { 2230 class IsIdentifierHelper {
2228 public: 2231 public:
(...skipping 7108 matching lines...) Expand 10 before | Expand all | Expand 10 after
9337 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9340 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
9338 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); 9341 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript);
9339 i::ScriptData* script_data = NULL; 9342 i::ScriptData* script_data = NULL;
9340 i::Handle<i::String> str = Utils::OpenHandle(*source); 9343 i::Handle<i::String> str = Utils::OpenHandle(*source);
9341 i::Handle<i::SharedFunctionInfo> result; 9344 i::Handle<i::SharedFunctionInfo> result;
9342 { 9345 {
9343 ScriptOriginOptions origin_options; 9346 ScriptOriginOptions origin_options;
9344 result = i::Compiler::GetSharedFunctionInfoForScript( 9347 result = i::Compiler::GetSharedFunctionInfoForScript(
9345 str, i::Handle<i::Object>(), 0, 0, origin_options, 9348 str, i::Handle<i::Object>(), 0, 0, origin_options,
9346 i::Handle<i::Object>(), isolate->native_context(), NULL, &script_data, 9349 i::Handle<i::Object>(), isolate->native_context(), NULL, &script_data,
9347 ScriptCompiler::kNoCompileOptions, i::INSPECTOR_CODE, false); 9350 ScriptCompiler::kNoCompileOptions, i::INSPECTOR_CODE);
9348 has_pending_exception = result.is_null(); 9351 has_pending_exception = result.is_null();
9349 RETURN_ON_FAILED_EXECUTION(UnboundScript); 9352 RETURN_ON_FAILED_EXECUTION(UnboundScript);
9350 } 9353 }
9351 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); 9354 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
9352 } 9355 }
9353 9356
9354 void debug::SetAsyncTaskListener(Isolate* v8_isolate, 9357 void debug::SetAsyncTaskListener(Isolate* v8_isolate,
9355 debug::AsyncTaskListener listener, 9358 debug::AsyncTaskListener listener,
9356 void* data) { 9359 void* data) {
9357 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9360 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
10039 Address callback_address = 10042 Address callback_address =
10040 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10043 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10041 VMState<EXTERNAL> state(isolate); 10044 VMState<EXTERNAL> state(isolate);
10042 ExternalCallbackScope call_scope(isolate, callback_address); 10045 ExternalCallbackScope call_scope(isolate, callback_address);
10043 callback(info); 10046 callback(info);
10044 } 10047 }
10045 10048
10046 10049
10047 } // namespace internal 10050 } // namespace internal
10048 } // namespace v8 10051 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698