Skip to content

Commit

Permalink
remove outdated lint (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver E. Anderson authored Feb 3, 2023
1 parent a58e7b8 commit 6225c8a
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions bindings/wasm/build/lints.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
/**
* Rejects any `<obj>.ptr = 0;` occurrence, excluding `this.ptr = 0;` in `free()` implementations.
*
* Prevents generated code that nulls out Wasm pointers without de-registering the finalizer, since they cause
* runtime errors during automatic garbage collection from WasmRefCell thinking the instance is still borrowed.
*
* Functions which take owned parameters cause this situation; the solution is to borrow and clone the parameter
* instead.
*/
function lintPtrNullWithoutFree(content) {
// Find line numbers of offending code.
const lines = content.split(/\r?\n/);
const matches = lines.flatMap(function(line, number) {
if (/(?<!this).ptr = 0;/.test(line)) {
return [(number + 1) + " " + line.trim()];
} else {
return [];
}
});
if (matches.length > 0) {
throw (`ERROR: generated Javascript should not include 'obj.ptr = 0;'.
When weak references are enabled with '--weak-refs', WasmRefCell in wasm-bindgen causes
runtime errors from automatic garbage collection trying to free objects taken as owned parameters.
Matches:
${matches}
SUGGESTION: change any exported functions which take an owned parameter (excluding flat enums) to use a borrow instead.
See: https://github.com/rustwasm/wasm-bindgen/pull/2677`);
}
}

/** Rejects any `imports['env']` occurrences, which cause failures at runtime.
*
* This is typically due to Wasm compatibility features not being enabled on crate dependencies. **/
Expand Down Expand Up @@ -66,7 +34,6 @@ See:
/** Runs all custom lints on the generated code. Exits the process immediately with code 1 if any fail. **/
function lintAll(content) {
try {
lintPtrNullWithoutFree(content);
lintImportEnv(content);
} catch (err) {
console.error("Custom lint failed!");
Expand Down

0 comments on commit 6225c8a

Please sign in to comment.