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 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 } | 1835 } |
1836 | 1836 |
1837 | 1837 |
1838 MaybeLocal<Value> Script::Run(Local<Context> context) { | 1838 MaybeLocal<Value> Script::Run(Local<Context> context) { |
1839 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) | 1839 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) |
1840 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 1840 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
1841 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 1841 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
1842 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 1842 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
1843 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); | 1843 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); |
1844 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); | 1844 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); |
1845 i::Handle<i::Object> receiver = isolate->global_proxy(); | 1845 |
| 1846 i::Handle<i::Object> receiver; |
1846 Local<Value> result; | 1847 Local<Value> result; |
1847 has_pending_exception = | 1848 |
1848 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), | 1849 // TODO(neis): Make sure this is the only path that executes a module. |
1849 &result); | 1850 if (fun->shared()->scope_info()->scope_type() == i::MODULE_SCOPE) { |
| 1851 receiver = isolate->factory()->undefined_value(); |
| 1852 i::Handle<i::Object> argv[] = {handle(isolate->native_context()->current_mod
ule())}; |
| 1853 has_pending_exception = !ToLocal<Value>( |
| 1854 i::Execution::Call(isolate, fun, receiver, 1, argv), &result); |
| 1855 } else { |
| 1856 receiver = isolate->global_proxy(); |
| 1857 has_pending_exception = !ToLocal<Value>( |
| 1858 i::Execution::Call(isolate, fun, receiver, 0, nullptr), &result); |
| 1859 } |
| 1860 |
1850 RETURN_ON_FAILED_EXECUTION(Value); | 1861 RETURN_ON_FAILED_EXECUTION(Value); |
1851 RETURN_ESCAPED(result); | 1862 RETURN_ESCAPED(result); |
1852 } | 1863 } |
1853 | 1864 |
1854 | 1865 |
1855 Local<Value> Script::Run() { | 1866 Local<Value> Script::Run() { |
1856 auto self = Utils::OpenHandle(this, true); | 1867 auto self = Utils::OpenHandle(this, true); |
1857 // If execution is terminating, Compile(..)->Run() requires this | 1868 // If execution is terminating, Compile(..)->Run() requires this |
1858 // check. | 1869 // check. |
1859 if (self.is_null()) return Local<Value>(); | 1870 if (self.is_null()) return Local<Value>(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1980 | 1991 |
1981 | 1992 |
1982 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, | 1993 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, |
1983 Source* source, | 1994 Source* source, |
1984 CompileOptions options) { | 1995 CompileOptions options) { |
1985 auto isolate = context->GetIsolate(); | 1996 auto isolate = context->GetIsolate(); |
1986 auto maybe = CompileUnboundInternal(isolate, source, options, true); | 1997 auto maybe = CompileUnboundInternal(isolate, source, options, true); |
1987 Local<UnboundScript> generic; | 1998 Local<UnboundScript> generic; |
1988 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); | 1999 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); |
1989 v8::Context::Scope scope(context); | 2000 v8::Context::Scope scope(context); |
1990 return generic->BindToCurrentContext(); | 2001 auto result = generic->BindToCurrentContext(); |
| 2002 |
| 2003 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2004 i::Handle<i::JSModule> module = i_isolate->factory()->NewJSModule(); |
| 2005 // TODO: Storing the module into the native context is a temporary hack to |
| 2006 // pass it to the Script::Run function. |
| 2007 i_isolate->native_context()->set_current_module(*module); |
| 2008 |
| 2009 i::Handle<i::SharedFunctionInfo> shared = |
| 2010 i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(*generic)); |
| 2011 i::Handle<i::FixedArray> regular_exports = |
| 2012 i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(), |
| 2013 i_isolate); |
| 2014 for (int i = 0; i < regular_exports->length(); ++i) { |
| 2015 i::Handle<i::ModuleInfoEntry> entry = |
| 2016 i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate); |
| 2017 DCHECK(entry->import_name()->IsUndefined(i_isolate)); |
| 2018 i::Handle<i::String> export_name = |
| 2019 handle(i::String::cast(entry->export_name()), i_isolate); |
| 2020 i::JSModule::CreateExport(module, export_name); |
| 2021 #ifdef DEBUG |
| 2022 // TODO: Remove before landing. |
| 2023 printf("Created cell for export "); |
| 2024 export_name->Print(); |
| 2025 printf("\n"); |
| 2026 #endif // DEBUG |
| 2027 } |
| 2028 |
| 2029 return result; |
1991 } | 2030 } |
1992 | 2031 |
1993 | 2032 |
1994 class IsIdentifierHelper { | 2033 class IsIdentifierHelper { |
1995 public: | 2034 public: |
1996 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} | 2035 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} |
1997 | 2036 |
1998 bool Check(i::String* string) { | 2037 bool Check(i::String* string) { |
1999 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); | 2038 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); |
2000 if (cons_string == NULL) return is_identifier_; | 2039 if (cons_string == NULL) return is_identifier_; |
(...skipping 7106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9107 Address callback_address = | 9146 Address callback_address = |
9108 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9147 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9109 VMState<EXTERNAL> state(isolate); | 9148 VMState<EXTERNAL> state(isolate); |
9110 ExternalCallbackScope call_scope(isolate, callback_address); | 9149 ExternalCallbackScope call_scope(isolate, callback_address); |
9111 callback(info); | 9150 callback(info); |
9112 } | 9151 } |
9113 | 9152 |
9114 | 9153 |
9115 } // namespace internal | 9154 } // namespace internal |
9116 } // namespace v8 | 9155 } // namespace v8 |
OLD | NEW |