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

Side by Side Diff: samples/process.cc

Issue 2101413002: Provide a convenience array buffer allocator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 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
« no previous file with comments | « samples/hello-world.cc ('k') | samples/shell.cc » ('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 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 20 matching lines...) Expand all
31 31
32 #include <stdlib.h> 32 #include <stdlib.h>
33 #include <string.h> 33 #include <string.h>
34 34
35 #include <map> 35 #include <map>
36 #include <string> 36 #include <string>
37 37
38 using namespace std; 38 using namespace std;
39 using namespace v8; 39 using namespace v8;
40 40
41 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
42 public:
43 virtual void* Allocate(size_t length) {
44 void* data = AllocateUninitialized(length);
45 return data == NULL ? data : memset(data, 0, length);
46 }
47 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
48 virtual void Free(void* data, size_t) { free(data); }
49 };
50
51
52 // These interfaces represent an existing request processing interface. 41 // These interfaces represent an existing request processing interface.
53 // The idea is to imagine a real application that uses these interfaces 42 // The idea is to imagine a real application that uses these interfaces
54 // and then add scripting capabilities that allow you to interact with 43 // and then add scripting capabilities that allow you to interact with
55 // the objects through JavaScript. 44 // the objects through JavaScript.
56 45
57 /** 46 /**
58 * A simplified http request. 47 * A simplified http request.
59 */ 48 */
60 class HttpRequest { 49 class HttpRequest {
61 public: 50 public:
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); 681 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
693 v8::V8::InitializePlatform(platform); 682 v8::V8::InitializePlatform(platform);
694 v8::V8::Initialize(); 683 v8::V8::Initialize();
695 map<string, string> options; 684 map<string, string> options;
696 string file; 685 string file;
697 ParseOptions(argc, argv, &options, &file); 686 ParseOptions(argc, argv, &options, &file);
698 if (file.empty()) { 687 if (file.empty()) {
699 fprintf(stderr, "No script was specified.\n"); 688 fprintf(stderr, "No script was specified.\n");
700 return 1; 689 return 1;
701 } 690 }
702 ArrayBufferAllocator array_buffer_allocator;
703 Isolate::CreateParams create_params; 691 Isolate::CreateParams create_params;
704 create_params.array_buffer_allocator = &array_buffer_allocator; 692 create_params.array_buffer_allocator =
693 v8::ArrayBuffer::Allocator::NewDefaultAllocator();
705 Isolate* isolate = Isolate::New(create_params); 694 Isolate* isolate = Isolate::New(create_params);
706 Isolate::Scope isolate_scope(isolate); 695 Isolate::Scope isolate_scope(isolate);
707 HandleScope scope(isolate); 696 HandleScope scope(isolate);
708 Local<String> source; 697 Local<String> source;
709 if (!ReadFile(isolate, file).ToLocal(&source)) { 698 if (!ReadFile(isolate, file).ToLocal(&source)) {
710 fprintf(stderr, "Error reading '%s'.\n", file.c_str()); 699 fprintf(stderr, "Error reading '%s'.\n", file.c_str());
711 return 1; 700 return 1;
712 } 701 }
713 JsHttpRequestProcessor processor(isolate, source); 702 JsHttpRequestProcessor processor(isolate, source);
714 map<string, string> output; 703 map<string, string> output;
715 if (!processor.Initialize(&options, &output)) { 704 if (!processor.Initialize(&options, &output)) {
716 fprintf(stderr, "Error initializing processor.\n"); 705 fprintf(stderr, "Error initializing processor.\n");
717 return 1; 706 return 1;
718 } 707 }
719 if (!ProcessEntries(platform, &processor, kSampleSize, kSampleRequests)) 708 if (!ProcessEntries(platform, &processor, kSampleSize, kSampleRequests))
720 return 1; 709 return 1;
721 PrintMap(&output); 710 PrintMap(&output);
722 } 711 }
OLDNEW
« no previous file with comments | « samples/hello-world.cc ('k') | samples/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698