Skip to content

Commit 07d8b3f

Browse files
committed
Merge branch 'main' into update_libcxx_libcxxabi_19
2 parents 093c537 + 3dff04c commit 07d8b3f

File tree

107 files changed

+318
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+318
-206
lines changed

src/closure-externs/node-externs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ fs.Stats.prototype.mtimeMs;
119119
* @type {number}
120120
*/
121121
fs.Stats.prototype.ctimeMs;
122+
123+
/**
124+
* @param {string} p
125+
* @return {boolean}
126+
* @nosideeffects
127+
*/
128+
path.isAbsolute;
129+
130+
/**
131+
* @type {Object.<string,*>}
132+
*/
133+
path.posix;

src/library_fs.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,18 @@ FS.staticInit();
193193
break;
194194
}
195195

196-
current = FS.lookupNode(current, parts[i]);
197196
current_path = PATH.join2(current_path, parts[i]);
197+
try {
198+
current = FS.lookupNode(current, parts[i]);
199+
} catch (e) {
200+
// if noent_okay is true, suppress a ENOENT in the last component
201+
// and return an object with an undefined node. This is needed for
202+
// resolving symlinks in the path when creating a file.
203+
if ((e?.errno === {{{ cDefs.ENOENT }}}) && islast && opts.noent_okay) {
204+
return { path: current_path };
205+
}
206+
throw e;
207+
}
198208

199209
// jump to the mount's root node if this is a mountpoint
200210
if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) {
@@ -1036,14 +1046,15 @@ FS.staticInit();
10361046
node = path;
10371047
} else {
10381048
path = PATH.normalize(path);
1039-
try {
1040-
var lookup = FS.lookupPath(path, {
1041-
follow: !(flags & {{{ cDefs.O_NOFOLLOW }}})
1042-
});
1043-
node = lookup.node;
1044-
} catch (e) {
1045-
// ignore
1046-
}
1049+
// noent_okay makes it so that if the final component of the path
1050+
// doesn't exist, lookupPath returns `node: undefined`. `path` will be
1051+
// updated to point to the target of all symlinks.
1052+
var lookup = FS.lookupPath(path, {
1053+
follow: !(flags & {{{ cDefs.O_NOFOLLOW }}}),
1054+
noent_okay: true
1055+
});
1056+
node = lookup.node;
1057+
path = lookup.path;
10471058
}
10481059
// perhaps we need to create the node
10491060
var created = false;

