Skip to content

Commit b223bec

Browse files
committed
Merge branch 'master' into xxhash64
2 parents 9c3e548 + bef5bea commit b223bec

File tree

237 files changed

+7703
-6984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+7703
-6984
lines changed

cli/asc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const fs = require("fs");
3434
const path = require("path");
3535
const process = require("process"); // ensure shim
3636

37+
process.exit = ((exit) => function(code) {
38+
if (code) console.log(new Error("exit " + code.toString()).stack);
39+
exit(code);
40+
})(process.exit);
41+
3742
const utf8 = require("./util/utf8");
3843
const colorsUtil = require("./util/colors");
3944
const optionsUtil = require("./util/options");

lib/loader/index.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ function postInstantiate(extendedExports, instance) {
8181
const exports = instance.exports;
8282
const memory = exports.memory;
8383
const table = exports.table;
84-
const new_ = exports["__new"];
85-
const retain = exports["__retain"];
86-
const rttiBase = exports["__rtti_base"] || ~0; // oob if not present
84+
const __new = exports["__new"];
85+
const __retain = exports["__retain"];
86+
const __rtti_base = exports["__rtti_base"] || ~0; // oob if not present
8787

8888
/** Gets the runtime type info for the given id. */
8989
function getInfo(id) {
9090
const U32 = new Uint32Array(memory.buffer);
91-
const count = U32[rttiBase >>> 2];
91+
const count = U32[__rtti_base >>> 2];
9292
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
93-
return U32[(rttiBase + 4 >>> 2) + id * 2];
93+
return U32[(__rtti_base + 4 >>> 2) + id * 2];
9494
}
9595

9696
/** Gets and validate runtime type info for the given id for array like objects */
@@ -103,9 +103,9 @@ function postInstantiate(extendedExports, instance) {
103103
/** Gets the runtime base id for the given id. */
104104
function getBase(id) {
105105
const U32 = new Uint32Array(memory.buffer);
106-
const count = U32[rttiBase >>> 2];
106+
const count = U32[__rtti_base >>> 2];
107107
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
108-
return U32[(rttiBase + 4 >>> 2) + id * 2 + 1];
108+
return U32[(__rtti_base + 4 >>> 2) + id * 2 + 1];
109109
}
110110

111111
/** Gets the runtime alignment of a collection's values. */
@@ -120,8 +120,9 @@ function postInstantiate(extendedExports, instance) {
120120

121121
/** Allocates a new string in the module's memory and returns its retained pointer. */
122122
function __newString(str) {
123+
if (str == null) return 0;
123124
const length = str.length;
124-
const ptr = new_(length << 1, STRING_ID);
125+
const ptr = __new(length << 1, STRING_ID);
125126
const U16 = new Uint16Array(memory.buffer);
126127
for (var i = 0, p = ptr >>> 1; i < length; ++i) U16[p + i] = str.charCodeAt(i);
127128
return ptr;
@@ -131,6 +132,7 @@ function postInstantiate(extendedExports, instance) {
131132

132133
/** Reads a string from the module's memory by its pointer. */
133134
function __getString(ptr) {
135+
if (!ptr) return null;
134136
const buffer = memory.buffer;
135137
const id = new Uint32Array(buffer)[ptr + ID_OFFSET >>> 2];
136138
if (id !== STRING_ID) throw Error(`not a string: ${ptr}`);
@@ -163,22 +165,22 @@ function postInstantiate(extendedExports, instance) {
163165
const info = getArrayInfo(id);
164166
const align = getValueAlign(info);
165167
const length = values.length;
166-
const buf = new_(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID);
168+
const buf = __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID);
167169
let result;
168170
if (info & STATICARRAY) {
169171
result = buf;
170172
} else {
171-
const arr = new_(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id);
173+
const arr = __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id);
172174
const U32 = new Uint32Array(memory.buffer);
173-
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = retain(buf);
175+
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = __retain(buf);
174176
U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf;
175177
U32[arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2] = length << align;
176178
if (info & ARRAY) U32[arr + ARRAY_LENGTH_OFFSET >>> 2] = length;
177179
result = arr;
178180
}
179181
const view = getView(align, info & VAL_SIGNED, info & VAL_FLOAT);
180182
if (info & VAL_MANAGED) {
181-
for (let i = 0; i < length; ++i) view[(buf >>> align) + i] = retain(values[i]);
183+
for (let i = 0; i < length; ++i) view[(buf >>> align) + i] = __retain(values[i]);
182184
} else {
183185
view.set(values, buf >>> align);
184186
}
@@ -267,7 +269,7 @@ function postInstantiate(extendedExports, instance) {
267269
function __instanceof(ptr, baseId) {
268270
const U32 = new Uint32Array(memory.buffer);
269271
let id = U32[ptr + ID_OFFSET >>> 2];
270-
if (id <= U32[rttiBase >>> 2]) {
272+
if (id <= U32[__rtti_base >>> 2]) {
271273
do {
272274
if (id == baseId) return true;
273275
id = getBase(id);
@@ -331,7 +333,6 @@ export async function instantiateStreaming(source, imports = {}) {
331333

332334
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
333335
export function demangle(exports, extendedExports = {}) {
334-
extendedExports = Object.create(extendedExports);
335336
const setArgumentsLength = exports["__argumentsLength"]
336337
? length => { exports["__argumentsLength"].value = length; }
337338
: exports["__setArgumentsLength"] || exports["__setargc"] || (() => { /* nop */ });

lib/loader/umd/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "..";
1+
export * from "../index";

lib/loader/umd/index.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,19 @@ var loader = (function(exports) {
9595
const exports = instance.exports;
9696
const memory = exports.memory;
9797
const table = exports.table;
98-
const new_ = exports["__new"];
99-
const retain = exports["__retain"];
100-
const rttiBase = exports["__rtti_base"] || ~0; // oob if not present
98+
const __new = exports["__new"];
99+
const __retain = exports["__retain"];
100+
101+
const __rtti_base = exports["__rtti_base"] || ~0; // oob if not present
101102

102103
/** Gets the runtime type info for the given id. */
103104

105+
104106
function getInfo(id) {
105107
const U32 = new Uint32Array(memory.buffer);
106-
const count = U32[rttiBase >>> 2];
108+
const count = U32[__rtti_base >>> 2];
107109
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
108-
return U32[(rttiBase + 4 >>> 2) + id * 2];
110+
return U32[(__rtti_base + 4 >>> 2) + id * 2];
109111
}
110112
/** Gets and validate runtime type info for the given id for array like objects */
111113

@@ -120,9 +122,9 @@ var loader = (function(exports) {
120122

121123
function getBase(id) {
122124
const U32 = new Uint32Array(memory.buffer);
123-
const count = U32[rttiBase >>> 2];
125+
const count = U32[__rtti_base >>> 2];
124126
if ((id >>>= 0) >= count) throw Error(`invalid id: ${id}`);
125-
return U32[(rttiBase + 4 >>> 2) + id * 2 + 1];
127+
return U32[(__rtti_base + 4 >>> 2) + id * 2 + 1];
126128
}
127129
/** Gets the runtime alignment of a collection's values. */
128130

@@ -139,8 +141,11 @@ var loader = (function(exports) {
139141

140142

141143
function __newString(str) {
144+
if (str == null) return 0;
142145
const length = str.length;
143-
const ptr = new_(length << 1, STRING_ID);
146+
147+
const ptr = __new(length << 1, STRING_ID);
148+
144149
const U16 = new Uint16Array(memory.buffer);
145150

146151
for (var i = 0, p = ptr >>> 1; i < length; ++i) U16[p + i] = str.charCodeAt(i);
@@ -152,6 +157,7 @@ var loader = (function(exports) {
152157
/** Reads a string from the module's memory by its pointer. */
153158

154159
function __getString(ptr) {
160+
if (!ptr) return null;
155161
const buffer = memory.buffer;
156162
const id = new Uint32Array(buffer)[ptr + ID_OFFSET >>> 2];
157163
if (id !== STRING_ID) throw Error(`not a string: ${ptr}`);
@@ -197,15 +203,18 @@ var loader = (function(exports) {
197203
const info = getArrayInfo(id);
198204
const align = getValueAlign(info);
199205
const length = values.length;
200-
const buf = new_(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID);
206+
207+
const buf = __new(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID);
208+
201209
let result;
202210

203211
if (info & STATICARRAY) {
204212
result = buf;
205213
} else {
206-
const arr = new_(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id);
214+
const arr = __new(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id);
215+
207216
const U32 = new Uint32Array(memory.buffer);
208-
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = retain(buf);
217+
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = __retain(buf);
209218
U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf;
210219
U32[arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2] = length << align;
211220
if (info & ARRAY) U32[arr + ARRAY_LENGTH_OFFSET >>> 2] = length;
@@ -215,7 +224,7 @@ var loader = (function(exports) {
215224
const view = getView(align, info & VAL_SIGNED, info & VAL_FLOAT);
216225

217226
if (info & VAL_MANAGED) {
218-
for (let i = 0; i < length; ++i) view[(buf >>> align) + i] = retain(values[i]);
227+
for (let i = 0; i < length; ++i) view[(buf >>> align) + i] = __retain(values[i]);
219228
} else {
220229
view.set(values, buf >>> align);
221230
}
@@ -298,7 +307,7 @@ var loader = (function(exports) {
298307
const U32 = new Uint32Array(memory.buffer);
299308
let id = U32[ptr + ID_OFFSET >>> 2];
300309

301-
if (id <= U32[rttiBase >>> 2]) {
310+
if (id <= U32[__rtti_base >>> 2]) {
302311
do {
303312
if (id == baseId) return true;
304313
id = getBase(id);
@@ -371,7 +380,6 @@ var loader = (function(exports) {
371380

372381

373382
function demangle(exports, extendedExports = {}) {
374-
extendedExports = Object.create(extendedExports);
375383
const setArgumentsLength = exports["__argumentsLength"] ? length => {
376384
exports["__argumentsLength"].value = length;
377385
} : exports["__setArgumentsLength"] || exports["__setargc"] || (() => {

lib/rtrace/umd/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "..";
1+
export * from "../index";

0 commit comments

Comments
 (0)