| 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 5465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5476 LOG_API(isolate, "String::New(char)"); | 5476 LOG_API(isolate, "String::New(char)"); |
| 5477 ENTER_V8(isolate); | 5477 ENTER_V8(isolate); |
| 5478 i::Handle<i::String> right_string = Utils::OpenHandle(*right); | 5478 i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
| 5479 // We do not expect this to fail. Change this if it does. | 5479 // We do not expect this to fail. Change this if it does. |
| 5480 i::Handle<i::String> result = isolate->factory()->NewConsString( | 5480 i::Handle<i::String> result = isolate->factory()->NewConsString( |
| 5481 left_string, right_string).ToHandleChecked(); | 5481 left_string, right_string).ToHandleChecked(); |
| 5482 return Utils::ToLocal(result); | 5482 return Utils::ToLocal(result); |
| 5483 } | 5483 } |
| 5484 | 5484 |
| 5485 | 5485 |
| 5486 static i::Handle<i::String> NewExternalStringHandle( | 5486 static i::MaybeHandle<i::String> NewExternalStringHandle( |
| 5487 i::Isolate* isolate, | 5487 i::Isolate* isolate, v8::String::ExternalStringResource* resource) { |
| 5488 v8::String::ExternalStringResource* resource) { | 5488 return isolate->factory()->NewExternalStringFromTwoByte(resource); |
| 5489 // We do not expect this to fail. Change this if it does. | |
| 5490 return isolate->factory()->NewExternalStringFromTwoByte( | |
| 5491 resource).ToHandleChecked(); | |
| 5492 } | 5489 } |
| 5493 | 5490 |
| 5494 | 5491 |
| 5495 static i::Handle<i::String> NewExternalOneByteStringHandle( | 5492 static i::MaybeHandle<i::String> NewExternalOneByteStringHandle( |
| 5496 i::Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { | 5493 i::Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { |
| 5497 // We do not expect this to fail. Change this if it does. | 5494 return isolate->factory()->NewExternalStringFromOneByte(resource); |
| 5498 return isolate->factory() | |
| 5499 ->NewExternalStringFromOneByte(resource) | |
| 5500 .ToHandleChecked(); | |
| 5501 } | 5495 } |
| 5502 | 5496 |
| 5503 | 5497 |
| 5504 Local<String> v8::String::NewExternal( | 5498 Local<String> v8::String::NewExternal( |
| 5505 Isolate* isolate, | 5499 Isolate* isolate, |
| 5506 v8::String::ExternalStringResource* resource) { | 5500 v8::String::ExternalStringResource* resource) { |
| 5507 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 5501 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5508 LOG_API(i_isolate, "String::NewExternal"); | 5502 LOG_API(i_isolate, "String::NewExternal"); |
| 5509 ENTER_V8(i_isolate); | 5503 ENTER_V8(i_isolate); |
| 5510 CHECK(resource && resource->data()); | 5504 CHECK(resource && resource->data()); |
| 5511 i::Handle<i::String> result = NewExternalStringHandle(i_isolate, resource); | 5505 EXCEPTION_PREAMBLE(i_isolate); |
| 5512 i_isolate->heap()->external_string_table()->AddString(*result); | 5506 i::Handle<i::String> string; |
| 5513 return Utils::ToLocal(result); | 5507 has_pending_exception = |
| 5508 !NewExternalStringHandle(i_isolate, resource).ToHandle(&string); |
| 5509 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<String>()); |
| 5510 i_isolate->heap()->external_string_table()->AddString(*string); |
| 5511 return Utils::ToLocal(string); |
| 5514 } | 5512 } |
| 5515 | 5513 |
| 5516 | 5514 |
| 5517 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { | 5515 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
| 5518 i::Handle<i::String> obj = Utils::OpenHandle(this); | 5516 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5519 i::Isolate* isolate = obj->GetIsolate(); | 5517 i::Isolate* isolate = obj->GetIsolate(); |
| 5520 if (i::StringShape(*obj).IsExternal()) { | 5518 if (i::StringShape(*obj).IsExternal()) { |
| 5521 return false; // Already an external string. | 5519 return false; // Already an external string. |
| 5522 } | 5520 } |
| 5523 ENTER_V8(isolate); | 5521 ENTER_V8(isolate); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5539 return result; | 5537 return result; |
| 5540 } | 5538 } |
| 5541 | 5539 |
| 5542 | 5540 |
| 5543 Local<String> v8::String::NewExternal( | 5541 Local<String> v8::String::NewExternal( |
| 5544 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { | 5542 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { |
| 5545 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 5543 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5546 LOG_API(i_isolate, "String::NewExternal"); | 5544 LOG_API(i_isolate, "String::NewExternal"); |
| 5547 ENTER_V8(i_isolate); | 5545 ENTER_V8(i_isolate); |
| 5548 CHECK(resource && resource->data()); | 5546 CHECK(resource && resource->data()); |
| 5549 i::Handle<i::String> result = | 5547 EXCEPTION_PREAMBLE(i_isolate); |
| 5550 NewExternalOneByteStringHandle(i_isolate, resource); | 5548 i::Handle<i::String> string; |
| 5551 i_isolate->heap()->external_string_table()->AddString(*result); | 5549 has_pending_exception = |
| 5552 return Utils::ToLocal(result); | 5550 !NewExternalOneByteStringHandle(i_isolate, resource).ToHandle(&string); |
| 5551 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<String>()); |
| 5552 i_isolate->heap()->external_string_table()->AddString(*string); |
| 5553 return Utils::ToLocal(string); |
| 5553 } | 5554 } |
| 5554 | 5555 |
| 5555 | 5556 |
| 5556 bool v8::String::MakeExternal( | 5557 bool v8::String::MakeExternal( |
| 5557 v8::String::ExternalOneByteStringResource* resource) { | 5558 v8::String::ExternalOneByteStringResource* resource) { |
| 5558 i::Handle<i::String> obj = Utils::OpenHandle(this); | 5559 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5559 i::Isolate* isolate = obj->GetIsolate(); | 5560 i::Isolate* isolate = obj->GetIsolate(); |
| 5560 if (i::StringShape(*obj).IsExternal()) { | 5561 if (i::StringShape(*obj).IsExternal()) { |
| 5561 return false; // Already an external string. | 5562 return false; // Already an external string. |
| 5562 } | 5563 } |
| (...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7655 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7656 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7656 Address callback_address = | 7657 Address callback_address = |
| 7657 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7658 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7658 VMState<EXTERNAL> state(isolate); | 7659 VMState<EXTERNAL> state(isolate); |
| 7659 ExternalCallbackScope call_scope(isolate, callback_address); | 7660 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7660 callback(info); | 7661 callback(info); |
| 7661 } | 7662 } |
| 7662 | 7663 |
| 7663 | 7664 |
| 7664 } } // namespace v8::internal | 7665 } } // namespace v8::internal |
| OLD | NEW |