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 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 } | 1833 } |
1834 | 1834 |
1835 | 1835 |
1836 MaybeLocal<Value> Script::Run(Local<Context> context) { | 1836 MaybeLocal<Value> Script::Run(Local<Context> context) { |
1837 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) | 1837 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) |
1838 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 1838 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
1839 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 1839 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
1840 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 1840 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
1841 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); | 1841 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); |
1842 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); | 1842 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); |
1843 i::Handle<i::Object> receiver = isolate->global_proxy(); | 1843 |
| 1844 i::Handle<i::Object> receiver; |
1844 Local<Value> result; | 1845 Local<Value> result; |
1845 has_pending_exception = | 1846 |
1846 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), | 1847 if (fun->shared()->scope_info()->scope_type() == i::MODULE_SCOPE) { |
1847 &result); | 1848 receiver = isolate->factory()->undefined_value(); |
| 1849 i::Handle<i::Object> argv[] = { |
| 1850 handle(isolate->native_context()->current_module())}; |
| 1851 has_pending_exception = !ToLocal<Value>( |
| 1852 i::Execution::Call(isolate, fun, receiver, 1, argv), &result); |
| 1853 } else { |
| 1854 receiver = isolate->global_proxy(); |
| 1855 has_pending_exception = !ToLocal<Value>( |
| 1856 i::Execution::Call(isolate, fun, receiver, 0, nullptr), &result); |
| 1857 } |
| 1858 |
1848 RETURN_ON_FAILED_EXECUTION(Value); | 1859 RETURN_ON_FAILED_EXECUTION(Value); |
1849 RETURN_ESCAPED(result); | 1860 RETURN_ESCAPED(result); |
1850 } | 1861 } |
1851 | 1862 |
1852 | 1863 |
1853 Local<Value> Script::Run() { | 1864 Local<Value> Script::Run() { |
1854 auto self = Utils::OpenHandle(this, true); | 1865 auto self = Utils::OpenHandle(this, true); |
1855 // If execution is terminating, Compile(..)->Run() requires this | 1866 // If execution is terminating, Compile(..)->Run() requires this |
1856 // check. | 1867 // check. |
1857 if (self.is_null()) return Local<Value>(); | 1868 if (self.is_null()) return Local<Value>(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 | 1989 |
1979 | 1990 |
1980 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, | 1991 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, |
1981 Source* source, | 1992 Source* source, |
1982 CompileOptions options) { | 1993 CompileOptions options) { |
1983 auto isolate = context->GetIsolate(); | 1994 auto isolate = context->GetIsolate(); |
1984 auto maybe = CompileUnboundInternal(isolate, source, options, true); | 1995 auto maybe = CompileUnboundInternal(isolate, source, options, true); |
1985 Local<UnboundScript> generic; | 1996 Local<UnboundScript> generic; |
1986 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); | 1997 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); |
1987 v8::Context::Scope scope(context); | 1998 v8::Context::Scope scope(context); |
1988 return generic->BindToCurrentContext(); | 1999 auto result = generic->BindToCurrentContext(); |
| 2000 |
| 2001 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2002 i::Handle<i::JSModule> module = i_isolate->factory()->NewJSModule(); |
| 2003 // TODO(neis): Storing the module into the native context is a temporary hack |
| 2004 // to pass it to the Script::Run function. This will be removed once we |
| 2005 // support modules in the API. |
| 2006 i_isolate->native_context()->set_current_module(*module); |
| 2007 |
| 2008 i::Handle<i::SharedFunctionInfo> shared = |
| 2009 i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(*generic)); |
| 2010 i::Handle<i::FixedArray> regular_exports = |
| 2011 i::handle(shared->scope_info()->ModuleDescriptorInfo()->regular_exports(), |
| 2012 i_isolate); |
| 2013 // TODO(neis): This will create multiple cells for the same local variable if |
| 2014 // exported under multiple names, which is wrong but cannot be observed at the |
| 2015 // moment. This will be fixed by doing the full-fledged linking here once we |
| 2016 // get there. |
| 2017 for (int i = 0; i < regular_exports->length(); ++i) { |
| 2018 i::Handle<i::ModuleInfoEntry> entry = |
| 2019 i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate); |
| 2020 DCHECK(entry->import_name()->IsUndefined(i_isolate)); |
| 2021 i::Handle<i::String> export_name = |
| 2022 handle(i::String::cast(entry->export_name()), i_isolate); |
| 2023 i::JSModule::CreateExport(module, export_name); |
| 2024 } |
| 2025 |
| 2026 return result; |
1989 } | 2027 } |
1990 | 2028 |
1991 | 2029 |
1992 class IsIdentifierHelper { | 2030 class IsIdentifierHelper { |
1993 public: | 2031 public: |
1994 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} | 2032 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} |
1995 | 2033 |
1996 bool Check(i::String* string) { | 2034 bool Check(i::String* string) { |
1997 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); | 2035 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); |
1998 if (cons_string == NULL) return is_identifier_; | 2036 if (cons_string == NULL) return is_identifier_; |
(...skipping 7205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9204 Address callback_address = | 9242 Address callback_address = |
9205 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9243 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9206 VMState<EXTERNAL> state(isolate); | 9244 VMState<EXTERNAL> state(isolate); |
9207 ExternalCallbackScope call_scope(isolate, callback_address); | 9245 ExternalCallbackScope call_scope(isolate, callback_address); |
9208 callback(info); | 9246 callback(info); |
9209 } | 9247 } |
9210 | 9248 |
9211 | 9249 |
9212 } // namespace internal | 9250 } // namespace internal |
9213 } // namespace v8 | 9251 } // namespace v8 |
OLD | NEW |