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

Side by Side Diff: src/d8.cc

Issue 10441091: Fix broken change to d8 typed arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 element_size = 1; 331 element_size = 1;
332 } 332 }
333 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 || 333 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 ||
334 element_size == 8); 334 element_size == 8);
335 if (args.Length() == 0) { 335 if (args.Length() == 0) {
336 return ThrowException( 336 return ThrowException(
337 String::New("Array constructor must have at least one parameter.")); 337 String::New("Array constructor must have at least one parameter."));
338 } 338 }
339 bool first_arg_is_array_buffer = 339 bool first_arg_is_array_buffer =
340 args[0]->IsObject() && 340 args[0]->IsObject() &&
341 args[0]->ToObject()->GetHiddenValue( 341 !args[0]->ToObject()->GetHiddenValue(
342 String::New(kArrayBufferMarkerPropName))->IsTrue(); 342 String::New(kArrayBufferMarkerPropName)).IsEmpty();
343 // Currently, only the following constructors are supported: 343 // Currently, only the following constructors are supported:
344 // ArrayBuffer(unsigned long length) 344 // ArrayBuffer(unsigned long length)
345 // TypedArray(unsigned long length) 345 // TypedArray(unsigned long length)
346 // TypedArray(ArrayBuffer buffer, 346 // TypedArray(ArrayBuffer buffer,
347 // optional unsigned long byteOffset, 347 // optional unsigned long byteOffset,
348 // optional unsigned long length) 348 // optional unsigned long length)
349 size_t length; 349 size_t length;
350 size_t byteLength; 350 size_t byteLength;
351 size_t byteOffset; 351 size_t byteOffset;
352 void* data = NULL; 352 void* data = NULL;
(...skipping 13 matching lines...) Expand all
366 if (try_catch.HasCaught()) return try_catch.Exception(); 366 if (try_catch.HasCaught()) return try_catch.Exception();
367 if (data == NULL && byteLength != 0) { 367 if (data == NULL && byteLength != 0) {
368 return ThrowException(String::New("ArrayBuffer does not have data")); 368 return ThrowException(String::New("ArrayBuffer does not have data"));
369 } 369 }
370 370
371 if (args.Length() < 2 || args[1]->IsUndefined()) { 371 if (args.Length() < 2 || args[1]->IsUndefined()) {
372 byteOffset = 0; 372 byteOffset = 0;
373 } else { 373 } else {
374 byteOffset = convertToUint(args[1], &try_catch); 374 byteOffset = convertToUint(args[1], &try_catch);
375 if (try_catch.HasCaught()) return try_catch.Exception(); 375 if (try_catch.HasCaught()) return try_catch.Exception();
376 if (byteOffset > byteLength) {
377 return ThrowException(
378 String::New("byteOffset out of bounds"));
Michael Starzinger 2012/05/30 14:25:08 That should fit into one line.
379 }
376 if (byteOffset % element_size != 0) { 380 if (byteOffset % element_size != 0) {
377 return ThrowException( 381 return ThrowException(
378 String::New("byteOffset must be multiple of element_size")); 382 String::New("byteOffset must be multiple of element_size"));
379 } 383 }
380 } 384 }
381 385
382 if (args.Length() < 3 || args[2]->IsUndefined()) { 386 if (args.Length() < 3 || args[2]->IsUndefined()) {
383 if (byteLength % element_size != 0) { 387 if (byteLength % element_size != 0) {
384 return ThrowException( 388 return ThrowException(
385 String::New("buffer size must be multiple of element_size")); 389 String::New("buffer size must be multiple of element_size"));
386 } 390 }
387 length = (byteLength - byteOffset) / element_size; 391 length = (byteLength - byteOffset) / element_size;
388 } else { 392 } else {
389 length = convertToUint(args[2], &try_catch); 393 length = convertToUint(args[2], &try_catch);
390 if (try_catch.HasCaught()) return try_catch.Exception(); 394 if (try_catch.HasCaught()) return try_catch.Exception();
391 } 395 }
392 396
393 if (byteOffset + length * element_size > byteLength) { 397 if (byteOffset + length * element_size > byteLength) {
394 return ThrowException( 398 return ThrowException(String::New("length out of bounds"));
395 String::New("byteOffset or length out of bounds"));
396 } 399 }
397 byteLength = byteOffset + length * element_size; 400 byteLength = byteOffset + length * element_size;
398 401
399 // Hold a reference to the ArrayBuffer so its buffer doesn't get collected. 402 // Hold a reference to the ArrayBuffer so its buffer doesn't get collected.
400 array->SetHiddenValue( 403 array->SetHiddenValue(
401 String::New(kArrayBufferReferencePropName), args[0]); 404 String::New(kArrayBufferReferencePropName), args[0]);
402 } else { 405 } else {
403 length = convertToUint(args[0], &try_catch); 406 length = convertToUint(args[0], &try_catch);
404 byteLength = length * element_size; 407 byteLength = length * element_size;
405 byteOffset = 0; 408 byteOffset = 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 450 }
448 return array; 451 return array;
449 } 452 }
450 453
451 454
452 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { 455 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) {
453 HandleScope scope; 456 HandleScope scope;
454 Handle<String> prop_name = String::New(kArrayBufferReferencePropName); 457 Handle<String> prop_name = String::New(kArrayBufferReferencePropName);
455 Handle<Object> converted_object = object->ToObject(); 458 Handle<Object> converted_object = object->ToObject();
456 Local<Value> prop_value = converted_object->GetHiddenValue(prop_name); 459 Local<Value> prop_value = converted_object->GetHiddenValue(prop_name);
457 if (data != NULL && !prop_value->IsObject()) { 460 if (data != NULL && prop_value.IsEmpty()) {
458 data = reinterpret_cast<size_t*>(data) - kExternalArrayAllocationHeaderSize; 461 data = reinterpret_cast<size_t*>(data) - kExternalArrayAllocationHeaderSize;
459 V8::AdjustAmountOfExternalAllocatedMemory( 462 V8::AdjustAmountOfExternalAllocatedMemory(
460 -static_cast<int>(*reinterpret_cast<size_t*>(data))); 463 -static_cast<int>(*reinterpret_cast<size_t*>(data)));
461 free(data); 464 free(data);
462 } 465 }
463 object.Dispose(); 466 object.Dispose();
464 } 467 }
465 468
466 469
467 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { 470 Handle<Value> Shell::ArrayBuffer(const Arguments& args) {
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 } 1557 }
1555 1558
1556 } // namespace v8 1559 } // namespace v8
1557 1560
1558 1561
1559 #ifndef GOOGLE3 1562 #ifndef GOOGLE3
1560 int main(int argc, char* argv[]) { 1563 int main(int argc, char* argv[]) {
1561 return v8::Shell::Main(argc, argv); 1564 return v8::Shell::Main(argc, argv);
1562 } 1565 }
1563 #endif 1566 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698