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

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

Issue 83323003: Remove usage of deprecated APIs from v8 itself (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | « src/debug.cc ('k') | src/extensions/statistics-extension.cc » ('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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } else { 68 } else {
69 ASSERT(strcmp(*v8::String::Utf8Value(str), "isAsciiString") == 0); 69 ASSERT(strcmp(*v8::String::Utf8Value(str), "isAsciiString") == 0);
70 return v8::FunctionTemplate::New(ExternalizeStringExtension::IsAscii); 70 return v8::FunctionTemplate::New(ExternalizeStringExtension::IsAscii);
71 } 71 }
72 } 72 }
73 73
74 74
75 void ExternalizeStringExtension::Externalize( 75 void ExternalizeStringExtension::Externalize(
76 const v8::FunctionCallbackInfo<v8::Value>& args) { 76 const v8::FunctionCallbackInfo<v8::Value>& args) {
77 if (args.Length() < 1 || !args[0]->IsString()) { 77 if (args.Length() < 1 || !args[0]->IsString()) {
78 args.GetIsolate()->ThrowException(v8::String::New( 78 args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
79 args.GetIsolate(),
79 "First parameter to externalizeString() must be a string.")); 80 "First parameter to externalizeString() must be a string."));
80 return; 81 return;
81 } 82 }
82 bool force_two_byte = false; 83 bool force_two_byte = false;
83 if (args.Length() >= 2) { 84 if (args.Length() >= 2) {
84 if (args[1]->IsBoolean()) { 85 if (args[1]->IsBoolean()) {
85 force_two_byte = args[1]->BooleanValue(); 86 force_two_byte = args[1]->BooleanValue();
86 } else { 87 } else {
87 args.GetIsolate()->ThrowException(v8::String::New( 88 args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
89 args.GetIsolate(),
88 "Second parameter to externalizeString() must be a boolean.")); 90 "Second parameter to externalizeString() must be a boolean."));
89 return; 91 return;
90 } 92 }
91 } 93 }
92 bool result = false; 94 bool result = false;
93 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>()); 95 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
94 if (string->IsExternalString()) { 96 if (string->IsExternalString()) {
95 args.GetIsolate()->ThrowException(v8::String::New( 97 args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
98 args.GetIsolate(),
96 "externalizeString() can't externalize twice.")); 99 "externalizeString() can't externalize twice."));
97 return; 100 return;
98 } 101 }
99 if (string->IsOneByteRepresentation() && !force_two_byte) { 102 if (string->IsOneByteRepresentation() && !force_two_byte) {
100 uint8_t* data = new uint8_t[string->length()]; 103 uint8_t* data = new uint8_t[string->length()];
101 String::WriteToFlat(*string, data, 0, string->length()); 104 String::WriteToFlat(*string, data, 0, string->length());
102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( 105 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource(
103 reinterpret_cast<char*>(data), string->length()); 106 reinterpret_cast<char*>(data), string->length());
104 result = string->MakeExternal(resource); 107 result = string->MakeExternal(resource);
105 if (result && !string->IsInternalizedString()) { 108 if (result && !string->IsInternalizedString()) {
106 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 109 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
107 isolate->heap()->external_string_table()->AddString(*string); 110 isolate->heap()->external_string_table()->AddString(*string);
108 } 111 }
109 if (!result) delete resource; 112 if (!result) delete resource;
110 } else { 113 } else {
111 uc16* data = new uc16[string->length()]; 114 uc16* data = new uc16[string->length()];
112 String::WriteToFlat(*string, data, 0, string->length()); 115 String::WriteToFlat(*string, data, 0, string->length());
113 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( 116 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource(
114 data, string->length()); 117 data, string->length());
115 result = string->MakeExternal(resource); 118 result = string->MakeExternal(resource);
116 if (result && !string->IsInternalizedString()) { 119 if (result && !string->IsInternalizedString()) {
117 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 120 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
118 isolate->heap()->external_string_table()->AddString(*string); 121 isolate->heap()->external_string_table()->AddString(*string);
119 } 122 }
120 if (!result) delete resource; 123 if (!result) delete resource;
121 } 124 }
122 if (!result) { 125 if (!result) {
123 args.GetIsolate()->ThrowException( 126 args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
124 v8::String::New("externalizeString() failed.")); 127 args.GetIsolate(), "externalizeString() failed."));
125 return; 128 return;
126 } 129 }
127 } 130 }
128 131
129 132
130 void ExternalizeStringExtension::IsAscii( 133 void ExternalizeStringExtension::IsAscii(
131 const v8::FunctionCallbackInfo<v8::Value>& args) { 134 const v8::FunctionCallbackInfo<v8::Value>& args) {
132 if (args.Length() != 1 || !args[0]->IsString()) { 135 if (args.Length() != 1 || !args[0]->IsString()) {
133 args.GetIsolate()->ThrowException(v8::String::New( 136 args.GetIsolate()->ThrowException(v8::String::NewFromUtf8(
137 args.GetIsolate(),
134 "isAsciiString() requires a single string argument.")); 138 "isAsciiString() requires a single string argument."));
135 return; 139 return;
136 } 140 }
137 bool is_one_byte = 141 bool is_one_byte =
138 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation(); 142 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation();
139 args.GetReturnValue().Set(is_one_byte); 143 args.GetReturnValue().Set(is_one_byte);
140 } 144 }
141 145
142 146
143 void ExternalizeStringExtension::Register() { 147 void ExternalizeStringExtension::Register() {
144 static ExternalizeStringExtension externalize_extension; 148 static ExternalizeStringExtension externalize_extension;
145 static v8::DeclareExtension declaration(&externalize_extension); 149 static v8::DeclareExtension declaration(&externalize_extension);
146 } 150 }
147 151
148 } } // namespace v8::internal 152 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | src/extensions/statistics-extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698