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

Side by Side Diff: src/wasm/wasm-js.cc

Issue 1767203002: [wasm] Allow Uint8Array in _WASMEXP_.instantiateModule() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | test/mjsunit/wasm/test-wasm-module-builder.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 #include "src/api-natives.h" 6 #include "src/api-natives.h"
7 #include "src/assert-scope.h" 7 #include "src/assert-scope.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 19 matching lines...) Expand all
30 namespace { 30 namespace {
31 struct RawBuffer { 31 struct RawBuffer {
32 const byte* start; 32 const byte* start;
33 const byte* end; 33 const byte* end;
34 size_t size() { return static_cast<size_t>(end - start); } 34 size_t size() { return static_cast<size_t>(end - start); }
35 }; 35 };
36 36
37 37
38 RawBuffer GetRawBufferArgument( 38 RawBuffer GetRawBufferArgument(
39 ErrorThrower& thrower, const v8::FunctionCallbackInfo<v8::Value>& args) { 39 ErrorThrower& thrower, const v8::FunctionCallbackInfo<v8::Value>& args) {
40 // TODO(titzer): allow typed array views. 40 if (args.Length() < 1) {
41 if (args.Length() < 1 || !args[0]->IsArrayBuffer()) {
42 thrower.Error("Argument 0 must be an array buffer"); 41 thrower.Error("Argument 0 must be an array buffer");
43 return {nullptr, nullptr}; 42 return {nullptr, nullptr};
44 } 43 }
45 Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(args[0]);
46 ArrayBuffer::Contents contents = buffer->GetContents();
47 44
48 const byte* start = reinterpret_cast<const byte*>(contents.Data()); 45 const byte* start = nullptr;
49 const byte* end = start + contents.ByteLength(); 46 const byte* end = nullptr;
50 47
51 if (start == nullptr) { 48 if (args[0]->IsArrayBuffer()) {
52 thrower.Error("ArrayBuffer argument is empty"); 49 // A raw array buffer was passed.
50 Local<ArrayBuffer> buffer = Local<ArrayBuffer>::Cast(args[0]);
51 ArrayBuffer::Contents contents = buffer->GetContents();
52
53 start = reinterpret_cast<const byte*>(contents.Data());
54 end = start + contents.ByteLength();
55
56 if (start == nullptr || end == start) {
57 thrower.Error("ArrayBuffer argument is empty");
58 }
59 } else if (args[0]->IsTypedArray()) {
60 // A TypedArray was passed.
61 Local<TypedArray> array = Local<TypedArray>::Cast(args[0]);
62 Local<ArrayBuffer> buffer = array->Buffer();
63
64 ArrayBuffer::Contents contents = buffer->GetContents();
65
66 start =
67 reinterpret_cast<const byte*>(contents.Data()) + array->ByteOffset();
68 end = start + array->ByteLength();
69
70 if (start == nullptr || end == start) {
71 thrower.Error("ArrayBuffer argument is empty");
72 }
73 } else {
74 thrower.Error("Argument 0 must be an ArrayBuffer or Uint8Array");
53 } 75 }
76
54 return {start, end}; 77 return {start, end};
55 } 78 }
56 79
57 80
58 void VerifyModule(const v8::FunctionCallbackInfo<v8::Value>& args) { 81 void VerifyModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
59 HandleScope scope(args.GetIsolate()); 82 HandleScope scope(args.GetIsolate());
60 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); 83 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate());
61 ErrorThrower thrower(isolate, "WASM.verifyModule()"); 84 ErrorThrower thrower(isolate, "WASM.verifyModule()");
62 85
63 RawBuffer buffer = GetRawBufferArgument(thrower, args); 86 RawBuffer buffer = GetRawBufferArgument(thrower, args);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { 309 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) {
287 Handle<Map> wasm_function_map = isolate->factory()->NewMap( 310 Handle<Map> wasm_function_map = isolate->factory()->NewMap(
288 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); 311 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize);
289 wasm_function_map->set_is_callable(); 312 wasm_function_map->set_is_callable();
290 context->set_wasm_function_map(*wasm_function_map); 313 context->set_wasm_function_map(*wasm_function_map);
291 } 314 }
292 } 315 }
293 316
294 } // namespace internal 317 } // namespace internal
295 } // namespace v8 318 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/wasm/test-wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698