Skip to content

Commit ce80bf9

Browse files
authored
fix: emit warn when using some sync apis in async callback (#555)
* fix: emit warn when using some sync apis in async callback * stamp: word * stamp: oops
1 parent 8750a48 commit ce80bf9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

ext/runtime/js/bootstrap.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ const MAKE_HARD_ERR_FN = (msg) => {
408408
const DENIED_DENO_FS_API_LIST = ObjectKeys(fsVars)
409409
.reduce(
410410
(acc, it) => {
411-
acc[it] = MAKE_HARD_ERR_FN(`Deno.${it} is blocklisted`);
411+
if (fsVars[it] !== void 0) {
412+
acc[it] = MAKE_HARD_ERR_FN(`Deno.${it} is blocklisted`);
413+
}
412414
return acc;
413415
},
414416
{},
@@ -685,9 +687,8 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
685687
};
686688

687689
if (ctx?.useReadSyncFileAPI) {
688-
apisToBeOverridden["readFileSync"] = true;
689-
apisToBeOverridden["readTextFileSync"] = true;
690-
apisToBeOverridden["openSync"] = true;
690+
apisToBeOverridden["readFileSync"] = "warnIfRuntimeIsAlreadyInit";
691+
apisToBeOverridden["readTextFileSync"] = "warnIfRuntimeIsAlreadyInit";
691692
}
692693

693694
const apiNames = ObjectKeys(apisToBeOverridden);
@@ -723,6 +724,20 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
723724
};
724725
break;
725726
}
727+
case "warnIfRuntimeIsAlreadyInit": {
728+
const originalFn = Deno[name];
729+
Deno[name] = (...args) => {
730+
if (ops.op_is_runtime_init()) {
731+
return originalFn(...args);
732+
} else {
733+
globalThis.console.error(
734+
`WARNING: Do not use Deno.${name} inside the async callback. This has performance impacts and will be disallowed in the future.\nUse the async version instead.`,
735+
);
736+
return originalFn(...args);
737+
}
738+
};
739+
break;
740+
}
726741
}
727742
}
728743
}

0 commit comments

Comments
 (0)