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

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

Issue 15793007: Cutover v8 to use new style callbacks internally (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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/extensions/externalize-string-extension.h ('k') | src/extensions/gc-extension.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 // 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 v8::Handle<v8::String> str) { 65 v8::Handle<v8::String> str) {
66 if (strcmp(*v8::String::Utf8Value(str), "externalizeString") == 0) { 66 if (strcmp(*v8::String::Utf8Value(str), "externalizeString") == 0) {
67 return v8::FunctionTemplate::New(ExternalizeStringExtension::Externalize); 67 return v8::FunctionTemplate::New(ExternalizeStringExtension::Externalize);
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 v8::Handle<v8::Value> ExternalizeStringExtension::Externalize( 75 void ExternalizeStringExtension::Externalize(
76 const v8::Arguments& 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 return v8::ThrowException(v8::String::New( 78 v8::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 } 81 }
81 bool force_two_byte = false; 82 bool force_two_byte = false;
82 if (args.Length() >= 2) { 83 if (args.Length() >= 2) {
83 if (args[1]->IsBoolean()) { 84 if (args[1]->IsBoolean()) {
84 force_two_byte = args[1]->BooleanValue(); 85 force_two_byte = args[1]->BooleanValue();
85 } else { 86 } else {
86 return v8::ThrowException(v8::String::New( 87 v8::ThrowException(v8::String::New(
87 "Second parameter to externalizeString() must be a boolean.")); 88 "Second parameter to externalizeString() must be a boolean."));
89 return;
88 } 90 }
89 } 91 }
90 bool result = false; 92 bool result = false;
91 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>()); 93 Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
92 if (string->IsExternalString()) { 94 if (string->IsExternalString()) {
93 return v8::ThrowException(v8::String::New( 95 v8::ThrowException(v8::String::New(
94 "externalizeString() can't externalize twice.")); 96 "externalizeString() can't externalize twice."));
97 return;
95 } 98 }
96 if (string->IsOneByteRepresentation() && !force_two_byte) { 99 if (string->IsOneByteRepresentation() && !force_two_byte) {
97 uint8_t* data = new uint8_t[string->length()]; 100 uint8_t* data = new uint8_t[string->length()];
98 String::WriteToFlat(*string, data, 0, string->length()); 101 String::WriteToFlat(*string, data, 0, string->length());
99 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource( 102 SimpleAsciiStringResource* resource = new SimpleAsciiStringResource(
100 reinterpret_cast<char*>(data), string->length()); 103 reinterpret_cast<char*>(data), string->length());
101 result = string->MakeExternal(resource); 104 result = string->MakeExternal(resource);
102 if (result && !string->IsInternalizedString()) { 105 if (result && !string->IsInternalizedString()) {
103 HEAP->external_string_table()->AddString(*string); 106 HEAP->external_string_table()->AddString(*string);
104 } 107 }
105 if (!result) delete resource; 108 if (!result) delete resource;
106 } else { 109 } else {
107 uc16* data = new uc16[string->length()]; 110 uc16* data = new uc16[string->length()];
108 String::WriteToFlat(*string, data, 0, string->length()); 111 String::WriteToFlat(*string, data, 0, string->length());
109 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource( 112 SimpleTwoByteStringResource* resource = new SimpleTwoByteStringResource(
110 data, string->length()); 113 data, string->length());
111 result = string->MakeExternal(resource); 114 result = string->MakeExternal(resource);
112 if (result && !string->IsInternalizedString()) { 115 if (result && !string->IsInternalizedString()) {
113 HEAP->external_string_table()->AddString(*string); 116 HEAP->external_string_table()->AddString(*string);
114 } 117 }
115 if (!result) delete resource; 118 if (!result) delete resource;
116 } 119 }
117 if (!result) { 120 if (!result) {
118 return v8::ThrowException(v8::String::New("externalizeString() failed.")); 121 v8::ThrowException(v8::String::New("externalizeString() failed."));
122 return;
119 } 123 }
120 return v8::Undefined();
121 } 124 }
122 125
123 126
124 v8::Handle<v8::Value> ExternalizeStringExtension::IsAscii( 127 void ExternalizeStringExtension::IsAscii(
125 const v8::Arguments& args) { 128 const v8::FunctionCallbackInfo<v8::Value>& args) {
126 if (args.Length() != 1 || !args[0]->IsString()) { 129 if (args.Length() != 1 || !args[0]->IsString()) {
127 return v8::ThrowException(v8::String::New( 130 v8::ThrowException(v8::String::New(
128 "isAsciiString() requires a single string argument.")); 131 "isAsciiString() requires a single string argument."));
132 return;
129 } 133 }
130 return 134 bool is_one_byte =
131 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation() ? 135 Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation();
132 v8::True() : v8::False(); 136 args.GetReturnValue().Set(is_one_byte);
133 } 137 }
134 138
135 139
136 void ExternalizeStringExtension::Register() { 140 void ExternalizeStringExtension::Register() {
137 static ExternalizeStringExtension externalize_extension; 141 static ExternalizeStringExtension externalize_extension;
138 static v8::DeclareExtension declaration(&externalize_extension); 142 static v8::DeclareExtension declaration(&externalize_extension);
139 } 143 }
140 144
141 } } // namespace v8::internal 145 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/extensions/externalize-string-extension.h ('k') | src/extensions/gc-extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698