src/library_memfs.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ addToLibrary({
191191
return MEMFS.createNode(parent, name, mode, dev);
192192
},
193193
rename(old_node, new_dir, new_name) {
194-
// if we're overwriting a directory at new_name, make sure it's empty.
195-
if (FS.isDir(old_node.mode)) {
196-
var new_node;
197-
try {
198-
new_node = FS.lookupNode(new_dir, new_name);
199-
} catch (e) {
200-
}
201-
if (new_node) {
194+
var new_node;
195+
try {
196+
new_node = FS.lookupNode(new_dir, new_name);
197+
} catch (e) {}
198+
if (new_node) {
199+
if (FS.isDir(old_node.mode)) {
200+
// if we're overwriting a directory at new_name, make sure it's empty.
202201
for (var i in new_node.contents) {
203202
throw new FS.ErrnoError({{{ cDefs.ENOTEMPTY }}});
204203
}
205204
}
205+
FS.hashRemoveNode(new_node);
206206
}
207207
// do the internal rewiring
208208
delete old_node.parent.contents[old_node.name];
@@ -223,11 +223,7 @@ addToLibrary({
223223
parent.ctime = parent.mtime = Date.now();
224224
},
225225
readdir(node) {
226-
var entries = ['.', '..'];
227-
for (var key of Object.keys(node.contents)) {
228-
entries.push(key);
229-
}
230-
return entries;
226+
return ['.', '..', ...Object.keys(node.contents)];
231227
},
232228
symlink(parent, newname, oldpath) {
233229
var node = MEMFS.createNode(parent, newname, 0o777 | {{{ cDefs.S_IFLNK }}}, 0);

src/library_nodefs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ addToLibrary({
197197
rename(oldNode, newDir, newName) {
198198
var oldPath = NODEFS.realPath(oldNode);
199199
var newPath = PATH.join2(NODEFS.realPath(newDir), newName);
200+
try {
201+
FS.unlink(newPath);
202+
} catch(e) {}
200203
NODEFS.tryFSOperation(() => fs.renameSync(oldPath, newPath));
201204
oldNode.name = newName;
202205
},

src/library_nodepath.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
// operations. Hence, using `nodePath` should be safe here.
1313

1414
addToLibrary({
15-
$PATH: {
16-
isAbs: (path) => nodePath['isAbsolute'](path),
17-
normalize: (path) => nodePath['normalize'](path),
18-
dirname: (path) => nodePath['dirname'](path),
19-
basename: (path) => nodePath['basename'](path),
20-
join: (...args) => nodePath['join'](...args),
21-
join2: (l, r) => nodePath['join'](l, r),
22-
},
15+
$PATH: `{
16+
isAbs: nodePath.isAbsolute,
17+
normalize: nodePath.normalize,
18+
dirname: nodePath.dirname,
19+
basename: nodePath.basename,
20+
join: nodePath.join,
21+
join2: nodePath.join,
22+
}`,
2323
// The FS-using parts are split out into a separate object, so simple path
2424
// usage does not require the FS.
2525
$PATH_FS__deps: ['$FS'],
2626
$PATH_FS__docs: '/** @type{{resolve: function(...*)}} */',
2727
$PATH_FS: {
2828
resolve: (...paths) => {
2929
paths.unshift(FS.cwd());
30-
return nodePath['posix']['resolve'](...paths);
30+
return nodePath.posix.resolve(...paths);
3131
},
32-
relative: (from, to) => nodePath['posix']['relative'](from || FS.cwd(), to || FS.cwd()),
32+
relative: (from, to) => nodePath.posix.relative(from || FS.cwd(), to || FS.cwd()),
3333
}
3434
});

src/library_noderawfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ addToLibrary({
4040
},
4141
lookupPath(path, opts = {}) {
4242
if (opts.parent) {
43-
path = nodePath.dirname(path);
43+
path = PATH.dirname(path);
4444
}
4545
var st = fs.lstatSync(path);
4646
var mode = NODEFS.getMode(path);

src/node_shell_read.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
*/
66

77
readBinary = (filename) => {
8-
// We need to re-wrap `file://` strings to URLs. Normalizing isn't
9-
// necessary in that case, the path should already be absolute.
10-
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
8+
// We need to re-wrap `file://` strings to URLs.
9+
filename = isFileURI(filename) ? new URL(filename) : filename;
1110
var ret = fs.readFileSync(filename);
1211
#if ASSERTIONS
1312
assert(ret.buffer);
@@ -17,7 +16,7 @@ readBinary = (filename) => {
1716

1817
readAsync = (filename, binary = true) => {
1918
// See the comment in the `readBinary` function.
20-
filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename);
19+
filename = isFileURI(filename) ? new URL(filename) : filename;
2120
return new Promise((resolve, reject) => {
2221
fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
2322
if (err) reject(err);

test/benchmark/benchmark_utf16.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ unsigned short *randomString(int len) {
5454
}
5555

5656
int main() {
57-
srand(time(NULL));
5857
double t = 0;
5958
double t2 = emscripten_get_now();
6059
for(int i = 0; i < 10; ++i) {

test/benchmark/benchmark_utf8.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ char *randomString(int len) {
5454
}
5555

5656
int main() {
57-
time_t seed = time(NULL);
58-
printf("Random seed: %lld\n", seed);
59-
srand(seed);
6057
double t = 0;
6158
double t2 = emscripten_get_now();
6259
for (int i = 0; i < 100000; ++i) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12686,
3-
"a.html.gz": 6930,
4-
"total": 12686,
5-
"total_gz": 6930
2+
"a.html": 12597,
3+
"a.html.gz": 6882,
4+
"total": 12597,
5+
"total_gz": 6882
66
}

0 commit comments

Comments
 (0)