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

Side by Side Diff: src/d8.cc

Issue 10700031: Improve creating external array buffer in d8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 if (try_catch.HasCaught()) return try_catch.Exception(); 481 if (try_catch.HasCaught()) return try_catch.Exception();
482 init_from_array = true; 482 init_from_array = true;
483 } else { 483 } else {
484 // Construct from size. 484 // Construct from size.
485 length = convertToUint(args[0], &try_catch); 485 length = convertToUint(args[0], &try_catch);
486 if (try_catch.HasCaught()) return try_catch.Exception(); 486 if (try_catch.HasCaught()) return try_catch.Exception();
487 } 487 }
488 byteLength = length * element_size; 488 byteLength = length * element_size;
489 byteOffset = 0; 489 byteOffset = 0;
490 490
491 Handle<Object> global = Context::GetCurrent()->Global(); 491 buffer = CreateExternalArrayBuffer(Object::New(), byteLength)->ToObject();
492 Handle<Value> array_buffer = global->Get(String::New("ArrayBuffer"));
493 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction());
494 Handle<Value> buffer_args[] = { Uint32::New(byteLength) };
495 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance(
496 1, buffer_args);
497 if (try_catch.HasCaught()) return result;
498 buffer = result->ToObject();
499 } 492 }
500 493
501 Handle<Object> array = CreateExternalArray( 494 Handle<Object> array = CreateExternalArray(
502 args.This(), buffer, type, length, byteLength, byteOffset, element_size); 495 args.This(), buffer, type, length, byteLength, byteOffset, element_size);
503 496
504 if (init_from_array) { 497 if (init_from_array) {
505 Handle<Object> init = args[0]->ToObject(); 498 Handle<Object> init = args[0]->ToObject();
506 for (int i = 0; i < length; ++i) array->Set(i, init->Get(i)); 499 for (int i = 0; i < length; ++i) array->Set(i, init->Get(i));
507 } 500 }
508 501
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 } 1670 }
1678 1671
1679 } // namespace v8 1672 } // namespace v8
1680 1673
1681 1674
1682 #ifndef GOOGLE3 1675 #ifndef GOOGLE3
1683 int main(int argc, char* argv[]) { 1676 int main(int argc, char* argv[]) {
1684 return v8::Shell::Main(argc, argv); 1677 return v8::Shell::Main(argc, argv);
1685 } 1678 }
1686 #endif 1679 #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