mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-31 11:44:31 +01:00 
			
		
		
		
	* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import * as assert from '../assert.js';
 | |
| import Builder from '../Builder.js';
 | |
| 
 | |
| (function StartNamedFunction() {
 | |
|     const b = (new Builder())
 | |
|         .Type().End()
 | |
|         .Import()
 | |
|             .Function("imp", "func", { params: ["i32"] })
 | |
|         .End()
 | |
|         .Function().End()
 | |
|         .Start("foo").End()
 | |
|         .Code()
 | |
|             .Function("foo", { params: [] })
 | |
|                 .I32Const(42)
 | |
|                 .Call(0) // Calls func(42).
 | |
|             .End()
 | |
|         .End();
 | |
|     const bin = b.WebAssembly().get();
 | |
|     const module = new WebAssembly.Module(bin);
 | |
|     let value = 0;
 | |
|     const setter = v => value = v;
 | |
|     const instance = new WebAssembly.Instance(module, { imp: { func: setter } });
 | |
|     assert.eq(value, 42);
 | |
| })();
 | |
| 
 | |
| (function InvalidStartFunctionIndex() {
 | |
|     const b = (new Builder())
 | |
|         .setChecked(false)
 | |
|         .Type().End()
 | |
|         .Function().End()
 | |
|         .Start(0).End() // Invalid index.
 | |
|         .Code().End();
 | |
|     const bin = b.WebAssembly().get();
 | |
|     assert.throws(() => new WebAssembly.Module(bin), Error, `WebAssembly.Module doesn't parse at byte 17 / 20: Start index 0 exceeds function index space 0 (evaluating 'new WebAssembly.Module(bin)')`);
 | |
| })();
 |