| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 private: | 208 private: |
| 209 i::Isolate* const isolate_; | 209 i::Isolate* const isolate_; |
| 210 Local<Context> context_; | 210 Local<Context> context_; |
| 211 bool escaped_; | 211 bool escaped_; |
| 212 bool do_callback_; | 212 bool do_callback_; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 } // namespace | 215 } // namespace |
| 216 | 216 |
| 217 | 217 |
| 218 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, |
| 219 i::Handle<i::Script> script) { |
| 220 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); |
| 221 i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate); |
| 222 v8::Isolate* v8_isolate = |
| 223 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); |
| 224 v8::ScriptOrigin origin( |
| 225 Utils::ToLocal(scriptName), |
| 226 v8::Integer::New(v8_isolate, script->line_offset()->value()), |
| 227 v8::Integer::New(v8_isolate, script->column_offset()->value()), |
| 228 v8::Boolean::New(v8_isolate, script->is_shared_cross_origin()), |
| 229 v8::Integer::New(v8_isolate, script->id()->value()), |
| 230 v8::Boolean::New(v8_isolate, script->is_embedder_debug_script()), |
| 231 Utils::ToLocal(source_map_url)); |
| 232 return origin; |
| 233 } |
| 234 |
| 235 |
| 218 // --- E x c e p t i o n B e h a v i o r --- | 236 // --- E x c e p t i o n B e h a v i o r --- |
| 219 | 237 |
| 220 | 238 |
| 221 void i::FatalProcessOutOfMemory(const char* location) { | 239 void i::FatalProcessOutOfMemory(const char* location) { |
| 222 i::V8::FatalProcessOutOfMemory(location, false); | 240 i::V8::FatalProcessOutOfMemory(location, false); |
| 223 } | 241 } |
| 224 | 242 |
| 225 | 243 |
| 226 // When V8 cannot allocated memory FatalProcessOutOfMemory is called. | 244 // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 227 // The default fatal error handler is called and execution is stopped. | 245 // The default fatal error handler is called and execution is stopped. |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 // ScriptData takes care of pointer-aligning the data. | 1641 // ScriptData takes care of pointer-aligning the data. |
| 1624 script_data = new i::ScriptData(source->cached_data->data, | 1642 script_data = new i::ScriptData(source->cached_data->data, |
| 1625 source->cached_data->length); | 1643 source->cached_data->length); |
| 1626 } | 1644 } |
| 1627 | 1645 |
| 1628 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); | 1646 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); |
| 1629 i::SharedFunctionInfo* raw_result = NULL; | 1647 i::SharedFunctionInfo* raw_result = NULL; |
| 1630 { i::HandleScope scope(isolate); | 1648 { i::HandleScope scope(isolate); |
| 1631 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); | 1649 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); |
| 1632 i::Handle<i::Object> name_obj; | 1650 i::Handle<i::Object> name_obj; |
| 1651 i::Handle<i::Object> source_map_url; |
| 1633 int line_offset = 0; | 1652 int line_offset = 0; |
| 1634 int column_offset = 0; | 1653 int column_offset = 0; |
| 1635 bool is_embedder_debug_script = false; | 1654 bool is_embedder_debug_script = false; |
| 1636 bool is_shared_cross_origin = false; | 1655 bool is_shared_cross_origin = false; |
| 1637 if (!source->resource_name.IsEmpty()) { | 1656 if (!source->resource_name.IsEmpty()) { |
| 1638 name_obj = Utils::OpenHandle(*(source->resource_name)); | 1657 name_obj = Utils::OpenHandle(*(source->resource_name)); |
| 1639 } | 1658 } |
| 1640 if (!source->resource_line_offset.IsEmpty()) { | 1659 if (!source->resource_line_offset.IsEmpty()) { |
| 1641 line_offset = static_cast<int>(source->resource_line_offset->Value()); | 1660 line_offset = static_cast<int>(source->resource_line_offset->Value()); |
| 1642 } | 1661 } |
| 1643 if (!source->resource_column_offset.IsEmpty()) { | 1662 if (!source->resource_column_offset.IsEmpty()) { |
| 1644 column_offset = | 1663 column_offset = |
| 1645 static_cast<int>(source->resource_column_offset->Value()); | 1664 static_cast<int>(source->resource_column_offset->Value()); |
| 1646 } | 1665 } |
| 1647 if (!source->resource_is_shared_cross_origin.IsEmpty()) { | 1666 if (!source->resource_is_shared_cross_origin.IsEmpty()) { |
| 1648 is_shared_cross_origin = | 1667 is_shared_cross_origin = |
| 1649 source->resource_is_shared_cross_origin->IsTrue(); | 1668 source->resource_is_shared_cross_origin->IsTrue(); |
| 1650 } | 1669 } |
| 1651 if (!source->resource_is_embedder_debug_script.IsEmpty()) { | 1670 if (!source->resource_is_embedder_debug_script.IsEmpty()) { |
| 1652 is_embedder_debug_script = | 1671 is_embedder_debug_script = |
| 1653 source->resource_is_embedder_debug_script->IsTrue(); | 1672 source->resource_is_embedder_debug_script->IsTrue(); |
| 1654 } | 1673 } |
| 1674 if (!source->source_map_url.IsEmpty()) { |
| 1675 source_map_url = Utils::OpenHandle(*(source->source_map_url)); |
| 1676 } |
| 1655 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( | 1677 i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( |
| 1656 str, name_obj, line_offset, column_offset, is_embedder_debug_script, | 1678 str, name_obj, line_offset, column_offset, is_embedder_debug_script, |
| 1657 is_shared_cross_origin, isolate->native_context(), NULL, &script_data, | 1679 is_shared_cross_origin, source_map_url, isolate->native_context(), NULL, |
| 1658 options, i::NOT_NATIVES_CODE, is_module); | 1680 &script_data, options, i::NOT_NATIVES_CODE, is_module); |
| 1659 has_pending_exception = result.is_null(); | 1681 has_pending_exception = result.is_null(); |
| 1660 if (has_pending_exception && script_data != NULL) { | 1682 if (has_pending_exception && script_data != NULL) { |
| 1661 // This case won't happen during normal operation; we have compiled | 1683 // This case won't happen during normal operation; we have compiled |
| 1662 // successfully and produced cached data, and but the second compilation | 1684 // successfully and produced cached data, and but the second compilation |
| 1663 // of the same source code fails. | 1685 // of the same source code fails. |
| 1664 delete script_data; | 1686 delete script_data; |
| 1665 script_data = NULL; | 1687 script_data = NULL; |
| 1666 } | 1688 } |
| 1667 RETURN_ON_FAILED_EXECUTION(UnboundScript); | 1689 RETURN_ON_FAILED_EXECUTION(UnboundScript); |
| 1668 raw_result = *result; | 1690 raw_result = *result; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 static_cast<int>(origin.ResourceColumnOffset()->Value()))); | 1917 static_cast<int>(origin.ResourceColumnOffset()->Value()))); |
| 1896 } | 1918 } |
| 1897 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { | 1919 if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) { |
| 1898 script->set_is_shared_cross_origin( | 1920 script->set_is_shared_cross_origin( |
| 1899 origin.ResourceIsSharedCrossOrigin()->IsTrue()); | 1921 origin.ResourceIsSharedCrossOrigin()->IsTrue()); |
| 1900 } | 1922 } |
| 1901 if (!origin.ResourceIsEmbedderDebugScript().IsEmpty()) { | 1923 if (!origin.ResourceIsEmbedderDebugScript().IsEmpty()) { |
| 1902 script->set_is_embedder_debug_script( | 1924 script->set_is_embedder_debug_script( |
| 1903 origin.ResourceIsEmbedderDebugScript()->IsTrue()); | 1925 origin.ResourceIsEmbedderDebugScript()->IsTrue()); |
| 1904 } | 1926 } |
| 1927 if (!origin.SourceMapUrl().IsEmpty()) { |
| 1928 script->set_source_mapping_url( |
| 1929 *Utils::OpenHandle(*(origin.SourceMapUrl()))); |
| 1930 } |
| 1931 |
| 1905 source->info->set_script(script); | 1932 source->info->set_script(script); |
| 1906 source->info->SetContext(isolate->native_context()); | 1933 source->info->SetContext(isolate->native_context()); |
| 1907 | 1934 |
| 1908 // Do the parsing tasks which need to be done on the main thread. This will | 1935 // Do the parsing tasks which need to be done on the main thread. This will |
| 1909 // also handle parse errors. | 1936 // also handle parse errors. |
| 1910 source->parser->Internalize(isolate, script, | 1937 source->parser->Internalize(isolate, script, |
| 1911 source->info->function() == nullptr); | 1938 source->info->function() == nullptr); |
| 1912 source->parser->HandleSourceURLComments(isolate, script); | 1939 source->parser->HandleSourceURLComments(isolate, script); |
| 1913 | 1940 |
| 1914 i::Handle<i::SharedFunctionInfo> result; | 1941 i::Handle<i::SharedFunctionInfo> result; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 | 2188 |
| 2162 ScriptOrigin Message::GetScriptOrigin() const { | 2189 ScriptOrigin Message::GetScriptOrigin() const { |
| 2163 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2190 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2164 i::Handle<i::JSMessageObject> message = | 2191 i::Handle<i::JSMessageObject> message = |
| 2165 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2192 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2166 i::Handle<i::Object> script_wraper = | 2193 i::Handle<i::Object> script_wraper = |
| 2167 i::Handle<i::Object>(message->script(), isolate); | 2194 i::Handle<i::Object>(message->script(), isolate); |
| 2168 i::Handle<i::JSValue> script_value = | 2195 i::Handle<i::JSValue> script_value = |
| 2169 i::Handle<i::JSValue>::cast(script_wraper); | 2196 i::Handle<i::JSValue>::cast(script_wraper); |
| 2170 i::Handle<i::Script> script(i::Script::cast(script_value->value())); | 2197 i::Handle<i::Script> script(i::Script::cast(script_value->value())); |
| 2171 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); | 2198 return GetScriptOriginForScript(isolate, script); |
| 2172 v8::Isolate* v8_isolate = | |
| 2173 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); | |
| 2174 v8::ScriptOrigin origin( | |
| 2175 Utils::ToLocal(scriptName), | |
| 2176 v8::Integer::New(v8_isolate, script->line_offset()->value()), | |
| 2177 v8::Integer::New(v8_isolate, script->column_offset()->value()), | |
| 2178 v8::Boolean::New(v8_isolate, script->is_shared_cross_origin()), | |
| 2179 v8::Integer::New(v8_isolate, script->id()->value()), | |
| 2180 v8::Boolean::New(v8_isolate, script->is_embedder_debug_script())); | |
| 2181 return origin; | |
| 2182 } | 2199 } |
| 2183 | 2200 |
| 2184 | 2201 |
| 2185 v8::Handle<Value> Message::GetScriptResourceName() const { | 2202 v8::Handle<Value> Message::GetScriptResourceName() const { |
| 2186 return GetScriptOrigin().ResourceName(); | 2203 return GetScriptOrigin().ResourceName(); |
| 2187 } | 2204 } |
| 2188 | 2205 |
| 2189 | 2206 |
| 2190 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { | 2207 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
| 2191 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2208 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| (...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4469 } | 4486 } |
| 4470 | 4487 |
| 4471 return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); | 4488 return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); |
| 4472 } | 4489 } |
| 4473 | 4490 |
| 4474 | 4491 |
| 4475 ScriptOrigin Function::GetScriptOrigin() const { | 4492 ScriptOrigin Function::GetScriptOrigin() const { |
| 4476 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4493 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4477 if (func->shared()->script()->IsScript()) { | 4494 if (func->shared()->script()->IsScript()) { |
| 4478 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); | 4495 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4479 i::Handle<i::Object> scriptName = i::Script::GetNameOrSourceURL(script); | 4496 return GetScriptOriginForScript(func->GetIsolate(), script); |
| 4480 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(func->GetIsolate()); | |
| 4481 v8::ScriptOrigin origin( | |
| 4482 Utils::ToLocal(scriptName), | |
| 4483 v8::Integer::New(isolate, script->line_offset()->value()), | |
| 4484 v8::Integer::New(isolate, script->column_offset()->value()), | |
| 4485 v8::Boolean::New(isolate, script->is_shared_cross_origin()), | |
| 4486 v8::Integer::New(isolate, script->id()->value()), | |
| 4487 v8::Boolean::New(isolate, script->is_embedder_debug_script())); | |
| 4488 return origin; | |
| 4489 } | 4497 } |
| 4490 return v8::ScriptOrigin(Handle<Value>()); | 4498 return v8::ScriptOrigin(Handle<Value>()); |
| 4491 } | 4499 } |
| 4492 | 4500 |
| 4493 | 4501 |
| 4494 const int Function::kLineOffsetNotFound = -1; | 4502 const int Function::kLineOffsetNotFound = -1; |
| 4495 | 4503 |
| 4496 | 4504 |
| 4497 int Function::GetScriptLineNumber() const { | 4505 int Function::GetScriptLineNumber() const { |
| 4498 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4506 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| (...skipping 3519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8018 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8026 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 8019 Address callback_address = | 8027 Address callback_address = |
| 8020 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8028 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8021 VMState<EXTERNAL> state(isolate); | 8029 VMState<EXTERNAL> state(isolate); |
| 8022 ExternalCallbackScope call_scope(isolate, callback_address); | 8030 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8023 callback(info); | 8031 callback(info); |
| 8024 } | 8032 } |
| 8025 | 8033 |
| 8026 | 8034 |
| 8027 } } // namespace v8::internal | 8035 } } // namespace v8::internal |
| OLD | NEW |