Skip to content

Commit f5b00c8

Browse files
authored
Allow internal abort to be disabled (AssemblyScript#677)
1 parent c99becc commit f5b00c8

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

cli/asc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,10 @@ exports.main = function main(argv, options, callback) {
459459
let part = aliases[i];
460460
let p = part.indexOf("=");
461461
if (p < 0) return callback(Error("Global alias '" + part + "' is invalid."));
462-
let name = part.substring(0, p).trim();
463-
let alias = part.substring(p + 1).trim();
464-
if (!name.length) return callback(Error("Global alias '" + part + "' is invalid."));
465-
assemblyscript.setGlobalAlias(compilerOptions, name, alias);
462+
let alias = part.substring(0, p).trim();
463+
let name = part.substring(p + 1).trim();
464+
if (!alias.length) return callback(Error("Global alias '" + part + "' is invalid."));
465+
assemblyscript.setGlobalAlias(compilerOptions, alias, name);
466466
}
467467
}
468468

src/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class Options {
197197
explicitStart: bool = false;
198198
/** Static memory start offset. */
199199
memoryBase: i32 = 0;
200-
/** Global aliases. */
200+
/** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
201201
globalAliases: Map<string,string> | null = null;
202202
/** Additional features to activate. */
203203
features: Feature = Feature.NONE;

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export function setMemoryBase(options: Options, memoryBase: u32): void {
9393
}
9494

9595
/** Sets a 'globalAliases' value. */
96-
export function setGlobalAlias(options: Options, name: string, alias: string): void {
96+
export function setGlobalAlias(options: Options, alias: string, name: string): void {
9797
var globalAliases = options.globalAliases;
9898
if (!globalAliases) options.globalAliases = globalAliases = new Map();
99-
globalAliases.set(name, alias);
99+
globalAliases.set(alias, name);
100100
}
101101

102102
/** Sets the `explicitStart` option. */

src/program.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ export class Program extends DiagnosticEmitter {
375375
f64ArrayPrototype: ClassPrototype;
376376
/** String instance reference. */
377377
stringInstance: Class;
378-
/** Abort function reference, if present. */
379-
abortInstance: Function;
378+
/** Abort function reference, if not explicitly disabled. */
379+
abortInstance: Function | null;
380380

381381
// runtime references
382382

@@ -861,7 +861,7 @@ export class Program extends DiagnosticEmitter {
861861
this.fixedArrayPrototype = <ClassPrototype>this.require(CommonSymbols.FixedArray, ElementKind.CLASS_PROTOTYPE);
862862
this.setPrototype = <ClassPrototype>this.require(CommonSymbols.Set, ElementKind.CLASS_PROTOTYPE);
863863
this.mapPrototype = <ClassPrototype>this.require(CommonSymbols.Map, ElementKind.CLASS_PROTOTYPE);
864-
this.abortInstance = this.requireFunction(CommonSymbols.abort);
864+
this.abortInstance = this.lookupFunction(CommonSymbols.abort); // can be disabled
865865
this.allocInstance = this.requireFunction(CommonSymbols.alloc);
866866
this.reallocInstance = this.requireFunction(CommonSymbols.realloc);
867867
this.freeInstance = this.requireFunction(CommonSymbols.free);
@@ -897,6 +897,13 @@ export class Program extends DiagnosticEmitter {
897897
return resolved;
898898
}
899899

900+
/** Obtains a non-generic global function and returns it. Returns `null` if it does not exist. */
901+
private lookupFunction(name: string): Function | null {
902+
var prototype = this.lookupGlobal(name);
903+
if (!prototype || prototype.kind != ElementKind.FUNCTION_PROTOTYPE) return null;
904+
return this.resolver.resolveFunction(<FunctionPrototype>prototype, null);
905+
}
906+
900907
/** Requires that a non-generic global function is present and returns it. */
901908
private requireFunction(name: string): Function {
902909
var prototype = this.require(name, ElementKind.FUNCTION_PROTOTYPE);

0 commit comments

Comments
 (0)