Skip to content

Commit

Permalink
feat: add Array.fromAsync polyfill (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jan 28, 2024
1 parent 3d9e465 commit db51ed3
Show file tree
Hide file tree
Showing 16 changed files with 431 additions and 159 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[profile.release]
codegen-units = 1
incremental = true
lto = true
opt-level = "z"

[workspace]
resolver = "2"
members = [
Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"lock": false,
"tasks": {
"test": "deno test -A",
"build": "deno run -A --no-check --unstable https://deno.land/x/[email protected]/main.ts --out lib/pkg"
"build": "deno run -A https://deno.land/x/[email protected]/main.ts --out lib/pkg"
},
"lint": {
"rules": {
Expand Down
199 changes: 99 additions & 100 deletions lib/pkg/dnt_wasm.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ function getObject(idx) {
return heap[idx];
}

let heap_next = heap.length;

function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}

function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}

let WASM_VECTOR_LEN = 0;

let cachedUint8Memory0 = null;
Expand Down Expand Up @@ -97,6 +83,10 @@ function getInt32Memory0() {
return cachedInt32Memory0;
}

function isLikeNone(x) {
return x === undefined || x === null;
}

const cachedTextDecoder = typeof TextDecoder !== "undefined"
? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true })
: {
Expand All @@ -112,6 +102,8 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

let heap_next = heap.length;

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
Expand All @@ -121,8 +113,16 @@ function addHeapObject(obj) {
return idx;
}

function isLikeNone(x) {
return x === undefined || x === null;
function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}

function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}

let cachedFloat64Memory0 = null;
Expand Down Expand Up @@ -228,12 +228,11 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_38(arg0, arg1, arg2) {
wasm
._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcb1aeb548f2ce6a9(
arg0,
arg1,
addHeapObject(arg2),
);
wasm.wasm_bindgen__convert__closures__invoke1_mut__h149419f4f90230dc(
arg0,
arg1,
addHeapObject(arg2),
);
}

