Skip to content

Commit 5947eb4

Browse files
committed
Revert "Remove SafeJSON."
This reverts commit 713171e.
1 parent c0aad80 commit 5947eb4

File tree

5 files changed

+14
-42
lines changed

5 files changed

+14
-42
lines changed

src/module/esm/extensions.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import SafeJSON from "../../safe/json.js"
2+
13
import { dlopen } from "../../safe/process.js"
24
import { readFileSync } from "../../safe/fs.js"
35
import stripBOM from "../../util/strip-bom.js"
4-
import toExternalError from "../../util/to-external-error.js"
5-
import toExternalObject from "../../util/to-external-object.js"
66
import toNamespacedPath from "../../path/to-namespaced-path.js"
77

88
const extensions = { __proto__: null }
@@ -17,17 +17,13 @@ extensions[".json"] = function (mod, filename) {
1717
let exported
1818

1919
try {
20-
exported = JSON.parse(content)
20+
exported = SafeJSON.parse(content)
2121
} catch (e) {
2222
e.message = filename + ": " + e.message
2323

24-
toExternalError(e)
25-
2624
throw e
2725
}
2826

29-
toExternalObject(exported)
30-
3127
mod.exports = exported
3228
}
3329

src/module/internal/compile.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Entry from "../../entry.js"
1010
import GenericObject from "../../generic/object.js"
1111
import Loader from "../../loader.js"
1212
import Runtime from "../../runtime.js"
13+
import SafeJSON from "../../safe/json.js"
1314

1415
import assign from "../../util/assign.js"
1516
import captureStackTrace from "../../error/capture-stack-trace.js"
@@ -36,7 +37,6 @@ import shared from "../../shared.js"
3637
import stripBOM from "../../util/strip-bom.js"
3738
import toExternalError from "../../util/to-external-error.js"
3839
import toExternalFunction from "../../util/to-external-function.js"
39-
import toExternalObject from "../../util/to-external-object.js"
4040
import toString from "../../util/to-string.js"
4141

4242
const {
@@ -596,8 +596,7 @@ function jsonParse(entry, filename, fallback) {
596596
fallback()
597597
parsed = mod.exports
598598
} else {
599-
parsed = JSON.parse(content)
600-
toExternalObject(parsed)
599+
parsed = SafeJSON.parse(content)
601600
}
602601

603602
threw = false
@@ -606,7 +605,6 @@ function jsonParse(entry, filename, fallback) {
606605

607606
if (! useFallback) {
608607
error.message = filename + ": " + error.message
609-
toExternalError(error)
610608
}
611609
}
612610

src/safe/json.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import safe from "../util/safe.js"
2+
import shared from "../shared.js"
3+
4+
export default shared.inited
5+
? shared.module.safeJSON
6+
: shared.module.safeJSON = safe(shared.external.JSON)

src/util/to-external-object.js

-28
This file was deleted.

webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ const isProd = /production/.test(ESM_ENV)
7474
const isTest = /test/.test(ESM_ENV)
7575

7676
const externals = [
77-
"Array", "Buffer", "Error", "EvalError", "Function", "Object", "Promise",
78-
"RangeError", "ReferenceError", "Reflect", "SyntaxError", "TypeError",
79-
"URIError", "eval"
77+
"Array", "Buffer", "Error", "EvalError", "Function", "JSON", "Object",
78+
"Promise", "RangeError", "ReferenceError", "Reflect", "SyntaxError",
79+
"TypeError", "URIError", "eval"
8080
]
8181

8282
const hosted = [

0 commit comments

Comments
 (0)