Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: src/api.cc

Issue 603393004: String::NewExternal should not crash the renderer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-strings.cc » ('j') | test/cctest/test-strings.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 i::MaybeHandle<i::String> maybe_string =
5512 i_isolate->heap()->external_string_table()->AddString(*result); 5506 NewExternalStringHandle(i_isolate, resource);
5513 return Utils::ToLocal(result); 5507 i::Handle<i::String> string;
5508 if (maybe_string.ToHandle(&string))
Yang 2014/09/26 09:29:59 At this point we have a pending exception. It need
5509 i_isolate->heap()->external_string_table()->AddString(*string);
5510 return Utils::ToLocal(string);
5514 } 5511 }
5515 5512
5516 5513
5517 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { 5514 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
5518 i::Handle<i::String> obj = Utils::OpenHandle(this); 5515 i::Handle<i::String> obj = Utils::OpenHandle(this);
5519 i::Isolate* isolate = obj->GetIsolate(); 5516 i::Isolate* isolate = obj->GetIsolate();
5520 if (i::StringShape(*obj).IsExternal()) { 5517 if (i::StringShape(*obj).IsExternal()) {
5521 return false; // Already an external string. 5518 return false; // Already an external string.
5522 } 5519 }
5523 ENTER_V8(isolate); 5520 ENTER_V8(isolate);
(...skipping 15 matching lines...) Expand all
5539 return result; 5536 return result;
5540 } 5537 }
5541 5538
5542 5539
5543 Local<String> v8::String::NewExternal( 5540 Local<String> v8::String::NewExternal(
5544 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { 5541 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
5545 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 5542 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5546 LOG_API(i_isolate, "String::NewExternal"); 5543 LOG_API(i_isolate, "String::NewExternal");
5547 ENTER_V8(i_isolate); 5544 ENTER_V8(i_isolate);
5548 CHECK(resource && resource->data()); 5545 CHECK(resource && resource->data());
5549 i::Handle<i::String> result = 5546 i::MaybeHandle<i::String> maybe_string =
5550 NewExternalOneByteStringHandle(i_isolate, resource); 5547 NewExternalOneByteStringHandle(i_isolate, resource);
5551 i_isolate->heap()->external_string_table()->AddString(*result); 5548 i::Handle<i::String> string;
5552 return Utils::ToLocal(result); 5549 if (maybe_string.ToHandle(&string))
5550 i_isolate->heap()->external_string_table()->AddString(*string);
5551 return Utils::ToLocal(string);
Yang 2014/09/26 09:29:59 Ditto.
5553 } 5552 }
5554 5553
5555 5554
5556 bool v8::String::MakeExternal( 5555 bool v8::String::MakeExternal(
5557 v8::String::ExternalOneByteStringResource* resource) { 5556 v8::String::ExternalOneByteStringResource* resource) {
5558 i::Handle<i::String> obj = Utils::OpenHandle(this); 5557 i::Handle<i::String> obj = Utils::OpenHandle(this);
5559 i::Isolate* isolate = obj->GetIsolate(); 5558 i::Isolate* isolate = obj->GetIsolate();
5560 if (i::StringShape(*obj).IsExternal()) { 5559 if (i::StringShape(*obj).IsExternal()) {
5561 return false; // Already an external string. 5560 return false; // Already an external string.
5562 } 5561 }
(...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after
7655 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7654 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7656 Address callback_address = 7655 Address callback_address =
7657 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7656 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7658 VMState<EXTERNAL> state(isolate); 7657 VMState<EXTERNAL> state(isolate);
7659 ExternalCallbackScope call_scope(isolate, callback_address); 7658 ExternalCallbackScope call_scope(isolate, callback_address);
7660 callback(info); 7659 callback(info);
7661 } 7660 }
7662 7661
7663 7662
7664 } } // namespace v8::internal 7663 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-strings.cc » ('j') | test/cctest/test-strings.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698