forked from mirrors/gecko-dev
Bug 1811347 - Remove useless parameter from TextEncoder constructor r=emk,webdriver-reviewers,extension-reviewers,credential-management-reviewers,dimi,jdescottes,willdurand
Differential Revision: https://phabricator.services.mozilla.com/D167488
This commit is contained in:
parent
9e889916c5
commit
5d44f7a543
45 changed files with 67 additions and 83 deletions
|
|
@ -46,7 +46,7 @@ function getUint8Memory0() {
|
||||||
return cachedUint8Memory0;
|
return cachedUint8Memory0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedTextEncoder = new TextEncoder('utf-8');
|
const cachedTextEncoder = new TextEncoder();
|
||||||
|
|
||||||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
||||||
? function (arg, view) {
|
? function (arg, view) {
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ function test_base64URLEncode() {
|
||||||
testEncode(decoded, encoded);
|
testEncode(decoded, encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
let textEncoder = new TextEncoder("utf-8");
|
let textEncoder = new TextEncoder();
|
||||||
for (let decoded of Object.keys(textTests)) {
|
for (let decoded of Object.keys(textTests)) {
|
||||||
let input = textEncoder.encode(decoded);
|
let input = textEncoder.encode(decoded);
|
||||||
testEncode(input, textTests[decoded]);
|
testEncode(input, textTests[decoded]);
|
||||||
|
|
@ -132,7 +132,7 @@ function test_base64URLDecode() {
|
||||||
testDecode(encoded, decoded);
|
testDecode(encoded, decoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
let textEncoder = new TextEncoder("utf-8");
|
let textEncoder = new TextEncoder();
|
||||||
for (let decoded of Object.keys(textTests)) {
|
for (let decoded of Object.keys(textTests)) {
|
||||||
let expectedBuffer = textEncoder.encode(decoded);
|
let expectedBuffer = textEncoder.encode(decoded);
|
||||||
testDecode(textTests[decoded], expectedBuffer);
|
testDecode(textTests[decoded], expectedBuffer);
|
||||||
|
|
|
||||||
|
|
@ -695,10 +695,8 @@ let tv = {
|
||||||
|
|
||||||
// RFC 6070 <http://tools.ietf.org/html/rfc6070>
|
// RFC 6070 <http://tools.ietf.org/html/rfc6070>
|
||||||
pbkdf2_sha1: {
|
pbkdf2_sha1: {
|
||||||
password: new TextEncoder("utf-8").encode("passwordPASSWORDpassword"),
|
password: new TextEncoder().encode("passwordPASSWORDpassword"),
|
||||||
salt: new TextEncoder("utf-8").encode(
|
salt: new TextEncoder().encode("saltSALTsaltSALTsaltSALTsaltSALTsalt"),
|
||||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
|
||||||
),
|
|
||||||
iterations: 4096,
|
iterations: 4096,
|
||||||
length: 25 * 8,
|
length: 25 * 8,
|
||||||
|
|
||||||
|
|
@ -712,10 +710,8 @@ let tv = {
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
|
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
|
||||||
pbkdf2_sha256: {
|
pbkdf2_sha256: {
|
||||||
password: new TextEncoder("utf-8").encode("passwordPASSWORDpassword"),
|
password: new TextEncoder().encode("passwordPASSWORDpassword"),
|
||||||
salt: new TextEncoder("utf-8").encode(
|
salt: new TextEncoder().encode("saltSALTsaltSALTsaltSALTsaltSALTsalt"),
|
||||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
|
||||||
),
|
|
||||||
iterations: 4096,
|
iterations: 4096,
|
||||||
length: 40 * 8,
|
length: 40 * 8,
|
||||||
|
|
||||||
|
|
@ -739,9 +735,7 @@ let tv = {
|
||||||
|
|
||||||
pbkdf2_sha256_no_pwd: {
|
pbkdf2_sha256_no_pwd: {
|
||||||
password: new Uint8Array(),
|
password: new Uint8Array(),
|
||||||
salt: new TextEncoder("utf-8").encode(
|
salt: new TextEncoder().encode("saltSALTsaltSALTsaltSALTsaltSALTsalt"),
|
||||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt"
|
|
||||||
),
|
|
||||||
length: 32 * 8,
|
length: 32 * 8,
|
||||||
iterations: 1,
|
iterations: 1,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ TestArray.addTest(
|
||||||
function() {
|
function() {
|
||||||
var that = this;
|
var that = this;
|
||||||
var alg = "PBKDF2";
|
var alg = "PBKDF2";
|
||||||
var key = new TextEncoder("utf-8").encode("password");
|
var key = new TextEncoder().encode("password");
|
||||||
|
|
||||||
crypto.subtle.importKey("raw", key, alg, false, ["deriveKey"]).then(
|
crypto.subtle.importKey("raw", key, alg, false, ["deriveKey"]).then(
|
||||||
complete(that, hasKeyFields),
|
complete(that, hasKeyFields),
|
||||||
|
|
@ -42,7 +42,7 @@ TestArray.addTest(
|
||||||
"Unwrapping a PBKDF2 key in PKCS8 format should fail",
|
"Unwrapping a PBKDF2 key in PKCS8 format should fail",
|
||||||
function() {
|
function() {
|
||||||
var that = this;
|
var that = this;
|
||||||
var pbkdf2Key = new TextEncoder("utf-8").encode("password");
|
var pbkdf2Key = new TextEncoder().encode("password");
|
||||||
var alg = {name: "AES-GCM", length: 256, iv: new Uint8Array(16)};
|
var alg = {name: "AES-GCM", length: 256, iv: new Uint8Array(16)};
|
||||||
var wrappingKey;
|
var wrappingKey;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ TestArray.addTest(
|
||||||
"Structured Cloning: PBKDF2",
|
"Structured Cloning: PBKDF2",
|
||||||
function() {
|
function() {
|
||||||
var that = this;
|
var that = this;
|
||||||
var key = new TextEncoder("utf-8").encode("password");
|
var key = new TextEncoder().encode("password");
|
||||||
|
|
||||||
var alg = {
|
var alg = {
|
||||||
name: "PBKDF2",
|
name: "PBKDF2",
|
||||||
|
|
@ -128,7 +128,7 @@ TestArray.addTest(
|
||||||
"Structured Cloning: HKDF",
|
"Structured Cloning: HKDF",
|
||||||
function() {
|
function() {
|
||||||
var that = this;
|
var that = this;
|
||||||
var key = new TextEncoder("utf-8").encode("password");
|
var key = new TextEncoder().encode("password");
|
||||||
|
|
||||||
var alg = {
|
var alg = {
|
||||||
name: "HKDF",
|
name: "HKDF",
|
||||||
|
|
|
||||||
|
|
@ -385,7 +385,7 @@ TestArray.addTest(
|
||||||
var wrapKey;
|
var wrapKey;
|
||||||
|
|
||||||
function doBogusWrap() {
|
function doBogusWrap() {
|
||||||
var abv = new TextEncoder("utf-8").encode("I am so not JSON");
|
var abv = new TextEncoder().encode("I am so not JSON");
|
||||||
return crypto.subtle.encrypt(wrapAlg, wrapKey, abv);
|
return crypto.subtle.encrypt(wrapAlg, wrapKey, abv);
|
||||||
}
|
}
|
||||||
function doUnwrap(wrappedKey) {
|
function doUnwrap(wrappedKey) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ test(function() {
|
||||||
];
|
];
|
||||||
|
|
||||||
badStrings.forEach(function(t) {
|
badStrings.forEach(function(t) {
|
||||||
var encoded = new TextEncoder("utf-8").encode(t.input);
|
var encoded = new TextEncoder().encode(t.input);
|
||||||
var decoded = new TextDecoder("utf-8").decode(encoded);
|
var decoded = new TextDecoder("utf-8").decode(encoded);
|
||||||
assert_equals(t.expected, decoded);
|
assert_equals(t.expected, decoded);
|
||||||
});
|
});
|
||||||
|
|
@ -323,7 +323,7 @@ test(function() {
|
||||||
0xff,
|
0xff,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
var encoded = octets[encoding] || new TextEncoder(encoding).encode(string);
|
var encoded = octets[encoding] || new TextEncoder().encode(string);
|
||||||
|
|
||||||
for (var len = 1; len <= 5; ++len) {
|
for (var len = 1; len <= 5; ++len) {
|
||||||
var out = "",
|
var out = "",
|
||||||
|
|
@ -406,13 +406,13 @@ test(function() {
|
||||||
string += String.fromCharCode(i);
|
string += String.fromCharCode(i);
|
||||||
bytes.push(i);
|
bytes.push(i);
|
||||||
}
|
}
|
||||||
var ascii_encoded = new TextEncoder("utf-8").encode(string);
|
var ascii_encoded = new TextEncoder().encode(string);
|
||||||
assert_equals(
|
assert_equals(
|
||||||
new TextDecoder(encoding).decode(ascii_encoded),
|
new TextDecoder(encoding).decode(ascii_encoded),
|
||||||
string,
|
string,
|
||||||
encoding
|
encoding
|
||||||
);
|
);
|
||||||
//assert_array_equals(new TextEncoder(encoding).encode(string), bytes, encoding);
|
//assert_array_equals(new TextEncoder().encode(string), bytes, encoding);
|
||||||
});
|
});
|
||||||
}, "Supersets of ASCII decode ASCII correctly");
|
}, "Supersets of ASCII decode ASCII correctly");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1678,7 +1678,7 @@ class RTCPeerConnection {
|
||||||
// At least 65536/2 UTF-16 characters. UTF-8 might be too long.
|
// At least 65536/2 UTF-16 characters. UTF-8 might be too long.
|
||||||
// Spec says to check how long |protocol| and |label| are in _bytes_. This
|
// Spec says to check how long |protocol| and |label| are in _bytes_. This
|
||||||
// is a little ambiguous. For now, examine the length of the utf-8 encoding.
|
// is a little ambiguous. For now, examine the length of the utf-8 encoding.
|
||||||
const byteCounter = new TextEncoder("utf-8");
|
const byteCounter = new TextEncoder();
|
||||||
|
|
||||||
if (byteCounter.encode(protocol).length > 65535) {
|
if (byteCounter.encode(protocol).length > 65535) {
|
||||||
throw new this._win.TypeError(
|
throw new this._win.TypeError(
|
||||||
|
|
@ -1688,7 +1688,7 @@ class RTCPeerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label.length > 32767) {
|
if (label.length > 32767) {
|
||||||
const byteCounter = new TextEncoder("utf-8");
|
const byteCounter = new TextEncoder();
|
||||||
if (byteCounter.encode(label).length > 65535) {
|
if (byteCounter.encode(label).length > 65535) {
|
||||||
throw new this._win.TypeError(
|
throw new this._win.TypeError(
|
||||||
"label cannot be longer than 65535 bytes"
|
"label cannot be longer than 65535 bytes"
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ PeerConnectionTest.prototype.send = async function(data, options) {
|
||||||
} else if (d instanceof ArrayBuffer) {
|
} else if (d instanceof ArrayBuffer) {
|
||||||
return d.byteLength;
|
return d.byteLength;
|
||||||
} else if (d instanceof String || typeof d === "string") {
|
} else if (d instanceof String || typeof d === "string") {
|
||||||
return new TextEncoder("utf-8").encode(d).length;
|
return new TextEncoder().encode(d).length;
|
||||||
} else {
|
} else {
|
||||||
ok(false);
|
ok(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ XPCOMUtils.defineLazyGetter(lazy, "gDOMBundle", () =>
|
||||||
);
|
);
|
||||||
|
|
||||||
// getCryptoParamsFromHeaders is exported for test purposes.
|
// getCryptoParamsFromHeaders is exported for test purposes.
|
||||||
const UTF8 = new TextEncoder("utf-8");
|
const UTF8 = new TextEncoder();
|
||||||
|
|
||||||
const ECDH_KEY = { name: "ECDH", namedCurve: "P-256" };
|
const ECDH_KEY = { name: "ECDH", namedCurve: "P-256" };
|
||||||
const ECDSA_KEY = { name: "ECDSA", namedCurve: "P-256" };
|
const ECDSA_KEY = { name: "ECDSA", namedCurve: "P-256" };
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ http://creativecommons.org/licenses/publicdomain/
|
||||||
var idCounter = 1;
|
var idCounter = 1;
|
||||||
function waitForDeliveryError(request) {
|
function waitForDeliveryError(request) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
var data = new TextEncoder("utf-8").encode(JSON.stringify(request));
|
var data = new TextEncoder().encode(JSON.stringify(request));
|
||||||
var principal = SpecialPowers.wrap(window).clientPrincipal;
|
var principal = SpecialPowers.wrap(window).clientPrincipal;
|
||||||
|
|
||||||
let messageId = "message-" + (idCounter++);
|
let messageId = "message-" + (idCounter++);
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,8 @@
|
||||||
namedCurve: "P-256",
|
namedCurve: "P-256",
|
||||||
};
|
};
|
||||||
var webCrypto = g.crypto.subtle;
|
var webCrypto = g.crypto.subtle;
|
||||||
var ENCRYPT_INFO = new TextEncoder("utf-8").encode(
|
var ENCRYPT_INFO = new TextEncoder().encode("Content-Encoding: aesgcm128");
|
||||||
"Content-Encoding: aesgcm128"
|
var NONCE_INFO = new TextEncoder().encode("Content-Encoding: nonce");
|
||||||
);
|
|
||||||
var NONCE_INFO = new TextEncoder("utf-8").encode("Content-Encoding: nonce");
|
|
||||||
|
|
||||||
function chunkArray(array, size) {
|
function chunkArray(array, size) {
|
||||||
var start = array.byteOffset || 0;
|
var start = array.byteOffset || 0;
|
||||||
|
|
@ -86,7 +84,7 @@
|
||||||
/* Coerces data into a Uint8Array */
|
/* Coerces data into a Uint8Array */
|
||||||
function ensureView(data) {
|
function ensureView(data) {
|
||||||
if (typeof data === "string") {
|
if (typeof data === "string") {
|
||||||
return new TextEncoder("utf-8").encode(data);
|
return new TextEncoder().encode(data);
|
||||||
}
|
}
|
||||||
if (data instanceof ArrayBuffer) {
|
if (data instanceof ArrayBuffer) {
|
||||||
return new Uint8Array(data);
|
return new Uint8Array(data);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ add_task(async function static_aes128gcm() {
|
||||||
ciphertext: from64(`DGv6ra1nlYgDCS1FRnbzlwAAEABBBP4z9KsN6nGRTbVYI_c7VJSPQTBtkgcy27ml
|
ciphertext: from64(`DGv6ra1nlYgDCS1FRnbzlwAAEABBBP4z9KsN6nGRTbVYI_c7VJSPQTBtkgcy27ml
|
||||||
mlMoZIIgDll6e3vCYLocInmYWAmS6TlzAC8wEqKK6PBru3jl7A_yl95bQpu6cVPT
|
mlMoZIIgDll6e3vCYLocInmYWAmS6TlzAC8wEqKK6PBru3jl7A_yl95bQpu6cVPT
|
||||||
pK4Mqgkf1CXztLVBSt2Ks3oZwbuwXPXLWyouBWLVWGNWQexSgSxsj_Qulcy4a-fN`),
|
pK4Mqgkf1CXztLVBSt2Ks3oZwbuwXPXLWyouBWLVWGNWQexSgSxsj_Qulcy4a-fN`),
|
||||||
plaintext: new TextEncoder("utf-8").encode(
|
plaintext: new TextEncoder().encode(
|
||||||
"When I grow up, I want to be a watermelon"
|
"When I grow up, I want to be a watermelon"
|
||||||
),
|
),
|
||||||
authSecret: from64("BTBZMqHH6r4Tts7J_aSIgg"),
|
authSecret: from64("BTBZMqHH6r4Tts7J_aSIgg"),
|
||||||
|
|
@ -107,7 +107,7 @@ add_task(async function static_aes128gcm() {
|
||||||
add_task(async function aes128gcm_simple() {
|
add_task(async function aes128gcm_simple() {
|
||||||
let [recvPublicKey, recvPrivateKey] = await PushCrypto.generateKeys();
|
let [recvPublicKey, recvPrivateKey] = await PushCrypto.generateKeys();
|
||||||
|
|
||||||
let message = new TextEncoder("utf-8").encode("Fast for good.");
|
let message = new TextEncoder().encode("Fast for good.");
|
||||||
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
||||||
let { ciphertext, encoding } = await PushCrypto.encrypt(
|
let { ciphertext, encoding } = await PushCrypto.encrypt(
|
||||||
message,
|
message,
|
||||||
|
|
@ -133,7 +133,7 @@ add_task(async function aes128gcm_rs() {
|
||||||
for (let rs of [-1, 0, 1, 17]) {
|
for (let rs of [-1, 0, 1, 17]) {
|
||||||
let payload = "x".repeat(1024);
|
let payload = "x".repeat(1024);
|
||||||
info(`testing expected failure with rs=${rs}`);
|
info(`testing expected failure with rs=${rs}`);
|
||||||
let message = new TextEncoder("utf-8").encode(payload);
|
let message = new TextEncoder().encode(payload);
|
||||||
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
||||||
await Assert.rejects(
|
await Assert.rejects(
|
||||||
PushCrypto.encrypt(message, recvPublicKey, authSecret, { rs }),
|
PushCrypto.encrypt(message, recvPublicKey, authSecret, { rs }),
|
||||||
|
|
@ -143,7 +143,7 @@ add_task(async function aes128gcm_rs() {
|
||||||
for (let rs of [18, 50, 1024, 4096, 16384]) {
|
for (let rs of [18, 50, 1024, 4096, 16384]) {
|
||||||
info(`testing expected success with rs=${rs}`);
|
info(`testing expected success with rs=${rs}`);
|
||||||
let payload = "x".repeat(rs * 3);
|
let payload = "x".repeat(rs * 3);
|
||||||
let message = new TextEncoder("utf-8").encode(payload);
|
let message = new TextEncoder().encode(payload);
|
||||||
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
||||||
let { ciphertext, encoding } = await PushCrypto.encrypt(
|
let { ciphertext, encoding } = await PushCrypto.encrypt(
|
||||||
message,
|
message,
|
||||||
|
|
@ -179,7 +179,7 @@ add_task(async function aes128gcm_edgecases() {
|
||||||
10240,
|
10240,
|
||||||
]) {
|
]) {
|
||||||
info(`testing encryption of ${size} byte payload`);
|
info(`testing encryption of ${size} byte payload`);
|
||||||
let message = new TextEncoder("utf-8").encode("x".repeat(size));
|
let message = new TextEncoder().encode("x".repeat(size));
|
||||||
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
let authSecret = crypto.getRandomValues(new Uint8Array(16));
|
||||||
let { ciphertext, encoding } = await PushCrypto.encrypt(
|
let { ciphertext, encoding } = await PushCrypto.encrypt(
|
||||||
message,
|
message,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
|
||||||
|
|
||||||
add_task(async function test_notifyWithData() {
|
add_task(async function test_notifyWithData() {
|
||||||
let textData = '{"hello":"world"}';
|
let textData = '{"hello":"world"}';
|
||||||
let payload = new TextEncoder("utf-8").encode(textData);
|
let payload = new TextEncoder().encode(textData);
|
||||||
|
|
||||||
let notifyPromise = promiseObserverNotification(
|
let notifyPromise = promiseObserverNotification(
|
||||||
PushServiceComponent.pushTopic
|
PushServiceComponent.pushTopic
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ var waitForNotifierObservers = async function(
|
||||||
);
|
);
|
||||||
|
|
||||||
let scope = "chrome://test-scope";
|
let scope = "chrome://test-scope";
|
||||||
let data = new TextEncoder("utf-8").encode(text);
|
let data = new TextEncoder().encode(text);
|
||||||
|
|
||||||
if (shouldNotify) {
|
if (shouldNotify) {
|
||||||
pushNotifier.notifyPushWithData(scope, principal, "", data);
|
pushNotifier.notifyPushWithData(scope, principal, "", data);
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ function iterateForOf(iter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function byteInflate(str) {
|
function byteInflate(str) {
|
||||||
var encoder = new TextEncoder("utf-8");
|
var encoder = new TextEncoder();
|
||||||
var encoded = encoder.encode(str);
|
var encoded = encoder.encode(str);
|
||||||
var result = "";
|
var result = "";
|
||||||
for (var i = 0; i < encoded.length; ++i) {
|
for (var i = 0; i < encoded.length; ++i) {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ add_task(async function test_appid() {
|
||||||
.then(arrivingHereIsBad)
|
.then(arrivingHereIsBad)
|
||||||
.catch(expectInvalidStateError);
|
.catch(expectInvalidStateError);
|
||||||
|
|
||||||
let rpId = new TextEncoder("utf-8").encode(appid);
|
let rpId = new TextEncoder().encode(appid);
|
||||||
let rpIdHash = await crypto.subtle.digest("SHA-256", rpId);
|
let rpIdHash = await crypto.subtle.digest("SHA-256", rpId);
|
||||||
|
|
||||||
// Succeed with the right fallback rpId.
|
// Succeed with the right fallback rpId.
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ add_task(async function test_appid() {
|
||||||
.then(arrivingHereIsBad)
|
.then(arrivingHereIsBad)
|
||||||
.catch(expectInvalidStateError);
|
.catch(expectInvalidStateError);
|
||||||
|
|
||||||
let rpId = new TextEncoder("utf-8").encode(appid);
|
let rpId = new TextEncoder().encode(appid);
|
||||||
let rpIdHash = await crypto.subtle.digest("SHA-256", rpId);
|
let rpIdHash = await crypto.subtle.digest("SHA-256", rpId);
|
||||||
|
|
||||||
// Succeed with the right fallback rpId.
|
// Succeed with the right fallback rpId.
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ function run_test() {
|
||||||
sb.equal = equal;
|
sb.equal = equal;
|
||||||
let innerPromise = new Promise(r => (sb.test_done = r));
|
let innerPromise = new Promise(r => (sb.test_done = r));
|
||||||
Cu.evalInSandbox('crypto.subtle.digest("SHA-256", ' +
|
Cu.evalInSandbox('crypto.subtle.digest("SHA-256", ' +
|
||||||
' new TextEncoder("utf-8").encode("abc"))' +
|
' new TextEncoder().encode("abc"))' +
|
||||||
' .then(h => equal(new Uint16Array(h)[0], 30906))' +
|
' .then(h => equal(new Uint16Array(h)[0], 30906))' +
|
||||||
' .then(test_done);', sb);
|
' .then(test_done);', sb);
|
||||||
|
|
||||||
Cu.importGlobalProperties(["crypto"]);
|
Cu.importGlobalProperties(["crypto"]);
|
||||||
ok(crypto);
|
ok(crypto);
|
||||||
ok(crypto.subtle);
|
ok(crypto.subtle);
|
||||||
let outerPromise = crypto.subtle.digest("SHA-256", new TextEncoder("utf-8").encode("abc"))
|
let outerPromise = crypto.subtle.digest("SHA-256", new TextEncoder().encode("abc"))
|
||||||
.then(h => Assert.equal(new Uint16Array(h)[0], 30906));
|
.then(h => Assert.equal(new Uint16Array(h)[0], 30906));
|
||||||
|
|
||||||
do_test_pending();
|
do_test_pending();
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ function basic_auth(metadata, response) {
|
||||||
// Digest functions
|
// Digest functions
|
||||||
//
|
//
|
||||||
function bytesFromString(str) {
|
function bytesFromString(str) {
|
||||||
const encoder = new TextEncoder("utf-8");
|
const encoder = new TextEncoder();
|
||||||
return encoder.encode(str);
|
return encoder.encode(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ capture.toBase64 = function(canvas) {
|
||||||
*/
|
*/
|
||||||
capture.toHash = function(canvas) {
|
capture.toHash = function(canvas) {
|
||||||
let u = capture.toBase64(canvas);
|
let u = capture.toBase64(canvas);
|
||||||
let buffer = new TextEncoder("utf-8").encode(u);
|
let buffer = new TextEncoder().encode(u);
|
||||||
return crypto.subtle.digest("SHA-256", buffer).then(hash => hex(hash));
|
return crypto.subtle.digest("SHA-256", buffer).then(hash => hex(hash));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ CertPasswordPromptDefault=Please enter your Primary Password.
|
||||||
# It's possible to verify the length of a translation using the Browser Console
|
# It's possible to verify the length of a translation using the Browser Console
|
||||||
# in Firefox and evaluating the following code:
|
# in Firefox and evaluating the following code:
|
||||||
#
|
#
|
||||||
# (new TextEncoder('utf-8').encode('YOURSTRING')).length
|
# (new TextEncoder().encode('YOURSTRING')).length
|
||||||
#
|
#
|
||||||
# Simply replace YOURSTRING with your translation.
|
# Simply replace YOURSTRING with your translation.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ class SendTab {
|
||||||
async send(to, tab) {
|
async send(to, tab) {
|
||||||
log.info(`Sending a tab to ${to.length} devices.`);
|
log.info(`Sending a tab to ${to.length} devices.`);
|
||||||
const flowID = this._fxai.telemetry.generateFlowID();
|
const flowID = this._fxai.telemetry.generateFlowID();
|
||||||
const encoder = new TextEncoder("utf8");
|
const encoder = new TextEncoder();
|
||||||
const data = { entries: [{ title: tab.title, url: tab.url }] };
|
const data = { entries: [{ title: tab.title, url: tab.url }] };
|
||||||
const report = {
|
const report = {
|
||||||
succeeded: [],
|
succeeded: [],
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,7 @@ class FxAccountsKeys {
|
||||||
scopedKeyMetadata.keyRotationSecret
|
scopedKeyMetadata.keyRotationSecret
|
||||||
);
|
);
|
||||||
const salt = CommonUtils.hexToArrayBuffer(uid);
|
const salt = CommonUtils.hexToArrayBuffer(uid);
|
||||||
const context = new TextEncoder("utf8").encode(
|
const context = new TextEncoder().encode(
|
||||||
"identity.mozilla.com/picl/v1/scoped_key\n" + scopedKeyMetadata.identifier
|
"identity.mozilla.com/picl/v1/scoped_key\n" + scopedKeyMetadata.identifier
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ add_task(async function test_sendtab_receive_old_client() {
|
||||||
// No 'flowID' in the encrypted payload, no 'streamID' anywhere.
|
// No 'flowID' in the encrypted payload, no 'streamID' anywhere.
|
||||||
const payload = {
|
const payload = {
|
||||||
flowID: "flow-id",
|
flowID: "flow-id",
|
||||||
encrypted: new TextEncoder("utf8").encode(JSON.stringify(data)),
|
encrypted: new TextEncoder().encode(JSON.stringify(data)),
|
||||||
};
|
};
|
||||||
const reason = "push";
|
const reason = "push";
|
||||||
await sendTab.handle("sender-id", payload, reason);
|
await sendTab.handle("sender-id", payload, reason);
|
||||||
|
|
|
||||||
|
|
@ -775,11 +775,7 @@ XPCOMUtils.defineLazyGetter(Utils, "_utf8Converter", function() {
|
||||||
return converter;
|
return converter;
|
||||||
});
|
});
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(
|
XPCOMUtils.defineLazyGetter(Utils, "utf8Encoder", () => new TextEncoder());
|
||||||
Utils,
|
|
||||||
"utf8Encoder",
|
|
||||||
() => new TextEncoder("utf-8")
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Commonly-used services
|
* Commonly-used services
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ function toByteArray(data) {
|
||||||
tmpData = JSON.stringify(tmpData);
|
tmpData = JSON.stringify(tmpData);
|
||||||
|
|
||||||
if (typeof tmpData === 'string')
|
if (typeof tmpData === 'string')
|
||||||
byteArray = new TextEncoder('utf-8').encode(tmpData);
|
byteArray = new TextEncoder().encode(tmpData);
|
||||||
|
|
||||||
return byteArray;
|
return byteArray;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ function nfc_test(func, name, properties) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const test_text_data = 'Test text data.';
|
const test_text_data = 'Test text data.';
|
||||||
const test_text_byte_array = new TextEncoder('utf-8').encode(test_text_data);
|
const test_text_byte_array = new TextEncoder().encode(test_text_data);
|
||||||
const test_number_data = 42;
|
const test_number_data = 42;
|
||||||
const test_json_data = {level: 1, score: 100, label: 'Game'};
|
const test_json_data = {level: 1, score: 100, label: 'Game'};
|
||||||
const test_url_data = 'https://w3c.github.io/web-nfc/';
|
const test_url_data = 'https://w3c.github.io/web-nfc/';
|
||||||
|
|
@ -124,7 +124,7 @@ function createTextRecord(data, encoding, lang) {
|
||||||
|
|
||||||
function createMimeRecordFromJson(json) {
|
function createMimeRecordFromJson(json) {
|
||||||
return createRecord(
|
return createRecord(
|
||||||
'mime', new TextEncoder('utf-8').encode(JSON.stringify(json)),
|
'mime', new TextEncoder().encode(JSON.stringify(json)),
|
||||||
test_record_id, 'application/json');
|
test_record_id, 'application/json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ standardSetup(function() {
|
||||||
// The extension results will be in the authenticator outputs.
|
// The extension results will be in the authenticator outputs.
|
||||||
assert_true(new Uint8Array(credential.response.getAuthenticatorData())
|
assert_true(new Uint8Array(credential.response.getAuthenticatorData())
|
||||||
.toString()
|
.toString()
|
||||||
.includes(new TextEncoder("utf-8")
|
.includes(new TextEncoder()
|
||||||
.encode("minPinLength")
|
.encode("minPinLength")
|
||||||
.toString()));
|
.toString()));
|
||||||
}, "navigator.credentials.create() with minPinLength requested");
|
}, "navigator.credentials.create() with minPinLength requested");
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const AUTHENTICATOR_SELECTION_CRITERIA = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAKE_CREDENTIAL_OPTIONS = {
|
const MAKE_CREDENTIAL_OPTIONS = {
|
||||||
challenge: new TextEncoder("utf-8").encode(CHALLENGE),
|
challenge: new TextEncoder().encode(CHALLENGE),
|
||||||
rp: PUBLIC_KEY_RP,
|
rp: PUBLIC_KEY_RP,
|
||||||
user: PUBLIC_KEY_USER,
|
user: PUBLIC_KEY_USER,
|
||||||
pubKeyCredParams: PUBLIC_KEY_PARAMETERS,
|
pubKeyCredParams: PUBLIC_KEY_PARAMETERS,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ promise_test(async t => {
|
||||||
new Cbor(credential.response.attestationObject).getCBOR();
|
new Cbor(credential.response.attestationObject).getCBOR();
|
||||||
|
|
||||||
let rpIdHash = new Uint8Array(await crypto.subtle.digest(
|
let rpIdHash = new Uint8Array(await crypto.subtle.digest(
|
||||||
{ name: "SHA-256" }, new TextEncoder("utf-8").encode(PUBLIC_KEY_RP.id)));
|
{ name: "SHA-256" }, new TextEncoder().encode(PUBLIC_KEY_RP.id)));
|
||||||
|
|
||||||
let authenticatorData = parseAuthenticatorData(attestationObject.authData);
|
let authenticatorData = parseAuthenticatorData(attestationObject.authData);
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ promise_test(async t => {
|
||||||
promise_test(async t => {
|
promise_test(async t => {
|
||||||
let assertion = await navigator.credentials.get({
|
let assertion = await navigator.credentials.get({
|
||||||
publicKey: {
|
publicKey: {
|
||||||
challenge: new TextEncoder("utf-8").encode(CHALLENGE),
|
challenge: new TextEncoder().encode(CHALLENGE),
|
||||||
rpId: PUBLIC_KEY_RP.id,
|
rpId: PUBLIC_KEY_RP.id,
|
||||||
allowCredentials: [{
|
allowCredentials: [{
|
||||||
type: "public-key",
|
type: "public-key",
|
||||||
|
|
@ -87,7 +87,7 @@ promise_test(async t => {
|
||||||
let authenticatorData = parseAuthenticatorData(binaryAuthenticatorData);
|
let authenticatorData = parseAuthenticatorData(binaryAuthenticatorData);
|
||||||
|
|
||||||
let rpIdHash = new Uint8Array(await crypto.subtle.digest(
|
let rpIdHash = new Uint8Array(await crypto.subtle.digest(
|
||||||
{ name: "SHA-256" }, new TextEncoder("utf-8").encode(PUBLIC_KEY_RP.id)));
|
{ name: "SHA-256" }, new TextEncoder().encode(PUBLIC_KEY_RP.id)));
|
||||||
|
|
||||||
assert_array_equals(authenticatorData.rpIdHash, rpIdHash)
|
assert_array_equals(authenticatorData.rpIdHash, rpIdHash)
|
||||||
assert_true(authenticatorData.flags.up);
|
assert_true(authenticatorData.flags.up);
|
||||||
|
|
|
||||||
|
|
@ -521,7 +521,7 @@ ExtensionTestCommon = class ExtensionTestCommon {
|
||||||
for (let filename in files) {
|
for (let filename in files) {
|
||||||
let script = files[filename];
|
let script = files[filename];
|
||||||
if (!instanceOf(script, "ArrayBuffer")) {
|
if (!instanceOf(script, "ArrayBuffer")) {
|
||||||
script = new TextEncoder("utf-8").encode(script).buffer;
|
script = new TextEncoder().encode(script).buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = Cc[
|
let stream = Cc[
|
||||||
|
|
|
||||||
|
|
@ -375,9 +375,7 @@ add_task(async function test_filter_302() {
|
||||||
|
|
||||||
filter.ondata = event => {
|
filter.ondata = event => {
|
||||||
const script = "forceError();";
|
const script = "forceError();";
|
||||||
filter.write(
|
filter.write(new Uint8Array(new TextEncoder().encode(script)));
|
||||||
new Uint8Array(new TextEncoder("utf-8").encode(script))
|
|
||||||
);
|
|
||||||
filter.close();
|
filter.close();
|
||||||
browser.test.sendMessage("filter-ondata");
|
browser.test.sendMessage("filter-ondata");
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ const TASKS = [
|
||||||
{
|
{
|
||||||
url: "slow_response.sjs",
|
url: "slow_response.sjs",
|
||||||
task(filter, resolve, num) {
|
task(filter, resolve, num) {
|
||||||
let encoder = new TextEncoder("utf-8");
|
let encoder = new TextEncoder();
|
||||||
|
|
||||||
filter.onstop = event => {
|
filter.onstop = event => {
|
||||||
browser.test.fail(
|
browser.test.fail(
|
||||||
|
|
@ -344,7 +344,7 @@ const TASKS = [
|
||||||
{
|
{
|
||||||
url: "slow_response.sjs",
|
url: "slow_response.sjs",
|
||||||
task(filter, resolve, num) {
|
task(filter, resolve, num) {
|
||||||
let encoder = new TextEncoder("utf-8");
|
let encoder = new TextEncoder();
|
||||||
let decoder = new TextDecoder("utf-8");
|
let decoder = new TextDecoder("utf-8");
|
||||||
|
|
||||||
filter.onstop = event => {
|
filter.onstop = event => {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ add_task(async function test_StreamFilter_at_restart() {
|
||||||
details => {
|
details => {
|
||||||
let filter = browser.webRequest.filterResponseData(details.requestId);
|
let filter = browser.webRequest.filterResponseData(details.requestId);
|
||||||
filter.onstop = () => {
|
filter.onstop = () => {
|
||||||
let encoded = new TextEncoder("utf-8").encode(data);
|
let encoded = new TextEncoder().encode(data);
|
||||||
filter.write(encoded);
|
filter.write(encoded);
|
||||||
filter.close();
|
filter.close();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ function sha512(string) {
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let encoder = new TextEncoder("utf-8");
|
let encoder = new TextEncoder();
|
||||||
let bytes = encoder.encode(string);
|
let bytes = encoder.encode(string);
|
||||||
let hash = new CryptoHash("sha512");
|
let hash = new CryptoHash("sha512");
|
||||||
hash.update(bytes, bytes.length);
|
hash.update(bytes, bytes.length);
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,7 @@ var writeAtomic = function(path, buffer, options = {}) {
|
||||||
|
|
||||||
if (typeof buffer == "string") {
|
if (typeof buffer == "string") {
|
||||||
// Normalize buffer to a C buffer by encoding it
|
// Normalize buffer to a C buffer by encoding it
|
||||||
let encoding = options.encoding || "utf-8";
|
buffer = new TextEncoder().encode(buffer);
|
||||||
buffer = new TextEncoder(encoding).encode(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ArrayBuffer.isView(buffer)) {
|
if (ArrayBuffer.isView(buffer)) {
|
||||||
|
|
|
||||||
|
|
@ -432,8 +432,7 @@ if (typeof Components != "undefined") {
|
||||||
|
|
||||||
if (typeof buffer == "string") {
|
if (typeof buffer == "string") {
|
||||||
// Normalize buffer to a C buffer by encoding it
|
// Normalize buffer to a C buffer by encoding it
|
||||||
let encoding = options.encoding || "utf-8";
|
buffer = new TextEncoder().encode(buffer);
|
||||||
buffer = new TextEncoder(encoding).encode(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("compression" in options && options.compression == "lz4") {
|
if ("compression" in options && options.compression == "lz4") {
|
||||||
|
|
|
||||||
|
|
@ -2385,7 +2385,7 @@ PlacesUtils.metadata = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_base64Encode(str) {
|
_base64Encode(str) {
|
||||||
return ChromeUtils.base64URLEncode(new TextEncoder("utf-8").encode(str), {
|
return ChromeUtils.base64URLEncode(new TextEncoder().encode(str), {
|
||||||
pad: true,
|
pad: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,7 @@ export var SearchUtils = {
|
||||||
name +
|
name +
|
||||||
disclaimer.replace(/\$appName/g, Services.appinfo.name);
|
disclaimer.replace(/\$appName/g, Services.appinfo.name);
|
||||||
|
|
||||||
let data = new TextEncoder("utf-8").encode(salt);
|
let data = new TextEncoder().encode(salt);
|
||||||
let hasher = Cc["@mozilla.org/security/hash;1"].createInstance(
|
let hasher = Cc["@mozilla.org/security/hash;1"].createInstance(
|
||||||
Ci.nsICryptoHash
|
Ci.nsICryptoHash
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -486,7 +486,7 @@ var Impl = {
|
||||||
const payload = {};
|
const payload = {};
|
||||||
payload.encryptedData = await lazy.jwcrypto.generateJWE(
|
payload.encryptedData = await lazy.jwcrypto.generateJWE(
|
||||||
aOptions.publicKey,
|
aOptions.publicKey,
|
||||||
new TextEncoder("utf-8").encode(JSON.stringify(aPayload))
|
new TextEncoder().encode(JSON.stringify(aPayload))
|
||||||
);
|
);
|
||||||
|
|
||||||
payload.schemaVersion = aOptions.schemaVersion;
|
payload.schemaVersion = aOptions.schemaVersion;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ function write_string_to_file(file, contents) {
|
||||||
);
|
);
|
||||||
bos.setOutputStream(ostream);
|
bos.setOutputStream(ostream);
|
||||||
|
|
||||||
let utf8 = new TextEncoder("utf-8").encode(contents);
|
let utf8 = new TextEncoder().encode(contents);
|
||||||
bos.writeByteArray(utf8);
|
bos.writeByteArray(utf8);
|
||||||
ostream.QueryInterface(Ci.nsISafeOutputStream).finish();
|
ostream.QueryInterface(Ci.nsISafeOutputStream).finish();
|
||||||
ostream.close();
|
ostream.close();
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ var Sampling = {
|
||||||
*/
|
*/
|
||||||
async truncatedHash(data) {
|
async truncatedHash(data) {
|
||||||
const hasher = crypto.subtle;
|
const hasher = crypto.subtle;
|
||||||
const input = new TextEncoder("utf-8").encode(JSON.stringify(data));
|
const input = new TextEncoder().encode(JSON.stringify(data));
|
||||||
const hash = await hasher.digest("SHA-256", input);
|
const hash = await hasher.digest("SHA-256", input);
|
||||||
// truncate hash to 12 characters (2^48), because the full hash is larger
|
// truncate hash to 12 characters (2^48), because the full hash is larger
|
||||||
// than JS can meaningfully represent as a number.
|
// than JS can meaningfully represent as a number.
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ function encodeEnvVar(name, value) {
|
||||||
return `${name}=${value}`;
|
return `${name}=${value}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let encoder = new TextEncoder("utf-8");
|
let encoder = new TextEncoder();
|
||||||
function encode(val) {
|
function encode(val) {
|
||||||
return typeof val === "string" ? encoder.encode(val) : val;
|
return typeof val === "string" ? encoder.encode(val) : val;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -966,7 +966,7 @@ var AddonTestUtils = {
|
||||||
data = JSON.stringify(data);
|
data = JSON.stringify(data);
|
||||||
}
|
}
|
||||||
if (!(data instanceof ArrayBuffer)) {
|
if (!(data instanceof ArrayBuffer)) {
|
||||||
data = new TextEncoder("utf-8").encode(data).buffer;
|
data = new TextEncoder().encode(data).buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = ArrayBufferInputStream(data, 0, data.byteLength);
|
let stream = ArrayBufferInputStream(data, 0, data.byteLength);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue