OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
11 #include "src/frames-inl.h" | 11 #include "src/frames-inl.h" |
12 #include "src/full-codegen/full-codegen.h" | 12 #include "src/full-codegen/full-codegen.h" |
13 #include "src/isolate-inl.h" | 13 #include "src/isolate-inl.h" |
14 #include "src/snapshot/natives.h" | 14 #include "src/snapshot/natives.h" |
| 15 #include "src/wasm/wasm-module.h" |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
17 namespace internal { | 18 namespace internal { |
18 | 19 |
19 RUNTIME_FUNCTION(Runtime_ConstructDouble) { | 20 RUNTIME_FUNCTION(Runtime_ConstructDouble) { |
20 HandleScope scope(isolate); | 21 HandleScope scope(isolate); |
21 DCHECK(args.length() == 2); | 22 DCHECK(args.length() == 2); |
22 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); | 23 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); |
23 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); | 24 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); |
24 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; | 25 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 572 |
572 #undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION | 573 #undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION |
573 | 574 |
574 | 575 |
575 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { | 576 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { |
576 SealHandleScope shs(isolate); | 577 SealHandleScope shs(isolate); |
577 DCHECK_EQ(0, args.length()); | 578 DCHECK_EQ(0, args.length()); |
578 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); | 579 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); |
579 } | 580 } |
580 | 581 |
| 582 // Take a compiled wasm module, serialize it and copy the buffer into an array |
| 583 // buffer, which is then returned. |
| 584 RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { |
| 585 HandleScope shs(isolate); |
| 586 DCHECK(args.length() == 1); |
| 587 CONVERT_ARG_HANDLE_CHECKED(JSObject, module_obj, 0); |
| 588 |
| 589 Handle<FixedArray> orig = |
| 590 handle(FixedArray::cast(module_obj->GetInternalField(0))); |
| 591 std::unique_ptr<ScriptData> data = std::unique_ptr<ScriptData>( |
| 592 wasm::SerializeWasmCompiledModule(isolate, orig)); |
| 593 void* buff = isolate->array_buffer_allocator()->Allocate(data->length()); |
| 594 Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer(); |
| 595 JSArrayBuffer::Setup(ret, isolate, false, buff, data->length()); |
| 596 memcpy(buff, data->data(), data->length()); |
| 597 return *ret; |
| 598 } |
| 599 |
| 600 // Take an array buffer and attempt to reconstruct a compiled wasm module. |
| 601 // Return undefined if unsuccessful. |
| 602 RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) { |
| 603 HandleScope shs(isolate); |
| 604 DCHECK(args.length() == 1); |
| 605 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0); |
| 606 |
| 607 Address mem_start = static_cast<Address>(buffer->backing_store()); |
| 608 int mem_size = static_cast<int>(buffer->byte_length()->Number()); |
| 609 |
| 610 ScriptData sc(mem_start, mem_size); |
| 611 MaybeHandle<FixedArray> maybe_compiled_module = |
| 612 wasm::DeserializeWasmCompiledModule(isolate, &sc); |
| 613 Handle<FixedArray> compiled_module; |
| 614 if (!maybe_compiled_module.ToHandle(&compiled_module)) { |
| 615 return isolate->heap()->undefined_value(); |
| 616 } |
| 617 return *wasm::CreateCompiledModuleObject(isolate, compiled_module); |
| 618 } |
581 | 619 |
582 } // namespace internal | 620 } // namespace internal |
583 } // namespace v8 | 621 } // namespace v8 |
OLD | NEW |