Skip to content

Commit 2cb23ac

Browse files
author
Mert Can Altin
committed
tools: add WPT updater
1 parent 821ffab commit 2cb23ac

File tree

14 files changed

+142
-348
lines changed

14 files changed

+142
-348
lines changed

.github/workflows/update-wpt.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update WPT
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Run once a week at 12:00 AM UTC on Sunday.
7+
- cron: 0 0 * * *
8+
9+
jobs:
10+
update-wpt:
11+
name: Update WPT
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
19+
with:
20+
persist-credentials: false
21+
sparse-checkout: |
22+
!test/fixtures/wpt
23+
- name: Clone WPT Repository
24+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
25+
with:
26+
repository: web-platform-tests/wpt
27+
path: test/fixtures/wpt
28+
sparse_checkout: common/ eventsource/ fetch/ interfaces/ mimesniff/ resources/ service-workers/ storage/ websockets/ xhr/ LICENSE.md
29+
persist-credentials: false
30+
- name: Move WPT Files
31+
run: |
32+
rm -rf test/fixtures/wpt/.git
33+
echo "NEW_VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
34+
- name: Create Pull Request
35+
uses: gr2m/create-or-update-pull-request-action@86ec1766034c8173518f61d2075cc2a173fb8c97 # v1.9.4
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }}
38+
with:
39+
author: Node.js GitHub Bot <[email protected]>
40+
body: This is an automated update of the WPT to ${{ env.NEW_VERSION }}.
41+
branch: actions/update-wpt # Custom branch *just* for this Action.
42+
commit-message: 'test: update WPT to ${{ env.NEW_VERSION }}'
43+
labels: test
44+
title: 'test: update WPT to ${{ env.NEW_VERSION }}'
45+
update-pull-request-title-and-body: true

benchmark/buffers/buffer-transcode.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

doc/api/test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ added: v22.3.0
20502050

20512051
> Stability: 1.0 - Early development
20522052
2053-
* `specifier` {string|URL} A string identifying the module to mock.
2053+
* `specifier` {string} A string identifying the module to mock.
20542054
* `options` {Object} Optional configuration options for the mock module. The
20552055
following properties are supported:
20562056
* `cache` {boolean} If `false`, each call to `require()` or `import()`

lib/internal/modules/helpers.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,7 @@ function stripTypeScriptTypes(source, filename) {
371371
const base64SourceMap = Buffer.from(map).toString('base64');
372372
return `${code}\n\n//# sourceMappingURL=data:application/json;base64,${base64SourceMap}`;
373373
}
374-
// Source map is not necessary in strip-only mode. However, to map the source
375-
// file in debuggers to the original TypeScript source, add a sourceURL magic
376-
// comment to hint that it is a generated source.
377-
return `${code}\n\n//# sourceURL=${filename}`;
374+
return code;
378375
}
379376

