| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-wasm |
| 6 |
| 7 |
| 8 load("test/mjsunit/wasm/wasm-constants.js"); |
| 9 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 10 |
| 11 (function testImportsUseTheInstantiateRealm() { |
| 12 print("testImportsUseTheInstantiateRealm"); |
| 13 Realm.create(); |
| 14 |
| 15 Object.prototype.valueOf = function() { return 1; }; |
| 16 |
| 17 var builder = new WasmModuleBuilder(); |
| 18 |
| 19 var sig_index = builder.addType(kSig_i); |
| 20 builder.addImport("func", sig_index); |
| 21 builder.addFunction("main", sig_index) |
| 22 .addBody([ |
| 23 kExprCallImport, kArity0, 0 // -- |
| 24 ]) // -- |
| 25 .exportFunc(); |
| 26 |
| 27 var func = function() {return {};}; |
| 28 var main = builder.instantiate({func: func}).exports.main; |
| 29 assertEquals(1, main()); |
| 30 Realm.eval(1, "Object.prototype.valueOf = function() { return 2; };"); |
| 31 assertEquals(1, main()); |
| 32 assertEquals(1, Realm.eval(1, "x => { return x(); };")(main)); |
| 33 Object.prototype.valueOf = function() { return 3; }; |
| 34 assertEquals(3, main()); |
| 35 assertEquals(3, Realm.eval(1, "x => { return x(); };")(main)); |
| 36 })(); |
| OLD | NEW |