| 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 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 } | 1839 } |
| 1840 | 1840 |
| 1841 | 1841 |
| 1842 MaybeLocal<Value> Script::Run(Local<Context> context) { | 1842 MaybeLocal<Value> Script::Run(Local<Context> context) { |
| 1843 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) | 1843 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) |
| 1844 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 1844 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
| 1845 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 1845 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 1846 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 1846 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
| 1847 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); | 1847 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); |
| 1848 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); | 1848 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); |
| 1849 | 1849 i::Handle<i::Object> receiver = isolate->global_proxy(); |
| 1850 i::Handle<i::Object> receiver; | |
| 1851 Local<Value> result; | 1850 Local<Value> result; |
| 1852 | 1851 has_pending_exception = |
| 1853 if (fun->shared()->scope_info()->scope_type() == i::MODULE_SCOPE) { | 1852 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), |
| 1854 receiver = isolate->factory()->undefined_value(); | 1853 &result); |
| 1855 i::Handle<i::Object> argv[] = { | |
| 1856 handle(isolate->native_context()->current_module())}; | |
| 1857 has_pending_exception = !ToLocal<Value>( | |
| 1858 i::Execution::Call(isolate, fun, receiver, 1, argv), &result); | |
| 1859 } else { | |
| 1860 receiver = isolate->global_proxy(); | |
| 1861 has_pending_exception = !ToLocal<Value>( | |
| 1862 i::Execution::Call(isolate, fun, receiver, 0, nullptr), &result); | |
| 1863 } | |
| 1864 | |
| 1865 RETURN_ON_FAILED_EXECUTION(Value); | 1854 RETURN_ON_FAILED_EXECUTION(Value); |
| 1866 RETURN_ESCAPED(result); | 1855 RETURN_ESCAPED(result); |
| 1867 } | 1856 } |
| 1868 | 1857 |
| 1869 | 1858 |
| 1870 Local<Value> Script::Run() { | 1859 Local<Value> Script::Run() { |
| 1871 auto self = Utils::OpenHandle(this, true); | 1860 auto self = Utils::OpenHandle(this, true); |
| 1872 // If execution is terminating, Compile(..)->Run() requires this | 1861 // If execution is terminating, Compile(..)->Run() requires this |
| 1873 // check. | 1862 // check. |
| 1874 if (self.is_null()) return Local<Value>(); | 1863 if (self.is_null()) return Local<Value>(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 | 1984 |
| 1996 | 1985 |
| 1997 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, | 1986 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, |
| 1998 Source* source, | 1987 Source* source, |
| 1999 CompileOptions options) { | 1988 CompileOptions options) { |
| 2000 auto isolate = context->GetIsolate(); | 1989 auto isolate = context->GetIsolate(); |
| 2001 auto maybe = CompileUnboundInternal(isolate, source, options, true); | 1990 auto maybe = CompileUnboundInternal(isolate, source, options, true); |
| 2002 Local<UnboundScript> generic; | 1991 Local<UnboundScript> generic; |
| 2003 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); | 1992 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); |
| 2004 v8::Context::Scope scope(context); | 1993 v8::Context::Scope scope(context); |
| 2005 auto result = generic->BindToCurrentContext(); | 1994 return generic->BindToCurrentContext(); |
| 2006 | |
| 2007 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | |
| 2008 i::Handle<i::JSModule> module = i_isolate->factory()->NewJSModule(); | |
| 2009 // 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 | |
| 2011 // support modules in the API. | |
| 2012 i_isolate->native_context()->set_current_module(*module); | |
| 2013 | |
| 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 | |
| 2020 // 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 | |
| 2022 // get there. | |
| 2023 for (int i = 0; i < regular_exports->length(); ++i) { | |
| 2024 i::Handle<i::ModuleInfoEntry> entry = | |
| 2025 i::handle(i::ModuleInfoEntry::cast(regular_exports->get(i)), i_isolate); | |
| 2026 DCHECK(entry->import_name()->IsUndefined(i_isolate)); | |
| 2027 i::Handle<i::String> export_name = | |
| 2028 handle(i::String::cast(entry->export_name()), i_isolate); | |
| 2029 i::JSModule::CreateExport(module, export_name); | |
| 2030 } | |
| 2031 | |
| 2032 return result; | |
| 2033 } | 1995 } |
| 2034 | 1996 |
| 2035 | 1997 |
| 2036 class IsIdentifierHelper { | 1998 class IsIdentifierHelper { |
| 2037 public: | 1999 public: |
| 2038 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} | 2000 IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} |
| 2039 | 2001 |
| 2040 bool Check(i::String* string) { | 2002 bool Check(i::String* string) { |
| 2041 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); | 2003 i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); |
| 2042 if (cons_string == NULL) return is_identifier_; | 2004 if (cons_string == NULL) return is_identifier_; |
| (...skipping 7238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9281 Address callback_address = | 9243 Address callback_address = |
| 9282 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9244 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9283 VMState<EXTERNAL> state(isolate); | 9245 VMState<EXTERNAL> state(isolate); |
| 9284 ExternalCallbackScope call_scope(isolate, callback_address); | 9246 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9285 callback(info); | 9247 callback(info); |
| 9286 } | 9248 } |
| 9287 | 9249 |
| 9288 | 9250 |
| 9289 } // namespace internal | 9251 } // namespace internal |
| 9290 } // namespace v8 | 9252 } // namespace v8 |
| OLD | NEW |