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

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

Issue 24538002: add isolate parameter to ThrowException (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | « src/d8-posix.cc ('k') | test/cctest/test-accessors.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 v8::ThrowException(v8::String::New( 78 args.GetIsolate()->ThrowException(v8::String::New(
79 "First parameter to externalizeString() must be a string.")); 79 "First parameter to externalizeString() must be a string."));
80 return; 80 return;
81 } 81 }
82 bool force_two_byte = false; 82 bool force_two_byte = false;
83 if (args.Length() >= 2) { 83 if (args.Length() >= 2) {
84 if (args[1]->IsBoolean()) { 84 if (args[1]->IsBoolean()) {
85 force_two_byte = args[1]->BooleanValue(); 85 force_two_byte = args[1]->BooleanValue();
86 } else { 86 } else {
87 v8::ThrowException(v8::String::New( 87 args.GetIsolate()->ThrowException(v8::String::New(
88 "Second parameter to externalizeString() must be a boolean.")); 88 "Second parameter to externalizeString() must be a boolean."));
89 return; 89 return;
90 } 90 }
91 } 91 }
92 bool result = false; 92 bool result = false;
93 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>()); 93 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
94 if (string->IsExternalString()) { 94 if (string->IsExternalString()) {
95 v8::ThrowException(v8::String::New( 95 args.GetIsolate()->ThrowException(v8::String::New(
96 "externalizeString() can't externalize twice.")); 96 "externalizeString() can't externalize twice."));
97 return; 97 return;
98 } 98 }
99 if (string->IsOneByteRepresentation() && !force_two_byte) { 99 if (string->IsOneByteRepresentation() && !force_two_byte) {
100 uint8_t* data = new uint8_t[string->length()]; 100 uint8_t* data = new uint8_t[string->length()];
101 String::WriteToFlat(*string, data, 0, string->length()); 101 String::WriteToFlat(*string, data, 0, string->length());
102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( 102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource(
103 reinterpret_cast<char*>(data), string->length()); 103 reinterpret_cast<char*>(data), string->length());
104 result = string->MakeExternal(resource); 104 result = string->MakeExternal(resource);
105 if (result && !string->IsInternalizedString()) { 105 if (result && !string->IsInternalizedString()) {
106 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 106 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
107 isolate->heap()->external_string_table()->AddString(*string); 107 isolate->heap()->external_string_table()->AddString(*string);
108 } 108 }
109 if (!result) delete resource; 109 if (!result) delete resource;
110 } else { 110 } else {
111 uc16* data = new uc16[string->length()]; 111 uc16* data = new uc16[string->length()];
112 String::WriteToFlat(*string, data, 0, string->length()); 112 String::WriteToFlat(*string, data, 0, string->length());
113 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( 113 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource(
114 data, string->length()); 114 data, string->length());
115 result = string->MakeExternal(resource); 115 result = string->MakeExternal(resource);
116 if (result && !string->IsInternalizedString()) { 116 if (result && !string->IsInternalizedString()) {
117 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 117 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
118 isolate->heap()->external_string_table()->AddString(*string); 118 isolate->heap()->external_string_table()->AddString(*string);
119 } 119 }
120 if (!result) delete resource; 120 if (!result) delete resource;
121 } 121 }
122 if (!result) { 122 if (!result) {
123 v8::ThrowException(v8::String::New("externalizeString() failed.")); 123 args.GetIsolate()->ThrowException(
124 v8::String::New("externalizeString() failed."));
124 return; 125 return;
125 } 126 }
126 } 127 }
127 128
128 129
129 void ExternalizeStringExtension::IsAscii( 130 void ExternalizeStringExtension::IsAscii(
130 const v8::FunctionCallbackInfo<v8::Value>& args) { 131 const v8::FunctionCallbackInfo<v8::Value>& args) {
131 if (args.Length() != 1 || !args[0]->IsString()) { 132 if (args.Length() != 1 || !args[0]->IsString()) {
132 v8::ThrowException(v8::String::New( 133 args.GetIsolate()->ThrowException(v8::String::New(
133 "isAsciiString() requires a single string argument.")); 134 "isAsciiString() requires a single string argument."));
134 return; 135 return;
135 } 136 }
136 bool is_one_byte = 137 bool is_one_byte =
137 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation(); 138 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation();
138 args.GetReturnValue().Set(is_one_byte); 139 args.GetReturnValue().Set(is_one_byte);
139 } 140 }
140 141
141 142
142 void ExternalizeStringExtension::Register() { 143 void ExternalizeStringExtension::Register() {
143 static ExternalizeStringExtension externalize_extension; 144 static ExternalizeStringExtension externalize_extension;
144 static v8::DeclareExtension declaration(&externalize_extension); 145 static v8::DeclareExtension declaration(&externalize_extension);
145 } 146 }
146 147
147 } } // namespace v8::internal 148 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/d8-posix.cc ('k') | test/cctest/test-accessors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698