|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | #include "src/wasm/module-instantiate.h"
|
| 6 | + |
6 | 7 | #include "src/asmjs/asm-js.h"
|
| 8 | +#include "src/conversions-inl.h" |
7 | 9 | #include "src/heap/heap-inl.h" // For CodeSpaceMemoryModificationScope.
|
8 | 10 | #include "src/property-descriptor.h"
|
9 | 11 | #include "src/utils.h"
|
@@ -132,6 +134,7 @@ class InstanceBuilder {
|
132 | 134 | void LoadDataSegments(Handle<WasmInstanceObject> instance);
|
133 | 135 |
|
134 | 136 | void WriteGlobalValue(const WasmGlobal& global, double value);
|
| 137 | + void WriteGlobalValue(const WasmGlobal& global, int64_t num); |
135 | 138 | void WriteGlobalValue(const WasmGlobal& global,
|
136 | 139 | Handle<WasmGlobalObject> value);
|
137 | 140 |
|
@@ -653,25 +656,34 @@ void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, double num) {
|
653 | 656 | switch (global.type) {
|
654 | 657 | case kWasmI32:
|
655 | 658 | WriteLittleEndianValue<int32_t>(GetRawGlobalPtr<int32_t>(global),
|
656 |
| - static_cast<int32_t>(num)); |
| 659 | + DoubleToInt32(num)); |
657 | 660 | break;
|
658 | 661 | case kWasmI64:
|
659 |
| - WriteLittleEndianValue<int64_t>(GetRawGlobalPtr<int64_t>(global), |
660 |
| - static_cast<int64_t>(num)); |
| 662 | + // The Wasm-BigInt proposal currently says that i64 globals may |
| 663 | + // only be initialized with BigInts. See: |
| 664 | + // https://github.com/WebAssembly/JS-BigInt-integration/issues/12 |
| 665 | + UNREACHABLE(); |
661 | 666 | break;
|
662 | 667 | case kWasmF32:
|
663 | 668 | WriteLittleEndianValue<float>(GetRawGlobalPtr<float>(global),
|
664 |
| - static_cast<float>(num)); |
| 669 | + DoubleToFloat32(num)); |
665 | 670 | break;
|
666 | 671 | case kWasmF64:
|
667 |
| - WriteLittleEndianValue<double>(GetRawGlobalPtr<double>(global), |
668 |
| - static_cast<double>(num)); |
| 672 | + WriteLittleEndianValue<double>(GetRawGlobalPtr<double>(global), num); |
669 | 673 | break;
|
670 | 674 | default:
|
671 | 675 | UNREACHABLE();
|
672 | 676 | }
|
673 | 677 | }
|
674 | 678 |
|
| 679 | +void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, int64_t num) { |
| 680 | + TRACE("init [globals_start=%p + %u] = %" PRId64 ", type = %s\n", |
| 681 | + reinterpret_cast<void*>(raw_buffer_ptr(untagged_globals_, 0)), |
| 682 | + global.offset, num, ValueTypes::TypeName(global.type)); |
| 683 | + DCHECK_EQ(kWasmI64, global.type); |
| 684 | + WriteLittleEndianValue<int64_t>(GetRawGlobalPtr<int64_t>(global), num); |
| 685 | +} |
| 686 | + |
675 | 687 | void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global,
|
676 | 688 | Handle<WasmGlobalObject> value) {
|
677 | 689 | TRACE("init [globals_start=%p + %u] = ",
|
@@ -1051,7 +1063,7 @@ bool InstanceBuilder::ProcessImportedGlobal(Handle<WasmInstanceObject> instance,
|
1051 | 1063 | return true;
|
1052 | 1064 | }
|
1053 | 1065 |
|
1054 |
| - if (value->IsNumber()) { |
| 1066 | + if (value->IsNumber() && global.type != kWasmI64) { |
1055 | 1067 | WriteGlobalValue(global, value->Number());
|
1056 | 1068 | return true;
|
1057 | 1069 | }
|
|
0 commit comments