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

Side by Side Diff: src/extensions/externalize-string-extension.cc

Issue 1312553003: [heap] Prevent direct access to ExternalStringTable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-heap-root-set-1
Patch Set: Addressed comments. Created 5 years, 3 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
« no previous file with comments | « src/api.cc ('k') | src/heap/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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/extensions/externalize-string-extension.h" 5 #include "src/extensions/externalize-string-extension.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return; 91 return;
92 } 92 }
93 if (string->IsOneByteRepresentation() && !force_two_byte) { 93 if (string->IsOneByteRepresentation() && !force_two_byte) {
94 uint8_t* data = new uint8_t[string->length()]; 94 uint8_t* data = new uint8_t[string->length()];
95 String::WriteToFlat(*string, data, 0, string->length()); 95 String::WriteToFlat(*string, data, 0, string->length());
96 SimpleOneByteStringResource* resource = new SimpleOneByteStringResource( 96 SimpleOneByteStringResource* resource = new SimpleOneByteStringResource(
97 reinterpret_cast<char*>(data), string->length()); 97 reinterpret_cast<char*>(data), string->length());
98 result = string->MakeExternal(resource); 98 result = string->MakeExternal(resource);
99 if (result) { 99 if (result) {
100 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 100 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
101 isolate->heap()->external_string_table()->AddString(*string); 101 isolate->heap()->RegisterExternalString(*string);
102 } 102 }
103 if (!result) delete resource; 103 if (!result) delete resource;
104 } else { 104 } else {
105 uc16* data = new uc16[string->length()]; 105 uc16* data = new uc16[string->length()];
106 String::WriteToFlat(*string, data, 0, string->length()); 106 String::WriteToFlat(*string, data, 0, string->length());
107 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( 107 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource(
108 data, string->length()); 108 data, string->length());
109 result = string->MakeExternal(resource); 109 result = string->MakeExternal(resource);
110 if (result) { 110 if (result) {
111 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 111 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
112 isolate->heap()->external_string_table()->AddString(*string); 112 isolate->heap()->RegisterExternalString(*string);
113 } 113 }
114 if (!result) delete resource; 114 if (!result) delete resource;
115 } 115 }
116 if (!result) { 116 if (!result) {
117 args.GetIsolate()->ThrowException( 117 args.GetIsolate()->ThrowException(
118 v8::String::NewFromUtf8(args.GetIsolate(), 118 v8::String::NewFromUtf8(args.GetIsolate(),
119 "externalizeString() failed.", 119 "externalizeString() failed.",
120 NewStringType::kNormal).ToLocalChecked()); 120 NewStringType::kNormal).ToLocalChecked());
121 return; 121 return;
122 } 122 }
(...skipping 10 matching lines...) Expand all
133 NewStringType::kNormal).ToLocalChecked()); 133 NewStringType::kNormal).ToLocalChecked());
134 return; 134 return;
135 } 135 }
136 bool is_one_byte = 136 bool is_one_byte =
137 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation(); 137 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation();
138 args.GetReturnValue().Set(is_one_byte); 138 args.GetReturnValue().Set(is_one_byte);
139 } 139 }
140 140
141 } // namespace internal 141 } // namespace internal
142 } // namespace v8 142 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698