@assemblyscript/loader
Advanced tools
Comparing version
52
index.js
@@ -279,12 +279,2 @@ "use strict"; | ||
/** Wraps a WebAssembly function while also taking care of variable arguments. */ | ||
function wrapFunction(fn, argumentsLength) { | ||
var wrap = (...args) => { | ||
if (argumentsLength) argumentsLength.value = args.length; | ||
return fn(...args); | ||
} | ||
wrap.original = fn; | ||
return wrap; | ||
} | ||
function isResponse(o) { | ||
@@ -346,9 +336,8 @@ return typeof Response !== "undefined" && o instanceof Response; | ||
var module = baseModule ? Object.create(baseModule) : {}; | ||
var argumentsLength = exports["__argumentsLength"]; | ||
function hasOwnProperty(elem, prop) { | ||
return Object.prototype.hasOwnProperty.call(elem, prop); | ||
} | ||
var setArgumentsLength = exports["__argumentsLength"] | ||
? function(length) { exports["__argumentsLength"].value = length; } | ||
: exports["__setArgumentsLength"] || exports["__setargc"] || function() {}; | ||
for (let internalName in exports) { | ||
if (!hasOwnProperty(exports, internalName)) continue; | ||
let elem = exports[internalName]; | ||
if (!Object.prototype.hasOwnProperty.call(exports, internalName)) continue; | ||
const elem = exports[internalName]; | ||
let parts = internalName.split("."); | ||
@@ -358,3 +347,3 @@ let curr = module; | ||
let part = parts.shift(); | ||
if (!hasOwnProperty(curr, part)) curr[part] = {}; | ||
if (!Object.prototype.hasOwnProperty.call(curr, part)) curr[part] = {}; | ||
curr = curr[part]; | ||
@@ -387,3 +376,3 @@ } | ||
if (/^(get|set):/.test(name)) { | ||
if (!hasOwnProperty(curr, name = name.substring(4))) { | ||
if (!Object.prototype.hasOwnProperty.call(curr, name = name.substring(4))) { | ||
let getter = exports[internalName.replace("set:", "get:")]; | ||
@@ -399,10 +388,11 @@ let setter = exports[internalName.replace("get:", "set:")]; | ||
if (name === 'constructor') { | ||
curr[name] = wrapFunction(elem, argumentsLength); | ||
} else { // for methods | ||
Object.defineProperty(curr, name, { | ||
value: function (...args) { | ||
if (argumentsLength) argumentsLength.value = args.length; | ||
return elem(this[THIS], ...args); | ||
} | ||
}); | ||
(curr[name] = (...args) => { | ||
setArgumentsLength(args.length); | ||
return elem(...args); | ||
}).original = elem; | ||
} else { // instance method | ||
(curr[name] = function(...args) { // ! | ||
setArgumentsLength(args.length); | ||
return elem(this[THIS], ...args); | ||
}).original = elem; | ||
} | ||
@@ -412,3 +402,3 @@ } | ||
if (/^(get|set):/.test(name)) { | ||
if (!hasOwnProperty(curr, name = name.substring(4))) { | ||
if (!Object.prototype.hasOwnProperty.call(curr, name = name.substring(4))) { | ||
Object.defineProperty(curr, name, { | ||
@@ -420,4 +410,7 @@ get: exports[internalName.replace("set:", "get:")], | ||
} | ||
} else if (typeof elem === "function") { | ||
curr[name] = wrapFunction(elem, argumentsLength); | ||
} else if (typeof elem === "function" && elem !== setArgumentsLength) { | ||
(curr[name] = (...args) => { | ||
setArgumentsLength(args.length); | ||
return elem(...args); | ||
}).original = elem; | ||
} else { | ||
@@ -428,3 +421,2 @@ curr[name] = elem; | ||
} | ||
return module; | ||
@@ -431,0 +423,0 @@ } |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.9.0", | ||
"version": "0.9.1-nightly.20200131", | ||
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>", | ||
@@ -28,3 +28,5 @@ "license": "Apache-2.0", | ||
"scripts": { | ||
"test:build": "asc tests/assembly/index.ts -b tests/build/untouched.wasm", | ||
"asbuild": "npm run asbuild:default && npm run asbuild:legacy", | ||
"asbuild:default": "node ../../bin/asc tests/assembly/index.ts -b tests/build/default.wasm", | ||
"asbuild:legacy": "node ../../bin/asc tests/assembly/index.ts --disable mutable-globals -b tests/build/legacy.wasm", | ||
"test": "node tests" | ||
@@ -31,0 +33,0 @@ }, |
33106
0.66%466
-1.27%