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 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1991 CompileOptions options) { | 1991 CompileOptions options) { |
1992 auto context = v8_isolate->GetCurrentContext(); | 1992 auto context = v8_isolate->GetCurrentContext(); |
1993 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); | 1993 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); |
1994 } | 1994 } |
1995 | 1995 |
1996 | 1996 |
1997 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, | 1997 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, |
1998 Source* source, | 1998 Source* source, |
1999 CompileOptions options) { | 1999 CompileOptions options) { |
2000 auto isolate = context->GetIsolate(); | 2000 auto isolate = context->GetIsolate(); |
2001 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | |
2002 | |
2001 auto maybe = CompileUnboundInternal(isolate, source, options, true); | 2003 auto maybe = CompileUnboundInternal(isolate, source, options, true); |
2002 Local<UnboundScript> generic; | 2004 Local<UnboundScript> generic; |
2003 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); | 2005 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); |
2004 v8::Context::Scope scope(context); | 2006 v8::Context::Scope scope(context); |
2005 auto result = generic->BindToCurrentContext(); | 2007 auto result = generic->BindToCurrentContext(); |
2006 | 2008 |
2007 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2009 i::Handle<i::SharedFunctionInfo> shared = |
2008 i::Handle<i::JSModule> module = i_isolate->factory()->NewJSModule(); | 2010 i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(*generic)); |
adamk
2016/09/15 21:44:02
You shouldn't need this ::cast(), OpenHandle is su
neis
2016/09/15 23:22:58
Done.
| |
2011 i::Handle<i::FixedArray> regular_exports = | |
2012 i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(), | |
2013 i_isolate); | |
2014 int regular_exports_length = regular_exports->length(); | |
2015 | |
2016 i::Handle<i::Module> module = | |
2017 i_isolate->factory()->NewModule(regular_exports_length); | |
2018 | |
2009 // TODO(neis): Storing the module into the native context is a temporary hack | 2019 // TODO(neis): Storing the module into the native context is a temporary hack |
2010 // to pass it to the Script::Run function. This will be removed once we | 2020 // to pass it to the Script::Run function. This will be removed once we |
2011 // support modules in the API. | 2021 // support modules in the API. |
2012 i_isolate->native_context()->set_current_module(*module); | 2022 i_isolate->native_context()->set_current_module(*module); |
2013 | 2023 |
2014 i::Handle<i::SharedFunctionInfo> shared = | |
2015 i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(*generic)); | |
2016 i::Handle<i::FixedArray> regular_exports = | |
2017 i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(), | |
2018 i_isolate); | |
2019 // TODO(neis): This will create multiple cells for the same local variable if | 2024 // TODO(neis): This will create multiple cells for the same local variable if |
2020 // exported under multiple names, which is wrong but cannot be observed at the | 2025 // exported under multiple names, which is wrong but cannot be observed at the |
2021 // moment. This will be fixed by doing the full-fledged linking here once we | 2026 // moment. This will be fixed by doing the full-fledged linking here once we |
2022 // get there. | 2027 // get there. |
2023 for (int i = 0; i < regular_exports->length(); ++i) { | 2028 for (int i = 0; i < regular_exports_length; ++i) { |
2024 i::Handle<i::ModuleInfoEntry> entry = | 2029 i::Handle<i::ModuleInfoEntry> entry = |
2025 i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate); | 2030 i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate); |
2026 DCHECK(entry->import_name()->IsUndefined(i_isolate)); | 2031 DCHECK(entry->import_name()->IsUndefined(i_isolate)); |
2027 i::Handle<i::String> export_name = | 2032 i::Handle<i::String> export_name = |
2028 handle(i::String::cast(entry->export_name()), i_isolate); | 2033 handle(i::String::cast(entry->export_name()), i_isolate); |
2029 i::JSModule::CreateExport(module, export_name); | 2034 i::Module::CreateExport(module, export_name); |
2030 } | 2035 } |
2031 | 2036 |
2032 return result; | 2037 return result; |
2033 } | 2038 } |
2034 | 2039 |
2035 | 2040 |
2036 class IsIdentifierHelper { | 2041 class IsIdentifierHelper { |
2037 public: | 2042 public: |
2038 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} | 2043 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} |
2039 | 2044 |
(...skipping 7290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9330 Address callback_address = | 9335 Address callback_address = |
9331 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9336 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9332 VMState<EXTERNAL> state(isolate); | 9337 VMState<EXTERNAL> state(isolate); |
9333 ExternalCallbackScope call_scope(isolate, callback_address); | 9338 ExternalCallbackScope call_scope(isolate, callback_address); |
9334 callback(info); | 9339 callback(info); |
9335 } | 9340 } |
9336 | 9341 |
9337 | 9342 |
9338 } // namespace internal | 9343 } // namespace internal |
9339 } // namespace v8 | 9344 } // namespace v8 |
OLD | NEW |