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

Side by Side Diff: src/d8.cc

Issue 7867036: d8 external array c'tors: allow parameters that can be converted to numbers (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: add test Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/external-array.js » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return ThrowException( 288 return ThrowException(
289 String::New("Array constructor needs one parameter.")); 289 String::New("Array constructor needs one parameter."));
290 } 290 }
291 static const int kMaxLength = 0x3fffffff; 291 static const int kMaxLength = 0x3fffffff;
292 #ifndef V8_SHARED 292 #ifndef V8_SHARED
293 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); 293 ASSERT(kMaxLength == i::ExternalArray::kMaxLength);
294 #endif // V8_SHARED 294 #endif // V8_SHARED
295 size_t length = 0; 295 size_t length = 0;
296 if (args[0]->IsUint32()) { 296 if (args[0]->IsUint32()) {
297 length = args[0]->Uint32Value(); 297 length = args[0]->Uint32Value();
298 } else if (args[0]->IsNumber()) { 298 } else {
299 double raw_length = args[0]->NumberValue(); 299 Local<Number> number = args[0]->ToNumber();
300 if (number.IsEmpty() || !number->IsNumber()) {
301 return ThrowException(String::New("Array length must be a number."));
302 }
303 double raw_length = number->NumberValue();
300 if (raw_length < 0) { 304 if (raw_length < 0) {
301 return ThrowException(String::New("Array length must not be negative.")); 305 return ThrowException(String::New("Array length must not be negative."));
302 } 306 }
303 if (raw_length > kMaxLength) { 307 if (raw_length > kMaxLength) {
304 return ThrowException( 308 return ThrowException(
305 String::New("Array length exceeds maximum length.")); 309 String::New("Array length exceeds maximum length."));
306 } 310 }
307 length = static_cast<size_t>(raw_length); 311 length = static_cast<size_t>(raw_length);
308 } else {
309 return ThrowException(String::New("Array length must be a number."));
310 } 312 }
311 if (length > static_cast<size_t>(kMaxLength)) { 313 if (length > static_cast<size_t>(kMaxLength)) {
312 return ThrowException(String::New("Array length exceeds maximum length.")); 314 return ThrowException(String::New("Array length exceeds maximum length."));
313 } 315 }
314 void* data = calloc(length, element_size); 316 void* data = calloc(length, element_size);
315 if (data == NULL) { 317 if (data == NULL) {
316 return ThrowException(String::New("Memory allocation failed.")); 318 return ThrowException(String::New("Memory allocation failed."));
317 } 319 }
318 Handle<Object> array = Object::New(); 320 Handle<Object> array = Object::New();
319 Persistent<Object> persistent_array = Persistent<Object>::New(array); 321 Persistent<Object> persistent_array = Persistent<Object>::New(array);
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 } 1328 }
1327 1329
1328 } // namespace v8 1330 } // namespace v8
1329 1331
1330 1332
1331 #ifndef GOOGLE3 1333 #ifndef GOOGLE3
1332 int main(int argc, char* argv[]) { 1334 int main(int argc, char* argv[]) {
1333 return v8::Shell::Main(argc, argv); 1335 return v8::Shell::Main(argc, argv);
1334 } 1336 }
1335 #endif 1337 #endif
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/external-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698