380377
function isUnderNodeModules(filename) {

lib/internal/test_runner/coverage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ class TestCoverage {
340340
const { data, lineLengths } = sourceMapCache[url];
341341
let offset = 0;
342342
const executedLines = ArrayPrototypeMap(lineLengths, (length, i) => {
343-
const coverageLine = new CoverageLine(i + 1, offset, null, length + 1);
344-
offset += length + 1;
343+
const coverageLine = new CoverageLine(i + 1, offset, null, length);
344+
offset += length;
345345
return coverageLine;
346346
});
347347
if (data.sourcesContent != null) {

lib/internal/test_runner/mock/mock.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
} = require('internal/errors');
3535
const esmLoader = require('internal/modules/esm/loader');
3636
const { getOptionValue } = require('internal/options');
37-
const { fileURLToPath, toPathIfFileURL, URL, isURL } = require('internal/url');
37+
const { fileURLToPath, toPathIfFileURL, URL } = require('internal/url');
3838
const {
3939
emitExperimentalWarning,
4040
getStructuredStack,
@@ -49,6 +49,7 @@ const {
4949
validateInteger,
5050
validateObject,
5151
validateOneOf,
52+
validateString,
5253
} = require('internal/validators');
5354
const { MockTimers } = require('internal/test_runner/mock/mock_timers');
5455
const { strictEqual, notStrictEqual } = require('assert');
@@ -487,11 +488,7 @@ class MockTracker {
487488

488489
module(specifier, options = kEmptyObject) {
489490
emitExperimentalWarning('Module mocking');
490-
if (typeof specifier !== 'string') {
491-
if (!isURL(specifier))
492-
throw new ERR_INVALID_ARG_TYPE('specifier', ['string', 'URL'], specifier);
493-
specifier = `${specifier}`;
494-
}
491+
validateString(specifier, 'specifier');
495492
validateObject(options, 'options');
496493
debug('module mock entry, specifier = "%s", options = %o', specifier, options);
497494

src/node_i18n.cc

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
#include "node_i18n.h"
4444
#include "node_external_reference.h"
45-
#include "simdutf.h"
4645

4746
#if defined(NODE_HAVE_I18N_SUPPORT)
4847

@@ -148,6 +147,7 @@ MaybeLocal<Object> Transcode(Environment* env,
148147
const char* source,
149148
const size_t source_length,
150149
UErrorCode* status) {
150+
*status = U_ZERO_ERROR;
151151
MaybeLocal<Object> ret;
152152
MaybeStackBuffer<char> result;
153153
Converter to(toEncoding);
@@ -170,21 +170,22 @@ MaybeLocal<Object> Transcode(Environment* env,
170170
return ret;
171171
}
172172

173-
MaybeLocal<Object> TranscodeLatin1ToUcs2(Environment* env,
174-
const char* fromEncoding,
175-
const char* toEncoding,
176-
const char* source,
177-
const size_t source_length,
178-
UErrorCode* status) {
173+
MaybeLocal<Object> TranscodeToUcs2(Environment* env,
174+
const char* fromEncoding,
175+
const char* toEncoding,
176+
const char* source,
177+
const size_t source_length,
178+
UErrorCode* status) {
179+
*status = U_ZERO_ERROR;
180+
MaybeLocal<Object> ret;
179181
MaybeStackBuffer<UChar> destbuf(source_length);
180-
auto actual_length =
181-
simdutf::convert_latin1_to_utf16le(source, source_length, destbuf.out());
182-
if (actual_length == 0) {
183-
*status = U_INVALID_CHAR_FOUND;
184-
return {};
185-
}
186-
187-
return Buffer::New(env, &destbuf);
182+
Converter from(fromEncoding);
183+
const size_t length_in_chars = source_length * sizeof(UChar);
184+
ucnv_toUChars(from.conv(), *destbuf, length_in_chars,
185+
source, source_length, status);
186+
if (U_SUCCESS(*status))
187+
ret = ToBufferEndian(env, &destbuf);
188+
return ret;
188189
}
189190

190191
MaybeLocal<Object> TranscodeFromUcs2(Environment* env,
@@ -193,11 +194,13 @@ MaybeLocal<Object> TranscodeFromUcs2(Environment* env,
193194
const char* source,
194195
const size_t source_length,
195196
UErrorCode* status) {
197+
*status = U_ZERO_ERROR;
196198
MaybeStackBuffer<UChar> sourcebuf;
197199
MaybeLocal<Object> ret;
198200
Converter to(toEncoding);
199201

200-
std::string sub(to.min_char_size(), '?');
202+
size_t sublen = ucnv_getMinCharSize(to.conv());
203+
std::string sub(sublen, '?');
201204
to.set_subst_chars(sub.c_str());
202205

203206
const size_t length_in_chars = source_length / sizeof(UChar);
@@ -218,18 +221,26 @@ MaybeLocal<Object> TranscodeUcs2FromUtf8(Environment* env,
218221
const char* source,
219222
const size_t source_length,
220223
UErrorCode* status) {
221-
size_t expected_utf16_length =
222-
simdutf::utf16_length_from_utf8(source, source_length);
223-
MaybeStackBuffer<UChar> destbuf(expected_utf16_length);
224-
auto actual_length =
225-
simdutf::convert_utf8_to_utf16le(source, source_length, destbuf.out());
226-
227-
if (actual_length == 0) {
228-
*status = U_INVALID_CHAR_FOUND;
229-
return {};
224+
*status = U_ZERO_ERROR;
225+
MaybeStackBuffer<UChar> destbuf;
226+
int32_t result_length;
227+
u_strFromUTF8(*destbuf, destbuf.capacity(), &result_length,
228+
source, source_length, status);
229+
MaybeLocal<Object> ret;
230+
if (U_SUCCESS(*status)) {
231+
destbuf.SetLength(result_length);
232+
ret = ToBufferEndian(env, &destbuf);
233+
} else if (*status == U_BUFFER_OVERFLOW_ERROR) {
234+
*status = U_ZERO_ERROR;
235+
destbuf.AllocateSufficientStorage(result_length);
236+
u_strFromUTF8(*destbuf, result_length, &result_length,
237+
source, source_length, status);
238+
if (U_SUCCESS(*status)) {
239+
destbuf.SetLength(result_length);
240+
ret = ToBufferEndian(env, &destbuf);
241+
}
230242
}
231-
232-
return Buffer::New(env, &destbuf);
243+
return ret;
233244
}
234245

235246
MaybeLocal<Object> TranscodeUtf8FromUcs2(Environment* env,
@@ -238,25 +249,32 @@ MaybeLocal<Object> TranscodeUtf8FromUcs2(Environment* env,
238249
const char* source,
239250
const size_t source_length,
240251
UErrorCode* status) {
252+
*status = U_ZERO_ERROR;
253+
MaybeLocal<Object> ret;
241254
const size_t length_in_chars = source_length / sizeof(UChar);
242-
size_t expected_utf8_length = simdutf::utf8_length_from_utf16le(
243-
reinterpret_cast<const char16_t*>(source), length_in_chars);
244-
245-
MaybeStackBuffer<char> destbuf(expected_utf8_length);
246-
auto actual_length = simdutf::convert_utf16le_to_utf8(
247-
reinterpret_cast<const char16_t*>(source),
248-
length_in_chars,
249-
destbuf.out());
250-
251-
if (actual_length == 0) {
252-
*status = U_INVALID_CHAR_FOUND;
253-
return {};
255+
int32_t result_length;
256+
MaybeStackBuffer<UChar> sourcebuf;
257+
MaybeStackBuffer<char> destbuf;
258+
CopySourceBuffer(&sourcebuf, source, source_length, length_in_chars);
259+
u_strToUTF8(*destbuf, destbuf.capacity(), &result_length,
260+
*sourcebuf, length_in_chars, status);
261+
if (U_SUCCESS(*status)) {
262+
destbuf.SetLength(result_length);
263+
ret = ToBufferEndian(env, &destbuf);
264+
} else if (*status == U_BUFFER_OVERFLOW_ERROR) {
265+
*status = U_ZERO_ERROR;
266+
destbuf.AllocateSufficientStorage(result_length);
267+
u_strToUTF8(*destbuf, result_length, &result_length, *sourcebuf,
268+
length_in_chars, status);
269+
if (U_SUCCESS(*status)) {
270+
destbuf.SetLength(result_length);
271+
ret = ToBufferEndian(env, &destbuf);
272+
}
254273
}
255-
256-
return Buffer::New(env, &destbuf);
274+
return ret;
257275
}
258276

259-
constexpr const char* EncodingName(const enum encoding encoding) {
277+
const char* EncodingName(const enum encoding encoding) {
260278
switch (encoding) {
261279
case ASCII: return "us-ascii";
262280
case LATIN1: return "iso8859-1";
@@ -266,7 +284,7 @@ constexpr const char* EncodingName(const enum encoding encoding) {
266284
}
267285
}
268286

269-
constexpr bool SupportedEncoding(const enum encoding encoding) {
287+
bool SupportedEncoding(const enum encoding encoding) {
270288
switch (encoding) {
271289
case ASCII:
272290
case LATIN1:
@@ -291,7 +309,8 @@ void Transcode(const FunctionCallbackInfo<Value>&args) {
291309
switch (fromEncoding) {
292310
case ASCII:
293311
case LATIN1:
294-
if (toEncoding == UCS2) tfn = &TranscodeLatin1ToUcs2;
312+
if (toEncoding == UCS2)
313+
tfn = &TranscodeToUcs2;
295314
break;
296315
case UTF8:
297316
if (toEncoding == UCS2)

test/common/inspector-helper.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,6 @@ class InspectorSession {
271271
`break on ${url}:${line}`);
272272
}
273273

274-
waitForPauseOnStart() {
275-
return this
276-
.waitForNotification(
277-
(notification) =>
278-
notification.method === 'Debugger.paused' && notification.params.reason === 'Break on start',
279-
'break on start');
280-
}
281-
282274
pausedDetails() {
283275
return this._pausedDetails;
284276
}

0 commit comments

Comments
 (0)