Skip to content

Commit 4e07f9a

Browse files
committed
chore: Updating dependencies to latest working versions
1 parent 55e2e2f commit 4e07f9a

File tree

8 files changed

+4148
-4478
lines changed

8 files changed

+4148
-4478
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
/coverage/
55
/test/web-platform-tests/
66
/lib/*.json
7+
/lib/Function.js
78
/lib/TextEncoder.js
89
/lib/TextDecoder.js
910
/lib/TextDecodeOptions.js
1011
/lib/TextDecoderOptions.js
1112
/lib/TextEncoderEncodeIntoResult.js
13+
/lib/VoidFunction.js
1214
/lib/utils.js
1315
/live-viewer/whatwg-encoding.js

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
const { TextEncoder, TextDecoder } = require("./webidl2js-wrapper");
44
const whatwgEncoding = require("./lib/whatwg-encoding");
55

6-
const sharedGlobalObject = {};
7-
TextEncoder.install(sharedGlobalObject);
8-
TextDecoder.install(sharedGlobalObject);
6+
const sharedGlobalObject = globalThis;
7+
TextEncoder.install(sharedGlobalObject, ["Window"]);
8+
TextDecoder.install(sharedGlobalObject, ["Window"]);
99

1010
exports.TextEncoder = sharedGlobalObject.TextEncoder;
1111
exports.TextDecoder = sharedGlobalObject.TextDecoder;

lib/TextDecoder.js

+34-24
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ exports.is = value => {
1616
exports.isImpl = value => {
1717
return utils.isObject(value) && value instanceof Impl.implementation;
1818
};
19-
exports.convert = (value, { context = "The provided value" } = {}) => {
19+
exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
2020
if (exports.is(value)) {
2121
return utils.implForWrapper(value);
2222
}
23-
throw new TypeError(`${context} is not of type 'TextDecoder'.`);
23+
throw new globalObject.TypeError(`${context} is not of type 'TextDecoder'.`);
2424
};
2525

26-
function makeWrapper(globalObject) {
27-
if (globalObject[ctorRegistrySymbol] === undefined) {
28-
throw new Error("Internal error: invalid global object");
26+
function makeWrapper(globalObject, newTarget) {
27+
let proto;
28+
if (newTarget !== undefined) {
29+
proto = newTarget.prototype;
2930
}
3031

31-
const ctor = globalObject[ctorRegistrySymbol]["TextDecoder"];
32-
if (ctor === undefined) {
33-
throw new Error("Internal error: constructor TextDecoder is not installed on the passed global object");
32+
if (!utils.isObject(proto)) {
33+
proto = globalObject[ctorRegistrySymbol]["TextDecoder"].prototype;
3434
}
3535

36-
return Object.create(ctor.prototype);
36+
return Object.create(proto);
3737
}
3838

3939
exports.create = (globalObject, constructorArgs, privateData) => {
@@ -64,8 +64,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {})
6464
return wrapper;
6565
};
6666

67-
exports.new = globalObject => {
68-
const wrapper = makeWrapper(globalObject);
67+
exports.new = (globalObject, newTarget) => {
68+
const wrapper = makeWrapper(globalObject, newTarget);
6969

7070
exports._internalSetup(wrapper, globalObject);
7171
Object.defineProperty(wrapper, implSymbol, {
@@ -82,25 +82,32 @@ exports.new = globalObject => {
8282

8383
const exposed = new Set(["Window", "Worker"]);
8484

85-
exports.install = (globalObject, globalNames = ["Window"]) => {
85+
exports.install = (globalObject, globalNames) => {
8686
if (!globalNames.some(globalName => exposed.has(globalName))) {
8787
return;
8888
}
89+
90+
const ctorRegistry = utils.initCtorRegistry(globalObject);
8991
class TextDecoder {
9092
constructor() {
9193
const args = [];
9294
{
9395
let curArg = arguments[0];
9496
if (curArg !== undefined) {
95-
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'TextDecoder': parameter 1" });
97+
curArg = conversions["DOMString"](curArg, {
98+
context: "Failed to construct 'TextDecoder': parameter 1",
99+
globals: globalObject
100+
});
96101
} else {
97102
curArg = "utf-8";
98103
}
99104
args.push(curArg);
100105
}
101106
{
102107
let curArg = arguments[1];
103-
curArg = TextDecoderOptions.convert(curArg, { context: "Failed to construct 'TextDecoder': parameter 2" });
108+
curArg = TextDecoderOptions.convert(globalObject, curArg, {
109+
context: "Failed to construct 'TextDecoder': parameter 2"
110+
});
104111
args.push(curArg);
105112
}
106113
return exports.setup(Object.create(new.target.prototype), globalObject, args);
@@ -109,7 +116,7 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
109116
decode() {
110117
const esValue = this !== null && this !== undefined ? this : globalObject;
111118
if (!exports.is(esValue)) {
112-
throw new TypeError("Illegal invocation");
119+
throw new globalObject.TypeError("'decode' called on an object that is not a valid instance of TextDecoder.");
113120
}
114121
const args = [];
115122
{
@@ -118,7 +125,7 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
118125
if (utils.isArrayBuffer(curArg)) {
119126
} else if (ArrayBuffer.isView(curArg)) {
120127
} else {
121-
throw new TypeError(
128+
throw new globalObject.TypeError(
122129
"Failed to execute 'decode' on 'TextDecoder': parameter 1" + " is not of any supported type."
123130
);
124131
}
@@ -127,7 +134,7 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
127134
}
128135
{
129136
let curArg = arguments[1];
130-
curArg = TextDecodeOptions.convert(curArg, {
137+
curArg = TextDecodeOptions.convert(globalObject, curArg, {
131138
context: "Failed to execute 'decode' on 'TextDecoder': parameter 2"
132139
});
133140
args.push(curArg);
@@ -139,7 +146,9 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
139146
const esValue = this !== null && this !== undefined ? this : globalObject;
140147

141148
if (!exports.is(esValue)) {
142-
throw new TypeError("Illegal invocation");
149+
throw new globalObject.TypeError(
150+
"'get encoding' called on an object that is not a valid instance of TextDecoder."
151+
);
143152
}
144153

145154
return esValue[implSymbol]["encoding"];
@@ -149,7 +158,9 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
149158
const esValue = this !== null && this !== undefined ? this : globalObject;
150159

151160
if (!exports.is(esValue)) {
152-
throw new TypeError("Illegal invocation");
161+
throw new globalObject.TypeError(
162+
"'get fatal' called on an object that is not a valid instance of TextDecoder."
163+
);
153164
}
154165

155166
return esValue[implSymbol]["fatal"];
@@ -159,7 +170,9 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
159170
const esValue = this !== null && this !== undefined ? this : globalObject;
160171

161172
if (!exports.is(esValue)) {
162-
throw new TypeError("Illegal invocation");
173+
throw new globalObject.TypeError(
174+
"'get ignoreBOM' called on an object that is not a valid instance of TextDecoder."
175+
);
163176
}
164177

165178
return esValue[implSymbol]["ignoreBOM"];
@@ -172,10 +185,7 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
172185
ignoreBOM: { enumerable: true },
173186
[Symbol.toStringTag]: { value: "TextDecoder", configurable: true }
174187
});
175-
if (globalObject[ctorRegistrySymbol] === undefined) {
176-
globalObject[ctorRegistrySymbol] = Object.create(null);
177-
}
178-
globalObject[ctorRegistrySymbol][interfaceName] = TextDecoder;
188+
ctorRegistry[interfaceName] = TextDecoder;
179189

180190
Object.defineProperty(globalObject, interfaceName, {
181191
configurable: true,

lib/TextEncoder.js

+30-26
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ exports.is = value => {
1414
exports.isImpl = value => {
1515
return utils.isObject(value) && value instanceof Impl.implementation;
1616
};
17-
exports.convert = (value, { context = "The provided value" } = {}) => {
17+
exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
1818
if (exports.is(value)) {
1919
return utils.implForWrapper(value);
2020
}
21-
throw new TypeError(`${context} is not of type 'TextEncoder'.`);
21+
throw new globalObject.TypeError(`${context} is not of type 'TextEncoder'.`);
2222
};
2323

24-
function makeWrapper(globalObject) {
25-
if (globalObject[ctorRegistrySymbol] === undefined) {
26-
throw new Error("Internal error: invalid global object");
24+
function makeWrapper(globalObject, newTarget) {
25+
let proto;
26+
if (newTarget !== undefined) {
27+
proto = newTarget.prototype;
2728
}
2829

29-
const ctor = globalObject[ctorRegistrySymbol]["TextEncoder"];
30-
if (ctor === undefined) {
31-
throw new Error("Internal error: constructor TextEncoder is not installed on the passed global object");
30+
if (!utils.isObject(proto)) {
31+
proto = globalObject[ctorRegistrySymbol]["TextEncoder"].prototype;
3232
}
3333

34-
return Object.create(ctor.prototype);
34+
return Object.create(proto);
3535
}
3636

3737
exports.create = (globalObject, constructorArgs, privateData) => {
@@ -62,8 +62,8 @@ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {})
6262
return wrapper;
6363
};
6464

65-
exports.new = globalObject => {
66-
const wrapper = makeWrapper(globalObject);
65+
exports.new = (globalObject, newTarget) => {
66+
const wrapper = makeWrapper(globalObject, newTarget);
6767

6868
exports._internalSetup(wrapper, globalObject);
6969
Object.defineProperty(wrapper, implSymbol, {
@@ -80,10 +80,12 @@ exports.new = globalObject => {
8080

8181
const exposed = new Set(["Window", "Worker"]);
8282

83-
exports.install = (globalObject, globalNames = ["Window"]) => {
83+
exports.install = (globalObject, globalNames) => {
8484
if (!globalNames.some(globalName => exposed.has(globalName))) {
8585
return;
8686
}
87+
88+
const ctorRegistry = utils.initCtorRegistry(globalObject);
8789
class TextEncoder {
8890
constructor() {
8991
return exports.setup(Object.create(new.target.prototype), globalObject, undefined);
@@ -92,14 +94,15 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
9294
encode() {
9395
const esValue = this !== null && this !== undefined ? this : globalObject;
9496
if (!exports.is(esValue)) {
95-
throw new TypeError("Illegal invocation");
97+
throw new globalObject.TypeError("'encode' called on an object that is not a valid instance of TextEncoder.");
9698
}
9799
const args = [];
98100
{
99101
let curArg = arguments[0];
100102
if (curArg !== undefined) {
101103
curArg = conversions["USVString"](curArg, {
102-
context: "Failed to execute 'encode' on 'TextEncoder': parameter 1"
104+
context: "Failed to execute 'encode' on 'TextEncoder': parameter 1",
105+
globals: globalObject
103106
});
104107
} else {
105108
curArg = "";
@@ -112,28 +115,30 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
112115
encodeInto(source, destination) {
113116
const esValue = this !== null && this !== undefined ? this : globalObject;
114117
if (!exports.is(esValue)) {
115-
throw new TypeError("Illegal invocation");
118+
throw new globalObject.TypeError(
119+
"'encodeInto' called on an object that is not a valid instance of TextEncoder."
120+
);
116121
}
117122

118123
if (arguments.length < 2) {
119-
throw new TypeError(
120-
"Failed to execute 'encodeInto' on 'TextEncoder': 2 arguments required, but only " +
121-
arguments.length +
122-
" present."
124+
throw new globalObject.TypeError(
125+
`Failed to execute 'encodeInto' on 'TextEncoder': 2 arguments required, but only ${arguments.length} present.`
123126
);
124127
}
125128
const args = [];
126129
{
127130
let curArg = arguments[0];
128131
curArg = conversions["USVString"](curArg, {
129-
context: "Failed to execute 'encodeInto' on 'TextEncoder': parameter 1"
132+
context: "Failed to execute 'encodeInto' on 'TextEncoder': parameter 1",
133+
globals: globalObject
130134
});
131135
args.push(curArg);
132136
}
133137
{
134138
let curArg = arguments[1];
135139
curArg = conversions["Uint8Array"](curArg, {
136-
context: "Failed to execute 'encodeInto' on 'TextEncoder': parameter 2"
140+
context: "Failed to execute 'encodeInto' on 'TextEncoder': parameter 2",
141+
globals: globalObject
137142
});
138143
args.push(curArg);
139144
}
@@ -144,7 +149,9 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
144149
const esValue = this !== null && this !== undefined ? this : globalObject;
145150

146151
if (!exports.is(esValue)) {
147-
throw new TypeError("Illegal invocation");
152+
throw new globalObject.TypeError(
153+
"'get encoding' called on an object that is not a valid instance of TextEncoder."
154+
);
148155
}
149156

150157
return esValue[implSymbol]["encoding"];
@@ -156,10 +163,7 @@ exports.install = (globalObject, globalNames = ["Window"]) => {
156163
encoding: { enumerable: true },
157164
[Symbol.toStringTag]: { value: "TextEncoder", configurable: true }
158165
});
159-
if (globalObject[ctorRegistrySymbol] === undefined) {
160-
globalObject[ctorRegistrySymbol] = Object.create(null);
161-
}
162-
globalObject[ctorRegistrySymbol][interfaceName] = TextEncoder;
166+
ctorRegistry[interfaceName] = TextEncoder;
163167

164168
Object.defineProperty(globalObject, interfaceName, {
165169
configurable: true,

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
},
2727
"dependencies": {
2828
"iconv-lite": "^0.6.3",
29-
"webidl-conversions": "^6.1.0"
29+
"webidl-conversions": "^7.0.0"
3030
},
3131
"devDependencies": {
32-
"@domenic/eslint-config": "^1.3.0",
32+
"@domenic/eslint-config": "^2.0.0",
3333
"browserify": "^17.0.0",
34-
"eslint": "^7.32.0",
35-
"got": "^9.0.0",
36-
"jest": "^27.0.6",
37-
"webidl2js": "^15.3.0"
34+
"eslint": "^8.23.1",
35+
"got": "^11.8.5",
36+
"jest": "^29.0.3",
37+
"webidl2js": "^17.1.0"
3838
},
3939
"engines": {
4040
"node": ">=12"

scripts/update.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ const path = require("path");
55
const iconvLite = require("iconv-lite");
66
const got = require("got");
77

8-
got("https://encoding.spec.whatwg.org/encodings.json", { json: true }).then(({ body }) => {
8+
got("https://encoding.spec.whatwg.org/encodings.json").then(({ body }) => {
99
const labelsToNames = {};
1010
const supportedNames = [];
11-
for (const entry of body) {
11+
const parsedBody = JSON.parse(body);
12+
for (const entry of parsedBody) {
1213
for (const encoding of entry.encodings) {
1314
if (iconvLite.encodingExists(encoding.name)) {
1415
supportedNames.push(encoding.name);

test/web-platform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function createSandbox() {
1313
TextEncoder,
1414
TextDecoder,
1515
// eslint-disable-next-line camelcase
16-
encodings_table: encodingsTable
16+
encodings_table: JSON.parse(encodingsTable)
1717
};
1818
Object.assign(sandbox, testharness);
1919
vm.createContext(sandbox);

0 commit comments

Comments
 (0)