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

Side by Side Diff: src/d8.cc

Issue 7053038: Add support for external arrays to d8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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/d8.h ('k') | 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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return ThrowException(String::New("Error loading file")); 211 return ThrowException(String::New("Error loading file"));
212 } 212 }
213 if (!ExecuteString(source, String::New(*file), false, false)) { 213 if (!ExecuteString(source, String::New(*file), false, false)) {
214 return ThrowException(String::New("Error executing file")); 214 return ThrowException(String::New("Error executing file"));
215 } 215 }
216 } 216 }
217 return Undefined(); 217 return Undefined();
218 } 218 }
219 219
220 220
221 Handle<Value> Shell::CreateExternalArray(const Arguments& args,
222 ExternalArrayType type,
223 int element_size) {
224 if (args.Length() != 1) {
225 return ThrowException(
226 String::New("Array constructor needs one parameter."));
227 }
228 int length = args[0]->Int32Value();
229 void* data = malloc(length * element_size);
230 memset(data, 0, length * element_size);
231 Handle<Object> array = Object::New();
232 Persistent<Object> persistent_array = Persistent<Object>::New(array);
233 persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
234 persistent_array.MarkIndependent();
235 array->SetIndexedPropertiesToExternalArrayData(data, type, length);
236 array->Set(String::New("length"), Int32::New(length), ReadOnly);
237 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size));
238 return array;
239 }
240
241
242 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) {
243 free(data);
244 object.Dispose();
245 }
246
247
248 Handle<Value> Shell::Int8Array(const Arguments& args) {
249 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t));
250 }
251
252
253 Handle<Value> Shell::Uint8Array(const Arguments& args) {
254 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t));
255 }
256
257
258 Handle<Value> Shell::Int16Array(const Arguments& args) {
259 return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t));
260 }
261
262
263 Handle<Value> Shell::Uint16Array(const Arguments& args) {
264 return CreateExternalArray(args, kExternalUnsignedShortArray,
265 sizeof(uint16_t));
266 }
267
268 Handle<Value> Shell::Int32Array(const Arguments& args) {
269 return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t));
270 }
271
272
273 Handle<Value> Shell::Uint32Array(const Arguments& args) {
274 return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t));
275 }
276
277
278 Handle<Value> Shell::Float32Array(const Arguments& args) {
279 return CreateExternalArray(args, kExternalFloatArray,
280 sizeof(float)); // NOLINT
281 }
282
283
284 Handle<Value> Shell::Float64Array(const Arguments& args) {
285 return CreateExternalArray(args, kExternalDoubleArray,
286 sizeof(double)); // NOLINT
287 }
288
289
290 Handle<Value> Shell::PixelArray(const Arguments& args) {
291 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t));
292 }
293
294
221 Handle<Value> Shell::Yield(const Arguments& args) { 295 Handle<Value> Shell::Yield(const Arguments& args) {
222 v8::Unlocker unlocker; 296 v8::Unlocker unlocker;
223 return Undefined(); 297 return Undefined();
224 } 298 }
225 299
226 300
227 Handle<Value> Shell::Quit(const Arguments& args) { 301 Handle<Value> Shell::Quit(const Arguments& args) {
228 int exit_code = args[0]->Int32Value(); 302 int exit_code = args[0]->Int32Value();
229 OnExit(); 303 OnExit();
230 exit(exit_code); 304 exit(exit_code);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); 499 Handle<ObjectTemplate> global_template = ObjectTemplate::New();
426 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); 500 global_template->Set(String::New("print"), FunctionTemplate::New(Print));
427 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); 501 global_template->Set(String::New("write"), FunctionTemplate::New(Write));
428 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); 502 global_template->Set(String::New("read"), FunctionTemplate::New(Read));
429 global_template->Set(String::New("readline"), 503 global_template->Set(String::New("readline"),
430 FunctionTemplate::New(ReadLine)); 504 FunctionTemplate::New(ReadLine));
431 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); 505 global_template->Set(String::New("load"), FunctionTemplate::New(Load));
432 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); 506 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
433 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); 507 global_template->Set(String::New("version"), FunctionTemplate::New(Version));
434 508
509 // Bind the handlers for external arrays.
510 global_template->Set(String::New("Int8Array"),
511 FunctionTemplate::New(Int8Array));
512 global_template->Set(String::New("Uint8Array"),
513 FunctionTemplate::New(Uint8Array));
514 global_template->Set(String::New("Int16Array"),
515 FunctionTemplate::New(Int16Array));
516 global_template->Set(String::New("Uint16Array"),
517 FunctionTemplate::New(Uint16Array));
518 global_template->Set(String::New("Int32Array"),
519 FunctionTemplate::New(Int32Array));
520 global_template->Set(String::New("Uint32Array"),
521 FunctionTemplate::New(Uint32Array));
522 global_template->Set(String::New("Float32Array"),
523 FunctionTemplate::New(Float32Array));
524 global_template->Set(String::New("Float64Array"),
525 FunctionTemplate::New(Float64Array));
526 global_template->Set(String::New("PixelArray"),
527 FunctionTemplate::New(PixelArray));
528
435 #ifdef LIVE_OBJECT_LIST 529 #ifdef LIVE_OBJECT_LIST
436 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); 530 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
437 #else 531 #else
438 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); 532 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
439 #endif 533 #endif
440 534
441 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 535 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
442 AddOSMethods(os_templ); 536 AddOSMethods(os_templ);
443 global_template->Set(String::New("os"), os_templ); 537 global_template->Set(String::New("os"), os_templ);
444 538
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 888
795 889
796 } // namespace v8 890 } // namespace v8
797 891
798 892
799 #ifndef GOOGLE3 893 #ifndef GOOGLE3
800 int main(int argc, char* argv[]) { 894 int main(int argc, char* argv[]) {
801 return v8::Shell::Main(argc, argv); 895 return v8::Shell::Main(argc, argv);
802 } 896 }
803 #endif 897 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698