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

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
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 v8::ThrowException(
79 "First parameter to externalizeString() must be a string.")); 79 args.GetIsolate(),
80 v8::String::New(
81 "First parameter to externalizeString() must be a string."));
80 return; 82 return;
81 } 83 }
82 bool force_two_byte = false; 84 bool force_two_byte = false;
83 if (args.Length() >= 2) { 85 if (args.Length() >= 2) {
84 if (args[1]->IsBoolean()) { 86 if (args[1]->IsBoolean()) {
85 force_two_byte = args[1]->BooleanValue(); 87 force_two_byte = args[1]->BooleanValue();
86 } else { 88 } else {
87 v8::ThrowException(v8::String::New( 89 v8::ThrowException(
88 "Second parameter to externalizeString() must be a boolean.")); 90 args.GetIsolate(),
91 v8::String::New(
92 "Second parameter to externalizeString() must be a boolean."));
89 return; 93 return;
90 } 94 }
91 } 95 }
92 bool result = false; 96 bool result = false;
93 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>()); 97 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
94 if (string->IsExternalString()) { 98 if (string->IsExternalString()) {
95 v8::ThrowException(v8::String::New( 99 v8::ThrowException(
96 "externalizeString() can't externalize twice.")); 100 args.GetIsolate(),
101 v8::String::New(
102 "externalizeString() can't externalize twice."));
97 return; 103 return;
98 } 104 }
99 if (string->IsOneByteRepresentation() && !force_two_byte) { 105 if (string->IsOneByteRepresentation() && !force_two_byte) {
100 uint8_t* data = new uint8_t[string->length()]; 106 uint8_t* data = new uint8_t[string->length()];
101 String::WriteToFlat(*string, data, 0, string->length()); 107 String::WriteToFlat(*string, data, 0, string->length());
102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( 108 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource(
103 reinterpret_cast<char*>(data), string->length()); 109 reinterpret_cast<char*>(data), string->length());
104 result = string->MakeExternal(resource); 110 result = string->MakeExternal(resource);
105 if (result && !string->IsInternalizedString()) { 111 if (result && !string->IsInternalizedString()) {
106 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 112 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
(...skipping 15 matching lines...) Expand all
122 if (!result) { 128 if (!result) {
123 v8::ThrowException(v8::String::New("externalizeString() failed.")); 129 v8::ThrowException(v8::String::New("externalizeString() failed."));
124 return; 130 return;
125 } 131 }
126 } 132 }
127 133
128 134
129 void ExternalizeStringExtension::IsAscii( 135 void ExternalizeStringExtension::IsAscii(
130 const v8::FunctionCallbackInfo<v8::Value>& args) { 136 const v8::FunctionCallbackInfo<v8::Value>& args) {
131 if (args.Length() != 1 || !args[0]->IsString()) { 137 if (args.Length() != 1 || !args[0]->IsString()) {
132 v8::ThrowException(v8::String::New( 138 v8::ThrowException(
133 "isAsciiString() requires a single string argument.")); 139 args.GetIsolate(),
140 v8::String::New(
141 "isAsciiString() requires a single string argument."));
134 return; 142 return;
135 } 143 }
136 bool is_one_byte = 144 bool is_one_byte =
137 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation(); 145 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation();
138 args.GetReturnValue().Set(is_one_byte); 146 args.GetReturnValue().Set(is_one_byte);
139 } 147 }
140 148
141 149
142 void ExternalizeStringExtension::Register() { 150 void ExternalizeStringExtension::Register() {
143 static ExternalizeStringExtension externalize_extension; 151 static ExternalizeStringExtension externalize_extension;
144 static v8::DeclareExtension declaration(&externalize_extension); 152 static v8::DeclareExtension declaration(&externalize_extension);
145 } 153 }
146 154
147 } } // namespace v8::internal 155 } } // namespace v8::internal
OLDNEW
« include/v8.h ('K') | « 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