| OLD | NEW | 
|---|
| 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 <memory> | 5 #include <memory> | 
| 6 | 6 | 
| 7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" | 
| 8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" | 
| 9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" | 
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" | 
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1267     //-------------------------------------------------------------------------- | 1267     //-------------------------------------------------------------------------- | 
| 1268     int num_imported_functions = ProcessImports(code_table, instance); | 1268     int num_imported_functions = ProcessImports(code_table, instance); | 
| 1269     if (num_imported_functions < 0) return nothing; | 1269     if (num_imported_functions < 0) return nothing; | 
| 1270 | 1270 | 
| 1271     //-------------------------------------------------------------------------- | 1271     //-------------------------------------------------------------------------- | 
| 1272     // Process the initialization for the module's globals. | 1272     // Process the initialization for the module's globals. | 
| 1273     //-------------------------------------------------------------------------- | 1273     //-------------------------------------------------------------------------- | 
| 1274     InitGlobals(); | 1274     InitGlobals(); | 
| 1275 | 1275 | 
| 1276     //-------------------------------------------------------------------------- | 1276     //-------------------------------------------------------------------------- | 
|  | 1277     // Set up the indirect function tables for the new instance. | 
|  | 1278     //-------------------------------------------------------------------------- | 
|  | 1279     if (function_table_count > 0) InitializeTables(code_table, instance); | 
|  | 1280 | 
|  | 1281     //-------------------------------------------------------------------------- | 
| 1277     // Set up the memory for the new instance. | 1282     // Set up the memory for the new instance. | 
| 1278     //-------------------------------------------------------------------------- | 1283     //-------------------------------------------------------------------------- | 
| 1279     MaybeHandle<JSArrayBuffer> old_memory; | 1284     MaybeHandle<JSArrayBuffer> old_memory; | 
| 1280 | 1285 | 
| 1281     uint32_t min_mem_pages = module_->min_mem_pages; | 1286     uint32_t min_mem_pages = module_->min_mem_pages; | 
| 1282     isolate_->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages); | 1287     isolate_->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages); | 
| 1283 | 1288 | 
| 1284     if (!memory_.is_null()) { | 1289     if (!memory_.is_null()) { | 
| 1285       // Set externally passed ArrayBuffer non neuterable. | 1290       // Set externally passed ArrayBuffer non neuterable. | 
| 1286       memory_->set_is_neuterable(false); | 1291       memory_->set_is_neuterable(false); | 
| 1287 | 1292 | 
| 1288       DCHECK_IMPLIES(EnableGuardRegions(), module_->origin == kAsmJsOrigin || | 1293       DCHECK_IMPLIES(EnableGuardRegions(), module_->origin == kAsmJsOrigin || | 
| 1289                                                memory_->has_guard_region()); | 1294                                                memory_->has_guard_region()); | 
| 1290     } else if (min_mem_pages > 0) { | 1295     } else if (min_mem_pages > 0) { | 
| 1291       memory_ = AllocateMemory(min_mem_pages); | 1296       memory_ = AllocateMemory(min_mem_pages); | 
| 1292       if (memory_.is_null()) return nothing;  // failed to allocate memory | 1297       if (memory_.is_null()) return nothing;  // failed to allocate memory | 
| 1293     } | 1298     } | 
| 1294 | 1299 | 
|  | 1300     //-------------------------------------------------------------------------- | 
|  | 1301     // Check that indirect function table segments are within bounds. | 
|  | 1302     //-------------------------------------------------------------------------- | 
|  | 1303     for (WasmTableInit& table_init : module_->table_inits) { | 
|  | 1304       DCHECK(table_init.table_index < table_instances_.size()); | 
|  | 1305       uint32_t base = EvalUint32InitExpr(table_init.offset); | 
|  | 1306       uint32_t table_size = | 
|  | 1307           table_instances_[table_init.table_index].function_table->length(); | 
|  | 1308       if (!in_bounds(base, static_cast<uint32_t>(table_init.entries.size()), | 
|  | 1309                      table_size)) { | 
|  | 1310         thrower_->LinkError("table initializer is out of bounds"); | 
|  | 1311         return nothing; | 
|  | 1312       } | 
|  | 1313     } | 
|  | 1314 | 
|  | 1315     //-------------------------------------------------------------------------- | 
|  | 1316     // Check that memory segments are within bounds. | 
|  | 1317     //-------------------------------------------------------------------------- | 
|  | 1318     for (WasmDataSegment& seg : module_->data_segments) { | 
|  | 1319       uint32_t base = EvalUint32InitExpr(seg.dest_addr); | 
|  | 1320       uint32_t mem_size = memory_.is_null() | 
|  | 1321           ? 0 : static_cast<uint32_t>(memory_->byte_length()->Number()); | 
|  | 1322       if (!in_bounds(base, seg.source_size, mem_size)) { | 
|  | 1323         thrower_->LinkError("data segment is out of bounds"); | 
|  | 1324         return nothing; | 
|  | 1325       } | 
|  | 1326     } | 
|  | 1327 | 
|  | 1328     //-------------------------------------------------------------------------- | 
|  | 1329     // Initialize memory. | 
|  | 1330     //-------------------------------------------------------------------------- | 
| 1295     if (!memory_.is_null()) { | 1331     if (!memory_.is_null()) { | 
| 1296       instance->set_memory_buffer(*memory_); | 1332       instance->set_memory_buffer(*memory_); | 
| 1297       Address mem_start = static_cast<Address>(memory_->backing_store()); | 1333       Address mem_start = static_cast<Address>(memory_->backing_store()); | 
| 1298       uint32_t mem_size = | 1334       uint32_t mem_size = | 
| 1299           static_cast<uint32_t>(memory_->byte_length()->Number()); | 1335           static_cast<uint32_t>(memory_->byte_length()->Number()); | 
| 1300       if (!LoadDataSegments(mem_start, mem_size)) return nothing; | 1336       LoadDataSegments(mem_start, mem_size); | 
| 1301 | 1337 | 
| 1302       uint32_t old_mem_size = compiled_module_->mem_size(); | 1338       uint32_t old_mem_size = compiled_module_->mem_size(); | 
| 1303       Address old_mem_start = | 1339       Address old_mem_start = | 
| 1304           compiled_module_->has_memory() | 1340           compiled_module_->has_memory() | 
| 1305               ? static_cast<Address>( | 1341               ? static_cast<Address>( | 
| 1306                     compiled_module_->memory()->backing_store()) | 1342                     compiled_module_->memory()->backing_store()) | 
| 1307               : nullptr; | 1343               : nullptr; | 
| 1308       RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start, | 1344       RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start, | 
| 1309                                      old_mem_size, mem_size); | 1345                                      old_mem_size, mem_size); | 
| 1310       compiled_module_->set_memory(memory_); | 1346       compiled_module_->set_memory(memory_); | 
| 1311     } else { |  | 
| 1312       if (!LoadDataSegments(nullptr, 0)) return nothing; |  | 
| 1313     } | 1347     } | 
| 1314 | 1348 | 
| 1315     //-------------------------------------------------------------------------- | 1349     //-------------------------------------------------------------------------- | 
| 1316     // Set up the runtime support for the new instance. | 1350     // Set up the runtime support for the new instance. | 
| 1317     //-------------------------------------------------------------------------- | 1351     //-------------------------------------------------------------------------- | 
| 1318     Handle<WeakCell> weak_link = factory->NewWeakCell(instance); | 1352     Handle<WeakCell> weak_link = factory->NewWeakCell(instance); | 
| 1319 | 1353 | 
| 1320     for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; | 1354     for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; | 
| 1321          i < code_table->length(); ++i) { | 1355          i < code_table->length(); ++i) { | 
| 1322       Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); | 1356       Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 1336 | 1370 | 
| 1337     //-------------------------------------------------------------------------- | 1371     //-------------------------------------------------------------------------- | 
| 1338     // Add instance to Memory object | 1372     // Add instance to Memory object | 
| 1339     //-------------------------------------------------------------------------- | 1373     //-------------------------------------------------------------------------- | 
| 1340     DCHECK(wasm::IsWasmInstance(*instance)); | 1374     DCHECK(wasm::IsWasmInstance(*instance)); | 
| 1341     if (instance->has_memory_object()) { | 1375     if (instance->has_memory_object()) { | 
| 1342       instance->memory_object()->AddInstance(isolate_, instance); | 1376       instance->memory_object()->AddInstance(isolate_, instance); | 
| 1343     } | 1377     } | 
| 1344 | 1378 | 
| 1345     //-------------------------------------------------------------------------- | 1379     //-------------------------------------------------------------------------- | 
| 1346     // Set up the indirect function tables for the new instance. | 1380     // Initialize the indirect function tables. | 
| 1347     //-------------------------------------------------------------------------- | 1381     //-------------------------------------------------------------------------- | 
| 1348     if (function_table_count > 0) InitializeTables(code_table, instance); | 1382     if (function_table_count > 0) LoadTableSegments(code_table, instance); | 
| 1349 | 1383 | 
| 1350     // Patch new call sites and the context. | 1384     // Patch new call sites and the context. | 
| 1351     PatchDirectCallsAndContext(code_table, compiled_module_, module_, | 1385     PatchDirectCallsAndContext(code_table, compiled_module_, module_, | 
| 1352                                num_imported_functions); | 1386                                num_imported_functions); | 
| 1353 | 1387 | 
| 1354     FlushICache(isolate_, code_table); | 1388     FlushICache(isolate_, code_table); | 
| 1355 | 1389 | 
| 1356     //-------------------------------------------------------------------------- | 1390     //-------------------------------------------------------------------------- | 
| 1357     // Unpack and notify signal handler of protected instructions. | 1391     // Unpack and notify signal handler of protected instructions. | 
| 1358     //-------------------------------------------------------------------------- | 1392     //-------------------------------------------------------------------------- | 
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1541       case WasmInitExpr::kGlobalIndex: { | 1575       case WasmInitExpr::kGlobalIndex: { | 
| 1542         uint32_t offset = module_->globals[expr.val.global_index].offset; | 1576         uint32_t offset = module_->globals[expr.val.global_index].offset; | 
| 1543         return *reinterpret_cast<uint32_t*>(raw_buffer_ptr(globals_, offset)); | 1577         return *reinterpret_cast<uint32_t*>(raw_buffer_ptr(globals_, offset)); | 
| 1544       } | 1578       } | 
| 1545       default: | 1579       default: | 
| 1546         UNREACHABLE(); | 1580         UNREACHABLE(); | 
| 1547         return 0; | 1581         return 0; | 
| 1548     } | 1582     } | 
| 1549   } | 1583   } | 
| 1550 | 1584 | 
|  | 1585   bool in_bounds(uint32_t offset, uint32_t size, uint32_t upper) { | 
|  | 1586     return offset + size <= upper && offset + size >= offset; | 
|  | 1587   } | 
|  | 1588 | 
| 1551   // Load data segments into the memory. | 1589   // Load data segments into the memory. | 
| 1552   bool LoadDataSegments(Address mem_addr, size_t mem_size) { | 1590   void LoadDataSegments(Address mem_addr, size_t mem_size) { | 
| 1553     Handle<SeqOneByteString> module_bytes(compiled_module_->module_bytes(), | 1591     Handle<SeqOneByteString> module_bytes(compiled_module_->module_bytes(), | 
| 1554                                           isolate_); | 1592                                           isolate_); | 
| 1555     for (const WasmDataSegment& segment : module_->data_segments) { | 1593     for (const WasmDataSegment& segment : module_->data_segments) { | 
| 1556       uint32_t source_size = segment.source_size; | 1594       uint32_t source_size = segment.source_size; | 
| 1557       // Segments of size == 0 are just nops. | 1595       // Segments of size == 0 are just nops. | 
| 1558       if (source_size == 0) continue; | 1596       if (source_size == 0) continue; | 
| 1559       uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr); | 1597       uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr); | 
| 1560       if (dest_offset + source_size > mem_size || | 1598       DCHECK(in_bounds(dest_offset, source_size, | 
| 1561           dest_offset + source_size < dest_offset) { | 1599                        static_cast<uint32_t>(mem_size))); | 
| 1562         thrower_->LinkError("data segment (start = %" PRIu32 ", size = %" PRIu32 |  | 
| 1563                             ") does not fit into memory (size = %" PRIuS ")", |  | 
| 1564                             dest_offset, source_size, mem_size); |  | 
| 1565         return false; |  | 
| 1566       } |  | 
| 1567       byte* dest = mem_addr + dest_offset; | 1600       byte* dest = mem_addr + dest_offset; | 
| 1568       const byte* src = reinterpret_cast<const byte*>( | 1601       const byte* src = reinterpret_cast<const byte*>( | 
| 1569           module_bytes->GetCharsAddress() + segment.source_offset); | 1602           module_bytes->GetCharsAddress() + segment.source_offset); | 
| 1570       memcpy(dest, src, source_size); | 1603       memcpy(dest, src, source_size); | 
| 1571     } | 1604     } | 
| 1572     return true; |  | 
| 1573   } | 1605   } | 
| 1574 | 1606 | 
| 1575   void WriteGlobalValue(WasmGlobal& global, Handle<Object> value) { | 1607   void WriteGlobalValue(WasmGlobal& global, Handle<Object> value) { | 
| 1576     double num = 0; | 1608     double num = 0; | 
| 1577     if (value->IsSmi()) { | 1609     if (value->IsSmi()) { | 
| 1578       num = Smi::cast(*value)->value(); | 1610       num = Smi::cast(*value)->value(); | 
| 1579     } else if (value->IsHeapNumber()) { | 1611     } else if (value->IsHeapNumber()) { | 
| 1580       num = HeapNumber::cast(*value)->value(); | 1612       num = HeapNumber::cast(*value)->value(); | 
| 1581     } else { | 1613     } else { | 
| 1582       UNREACHABLE(); | 1614       UNREACHABLE(); | 
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2026     if (module_->origin == kWasmOrigin) { | 2058     if (module_->origin == kWasmOrigin) { | 
| 2027       v8::Maybe<bool> success = JSReceiver::SetIntegrityLevel( | 2059       v8::Maybe<bool> success = JSReceiver::SetIntegrityLevel( | 
| 2028           exports_object, FROZEN, Object::DONT_THROW); | 2060           exports_object, FROZEN, Object::DONT_THROW); | 
| 2029       DCHECK(success.FromMaybe(false)); | 2061       DCHECK(success.FromMaybe(false)); | 
| 2030       USE(success); | 2062       USE(success); | 
| 2031     } | 2063     } | 
| 2032   } | 2064   } | 
| 2033 | 2065 | 
| 2034   void InitializeTables(Handle<FixedArray> code_table, | 2066   void InitializeTables(Handle<FixedArray> code_table, | 
| 2035                         Handle<WasmInstanceObject> instance) { | 2067                         Handle<WasmInstanceObject> instance) { | 
| 2036     Handle<FixedArray> old_function_tables = |  | 
| 2037         compiled_module_->function_tables(); |  | 
| 2038     Handle<FixedArray> old_signature_tables = |  | 
| 2039         compiled_module_->signature_tables(); |  | 
| 2040     int function_table_count = | 2068     int function_table_count = | 
| 2041         static_cast<int>(module_->function_tables.size()); | 2069         static_cast<int>(module_->function_tables.size()); | 
| 2042     Handle<FixedArray> new_function_tables = | 2070     Handle<FixedArray> new_function_tables = | 
| 2043         isolate_->factory()->NewFixedArray(function_table_count); | 2071         isolate_->factory()->NewFixedArray(function_table_count); | 
| 2044     Handle<FixedArray> new_signature_tables = | 2072     Handle<FixedArray> new_signature_tables = | 
| 2045         isolate_->factory()->NewFixedArray(function_table_count); | 2073         isolate_->factory()->NewFixedArray(function_table_count); | 
| 2046     for (int index = 0; index < function_table_count; ++index) { | 2074     for (int index = 0; index < function_table_count; ++index) { | 
| 2047       WasmIndirectFunctionTable& table = module_->function_tables[index]; | 2075       WasmIndirectFunctionTable& table = module_->function_tables[index]; | 
| 2048       TableInstance& table_instance = table_instances_[index]; | 2076       TableInstance& table_instance = table_instances_[index]; | 
| 2049       int table_size = static_cast<int>(table.min_size); | 2077       int table_size = static_cast<int>(table.min_size); | 
| 2050 | 2078 | 
| 2051       if (table_instance.function_table.is_null()) { | 2079       if (table_instance.function_table.is_null()) { | 
| 2052         // Create a new dispatch table if necessary. | 2080         // Create a new dispatch table if necessary. | 
| 2053         table_instance.function_table = | 2081         table_instance.function_table = | 
| 2054             isolate_->factory()->NewFixedArray(table_size); | 2082             isolate_->factory()->NewFixedArray(table_size); | 
| 2055         table_instance.signature_table = | 2083         table_instance.signature_table = | 
| 2056             isolate_->factory()->NewFixedArray(table_size); | 2084             isolate_->factory()->NewFixedArray(table_size); | 
| 2057         for (int i = 0; i < table_size; ++i) { | 2085         for (int i = 0; i < table_size; ++i) { | 
| 2058           // Fill the table with invalid signature indexes so that | 2086           // Fill the table with invalid signature indexes so that | 
| 2059           // uninitialized entries will always fail the signature check. | 2087           // uninitialized entries will always fail the signature check. | 
| 2060           table_instance.signature_table->set(i, | 2088           table_instance.signature_table->set(i, | 
| 2061                                               Smi::FromInt(kInvalidSigIndex)); | 2089                                               Smi::FromInt(kInvalidSigIndex)); | 
| 2062         } | 2090         } | 
| 2063       } | 2091       } | 
| 2064 | 2092 | 
| 2065       new_function_tables->set(static_cast<int>(index), | 2093       new_function_tables->set(static_cast<int>(index), | 
| 2066                                *table_instance.function_table); | 2094                                *table_instance.function_table); | 
| 2067       new_signature_tables->set(static_cast<int>(index), | 2095       new_signature_tables->set(static_cast<int>(index), | 
| 2068                                 *table_instance.signature_table); | 2096                                 *table_instance.signature_table); | 
|  | 2097     } | 
|  | 2098 | 
|  | 2099     // Patch all code that has references to the old indirect tables. | 
|  | 2100     Handle<FixedArray> old_function_tables = | 
|  | 2101         compiled_module_->function_tables(); | 
|  | 2102     Handle<FixedArray> old_signature_tables = | 
|  | 2103         compiled_module_->signature_tables(); | 
|  | 2104     for (int i = 0; i < code_table->length(); ++i) { | 
|  | 2105       if (!code_table->get(i)->IsCode()) continue; | 
|  | 2106       Handle<Code> code(Code::cast(code_table->get(i)), isolate_); | 
|  | 2107       for (int j = 0; j < function_table_count; ++j) { | 
|  | 2108         ReplaceReferenceInCode( | 
|  | 2109             code, Handle<Object>(old_function_tables->get(j), isolate_), | 
|  | 2110             Handle<Object>(new_function_tables->get(j), isolate_)); | 
|  | 2111         ReplaceReferenceInCode( | 
|  | 2112             code, Handle<Object>(old_signature_tables->get(j), isolate_), | 
|  | 2113             Handle<Object>(new_signature_tables->get(j), isolate_)); | 
|  | 2114       } | 
|  | 2115     } | 
|  | 2116     compiled_module_->set_function_tables(new_function_tables); | 
|  | 2117     compiled_module_->set_signature_tables(new_signature_tables); | 
|  | 2118   } | 
|  | 2119 | 
|  | 2120   void LoadTableSegments(Handle<FixedArray> code_table, | 
|  | 2121                          Handle<WasmInstanceObject> instance) { | 
|  | 2122     int function_table_count = | 
|  | 2123         static_cast<int>(module_->function_tables.size()); | 
|  | 2124     for (int index = 0; index < function_table_count; ++index) { | 
|  | 2125       WasmIndirectFunctionTable& table = module_->function_tables[index]; | 
|  | 2126       TableInstance& table_instance = table_instances_[index]; | 
| 2069 | 2127 | 
| 2070       Handle<FixedArray> all_dispatch_tables; | 2128       Handle<FixedArray> all_dispatch_tables; | 
| 2071       if (!table_instance.table_object.is_null()) { | 2129       if (!table_instance.table_object.is_null()) { | 
| 2072         // Get the existing dispatch table(s) with the WebAssembly.Table object. | 2130         // Get the existing dispatch table(s) with the WebAssembly.Table object. | 
| 2073         all_dispatch_tables = WasmTableObject::AddDispatchTable( | 2131         all_dispatch_tables = WasmTableObject::AddDispatchTable( | 
| 2074             isolate_, table_instance.table_object, | 2132             isolate_, table_instance.table_object, | 
| 2075             Handle<WasmInstanceObject>::null(), index, | 2133             Handle<WasmInstanceObject>::null(), index, | 
| 2076             Handle<FixedArray>::null(), Handle<FixedArray>::null()); | 2134             Handle<FixedArray>::null(), Handle<FixedArray>::null()); | 
| 2077       } | 2135       } | 
| 2078 | 2136 | 
| 2079       // TODO(titzer): this does redundant work if there are multiple tables, | 2137       // TODO(titzer): this does redundant work if there are multiple tables, | 
| 2080       // since initializations are not sorted by table index. | 2138       // since initializations are not sorted by table index. | 
| 2081       for (auto table_init : module_->table_inits) { | 2139       for (auto table_init : module_->table_inits) { | 
| 2082         uint32_t base = EvalUint32InitExpr(table_init.offset); | 2140         uint32_t base = EvalUint32InitExpr(table_init.offset); | 
| 2083         if (base > static_cast<uint32_t>(table_size) || | 2141         DCHECK(in_bounds(base, static_cast<uint32_t>(table_init.entries.size()), | 
| 2084             (base + table_init.entries.size() > | 2142                          table_instance.function_table->length())); | 
| 2085              static_cast<uint32_t>(table_size))) { |  | 
| 2086           thrower_->LinkError("table initializer is out of bounds"); |  | 
| 2087           continue; |  | 
| 2088         } |  | 
| 2089         for (int i = 0; i < static_cast<int>(table_init.entries.size()); ++i) { | 2143         for (int i = 0; i < static_cast<int>(table_init.entries.size()); ++i) { | 
| 2090           uint32_t func_index = table_init.entries[i]; | 2144           uint32_t func_index = table_init.entries[i]; | 
| 2091           WasmFunction* function = &module_->functions[func_index]; | 2145           WasmFunction* function = &module_->functions[func_index]; | 
| 2092           int table_index = static_cast<int>(i + base); | 2146           int table_index = static_cast<int>(i + base); | 
| 2093           int32_t sig_index = table.map.Find(function->sig); | 2147           int32_t sig_index = table.map.Find(function->sig); | 
| 2094           DCHECK_GE(sig_index, 0); | 2148           DCHECK_GE(sig_index, 0); | 
| 2095           table_instance.signature_table->set(table_index, | 2149           table_instance.signature_table->set(table_index, | 
| 2096                                               Smi::FromInt(sig_index)); | 2150                                               Smi::FromInt(sig_index)); | 
| 2097           table_instance.function_table->set(table_index, | 2151           table_instance.function_table->set(table_index, | 
| 2098                                              code_table->get(func_index)); | 2152                                              code_table->get(func_index)); | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2141       // TODO(titzer): we add the new dispatch table at the end to avoid | 2195       // TODO(titzer): we add the new dispatch table at the end to avoid | 
| 2142       // redundant work and also because the new instance is not yet fully | 2196       // redundant work and also because the new instance is not yet fully | 
| 2143       // initialized. | 2197       // initialized. | 
| 2144       if (!table_instance.table_object.is_null()) { | 2198       if (!table_instance.table_object.is_null()) { | 
| 2145         // Add the new dispatch table to the WebAssembly.Table object. | 2199         // Add the new dispatch table to the WebAssembly.Table object. | 
| 2146         all_dispatch_tables = WasmTableObject::AddDispatchTable( | 2200         all_dispatch_tables = WasmTableObject::AddDispatchTable( | 
| 2147             isolate_, table_instance.table_object, instance, index, | 2201             isolate_, table_instance.table_object, instance, index, | 
| 2148             table_instance.function_table, table_instance.signature_table); | 2202             table_instance.function_table, table_instance.signature_table); | 
| 2149       } | 2203       } | 
| 2150     } | 2204     } | 
| 2151     // Patch all code that has references to the old indirect tables. |  | 
| 2152     for (int i = 0; i < code_table->length(); ++i) { |  | 
| 2153       if (!code_table->get(i)->IsCode()) continue; |  | 
| 2154       Handle<Code> code(Code::cast(code_table->get(i)), isolate_); |  | 
| 2155       for (int j = 0; j < function_table_count; ++j) { |  | 
| 2156         ReplaceReferenceInCode( |  | 
| 2157             code, Handle<Object>(old_function_tables->get(j), isolate_), |  | 
| 2158             Handle<Object>(new_function_tables->get(j), isolate_)); |  | 
| 2159         ReplaceReferenceInCode( |  | 
| 2160             code, Handle<Object>(old_signature_tables->get(j), isolate_), |  | 
| 2161             Handle<Object>(new_signature_tables->get(j), isolate_)); |  | 
| 2162       } |  | 
| 2163     } |  | 
| 2164     compiled_module_->set_function_tables(new_function_tables); |  | 
| 2165     compiled_module_->set_signature_tables(new_signature_tables); |  | 
| 2166   } | 2205   } | 
| 2167 }; | 2206 }; | 
| 2168 | 2207 | 
| 2169 // Instantiates a WASM module, creating a WebAssembly.Instance from a | 2208 // Instantiates a WASM module, creating a WebAssembly.Instance from a | 
| 2170 // WebAssembly.Module. | 2209 // WebAssembly.Module. | 
| 2171 MaybeHandle<WasmInstanceObject> WasmModule::Instantiate( | 2210 MaybeHandle<WasmInstanceObject> WasmModule::Instantiate( | 
| 2172     Isolate* isolate, ErrorThrower* thrower, | 2211     Isolate* isolate, ErrorThrower* thrower, | 
| 2173     Handle<WasmModuleObject> wasm_module, Handle<JSReceiver> ffi, | 2212     Handle<WasmModuleObject> wasm_module, Handle<JSReceiver> ffi, | 
| 2174     Handle<JSArrayBuffer> memory) { | 2213     Handle<JSArrayBuffer> memory) { | 
| 2175   WasmInstanceBuilder builder(isolate, thrower, wasm_module, ffi, memory); | 2214   WasmInstanceBuilder builder(isolate, thrower, wasm_module, ffi, memory); | 
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2642 | 2681 | 
| 2643     JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), | 2682     JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), | 
| 2644                           NONE); | 2683                           NONE); | 
| 2645     JSObject::AddProperty(entry, kind_string, export_kind, NONE); | 2684     JSObject::AddProperty(entry, kind_string, export_kind, NONE); | 
| 2646 | 2685 | 
| 2647     storage->set(index, *entry); | 2686     storage->set(index, *entry); | 
| 2648   } | 2687   } | 
| 2649 | 2688 | 
| 2650   return array_object; | 2689   return array_object; | 
| 2651 } | 2690 } | 
| OLD | NEW | 
|---|