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 6705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6716 MaybeLocal<String> v8::String::NewExternalTwoByte( | 6716 MaybeLocal<String> v8::String::NewExternalTwoByte( |
6717 Isolate* isolate, v8::String::ExternalStringResource* resource) { | 6717 Isolate* isolate, v8::String::ExternalStringResource* resource) { |
6718 CHECK(resource && resource->data()); | 6718 CHECK(resource && resource->data()); |
6719 // TODO(dcarney): throw a context free exception. | 6719 // TODO(dcarney): throw a context free exception. |
6720 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) { | 6720 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) { |
6721 return MaybeLocal<String>(); | 6721 return MaybeLocal<String>(); |
6722 } | 6722 } |
6723 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6723 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6724 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 6724 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
6725 LOG_API(i_isolate, String, NewExternalTwoByte); | 6725 LOG_API(i_isolate, String, NewExternalTwoByte); |
6726 i::Handle<i::String> string = i_isolate->factory() | 6726 if (resource->length() > 0) { |
6727 ->NewExternalStringFromTwoByte(resource) | 6727 i::Handle<i::String> string = i_isolate->factory() |
6728 .ToHandleChecked(); | 6728 ->NewExternalStringFromTwoByte(resource) |
6729 i_isolate->heap()->RegisterExternalString(*string); | 6729 .ToHandleChecked(); |
6730 return Utils::ToLocal(string); | 6730 i_isolate->heap()->RegisterExternalString(*string); |
| 6731 return Utils::ToLocal(string); |
| 6732 } else { |
| 6733 // The resource isn't going to be used, free it immediately. |
| 6734 resource->Dispose(); |
| 6735 return Utils::ToLocal(i_isolate->factory()->empty_string()); |
| 6736 } |
6731 } | 6737 } |
6732 | 6738 |
6733 | 6739 |
6734 Local<String> v8::String::NewExternal( | 6740 Local<String> v8::String::NewExternal( |
6735 Isolate* isolate, v8::String::ExternalStringResource* resource) { | 6741 Isolate* isolate, v8::String::ExternalStringResource* resource) { |
6736 RETURN_TO_LOCAL_UNCHECKED(NewExternalTwoByte(isolate, resource), String); | 6742 RETURN_TO_LOCAL_UNCHECKED(NewExternalTwoByte(isolate, resource), String); |
6737 } | 6743 } |
6738 | 6744 |
6739 | 6745 |
6740 MaybeLocal<String> v8::String::NewExternalOneByte( | 6746 MaybeLocal<String> v8::String::NewExternalOneByte( |
6741 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { | 6747 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { |
6742 CHECK(resource && resource->data()); | 6748 CHECK(resource && resource->data()); |
6743 // TODO(dcarney): throw a context free exception. | 6749 // TODO(dcarney): throw a context free exception. |
6744 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) { | 6750 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) { |
6745 return MaybeLocal<String>(); | 6751 return MaybeLocal<String>(); |
6746 } | 6752 } |
6747 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6753 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
6748 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 6754 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
6749 LOG_API(i_isolate, String, NewExternalOneByte); | 6755 LOG_API(i_isolate, String, NewExternalOneByte); |
6750 i::Handle<i::String> string = i_isolate->factory() | 6756 if (resource->length() > 0) { |
6751 ->NewExternalStringFromOneByte(resource) | 6757 i::Handle<i::String> string = i_isolate->factory() |
6752 .ToHandleChecked(); | 6758 ->NewExternalStringFromOneByte(resource) |
6753 i_isolate->heap()->RegisterExternalString(*string); | 6759 .ToHandleChecked(); |
6754 return Utils::ToLocal(string); | 6760 i_isolate->heap()->RegisterExternalString(*string); |
| 6761 return Utils::ToLocal(string); |
| 6762 } else { |
| 6763 // The resource isn't going to be used, free it immediately. |
| 6764 resource->Dispose(); |
| 6765 return Utils::ToLocal(i_isolate->factory()->empty_string()); |
| 6766 } |
6755 } | 6767 } |
6756 | 6768 |
6757 | 6769 |
6758 Local<String> v8::String::NewExternal( | 6770 Local<String> v8::String::NewExternal( |
6759 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { | 6771 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { |
6760 RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String); | 6772 RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String); |
6761 } | 6773 } |
6762 | 6774 |
6763 | 6775 |
6764 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { | 6776 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
(...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10136 Address callback_address = | 10148 Address callback_address = |
10137 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10149 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10138 VMState<EXTERNAL> state(isolate); | 10150 VMState<EXTERNAL> state(isolate); |
10139 ExternalCallbackScope call_scope(isolate, callback_address); | 10151 ExternalCallbackScope call_scope(isolate, callback_address); |
10140 callback(info); | 10152 callback(info); |
10141 } | 10153 } |
10142 | 10154 |
10143 | 10155 |
10144 } // namespace internal | 10156 } // namespace internal |
10145 } // namespace v8 | 10157 } // namespace v8 |
OLD | NEW |