/**
Expand All @@ -252,8 +251,8 @@ function handleError(f, args) {
wasm.__wbindgen_exn_store(addHeapObject(e));
}
}
function __wbg_adapter_74(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h3b4ea2930b1ebc90(
function __wbg_adapter_78(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h31d2f059f1e82adf(
arg0,
arg1,
addHeapObject(arg2),
Expand All @@ -263,9 +262,6 @@ function __wbg_adapter_74(arg0, arg1, arg2, arg3) {

const imports = {
__wbindgen_placeholder__: {
__wbindgen_object_drop_ref: function (arg0) {
takeObject(arg0);
},
__wbindgen_json_serialize: function (arg0, arg1) {
const obj = getObject(arg1);
const ret = JSON.stringify(obj === undefined ? null : obj);
Expand All @@ -278,9 +274,9 @@ const imports = {
getInt32Memory0()[arg0 / 4 + 1] = len1;
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
},
__wbindgen_string_new: function (arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
__wbindgen_is_undefined: function (arg0) {
const ret = getObject(arg0) === undefined;
return ret;
},
__wbindgen_string_get: function (arg0, arg1) {
const obj = getObject(arg1);
Expand All @@ -296,10 +292,26 @@ const imports = {
getInt32Memory0()[arg0 / 4 + 1] = len1;
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
},
__wbindgen_is_object: function (arg0) {
const val = getObject(arg0);
const ret = typeof val === "object" && val !== null;
return ret;
},
__wbindgen_error_new: function (arg0, arg1) {
const ret = new Error(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
},
__wbindgen_object_drop_ref: function (arg0) {
takeObject(arg0);
},
__wbindgen_in: function (arg0, arg1) {
const ret = getObject(arg0) in getObject(arg1);
return ret;
},
__wbindgen_string_new: function (arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
},
__wbg_fetchspecifier_a6bda29173284144: function (arg0, arg1, arg2) {
let deferred0_0;
let deferred0_1;
Expand All @@ -316,27 +328,11 @@ const imports = {
const ret = getObject(arg0) === null;
return ret;
},
__wbindgen_is_undefined: function (arg0) {
const ret = getObject(arg0) === undefined;
return ret;
},
__wbindgen_is_object: function (arg0) {
const val = getObject(arg0);
const ret = typeof val === "object" && val !== null;
return ret;
},
__wbindgen_in: function (arg0, arg1) {
const ret = getObject(arg0) in getObject(arg1);
return ret;
},
__wbindgen_cb_drop: function (arg0) {
const obj = takeObject(arg0).original;
if (obj.cnt-- == 1) {
obj.a = 0;
return true;
}
const ret = false;
return ret;
__wbindgen_number_get: function (arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof obj === "number" ? obj : undefined;
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
},
__wbindgen_object_clone_ref: function (arg0) {
const ret = getObject(arg0);
Expand All @@ -351,22 +347,25 @@ const imports = {
const ret = typeof v === "boolean" ? (v ? 1 : 0) : 2;
return ret;
},
__wbindgen_number_get: function (arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof obj === "number" ? obj : undefined;
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
},
__wbg_getwithrefkey_5e6d9547403deab8: function (arg0, arg1) {
const ret = getObject(arg0)[getObject(arg1)];
return addHeapObject(ret);
},
__wbg_set_841ac57cff3d672b: function (arg0, arg1, arg2) {
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
},
__wbg_get_44be0491f933a435: function (arg0, arg1) {
const ret = getObject(arg0)[arg1 >>> 0];
return addHeapObject(ret);
__wbindgen_cb_drop: function (arg0) {
const obj = takeObject(arg0).original;
if (obj.cnt-- == 1) {
obj.a = 0;
return true;
}
const ret = false;
return ret;
},
__wbindgen_is_function: function (arg0) {
const ret = typeof (getObject(arg0)) === "function";
return ret;
},
__wbg_length_fff51ee6522a1a18: function (arg0) {
const ret = getObject(arg0).length;
Expand All @@ -376,24 +375,10 @@ const imports = {
const ret = new Array();
return addHeapObject(ret);
},
__wbindgen_is_function: function (arg0) {
const ret = typeof (getObject(arg0)) === "function";
return ret;
},
__wbg_next_526fc47e980da008: function (arg0) {
const ret = getObject(arg0).next;
return addHeapObject(ret);
},
__wbg_next_ddb3312ca1c4e32a: function () {
return handleError(function (arg0) {
const ret = getObject(arg0).next();
return addHeapObject(ret);
}, arguments);
},
__wbg_done_5c1f01fb660d73b5: function (arg0) {
const ret = getObject(arg0).done;
return ret;
},
__wbg_value_1695675138684bd5: function (arg0) {
const ret = getObject(arg0).value;
return addHeapObject(ret);
Expand All @@ -402,22 +387,14 @@ const imports = {
const ret = Symbol.iterator;
return addHeapObject(ret);
},
__wbg_get_97b561fb56f034b5: function () {
return handleError(function (arg0, arg1) {
const ret = Reflect.get(getObject(arg0), getObject(arg1));
return addHeapObject(ret);
}, arguments);
},
__wbg_call_cb65541d95d71282: function () {
return handleError(function (arg0, arg1) {
const ret = getObject(arg0).call(getObject(arg1));
return addHeapObject(ret);
}, arguments);
},
__wbg_new_b51585de1b234aff: function () {
const ret = new Object();
return addHeapObject(ret);
},
__wbg_get_44be0491f933a435: function (arg0, arg1) {
const ret = getObject(arg0)[arg1 >>> 0];
return addHeapObject(ret);
},
__wbg_set_502d29070ea18557: function (arg0, arg1, arg2) {
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
},
Expand All @@ -431,24 +408,50 @@ const imports = {
const ret = result;
return ret;
},
__wbg_call_cb65541d95d71282: function () {
return handleError(function (arg0, arg1) {
const ret = getObject(arg0).call(getObject(arg1));
return addHeapObject(ret);
}, arguments);
},
__wbg_call_01734de55d61e11d: function () {
return handleError(function (arg0, arg1, arg2) {
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
return addHeapObject(ret);
}, arguments);
},
__wbg_next_ddb3312ca1c4e32a: function () {
return handleError(function (arg0) {
const ret = getObject(arg0).next();
return addHeapObject(ret);
}, arguments);
},
__wbg_done_5c1f01fb660d73b5: function (arg0) {
const ret = getObject(arg0).done;
return ret;
},
__wbg_entries_e51f29c7bba0c054: function (arg0) {
const ret = Object.entries(getObject(arg0));
return addHeapObject(ret);
},
__wbg_get_97b561fb56f034b5: function () {
return handleError(function (arg0, arg1) {
const ret = Reflect.get(getObject(arg0), getObject(arg1));
return addHeapObject(ret);
}, arguments);
},
__wbg_buffer_085ec1f694018c4f: function (arg0) {
const ret = getObject(arg0).buffer;
return addHeapObject(ret);
},
__wbg_new_43f1b47c28813cbd: function (arg0, arg1) {
try {
var state0 = { a: arg0, b: arg1 };
var cb0 = (arg0, arg1) => {
const a = state0.a;
state0.a = 0;
try {
return __wbg_adapter_74(a, state0.b, arg0, arg1);
return __wbg_adapter_78(a, state0.b, arg0, arg1);
} finally {
state0.a = a;
}
Expand All @@ -471,21 +474,10 @@ const imports = {
const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
return addHeapObject(ret);
},
__wbg_buffer_085ec1f694018c4f: function (arg0) {
const ret = getObject(arg0).buffer;
return addHeapObject(ret);
},
__wbg_new_8125e318e6245eed: function (arg0) {
const ret = new Uint8Array(getObject(arg0));
return addHeapObject(ret);
},
__wbg_set_5cf90238115182c3: function (arg0, arg1, arg2) {
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
},
__wbg_length_72e2208bbc0efc61: function (arg0) {
const ret = getObject(arg0).length;
return ret;
},
__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4: function (arg0) {
let result;
try {
Expand All @@ -496,6 +488,13 @@ const imports = {
const ret = result;
return ret;
},
__wbg_length_72e2208bbc0efc61: function (arg0) {
const ret = getObject(arg0).length;
return ret;
},
__wbg_set_5cf90238115182c3: function (arg0, arg1, arg2) {
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
},
__wbg_new_abda76e883ba8a5f: function () {
const ret = new Error();
return addHeapObject(ret);
Expand Down Expand Up @@ -540,8 +539,8 @@ const imports = {
const ret = wasm.memory;
return addHeapObject(ret);
},
__wbindgen_closure_wrapper726: function (arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 236, __wbg_adapter_38);
__wbindgen_closure_wrapper905: function (arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 131, __wbg_adapter_38);
return addHeapObject(ret);
},
},
Expand Down
Binary file modified lib/pkg/dnt_wasm_bg.wasm
Binary file not shown.
12 changes: 12 additions & 0 deletions rs-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,18 @@ fn check_add_polyfill_file_to_environment(
}
}
}
for polyfill in &env_context.found_polyfills {
for dep in polyfill.dependencies() {
if !env_context
.environment
.dependencies
.iter()
.any(|d| d.name == dep.name)
{
env_context.environment.dependencies.push(dep);
}
}
}
}

fn check_add_shim_file_to_environment(
Expand Down
Loading

0 comments on commit db51ed3

Please sign in to comment.