| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "src/vm-state-inl.h" | 52 #include "src/vm-state-inl.h" |
| 53 | 53 |
| 54 | 54 |
| 55 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) | 55 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
| 56 | 56 |
| 57 #define ENTER_V8(isolate) \ | 57 #define ENTER_V8(isolate) \ |
| 58 i::VMState<v8::OTHER> __state__((isolate)) | 58 i::VMState<v8::OTHER> __state__((isolate)) |
| 59 | 59 |
| 60 namespace v8 { | 60 namespace v8 { |
| 61 | 61 |
| 62 #define ON_BAILOUT(isolate, location, code) \ | |
| 63 if (IsExecutionTerminatingCheck(isolate)) { \ | |
| 64 code; \ | |
| 65 UNREACHABLE(); \ | |
| 66 } | |
| 67 | |
| 68 | |
| 69 #define EXCEPTION_PREAMBLE(isolate) \ | 62 #define EXCEPTION_PREAMBLE(isolate) \ |
| 70 (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ | 63 (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
| 71 DCHECK(!(isolate)->external_caught_exception()); \ | 64 DCHECK(!(isolate)->external_caught_exception()); \ |
| 72 bool has_pending_exception = false | 65 bool has_pending_exception = false |
| 73 | 66 |
| 74 | 67 |
| 75 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ | 68 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
| 76 do { \ | 69 do { \ |
| 77 i::HandleScopeImplementer* handle_scope_implementer = \ | 70 i::HandleScopeImplementer* handle_scope_implementer = \ |
| 78 (isolate)->handle_scope_implementer(); \ | 71 (isolate)->handle_scope_implementer(); \ |
| (...skipping 5399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5478 return env; | 5471 return env; |
| 5479 } | 5472 } |
| 5480 | 5473 |
| 5481 Local<Context> v8::Context::New( | 5474 Local<Context> v8::Context::New( |
| 5482 v8::Isolate* external_isolate, | 5475 v8::Isolate* external_isolate, |
| 5483 v8::ExtensionConfiguration* extensions, | 5476 v8::ExtensionConfiguration* extensions, |
| 5484 v8::Handle<ObjectTemplate> global_template, | 5477 v8::Handle<ObjectTemplate> global_template, |
| 5485 v8::Handle<Value> global_object) { | 5478 v8::Handle<Value> global_object) { |
| 5486 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 5479 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
| 5487 LOG_API(isolate, "Context::New"); | 5480 LOG_API(isolate, "Context::New"); |
| 5488 ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>()); | |
| 5489 i::HandleScope scope(isolate); | 5481 i::HandleScope scope(isolate); |
| 5490 ExtensionConfiguration no_extensions; | 5482 ExtensionConfiguration no_extensions; |
| 5491 if (extensions == NULL) extensions = &no_extensions; | 5483 if (extensions == NULL) extensions = &no_extensions; |
| 5492 i::Handle<i::Context> env = | 5484 i::Handle<i::Context> env = |
| 5493 CreateEnvironment(isolate, extensions, global_template, global_object); | 5485 CreateEnvironment(isolate, extensions, global_template, global_object); |
| 5494 if (env.is_null()) return Local<Context>(); | 5486 if (env.is_null()) return Local<Context>(); |
| 5495 return Utils::ToLocal(scope.CloseAndEscape(env)); | 5487 return Utils::ToLocal(scope.CloseAndEscape(env)); |
| 5496 } | 5488 } |
| 5497 | 5489 |
| 5498 | 5490 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5562 | 5554 |
| 5563 | 5555 |
| 5564 void Context::SetErrorMessageForCodeGenerationFromStrings( | 5556 void Context::SetErrorMessageForCodeGenerationFromStrings( |
| 5565 Handle<String> error) { | 5557 Handle<String> error) { |
| 5566 i::Handle<i::Context> context = Utils::OpenHandle(this); | 5558 i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5567 i::Handle<i::String> error_handle = Utils::OpenHandle(*error); | 5559 i::Handle<i::String> error_handle = Utils::OpenHandle(*error); |
| 5568 context->set_error_message_for_code_gen_from_strings(*error_handle); | 5560 context->set_error_message_for_code_gen_from_strings(*error_handle); |
| 5569 } | 5561 } |
| 5570 | 5562 |
| 5571 | 5563 |
| 5564 MaybeLocal<v8::Object> ObjectTemplate::NewInstance(Local<Context> context) { |
| 5565 PREPARE_FOR_EXECUTION(context, "v8::ObjectTemplate::NewInstance()", Object); |
| 5566 auto self = Utils::OpenHandle(this); |
| 5567 Local<Object> result; |
| 5568 has_pending_exception = |
| 5569 !ToLocal<Object>(i::ApiNatives::InstantiateObject(self), &result); |
| 5570 RETURN_ON_FAILED_EXECUTION(Object); |
| 5571 RETURN_ESCAPED(result); |
| 5572 } |
| 5573 |
| 5574 |
| 5572 Local<v8::Object> ObjectTemplate::NewInstance() { | 5575 Local<v8::Object> ObjectTemplate::NewInstance() { |
| 5573 i::Handle<i::ObjectTemplateInfo> info = Utils::OpenHandle(this); | 5576 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 5574 i::Isolate* isolate = info->GetIsolate(); | 5577 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context), Object); |
| 5575 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", | 5578 } |
| 5576 return Local<v8::Object>()); | 5579 |
| 5577 LOG_API(isolate, "ObjectTemplate::NewInstance"); | 5580 |
| 5578 ENTER_V8(isolate); | 5581 MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) { |
| 5579 EXCEPTION_PREAMBLE(isolate); | 5582 PREPARE_FOR_EXECUTION(context, "v8::FunctionTemplate::GetFunction()", |
| 5580 i::Handle<i::Object> obj; | 5583 Function); |
| 5584 auto self = Utils::OpenHandle(this); |
| 5585 Local<Function> result; |
| 5581 has_pending_exception = | 5586 has_pending_exception = |
| 5582 !i::ApiNatives::InstantiateObject(info).ToHandle(&obj); | 5587 !ToLocal<Function>(i::ApiNatives::InstantiateFunction(self), &result); |
| 5583 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); | 5588 RETURN_ON_FAILED_EXECUTION(Function); |
| 5584 return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); | 5589 RETURN_ESCAPED(result); |
| 5585 } | 5590 } |
| 5586 | 5591 |
| 5587 | 5592 |
| 5588 Local<v8::Function> FunctionTemplate::GetFunction() { | 5593 Local<v8::Function> FunctionTemplate::GetFunction() { |
| 5589 i::Handle<i::FunctionTemplateInfo> info = Utils::OpenHandle(this); | 5594 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 5590 i::Isolate* isolate = info->GetIsolate(); | 5595 RETURN_TO_LOCAL_UNCHECKED(GetFunction(context), Function); |
| 5591 ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", | |
| 5592 return Local<v8::Function>()); | |
| 5593 LOG_API(isolate, "FunctionTemplate::GetFunction"); | |
| 5594 ENTER_V8(isolate); | |
| 5595 EXCEPTION_PREAMBLE(isolate); | |
| 5596 i::Handle<i::Object> obj; | |
| 5597 has_pending_exception = | |
| 5598 !i::ApiNatives::InstantiateFunction(info).ToHandle(&obj); | |
| 5599 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); | |
| 5600 return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); | |
| 5601 } | 5596 } |
| 5602 | 5597 |
| 5603 | 5598 |
| 5604 bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { | 5599 bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
| 5605 i::Handle<i::FunctionTemplateInfo> info = Utils::OpenHandle(this); | 5600 auto self = Utils::OpenHandle(this); |
| 5606 i::Isolate* isolate = info->GetIsolate(); | 5601 auto obj = Utils::OpenHandle(*value); |
| 5607 ON_BAILOUT(isolate, "v8::FunctionTemplate::HasInstanceOf()", return false); | 5602 return self->IsTemplateFor(*obj); |
| 5608 i::Object* obj = *Utils::OpenHandle(*value); | |
| 5609 return info->IsTemplateFor(obj); | |
| 5610 } | 5603 } |
| 5611 | 5604 |
| 5612 | 5605 |
| 5613 Local<External> v8::External::New(Isolate* isolate, void* value) { | 5606 Local<External> v8::External::New(Isolate* isolate, void* value) { |
| 5614 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); | 5607 STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); |
| 5615 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 5608 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5616 LOG_API(i_isolate, "External::New"); | 5609 LOG_API(i_isolate, "External::New"); |
| 5617 ENTER_V8(i_isolate); | 5610 ENTER_V8(i_isolate); |
| 5618 i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value); | 5611 i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value); |
| 5619 return Utils::ExternalToLocal(external); | 5612 return Utils::ExternalToLocal(external); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5680 | 5673 |
| 5681 | 5674 |
| 5682 template<typename Char> | 5675 template<typename Char> |
| 5683 inline Local<String> NewString(Isolate* v8_isolate, | 5676 inline Local<String> NewString(Isolate* v8_isolate, |
| 5684 const char* location, | 5677 const char* location, |
| 5685 const char* env, | 5678 const char* env, |
| 5686 const Char* data, | 5679 const Char* data, |
| 5687 String::NewStringType type, | 5680 String::NewStringType type, |
| 5688 int length) { | 5681 int length) { |
| 5689 i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); | 5682 i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); |
| 5690 ON_BAILOUT(isolate, location, return Local<String>()); | |
| 5691 LOG_API(isolate, env); | 5683 LOG_API(isolate, env); |
| 5692 if (length == 0) { | 5684 if (length == 0) { |
| 5693 return String::Empty(v8_isolate); | 5685 return String::Empty(v8_isolate); |
| 5694 } | 5686 } |
| 5695 ENTER_V8(isolate); | 5687 ENTER_V8(isolate); |
| 5696 if (length == -1) length = StringLength(data); | 5688 if (length == -1) length = StringLength(data); |
| 5697 EXCEPTION_PREAMBLE(isolate); | 5689 EXCEPTION_PREAMBLE(isolate); |
| 5698 i::Handle<i::String> result; | 5690 i::Handle<i::String> result; |
| 5699 has_pending_exception = | 5691 has_pending_exception = |
| 5700 !NewString(isolate->factory(), type, i::Vector<const Char>(data, length)) | 5692 !NewString(isolate->factory(), type, i::Vector<const Char>(data, length)) |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5993 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 5985 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5994 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); | 5986 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); |
| 5995 i::Isolate* isolate = jsdate->GetIsolate(); | 5987 i::Isolate* isolate = jsdate->GetIsolate(); |
| 5996 LOG_API(isolate, "Date::NumberValue"); | 5988 LOG_API(isolate, "Date::NumberValue"); |
| 5997 return jsdate->value()->Number(); | 5989 return jsdate->value()->Number(); |
| 5998 } | 5990 } |
| 5999 | 5991 |
| 6000 | 5992 |
| 6001 void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { | 5993 void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { |
| 6002 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 5994 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6003 ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()", | |
| 6004 return); | |
| 6005 LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification"); | 5995 LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification"); |
| 6006 ENTER_V8(i_isolate); | 5996 ENTER_V8(i_isolate); |
| 6007 | |
| 6008 i_isolate->date_cache()->ResetDateCache(); | 5997 i_isolate->date_cache()->ResetDateCache(); |
| 6009 | |
| 6010 if (!i_isolate->eternal_handles()->Exists( | 5998 if (!i_isolate->eternal_handles()->Exists( |
| 6011 i::EternalHandles::DATE_CACHE_VERSION)) { | 5999 i::EternalHandles::DATE_CACHE_VERSION)) { |
| 6012 return; | 6000 return; |
| 6013 } | 6001 } |
| 6014 i::Handle<i::FixedArray> date_cache_version = | 6002 i::Handle<i::FixedArray> date_cache_version = |
| 6015 i::Handle<i::FixedArray>::cast(i_isolate->eternal_handles()->GetSingleton( | 6003 i::Handle<i::FixedArray>::cast(i_isolate->eternal_handles()->GetSingleton( |
| 6016 i::EternalHandles::DATE_CACHE_VERSION)); | 6004 i::EternalHandles::DATE_CACHE_VERSION)); |
| 6017 DCHECK_EQ(1, date_cache_version->length()); | 6005 DCHECK_EQ(1, date_cache_version->length()); |
| 6018 CHECK(date_cache_version->get(0)->IsSmi()); | 6006 CHECK(date_cache_version->get(0)->IsSmi()); |
| 6019 date_cache_version->set( | 6007 date_cache_version->set( |
| 6020 0, | 6008 0, |
| 6021 i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1)); | 6009 i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1)); |
| 6022 } | 6010 } |
| 6023 | 6011 |
| 6024 | 6012 |
| 6025 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { | 6013 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
| 6026 i::Isolate* isolate = i::Isolate::Current(); | 6014 i::Isolate* isolate = i::Isolate::Current(); |
| 6027 uint8_t flags_buf[3]; | 6015 uint8_t flags_buf[3]; |
| 6028 int num_flags = 0; | 6016 int num_flags = 0; |
| 6029 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; | 6017 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 6030 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; | 6018 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 6031 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; | 6019 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 6032 DCHECK(num_flags <= static_cast<int>(arraysize(flags_buf))); | 6020 DCHECK(num_flags <= static_cast<int>(arraysize(flags_buf))); |
| 6033 return isolate->factory()->InternalizeOneByteString( | 6021 return isolate->factory()->InternalizeOneByteString( |
| 6034 i::Vector<const uint8_t>(flags_buf, num_flags)); | 6022 i::Vector<const uint8_t>(flags_buf, num_flags)); |
| 6035 } | 6023 } |
| 6036 | 6024 |
| 6037 | 6025 |
| 6038 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, | 6026 MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context, |
| 6039 Flags flags) { | 6027 Handle<String> pattern, Flags flags) { |
| 6040 i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); | 6028 PREPARE_FOR_EXECUTION(context, "RegExp::New", RegExp); |
| 6041 LOG_API(isolate, "RegExp::New"); | 6029 Local<v8::RegExp> result; |
| 6042 ENTER_V8(isolate); | 6030 has_pending_exception = |
| 6043 EXCEPTION_PREAMBLE(isolate); | 6031 !ToLocal<RegExp>(i::Execution::NewJSRegExp(Utils::OpenHandle(*pattern), |
| 6044 i::Handle<i::JSRegExp> obj; | 6032 RegExpFlagsToString(flags)), |
| 6045 has_pending_exception = !i::Execution::NewJSRegExp( | 6033 &result); |
| 6046 Utils::OpenHandle(*pattern), | 6034 RETURN_ON_FAILED_EXECUTION(RegExp); |
| 6047 RegExpFlagsToString(flags)).ToHandle(&obj); | 6035 RETURN_ESCAPED(result); |
| 6048 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); | |
| 6049 return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); | |
| 6050 } | 6036 } |
| 6051 | 6037 |
| 6052 | 6038 |
| 6039 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, Flags flags) { |
| 6040 auto isolate = |
| 6041 reinterpret_cast<Isolate*>(Utils::OpenHandle(*pattern)->GetIsolate()); |
| 6042 auto context = isolate->GetCurrentContext(); |
| 6043 RETURN_TO_LOCAL_UNCHECKED(New(context, pattern, flags), RegExp); |
| 6044 } |
| 6045 |
| 6046 |
| 6053 Local<v8::String> v8::RegExp::GetSource() const { | 6047 Local<v8::String> v8::RegExp::GetSource() const { |
| 6054 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); | 6048 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 6055 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); | 6049 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 6056 } | 6050 } |
| 6057 | 6051 |
| 6058 | 6052 |
| 6059 // Assert that the static flags cast in GetFlags is valid. | 6053 // Assert that the static flags cast in GetFlags is valid. |
| 6060 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ | 6054 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 6061 STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ | 6055 STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 6062 static_cast<int>(i::JSRegExp::internal_flag)) | 6056 static_cast<int>(i::JSRegExp::internal_flag)) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 6089 i::Handle<i::JSArray> obj = Utils::OpenHandle(this); | 6083 i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 6090 i::Object* length = obj->length(); | 6084 i::Object* length = obj->length(); |
| 6091 if (length->IsSmi()) { | 6085 if (length->IsSmi()) { |
| 6092 return i::Smi::cast(length)->value(); | 6086 return i::Smi::cast(length)->value(); |
| 6093 } else { | 6087 } else { |
| 6094 return static_cast<uint32_t>(length->Number()); | 6088 return static_cast<uint32_t>(length->Number()); |
| 6095 } | 6089 } |
| 6096 } | 6090 } |
| 6097 | 6091 |
| 6098 | 6092 |
| 6093 MaybeLocal<Object> Array::CloneElementAt(Local<Context> context, |
| 6094 uint32_t index) { |
| 6095 PREPARE_FOR_EXECUTION(context, "v8::Array::CloneElementAt()", Object); |
| 6096 auto self = Utils::OpenHandle(this); |
| 6097 if (!self->HasFastObjectElements()) return Local<Object>(); |
| 6098 i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
| 6099 i::Object* paragon = elms->get(index); |
| 6100 if (!paragon->IsJSObject()) return Local<Object>(); |
| 6101 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
| 6102 Local<Object> result; |
| 6103 has_pending_exception = ToLocal<Object>( |
| 6104 isolate->factory()->CopyJSObject(paragon_handle), &result); |
| 6105 RETURN_ON_FAILED_EXECUTION(Object); |
| 6106 RETURN_ESCAPED(result); |
| 6107 } |
| 6108 |
| 6109 |
| 6099 Local<Object> Array::CloneElementAt(uint32_t index) { | 6110 Local<Object> Array::CloneElementAt(uint32_t index) { |
| 6100 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 6111 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 6101 ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); | 6112 RETURN_TO_LOCAL_UNCHECKED(CloneElementAt(context, index), Object); |
| 6102 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | |
| 6103 if (!self->HasFastObjectElements()) { | |
| 6104 return Local<Object>(); | |
| 6105 } | |
| 6106 i::FixedArray* elms = i::FixedArray::cast(self->elements()); | |
| 6107 i::Object* paragon = elms->get(index); | |
| 6108 if (!paragon->IsJSObject()) { | |
| 6109 return Local<Object>(); | |
| 6110 } | |
| 6111 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); | |
| 6112 EXCEPTION_PREAMBLE(isolate); | |
| 6113 ENTER_V8(isolate); | |
| 6114 i::Handle<i::JSObject> result = | |
| 6115 isolate->factory()->CopyJSObject(paragon_handle); | |
| 6116 has_pending_exception = result.is_null(); | |
| 6117 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); | |
| 6118 return Utils::ToLocal(result); | |
| 6119 } | 6113 } |
| 6120 | 6114 |
| 6121 | 6115 |
| 6122 bool Value::IsPromise() const { | 6116 bool Value::IsPromise() const { |
| 6123 i::Handle<i::Object> val = Utils::OpenHandle(this); | 6117 i::Handle<i::Object> val = Utils::OpenHandle(this); |
| 6124 if (!val->IsJSObject()) return false; | 6118 if (!val->IsJSObject()) return false; |
| 6125 i::Handle<i::JSObject> obj = i::Handle<i::JSObject>::cast(val); | 6119 i::Handle<i::JSObject> obj = i::Handle<i::JSObject>::cast(val); |
| 6126 i::Isolate* isolate = obj->GetIsolate(); | 6120 i::Isolate* isolate = obj->GetIsolate(); |
| 6127 LOG_API(isolate, "IsPromise"); | 6121 LOG_API(isolate, "IsPromise"); |
| 6128 ENTER_V8(isolate); | 6122 ENTER_V8(isolate); |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7047 | 7041 |
| 7048 | 7042 |
| 7049 bool Isolate::IsDead() { | 7043 bool Isolate::IsDead() { |
| 7050 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7044 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7051 return isolate->IsDead(); | 7045 return isolate->IsDead(); |
| 7052 } | 7046 } |
| 7053 | 7047 |
| 7054 | 7048 |
| 7055 bool Isolate::AddMessageListener(MessageCallback that, Handle<Value> data) { | 7049 bool Isolate::AddMessageListener(MessageCallback that, Handle<Value> data) { |
| 7056 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7050 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7057 ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); | |
| 7058 ENTER_V8(isolate); | 7051 ENTER_V8(isolate); |
| 7059 i::HandleScope scope(isolate); | 7052 i::HandleScope scope(isolate); |
| 7060 NeanderArray listeners(isolate->factory()->message_listeners()); | 7053 NeanderArray listeners(isolate->factory()->message_listeners()); |
| 7061 NeanderObject obj(isolate, 2); | 7054 NeanderObject obj(isolate, 2); |
| 7062 obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); | 7055 obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
| 7063 obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() | 7056 obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() |
| 7064 : *Utils::OpenHandle(*data)); | 7057 : *Utils::OpenHandle(*data)); |
| 7065 listeners.add(isolate, obj.value()); | 7058 listeners.add(isolate, obj.value()); |
| 7066 return true; | 7059 return true; |
| 7067 } | 7060 } |
| 7068 | 7061 |
| 7069 | 7062 |
| 7070 void Isolate::RemoveMessageListeners(MessageCallback that) { | 7063 void Isolate::RemoveMessageListeners(MessageCallback that) { |
| 7071 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7064 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 7072 ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); | |
| 7073 ENTER_V8(isolate); | 7065 ENTER_V8(isolate); |
| 7074 i::HandleScope scope(isolate); | 7066 i::HandleScope scope(isolate); |
| 7075 NeanderArray listeners(isolate->factory()->message_listeners()); | 7067 NeanderArray listeners(isolate->factory()->message_listeners()); |
| 7076 for (int i = 0; i < listeners.length(); i++) { | 7068 for (int i = 0; i < listeners.length(); i++) { |
| 7077 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones | 7069 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 7078 | 7070 |
| 7079 NeanderObject listener(i::JSObject::cast(listeners.get(i))); | 7071 NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
| 7080 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); | 7072 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); |
| 7081 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { | 7073 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { |
| 7082 listeners.set(i, isolate->heap()->undefined_value()); | 7074 listeners.set(i, isolate->heap()->undefined_value()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7180 | 7172 |
| 7181 String::Value::~Value() { | 7173 String::Value::~Value() { |
| 7182 i::DeleteArray(str_); | 7174 i::DeleteArray(str_); |
| 7183 } | 7175 } |
| 7184 | 7176 |
| 7185 | 7177 |
| 7186 #define DEFINE_ERROR(NAME) \ | 7178 #define DEFINE_ERROR(NAME) \ |
| 7187 Local<Value> Exception::NAME(v8::Handle<v8::String> raw_message) { \ | 7179 Local<Value> Exception::NAME(v8::Handle<v8::String> raw_message) { \ |
| 7188 i::Isolate* isolate = i::Isolate::Current(); \ | 7180 i::Isolate* isolate = i::Isolate::Current(); \ |
| 7189 LOG_API(isolate, #NAME); \ | 7181 LOG_API(isolate, #NAME); \ |
| 7190 ON_BAILOUT(isolate, "v8::Exception::" #NAME "()", return Local<Value>()); \ | |
| 7191 ENTER_V8(isolate); \ | 7182 ENTER_V8(isolate); \ |
| 7192 i::Object* error; \ | 7183 i::Object* error; \ |
| 7193 { \ | 7184 { \ |
| 7194 i::HandleScope scope(isolate); \ | 7185 i::HandleScope scope(isolate); \ |
| 7195 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \ | 7186 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \ |
| 7196 error = *isolate->factory()->New##NAME(message); \ | 7187 error = *isolate->factory()->New##NAME(message); \ |
| 7197 } \ | 7188 } \ |
| 7198 i::Handle<i::Object> result(error, isolate); \ | 7189 i::Handle<i::Object> result(error, isolate); \ |
| 7199 return Utils::ToLocal(result); \ | 7190 return Utils::ToLocal(result); \ |
| 7200 } | 7191 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 7226 i::Isolate* isolate = js_obj->GetIsolate(); | 7217 i::Isolate* isolate = js_obj->GetIsolate(); |
| 7227 ENTER_V8(isolate); | 7218 ENTER_V8(isolate); |
| 7228 return Utils::StackTraceToLocal(isolate->GetDetailedStackTrace(js_obj)); | 7219 return Utils::StackTraceToLocal(isolate->GetDetailedStackTrace(js_obj)); |
| 7229 } | 7220 } |
| 7230 | 7221 |
| 7231 | 7222 |
| 7232 // --- D e b u g S u p p o r t --- | 7223 // --- D e b u g S u p p o r t --- |
| 7233 | 7224 |
| 7234 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { | 7225 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { |
| 7235 i::Isolate* isolate = i::Isolate::Current(); | 7226 i::Isolate* isolate = i::Isolate::Current(); |
| 7236 ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); | |
| 7237 ENTER_V8(isolate); | 7227 ENTER_V8(isolate); |
| 7238 i::HandleScope scope(isolate); | 7228 i::HandleScope scope(isolate); |
| 7239 i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); | 7229 i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
| 7240 if (that != NULL) { | 7230 if (that != NULL) { |
| 7241 foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); | 7231 foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
| 7242 } | 7232 } |
| 7243 isolate->debug()->SetEventListener(foreign, | 7233 isolate->debug()->SetEventListener(foreign, |
| 7244 Utils::OpenHandle(*data, true)); | 7234 Utils::OpenHandle(*data, true)); |
| 7245 return true; | 7235 return true; |
| 7246 } | 7236 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7279 void Debug::SendCommand(Isolate* isolate, | 7269 void Debug::SendCommand(Isolate* isolate, |
| 7280 const uint16_t* command, | 7270 const uint16_t* command, |
| 7281 int length, | 7271 int length, |
| 7282 ClientData* client_data) { | 7272 ClientData* client_data) { |
| 7283 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7273 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 7284 internal_isolate->debug()->EnqueueCommandMessage( | 7274 internal_isolate->debug()->EnqueueCommandMessage( |
| 7285 i::Vector<const uint16_t>(command, length), client_data); | 7275 i::Vector<const uint16_t>(command, length), client_data); |
| 7286 } | 7276 } |
| 7287 | 7277 |
| 7288 | 7278 |
| 7279 MaybeLocal<Value> Debug::Call(Local<Context> context, |
| 7280 v8::Handle<v8::Function> fun, |
| 7281 v8::Handle<v8::Value> data) { |
| 7282 PREPARE_FOR_EXECUTION(context, "v8::Debug::Call()", Value); |
| 7283 i::Handle<i::Object> data_obj; |
| 7284 if (data.IsEmpty()) { |
| 7285 data_obj = isolate->factory()->undefined_value(); |
| 7286 } else { |
| 7287 data_obj = Utils::OpenHandle(*data); |
| 7288 } |
| 7289 Local<Value> result; |
| 7290 has_pending_exception = |
| 7291 !ToLocal<Value>(isolate->debug()->Call(Utils::OpenHandle(*fun), data_obj), |
| 7292 &result); |
| 7293 RETURN_ON_FAILED_EXECUTION(Value); |
| 7294 RETURN_ESCAPED(result); |
| 7295 } |
| 7296 |
| 7297 |
| 7289 Local<Value> Debug::Call(v8::Handle<v8::Function> fun, | 7298 Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 7290 v8::Handle<v8::Value> data) { | 7299 v8::Handle<v8::Value> data) { |
| 7291 i::Isolate* isolate = i::Isolate::Current(); | 7300 auto context = ContextFromHeapObject(Utils::OpenHandle(*fun)); |
| 7292 ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); | 7301 RETURN_TO_LOCAL_UNCHECKED(Call(context, fun, data), Value); |
| 7293 ENTER_V8(isolate); | 7302 } |
| 7294 i::MaybeHandle<i::Object> maybe_result; | 7303 |
| 7295 EXCEPTION_PREAMBLE(isolate); | 7304 |
| 7296 if (data.IsEmpty()) { | 7305 MaybeLocal<Value> Debug::GetMirror(Local<Context> context, |
| 7297 maybe_result = isolate->debug()->Call( | 7306 v8::Handle<v8::Value> obj) { |
| 7298 Utils::OpenHandle(*fun), isolate->factory()->undefined_value()); | 7307 PREPARE_FOR_EXECUTION(context, "v8::Debug::GetMirror()", Value); |
| 7299 } else { | 7308 i::Debug* isolate_debug = isolate->debug(); |
| 7300 maybe_result = isolate->debug()->Call( | 7309 has_pending_exception = !isolate_debug->Load(); |
| 7301 Utils::OpenHandle(*fun), Utils::OpenHandle(*data)); | 7310 RETURN_ON_FAILED_EXECUTION(Value); |
| 7302 } | 7311 i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object()); |
| 7303 i::Handle<i::Object> result; | 7312 auto name = isolate->factory()->NewStringFromStaticChars("MakeMirror"); |
| 7304 has_pending_exception = !maybe_result.ToHandle(&result); | 7313 auto fun_obj = i::Object::GetProperty(debug, name).ToHandleChecked(); |
| 7305 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); | 7314 auto v8_fun = Utils::ToLocal(i::Handle<i::JSFunction>::cast(fun_obj)); |
| 7306 return Utils::ToLocal(result); | 7315 const int kArgc = 1; |
| 7316 v8::Handle<v8::Value> argv[kArgc] = {obj}; |
| 7317 Local<Value> result; |
| 7318 has_pending_exception = !v8_fun->Call(context, Utils::ToLocal(debug), kArgc, |
| 7319 argv).ToLocal(&result); |
| 7320 RETURN_ON_FAILED_EXECUTION(Value); |
| 7321 RETURN_ESCAPED(result); |
| 7307 } | 7322 } |
| 7308 | 7323 |
| 7309 | 7324 |
| 7310 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { | 7325 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
| 7311 i::Isolate* isolate = i::Isolate::Current(); | 7326 RETURN_TO_LOCAL_UNCHECKED(GetMirror(Local<Context>(), obj), Value); |
| 7312 ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); | |
| 7313 ENTER_V8(isolate); | |
| 7314 v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | |
| 7315 i::Debug* isolate_debug = isolate->debug(); | |
| 7316 EXCEPTION_PREAMBLE(isolate); | |
| 7317 has_pending_exception = !isolate_debug->Load(); | |
| 7318 v8::Local<v8::Value> result; | |
| 7319 if (!has_pending_exception) { | |
| 7320 i::Handle<i::JSObject> debug( | |
| 7321 isolate_debug->debug_context()->global_object()); | |
| 7322 i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString( | |
| 7323 STATIC_CHAR_VECTOR("MakeMirror")); | |
| 7324 i::Handle<i::Object> fun_obj = | |
| 7325 i::Object::GetProperty(debug, name).ToHandleChecked(); | |
| 7326 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); | |
| 7327 v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); | |
| 7328 const int kArgc = 1; | |
| 7329 v8::Handle<v8::Value> argv[kArgc] = { obj }; | |
| 7330 result = v8_fun->Call(Utils::ToLocal(debug), kArgc, argv); | |
| 7331 has_pending_exception = result.IsEmpty(); | |
| 7332 } | |
| 7333 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); | |
| 7334 return scope.Escape(result); | |
| 7335 } | 7327 } |
| 7336 | 7328 |
| 7337 | 7329 |
| 7338 void Debug::ProcessDebugMessages() { | 7330 void Debug::ProcessDebugMessages() { |
| 7339 i::Isolate::Current()->debug()->ProcessDebugMessages(true); | 7331 i::Isolate::Current()->debug()->ProcessDebugMessages(true); |
| 7340 } | 7332 } |
| 7341 | 7333 |
| 7342 | 7334 |
| 7343 Local<Context> Debug::GetDebugContext() { | 7335 Local<Context> Debug::GetDebugContext() { |
| 7344 i::Isolate* isolate = i::Isolate::Current(); | 7336 i::Isolate* isolate = i::Isolate::Current(); |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7991 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7983 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7992 Address callback_address = | 7984 Address callback_address = |
| 7993 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7985 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7994 VMState<EXTERNAL> state(isolate); | 7986 VMState<EXTERNAL> state(isolate); |
| 7995 ExternalCallbackScope call_scope(isolate, callback_address); | 7987 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7996 callback(info); | 7988 callback(info); |
| 7997 } | 7989 } |
| 7998 | 7990 |
| 7999 | 7991 |
| 8000 } } // namespace v8::internal | 7992 } } // namespace v8::internal |
| OLD | NEW |