mirror of
https://github.com/oven-sh/bun
synced 2026-02-06 17:08:51 +00:00
Compare commits
11 Commits
dylan/ref-
...
nektro-pat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c622cc5410 | ||
|
|
850cdb0587 | ||
|
|
2f2a24f625 | ||
|
|
e448c4cc3b | ||
|
|
2d0b557ff7 | ||
|
|
15f5ba3e26 | ||
|
|
1385f9f686 | ||
|
|
07ccec0fd8 | ||
|
|
7283453eed | ||
|
|
1a08cfcd6b | ||
|
|
06e733cc64 |
70
.vscode/launch.json
generated
vendored
70
.vscode/launch.json
generated
vendored
@@ -14,7 +14,7 @@
|
||||
"name": "bun test [file]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -29,7 +29,7 @@
|
||||
"name": "bun test [file] --only",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--only", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -50,7 +50,7 @@
|
||||
"name": "bun test [file] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -65,7 +65,7 @@
|
||||
"name": "bun test [file] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "0",
|
||||
@@ -80,7 +80,7 @@
|
||||
"name": "bun test [file] --watch",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--watch", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -95,7 +95,7 @@
|
||||
"name": "bun test [file] --hot",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--hot", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -110,7 +110,7 @@
|
||||
"name": "bun test [file] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -131,7 +131,7 @@
|
||||
"name": "bun test [file] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -268,7 +268,7 @@
|
||||
"name": "bun test [...]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -283,7 +283,7 @@
|
||||
"name": "bun test [...] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -298,7 +298,7 @@
|
||||
"name": "bun test [...] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -313,7 +313,7 @@
|
||||
"name": "bun test [...] --watch",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--watch", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -328,7 +328,7 @@
|
||||
"name": "bun test [...] --hot",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--hot", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -343,7 +343,7 @@
|
||||
"name": "bun test [...] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -364,7 +364,7 @@
|
||||
"name": "bun test [...] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -401,7 +401,7 @@
|
||||
"name": "bun test [*]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -415,7 +415,7 @@
|
||||
"name": "bun test [*] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -429,7 +429,7 @@
|
||||
"name": "bun test [*] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"FORCE_COLOR": "1",
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -481,7 +481,7 @@
|
||||
"name": "Windows: bun test [file]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -510,7 +510,7 @@
|
||||
"name": "Windows: bun test --only [file]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--only", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -539,7 +539,7 @@
|
||||
"name": "Windows: bun test [file] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -568,7 +568,7 @@
|
||||
"name": "Windows: bun test [file] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -597,7 +597,7 @@
|
||||
"name": "Windows: bun test [file] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -635,7 +635,7 @@
|
||||
"name": "Windows: bun test [file] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -822,7 +822,7 @@
|
||||
"name": "Windows: bun test [...]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -851,7 +851,7 @@
|
||||
"name": "Windows: bun test [...] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -880,7 +880,7 @@
|
||||
"name": "Windows: bun test [...] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -909,7 +909,7 @@
|
||||
"name": "Windows: bun test [...] --watch",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--watch", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -938,7 +938,7 @@
|
||||
"name": "Windows: bun test [...] --hot",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--hot", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -967,7 +967,7 @@
|
||||
"name": "Windows: bun test [...] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -1005,7 +1005,7 @@
|
||||
"name": "Windows: bun test [...] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -1070,7 +1070,7 @@
|
||||
"name": "Windows: bun test [*]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -1095,7 +1095,7 @@
|
||||
"name": "Windows: bun test [*] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -1124,7 +1124,7 @@
|
||||
"name": "Windows: bun test [*] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test"],
|
||||
"cwd": "${workspaceFolder}/test",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
"name": "FORCE_COLOR",
|
||||
@@ -1196,4 +1196,4 @@
|
||||
"description": "Usage: bun test [...]",
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
"scripts": {
|
||||
"deps": "exit 0",
|
||||
"build": "exit 0",
|
||||
"bench:bun": "$BUN bun.js",
|
||||
"bench:node": "$NODE node.mjs",
|
||||
"bench:deno": "$DENO run -A --unstable deno.js",
|
||||
"bench:bun": "bun bun.js",
|
||||
"bench:node": "node node.mjs",
|
||||
"bench:deno": "deno run -A --unstable deno.js",
|
||||
"bench": "bun run bench:bun && bun run bench:node && bun run bench:deno"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "bench",
|
||||
"scripts": {
|
||||
"bench:bun": "$BUN bun.js",
|
||||
"bench:node": "$NODE node.mjs",
|
||||
"bench:bun": "bun bun.js",
|
||||
"bench:node": "node node.mjs",
|
||||
"deps": "cd src && bun run deps",
|
||||
"build": "cd src && bun run build",
|
||||
"bench:deno": "$DENO run -A --unstable deno.js",
|
||||
"bench:deno": "deno run -A --unstable deno.js",
|
||||
"bench": "bun run bench:bun && bun run bench:node && bun run bench:deno"
|
||||
}
|
||||
}
|
||||
|
||||
14
bench/grpc-server/benchmark.proto
Normal file
14
bench/grpc-server/benchmark.proto
Normal file
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
package benchmark;
|
||||
|
||||
service BenchmarkService {
|
||||
rpc Ping(Request) returns (Response);
|
||||
}
|
||||
|
||||
message Request {
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message Response {
|
||||
string message = 1;
|
||||
}
|
||||
33
bench/grpc-server/cert.pem
Normal file
33
bench/grpc-server/cert.pem
Normal file
@@ -0,0 +1,33 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
-----END CERTIFICATE-----
|
||||
31
bench/grpc-server/index.js
Normal file
31
bench/grpc-server/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const grpc = require("@grpc/grpc-js");
|
||||
const protoLoader = require("@grpc/proto-loader");
|
||||
const packageDefinition = protoLoader.loadSync("benchmark.proto", {});
|
||||
const proto = grpc.loadPackageDefinition(packageDefinition).benchmark;
|
||||
const fs = require("fs");
|
||||
|
||||
function ping(call, callback) {
|
||||
callback(null, { message: "Hello, World" });
|
||||
}
|
||||
|
||||
function main() {
|
||||
const server = new grpc.Server();
|
||||
server.addService(proto.BenchmarkService.service, { ping: ping });
|
||||
const tls = !!process.env.TLS && (process.env.TLS === "1" || process.env.TLS === "true");
|
||||
const port = process.env.PORT || 50051;
|
||||
const host = process.env.HOST || "localhost";
|
||||
let credentials;
|
||||
if (tls) {
|
||||
const ca = fs.readFileSync("./cert.pem");
|
||||
const key = fs.readFileSync("./key.pem");
|
||||
const cert = fs.readFileSync("./cert.pem");
|
||||
credentials = grpc.ServerCredentials.createSsl(ca, [{ private_key: key, cert_chain: cert }]);
|
||||
} else {
|
||||
credentials = grpc.ServerCredentials.createInsecure();
|
||||
}
|
||||
server.bindAsync(`${host}:${port}`, credentials, () => {
|
||||
console.log(`Server running at ${tls ? "https" : "http"}://${host}:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
52
bench/grpc-server/key.pem
Normal file
52
bench/grpc-server/key.pem
Normal file
@@ -0,0 +1,52 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
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
|
||||
z/cCLOrUJfealezimyd8SKPWPeHhrA==
|
||||
-----END PRIVATE KEY-----
|
||||
15
bench/grpc-server/package.json
Normal file
15
bench/grpc-server/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "bench",
|
||||
"scripts": {
|
||||
"deps": "exit 0",
|
||||
"build": "exit 0",
|
||||
"bun:server": "TLS=1 PORT=50051 bun ./index.js",
|
||||
"node:server": "TLS=1 PORT=50051 node ./index.js",
|
||||
"bench": "ghz --cacert ./cert.pem --proto ./benchmark.proto --call benchmark.BenchmarkService.Ping -d '{\"message\": \"Hello\"}' --total=100000 localhost:50051",
|
||||
"bench:insecure": "ghz --insecure --proto ./benchmark.proto --call benchmark.BenchmarkService.Ping -d '{\"message\": \"Hello\"}' --total=100000 localhost:50051"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "1.12.0",
|
||||
"@grpc/proto-loader": "0.7.10"
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
"scripts": {
|
||||
"deps": "exit 0",
|
||||
"build": "exit 0",
|
||||
"bench:bun": "$BUN bun.js",
|
||||
"bench:node": "$NODE node.mjs",
|
||||
"bench:deno": "$DENO run -A --unstable deno.js",
|
||||
"bench:bun": "bun bun.js",
|
||||
"bench:node": "node node.mjs",
|
||||
"bench:deno": "deno run -A --unstable deno.js",
|
||||
"bench": "bun run bench:bun && bun run bench:node && bun run bench:deno"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
"scripts": {
|
||||
"deps": "exit 0",
|
||||
"build": "exit 0",
|
||||
"bench:bun": "$BUN bun.js | grep iter",
|
||||
"bench:node": "$NODE node.mjs | grep iter",
|
||||
"bench:deno": "$DENO run -A --unstable deno.mjs | grep iter",
|
||||
"bench:bun": "bun bun.js | grep iter",
|
||||
"bench:node": "node node.mjs | grep iter",
|
||||
"bench:deno": "deno run -A --unstable deno.mjs | grep iter",
|
||||
"bench": "bun run bench:bun && bun run bench:node && bun run bench:deno"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
"scripts": {
|
||||
"deps": "exit 0",
|
||||
"build": "exit 0",
|
||||
"bench:bun": "$BUN bun.js",
|
||||
"bench:node": "$NODE node.mjs",
|
||||
"bench:bun": "bun bun.js",
|
||||
"bench:node": "node node.mjs",
|
||||
"bench": "bun run bench:bun && bun run bench:node"
|
||||
}
|
||||
}
|
||||
|
||||
15
bench/snippets/buffer-fill.mjs
Normal file
15
bench/snippets/buffer-fill.mjs
Normal file
@@ -0,0 +1,15 @@
|
||||
import { bench, run } from "./runner.mjs";
|
||||
|
||||
for (let size of [32, 2048, 1024 * 16, 1024 * 1024 * 2, 1024 * 1024 * 16]) {
|
||||
for (let fillSize of [4, 8, 16, 11]) {
|
||||
const buffer = Buffer.allocUnsafe(size);
|
||||
|
||||
const pattern = "x".repeat(fillSize);
|
||||
|
||||
bench(`Buffer.fill ${size} bytes with ${fillSize} byte value`, () => {
|
||||
buffer.fill(pattern);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await run();
|
||||
@@ -5,10 +5,10 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"bench:bun": "$BUN bun.js",
|
||||
"bench:node": "$NODE node.mjs",
|
||||
"bench:bun": "bun bun.js",
|
||||
"bench:node": "node node.mjs",
|
||||
"deps": "npm install && bash src/download.sh",
|
||||
"bench:deno": "$DENO run -A --unstable-ffi deno.js",
|
||||
"bench:deno": "deno run -A --unstable-ffi deno.js",
|
||||
"bench": "bun run bench:bun && bun run bench:node && bun run bench:deno"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
# https://clang.llvm.org/docs/ClangFormat.html
|
||||
|
||||
set(CLANG_FORMAT_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES})
|
||||
file(GLOB BUN_H_SOURCES LIST_DIRECTORIES false ${CONFIGURE_DEPENDS}
|
||||
${CWD}/src/bun.js/bindings/*.h
|
||||
${CWD}/src/bun.js/modules/*.h
|
||||
)
|
||||
|
||||
set(CLANG_FORMAT_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES} ${BUN_H_SOURCES})
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
|
||||
@@ -18,6 +18,7 @@ register_cmake_command(
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DCARES_SHARED=OFF
|
||||
-DCARES_BUILD_TOOLS=OFF # this was set to ON?
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
LIB_PATH
|
||||
lib
|
||||
LIBRARIES
|
||||
|
||||
@@ -1141,6 +1141,7 @@ pub const H2FrameParser = struct {
|
||||
this.signal = null;
|
||||
signal.deinit();
|
||||
}
|
||||
JSC.VirtualMachine.get().eventLoop().processGCTimer();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1611,7 +1612,7 @@ pub const H2FrameParser = struct {
|
||||
// fallback to onWrite non-native callback
|
||||
const output_value = this.handlers.binary_type.toJS(bytes, this.handlers.globalObject);
|
||||
const result = this.call(.onWrite, output_value);
|
||||
const code = result.to(i32);
|
||||
const code = if (result.isNumber()) result.to(i32) else -1;
|
||||
switch (code) {
|
||||
-1 => {
|
||||
// dropped
|
||||
@@ -1757,7 +1758,7 @@ pub const H2FrameParser = struct {
|
||||
return data.len;
|
||||
}
|
||||
|
||||
pub fn decodeHeaderBlock(this: *H2FrameParser, payload: []const u8, stream: *Stream, flags: u8) *Stream {
|
||||
pub fn decodeHeaderBlock(this: *H2FrameParser, payload: []const u8, stream: *Stream, flags: u8) ?*Stream {
|
||||
log("decodeHeaderBlock isSever: {}", .{this.isServer});
|
||||
|
||||
var offset: usize = 0;
|
||||
@@ -1776,7 +1777,9 @@ pub const H2FrameParser = struct {
|
||||
log("header {s} {s}", .{ header.name, header.value });
|
||||
if (this.isServer and strings.eqlComptime(header.name, ":status")) {
|
||||
this.sendGoAway(stream_id, ErrorCode.PROTOCOL_ERROR, "Server received :status header", this.lastStreamID, true);
|
||||
return this.streams.getEntry(stream_id).?.value_ptr;
|
||||
|
||||
if (this.streams.getEntry(stream_id)) |entry| return entry.value_ptr;
|
||||
return null;
|
||||
}
|
||||
count += 1;
|
||||
if (this.maxHeaderListPairs < count) {
|
||||
@@ -1786,7 +1789,8 @@ pub const H2FrameParser = struct {
|
||||
} else {
|
||||
this.endStream(stream, ErrorCode.ENHANCE_YOUR_CALM);
|
||||
}
|
||||
return this.streams.getEntry(stream_id).?.value_ptr;
|
||||
if (this.streams.getEntry(stream_id)) |entry| return entry.value_ptr;
|
||||
return null;
|
||||
}
|
||||
|
||||
const output = brk: {
|
||||
@@ -1817,7 +1821,8 @@ pub const H2FrameParser = struct {
|
||||
|
||||
this.dispatchWith3Extra(.onStreamHeaders, stream.getIdentifier(), headers, sensitiveHeaders, JSC.JSValue.jsNumber(flags));
|
||||
// callbacks can change the Stream ptr in this case we always return the new one
|
||||
return this.streams.getEntry(stream_id).?.value_ptr;
|
||||
if (this.streams.getEntry(stream_id)) |entry| return entry.value_ptr;
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn handleDataFrame(this: *H2FrameParser, frame: FrameHeader, data: []const u8, stream_: ?*Stream) usize {
|
||||
@@ -1882,7 +1887,8 @@ pub const H2FrameParser = struct {
|
||||
this.currentFrame = null;
|
||||
if (emitted) {
|
||||
// we need to revalidate the stream ptr after emitting onStreamData
|
||||
stream = this.streams.getEntry(frame.streamIdentifier).?.value_ptr;
|
||||
const entry = this.streams.getEntry(frame.streamIdentifier) orelse return end;
|
||||
stream = entry.value_ptr;
|
||||
}
|
||||
if (frame.flags & @intFromEnum(DataFrameFlags.END_STREAM) != 0) {
|
||||
const identifier = stream.getIdentifier();
|
||||
@@ -2029,7 +2035,10 @@ pub const H2FrameParser = struct {
|
||||
}
|
||||
if (handleIncommingPayload(this, data, frame.streamIdentifier)) |content| {
|
||||
const payload = content.data;
|
||||
stream = this.decodeHeaderBlock(payload[0..payload.len], stream, frame.flags);
|
||||
stream = this.decodeHeaderBlock(payload[0..payload.len], stream, frame.flags) orelse {
|
||||
this.readBuffer.reset();
|
||||
return content.end;
|
||||
};
|
||||
this.readBuffer.reset();
|
||||
if (frame.flags & @intFromEnum(HeadersFrameFlags.END_HEADERS) != 0) {
|
||||
stream.isWaitingMoreHeaders = false;
|
||||
@@ -2092,7 +2101,10 @@ pub const H2FrameParser = struct {
|
||||
this.sendGoAway(frame.streamIdentifier, ErrorCode.FRAME_SIZE_ERROR, "invalid Headers frame size", this.lastStreamID, true);
|
||||
return data.len;
|
||||
}
|
||||
stream = this.decodeHeaderBlock(payload[offset..end], stream, frame.flags);
|
||||
stream = this.decodeHeaderBlock(payload[offset..end], stream, frame.flags) orelse {
|
||||
this.readBuffer.reset();
|
||||
return content.end;
|
||||
};
|
||||
this.readBuffer.reset();
|
||||
stream.isWaitingMoreHeaders = frame.flags & @intFromEnum(HeadersFrameFlags.END_HEADERS) == 0;
|
||||
if (frame.flags & @intFromEnum(HeadersFrameFlags.END_STREAM) != 0) {
|
||||
@@ -3253,7 +3265,26 @@ pub const H2FrameParser = struct {
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
pub fn emitAbortToAllStreams(this: *H2FrameParser, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) JSC.JSValue {
|
||||
JSC.markBinding(@src());
|
||||
var it = StreamResumableIterator.init(this);
|
||||
while (it.next()) |stream| {
|
||||
// this is the oposite logic of emitErrorToallStreams, in this case we wanna to cancel this streams
|
||||
if (this.isServer) {
|
||||
if (stream.id % 2 == 0) continue;
|
||||
} else if (stream.id % 2 != 0) continue;
|
||||
if (stream.state != .CLOSED) {
|
||||
const old_state = stream.state;
|
||||
stream.state = .CLOSED;
|
||||
stream.rstCode = @intFromEnum(ErrorCode.CANCEL);
|
||||
const identifier = stream.getIdentifier();
|
||||
identifier.ensureStillAlive();
|
||||
stream.freeResources(this, false);
|
||||
this.dispatchWith2Extra(.onAborted, identifier, .undefined, JSC.JSValue.jsNumber(@intFromEnum(old_state)));
|
||||
}
|
||||
}
|
||||
return .undefined;
|
||||
}
|
||||
pub fn emitErrorToAllStreams(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) JSC.JSValue {
|
||||
JSC.markBinding(@src());
|
||||
|
||||
@@ -3265,6 +3296,9 @@ pub const H2FrameParser = struct {
|
||||
|
||||
var it = StreamResumableIterator.init(this);
|
||||
while (it.next()) |stream| {
|
||||
if (this.isServer) {
|
||||
if (stream.id % 2 != 0) continue;
|
||||
} else if (stream.id % 2 == 0) continue;
|
||||
if (stream.state != .CLOSED) {
|
||||
stream.state = .CLOSED;
|
||||
stream.rstCode = args_list.ptr[0].to(u32);
|
||||
@@ -3675,6 +3709,7 @@ pub const H2FrameParser = struct {
|
||||
}
|
||||
|
||||
const socket_js = args_list.ptr[0];
|
||||
this.detachNativeSocket();
|
||||
if (JSTLSSocket.fromJS(socket_js)) |socket| {
|
||||
log("TLSSocket attached", .{});
|
||||
if (socket.attachNativeCallback(.{ .h2 = this })) {
|
||||
@@ -3859,17 +3894,15 @@ pub const H2FrameParser = struct {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn deinit(this: *H2FrameParser) void {
|
||||
log("deinit", .{});
|
||||
|
||||
defer {
|
||||
if (ENABLE_ALLOCATOR_POOL) {
|
||||
H2FrameParser.pool.?.put(this);
|
||||
} else {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
pub fn detachFromJS(this: *H2FrameParser, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) JSValue {
|
||||
JSC.markBinding(@src());
|
||||
this.detach(false);
|
||||
return .undefined;
|
||||
}
|
||||
/// be careful when calling detach be sure that the socket is closed and the parser not accesible anymore
|
||||
/// this function can be called multiple times, it will erase stream info
|
||||
pub fn detach(this: *H2FrameParser, comptime finalizing: bool) void {
|
||||
this.flushCorked();
|
||||
this.detachNativeSocket();
|
||||
this.strong_ctx.deinit();
|
||||
this.handlers.deinit();
|
||||
@@ -3886,9 +3919,24 @@ pub const H2FrameParser = struct {
|
||||
}
|
||||
var it = this.streams.valueIterator();
|
||||
while (it.next()) |stream| {
|
||||
stream.freeResources(this, true);
|
||||
stream.freeResources(this, finalizing);
|
||||
}
|
||||
this.streams.deinit();
|
||||
var streams = this.streams;
|
||||
defer streams.deinit();
|
||||
this.streams = bun.U32HashMap(Stream).init(bun.default_allocator);
|
||||
}
|
||||
|
||||
pub fn deinit(this: *H2FrameParser) void {
|
||||
log("deinit", .{});
|
||||
|
||||
defer {
|
||||
if (ENABLE_ALLOCATOR_POOL) {
|
||||
H2FrameParser.pool.?.put(this);
|
||||
} else {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
this.detach(true);
|
||||
}
|
||||
|
||||
pub fn finalize(
|
||||
|
||||
@@ -37,6 +37,10 @@ export default [
|
||||
fn: "flushFromJS",
|
||||
length: 0,
|
||||
},
|
||||
detach: {
|
||||
fn: "detachFromJS",
|
||||
length: 0,
|
||||
},
|
||||
rstStream: {
|
||||
fn: "rstStream",
|
||||
length: 1,
|
||||
@@ -93,6 +97,10 @@ export default [
|
||||
fn: "emitErrorToAllStreams",
|
||||
length: 1,
|
||||
},
|
||||
emitAbortToAllStreams: {
|
||||
fn: "emitAbortToAllStreams",
|
||||
length: 0,
|
||||
},
|
||||
getNextStream: {
|
||||
fn: "getNextStream",
|
||||
length: 0,
|
||||
|
||||
@@ -17,4 +17,4 @@ enum class BufferEncodingType {
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,4 +199,4 @@ namespace WebCore {
|
||||
using JSVMClientData = WebCore::JSVMClientData;
|
||||
using JSHeapData = WebCore::JSHeapData;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ public:
|
||||
bool isHTMLAllCollection(JSC::VM&, JSC::JSValue) override { return false; }
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,4 +106,4 @@ class GlobalObject;
|
||||
namespace Bun {
|
||||
JSC::JSValue runVirtualModule(Zig::GlobalObject*, BunString* specifier, bool& wasModuleMock);
|
||||
JSC::Structure* createModuleMockStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +53,4 @@ public:
|
||||
private:
|
||||
MessagePortChannelProviderImpl* m_messagePortChannelProvider;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace WebCore {
|
||||
|
||||
class CachedScript {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,4 @@ private:
|
||||
void finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,4 @@ protected:
|
||||
bool m_isCleanupTask;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ ALWAYS_INLINE GCDeferralContext::~GCDeferralContext()
|
||||
m_vm.heap.collectIfNecessaryOrDefer();
|
||||
}
|
||||
|
||||
} // namespace JSC
|
||||
} // namespace JSC
|
||||
|
||||
@@ -414,4 +414,4 @@ template<typename T>
|
||||
struct IsIDLArrayBufferViewAllowShared : public std::integral_constant<bool, std::is_base_of<IDLAllowSharedAdaptor<IDLArrayBufferView>, T>::value> {
|
||||
};
|
||||
|
||||
} // namespace WebCore
|
||||
} // namespace WebCore
|
||||
|
||||
@@ -10,4 +10,4 @@ JSC_DECLARE_HOST_FUNCTION(jsDollarCpp);
|
||||
JSC_DECLARE_HOST_FUNCTION(jsDollarZig);
|
||||
|
||||
} // namespace JS2Native
|
||||
} // namespace Bun
|
||||
} // namespace Bun
|
||||
|
||||
@@ -69,4 +69,4 @@ public:
|
||||
bool tombstoned { false };
|
||||
};
|
||||
|
||||
} // namespace Zig
|
||||
} // namespace Zig
|
||||
|
||||
@@ -26,4 +26,4 @@ public:
|
||||
HashSet<Ref<JSC::DeferredWorkTimer::TicketData>> m_pendingTicketsOther;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ namespace Bun {
|
||||
|
||||
JSC::JSValue createJSCTestingHelpers(Zig::GlobalObject* global);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,4 @@ JSClass* toJSDOMGlobalObject(JSC::VM& vm, JSC::JSValue value)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ namespace Bun {
|
||||
|
||||
JSC::JSValue createEnvironmentVariablesMap(Zig::GlobalObject* globalObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ public:
|
||||
bool isEmpty();
|
||||
void drain(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,4 +71,4 @@ private:
|
||||
JSC::WriteBarrier<JSC::JSFunction> m_wrappedFn;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ZigGlobalObject.h"
|
||||
|
||||
namespace Bun {
|
||||
|
||||
|
||||
JSC::JSValue createAsyncHooksBinding(Zig::GlobalObject*);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ namespace Bun {
|
||||
|
||||
JSC::JSValue createNodeFetchInternalBinding(Zig::GlobalObject*);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "config.h"
|
||||
|
||||
namespace Bun {
|
||||
|
||||
|
||||
JSC_DECLARE_HOST_FUNCTION(jsHTTPAssignHeaders);
|
||||
JSC_DECLARE_HOST_FUNCTION(jsHTTPGetHeader);
|
||||
JSC_DECLARE_HOST_FUNCTION(jsHTTPSetHeader);
|
||||
|
||||
JSC::JSValue createNodeHTTPInternalBinding(Zig::GlobalObject*);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ZigGlobalObject.h"
|
||||
|
||||
namespace Bun {
|
||||
|
||||
|
||||
JSC::JSValue createNodeTLSBinding(Zig::GlobalObject*);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace Bun {
|
||||
|
||||
JSC::JSValue createNodeURLBinding(Zig::GlobalObject*);
|
||||
|
||||
} // namespace Bun
|
||||
} // namespace Bun
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ZigGlobalObject.h"
|
||||
|
||||
namespace Bun {
|
||||
|
||||
|
||||
JSC::JSValue createNodePathBinding(Zig::GlobalObject* globalObject);
|
||||
|
||||
} // namespace Bun
|
||||
|
||||
@@ -15,4 +15,4 @@ JSC::JSValue createNodeTTYWrapObject(JSC::JSGlobalObject* globalObject);
|
||||
|
||||
JSC_DECLARE_HOST_FUNCTION(Process_functionInternalGetWindowSize);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ JSC_DECLARE_HOST_FUNCTION(jsGetErrorMap);
|
||||
JSC::JSObject* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
|
||||
|
||||
} // namespace ProcessBindingUV
|
||||
} // namespace Bun
|
||||
} // namespace Bun
|
||||
|
||||
@@ -206,4 +206,4 @@ public:
|
||||
|
||||
ScriptExecutionContext* executionContext(JSC::JSGlobalObject*);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@ enum SinkID : uint8_t {
|
||||
static constexpr unsigned numberOfSinkIDs
|
||||
= 7;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ public:
|
||||
JSC::Strong<JSC::Unknown> m_cell;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ namespace Bun {
|
||||
|
||||
JSC::JSValue createUndiciInternalBinding(Zig::GlobalObject* globalObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ namespace Bun {
|
||||
|
||||
JSC::Structure* createUtilInspectOptionsStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,4 @@ Inspector::InspectorDebuggerAgent* debuggerAgent(JSC::JSGlobalObject* globalObje
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace Bun {
|
||||
bool isBuiltinModule(const String &namePossiblyWithNodePrefix);
|
||||
} // namespace Bun
|
||||
bool isBuiltinModule(const String& namePossiblyWithNodePrefix);
|
||||
} // namespace Bun
|
||||
|
||||
@@ -100,4 +100,4 @@ public:
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace Zig
|
||||
} // namespace Zig
|
||||
|
||||
@@ -12,4 +12,4 @@ class VM;
|
||||
namespace Bun {
|
||||
String base64URLEncodeToString(Vector<uint8_t> data);
|
||||
size_t toISOString(JSC::VM& vm, double date, char buffer[64]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,46 +9,44 @@ using namespace WebCore;
|
||||
namespace Zig {
|
||||
|
||||
inline void generateNativeModule_AbortControllerModule(
|
||||
JSC::JSGlobalObject *lexicalGlobalObject, JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4> &exportNames,
|
||||
JSC::MarkedArgumentBuffer &exportValues) {
|
||||
JSC::JSGlobalObject* lexicalGlobalObject, JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4>& exportNames,
|
||||
JSC::MarkedArgumentBuffer& exportValues)
|
||||
{
|
||||
|
||||
Zig::GlobalObject *globalObject =
|
||||
reinterpret_cast<Zig::GlobalObject *>(lexicalGlobalObject);
|
||||
JSC::VM &vm = globalObject->vm();
|
||||
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
|
||||
JSC::VM& vm = globalObject->vm();
|
||||
|
||||
auto *abortController =
|
||||
WebCore::JSAbortController::getConstructor(vm, globalObject).getObject();
|
||||
JSValue abortSignal =
|
||||
WebCore::JSAbortSignal::getConstructor(vm, globalObject);
|
||||
auto* abortController = WebCore::JSAbortController::getConstructor(vm, globalObject).getObject();
|
||||
JSValue abortSignal = WebCore::JSAbortSignal::getConstructor(vm, globalObject);
|
||||
|
||||
const auto controllerIdent = Identifier::fromString(vm, "AbortController"_s);
|
||||
const auto signalIdent = Identifier::fromString(vm, "AbortSignal"_s);
|
||||
const Identifier esModuleMarker = builtinNames(vm).__esModulePublicName();
|
||||
const auto controllerIdent = Identifier::fromString(vm, "AbortController"_s);
|
||||
const auto signalIdent = Identifier::fromString(vm, "AbortSignal"_s);
|
||||
const Identifier esModuleMarker = builtinNames(vm).__esModulePublicName();
|
||||
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(abortController);
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(abortController);
|
||||
|
||||
exportNames.append(signalIdent);
|
||||
exportValues.append(abortSignal);
|
||||
exportNames.append(signalIdent);
|
||||
exportValues.append(abortSignal);
|
||||
|
||||
exportNames.append(controllerIdent);
|
||||
exportValues.append(abortController);
|
||||
exportNames.append(controllerIdent);
|
||||
exportValues.append(abortController);
|
||||
|
||||
exportNames.append(esModuleMarker);
|
||||
exportValues.append(jsBoolean(true));
|
||||
exportNames.append(esModuleMarker);
|
||||
exportValues.append(jsBoolean(true));
|
||||
|
||||
// https://github.com/mysticatea/abort-controller/blob/a935d38e09eb95d6b633a8c42fcceec9969e7b05/dist/abort-controller.js#L125
|
||||
abortController->putDirect(
|
||||
vm, signalIdent, abortSignal,
|
||||
static_cast<unsigned>(PropertyAttribute::DontDelete));
|
||||
// https://github.com/mysticatea/abort-controller/blob/a935d38e09eb95d6b633a8c42fcceec9969e7b05/dist/abort-controller.js#L125
|
||||
abortController->putDirect(
|
||||
vm, signalIdent, abortSignal,
|
||||
static_cast<unsigned>(PropertyAttribute::DontDelete));
|
||||
|
||||
abortController->putDirect(
|
||||
vm, controllerIdent, abortController,
|
||||
static_cast<unsigned>(PropertyAttribute::DontDelete));
|
||||
abortController->putDirect(
|
||||
vm, controllerIdent, abortController,
|
||||
static_cast<unsigned>(PropertyAttribute::DontDelete));
|
||||
|
||||
abortController->putDirect(
|
||||
vm, vm.propertyNames->defaultKeyword, abortController,
|
||||
static_cast<unsigned>(PropertyAttribute::DontDelete));
|
||||
abortController->putDirect(
|
||||
vm, vm.propertyNames->defaultKeyword, abortController,
|
||||
static_cast<unsigned>(PropertyAttribute::DontDelete));
|
||||
}
|
||||
} // namespace Zig
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
|
||||
namespace Zig {
|
||||
void generateNativeModule_BunObject(JSC::JSGlobalObject *lexicalGlobalObject,
|
||||
JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4> &exportNames,
|
||||
JSC::MarkedArgumentBuffer &exportValues);
|
||||
void generateNativeModule_BunObject(JSC::JSGlobalObject* lexicalGlobalObject,
|
||||
JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4>& exportNames,
|
||||
JSC::MarkedArgumentBuffer& exportValues);
|
||||
|
||||
} // namespace Zig
|
||||
} // namespace Zig
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
|
||||
namespace Zig {
|
||||
void generateNativeModule_BunTest(
|
||||
JSC::JSGlobalObject *lexicalGlobalObject,
|
||||
JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4> &exportNames,
|
||||
JSC::MarkedArgumentBuffer &exportValues) {
|
||||
JSC::VM &vm = lexicalGlobalObject->vm();
|
||||
auto globalObject = jsCast<Zig::GlobalObject*>(lexicalGlobalObject);
|
||||
JSC::JSGlobalObject* lexicalGlobalObject,
|
||||
JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4>& exportNames,
|
||||
JSC::MarkedArgumentBuffer& exportValues)
|
||||
{
|
||||
JSC::VM& vm = lexicalGlobalObject->vm();
|
||||
auto globalObject = jsCast<Zig::GlobalObject*>(lexicalGlobalObject);
|
||||
|
||||
JSObject *object = globalObject->lazyPreloadTestModuleObject();
|
||||
JSObject* object = globalObject->lazyPreloadTestModuleObject();
|
||||
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(object);
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(object);
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
} // namespace Zig
|
||||
|
||||
@@ -16,219 +16,218 @@ using namespace JSC;
|
||||
|
||||
// TODO: Add DOMJIT fast path
|
||||
JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isUtf8,
|
||||
(JSC::JSGlobalObject * lexicalGlobalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm());
|
||||
(JSC::JSGlobalObject * lexicalGlobalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm());
|
||||
|
||||
auto buffer = callframe->argument(0);
|
||||
auto *bufferView = JSC::jsDynamicCast<JSC::JSArrayBufferView *>(buffer);
|
||||
const char *ptr = nullptr;
|
||||
size_t byteLength = 0;
|
||||
if (bufferView) {
|
||||
if (UNLIKELY(bufferView->isDetached())) {
|
||||
throwTypeError(lexicalGlobalObject, throwScope,
|
||||
"ArrayBufferView is detached"_s);
|
||||
return {};
|
||||
auto buffer = callframe->argument(0);
|
||||
auto* bufferView = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(buffer);
|
||||
const char* ptr = nullptr;
|
||||
size_t byteLength = 0;
|
||||
if (bufferView) {
|
||||
if (UNLIKELY(bufferView->isDetached())) {
|
||||
throwTypeError(lexicalGlobalObject, throwScope,
|
||||
"ArrayBufferView is detached"_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
byteLength = bufferView->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char*>(bufferView->vector());
|
||||
} else if (auto* arrayBuffer = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(buffer)) {
|
||||
auto* impl = arrayBuffer->impl();
|
||||
|
||||
if (!impl) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
if (UNLIKELY(impl->isDetached())) {
|
||||
return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject,
|
||||
"Cannot validate on a detached buffer"_s);
|
||||
}
|
||||
|
||||
byteLength = impl->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char*>(impl->data());
|
||||
} else {
|
||||
Bun::throwError(lexicalGlobalObject, throwScope,
|
||||
Bun::ErrorCode::ERR_INVALID_ARG_TYPE,
|
||||
"First argument must be an ArrayBufferView"_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
byteLength = bufferView->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char *>(bufferView->vector());
|
||||
} else if (auto *arrayBuffer =
|
||||
JSC::jsDynamicCast<JSC::JSArrayBuffer *>(buffer)) {
|
||||
auto *impl = arrayBuffer->impl();
|
||||
|
||||
if (!impl) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
if (UNLIKELY(impl->isDetached())) {
|
||||
return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject,
|
||||
"Cannot validate on a detached buffer"_s);
|
||||
}
|
||||
|
||||
byteLength = impl->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char *>(impl->data());
|
||||
} else {
|
||||
Bun::throwError(lexicalGlobalObject, throwScope,
|
||||
Bun::ErrorCode::ERR_INVALID_ARG_TYPE,
|
||||
"First argument must be an ArrayBufferView"_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
RELEASE_AND_RETURN(throwScope, JSValue::encode(jsBoolean(
|
||||
simdutf::validate_utf8(ptr, byteLength))));
|
||||
RELEASE_AND_RETURN(throwScope, JSValue::encode(jsBoolean(simdutf::validate_utf8(ptr, byteLength))));
|
||||
}
|
||||
|
||||
// TODO: Add DOMJIT fast path
|
||||
JSC_DEFINE_HOST_FUNCTION(jsBufferConstructorFunction_isAscii,
|
||||
(JSC::JSGlobalObject * lexicalGlobalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm());
|
||||
(JSC::JSGlobalObject * lexicalGlobalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm());
|
||||
|
||||
auto buffer = callframe->argument(0);
|
||||
auto *bufferView = JSC::jsDynamicCast<JSC::JSArrayBufferView *>(buffer);
|
||||
const char *ptr = nullptr;
|
||||
size_t byteLength = 0;
|
||||
if (bufferView) {
|
||||
auto buffer = callframe->argument(0);
|
||||
auto* bufferView = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(buffer);
|
||||
const char* ptr = nullptr;
|
||||
size_t byteLength = 0;
|
||||
if (bufferView) {
|
||||
|
||||
if (UNLIKELY(bufferView->isDetached())) {
|
||||
return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject,
|
||||
"Cannot validate on a detached buffer"_s);
|
||||
if (UNLIKELY(bufferView->isDetached())) {
|
||||
return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject,
|
||||
"Cannot validate on a detached buffer"_s);
|
||||
}
|
||||
|
||||
byteLength = bufferView->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char*>(bufferView->vector());
|
||||
} else if (auto* arrayBuffer = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(buffer)) {
|
||||
auto* impl = arrayBuffer->impl();
|
||||
if (UNLIKELY(impl->isDetached())) {
|
||||
return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject,
|
||||
"Cannot validate on a detached buffer"_s);
|
||||
}
|
||||
|
||||
if (!impl) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
byteLength = impl->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char*>(impl->data());
|
||||
} else {
|
||||
Bun::throwError(lexicalGlobalObject, throwScope,
|
||||
Bun::ErrorCode::ERR_INVALID_ARG_TYPE,
|
||||
"First argument must be an ArrayBufferView"_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
byteLength = bufferView->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char *>(bufferView->vector());
|
||||
} else if (auto *arrayBuffer =
|
||||
JSC::jsDynamicCast<JSC::JSArrayBuffer *>(buffer)) {
|
||||
auto *impl = arrayBuffer->impl();
|
||||
if (UNLIKELY(impl->isDetached())) {
|
||||
return Bun::ERR::INVALID_STATE(throwScope, lexicalGlobalObject,
|
||||
"Cannot validate on a detached buffer"_s);
|
||||
}
|
||||
|
||||
if (!impl) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
byteLength = impl->byteLength();
|
||||
|
||||
if (byteLength == 0) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
ptr = reinterpret_cast<const char *>(impl->data());
|
||||
} else {
|
||||
Bun::throwError(lexicalGlobalObject, throwScope,
|
||||
Bun::ErrorCode::ERR_INVALID_ARG_TYPE,
|
||||
"First argument must be an ArrayBufferView"_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
RELEASE_AND_RETURN(
|
||||
throwScope,
|
||||
JSValue::encode(jsBoolean(simdutf::validate_ascii(ptr, byteLength))));
|
||||
RELEASE_AND_RETURN(
|
||||
throwScope,
|
||||
JSValue::encode(jsBoolean(simdutf::validate_ascii(ptr, byteLength))));
|
||||
}
|
||||
|
||||
BUN_DECLARE_HOST_FUNCTION(jsFunctionResolveObjectURL);
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionNotImplemented,
|
||||
(JSGlobalObject * globalObject,
|
||||
CallFrame *callFrame)) {
|
||||
VM &vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
(JSGlobalObject * globalObject,
|
||||
CallFrame* callFrame))
|
||||
{
|
||||
VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
throwException(globalObject, scope,
|
||||
createError(globalObject, "Not implemented"_s));
|
||||
return {};
|
||||
throwException(globalObject, scope,
|
||||
createError(globalObject, "Not implemented"_s));
|
||||
return {};
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_GETTER(jsGetter_INSPECT_MAX_BYTES, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName))
|
||||
{
|
||||
auto globalObject = reinterpret_cast<Zig::GlobalObject *>(lexicalGlobalObject);
|
||||
return JSValue::encode(jsNumber(globalObject->INSPECT_MAX_BYTES));
|
||||
auto globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
|
||||
return JSValue::encode(jsNumber(globalObject->INSPECT_MAX_BYTES));
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_SETTER(jsSetter_INSPECT_MAX_BYTES, (JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue value, PropertyName propertyName))
|
||||
{
|
||||
auto globalObject = reinterpret_cast<Zig::GlobalObject *>(lexicalGlobalObject);
|
||||
auto &vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
auto val = JSValue::decode(value);
|
||||
Bun::V::validateNumber(scope, globalObject, val, jsString(vm, String("INSPECT_MAX_BYTES"_s)), jsNumber(0), jsUndefined());
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
globalObject->INSPECT_MAX_BYTES = val.asNumber();
|
||||
return JSValue::encode(jsUndefined());
|
||||
auto globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
|
||||
auto& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
auto val = JSValue::decode(value);
|
||||
Bun::V::validateNumber(scope, globalObject, val, jsString(vm, String("INSPECT_MAX_BYTES"_s)), jsNumber(0), jsUndefined());
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
globalObject->INSPECT_MAX_BYTES = val.asNumber();
|
||||
return JSValue::encode(jsUndefined());
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_MODULE(NodeBuffer) {
|
||||
INIT_NATIVE_MODULE(12);
|
||||
DEFINE_NATIVE_MODULE(NodeBuffer)
|
||||
{
|
||||
INIT_NATIVE_MODULE(12);
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "Buffer"_s),
|
||||
globalObject->JSBufferConstructor());
|
||||
put(JSC::Identifier::fromString(vm, "Buffer"_s),
|
||||
globalObject->JSBufferConstructor());
|
||||
|
||||
auto *slowBuffer = JSC::JSFunction::create(
|
||||
vm, globalObject, 0, "SlowBuffer"_s, WebCore::constructSlowBuffer,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
WebCore::constructSlowBuffer);
|
||||
slowBuffer->putDirect(
|
||||
vm, vm.propertyNames->prototype, globalObject->JSBufferPrototype(),
|
||||
JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum |
|
||||
JSC::PropertyAttribute::DontDelete);
|
||||
put(JSC::Identifier::fromString(vm, "SlowBuffer"_s), slowBuffer);
|
||||
auto blobIdent = JSC::Identifier::fromString(vm, "Blob"_s);
|
||||
auto* slowBuffer = JSC::JSFunction::create(
|
||||
vm, globalObject, 0, "SlowBuffer"_s, WebCore::constructSlowBuffer,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
WebCore::constructSlowBuffer);
|
||||
slowBuffer->putDirect(
|
||||
vm, vm.propertyNames->prototype, globalObject->JSBufferPrototype(),
|
||||
JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete);
|
||||
put(JSC::Identifier::fromString(vm, "SlowBuffer"_s), slowBuffer);
|
||||
auto blobIdent = JSC::Identifier::fromString(vm, "Blob"_s);
|
||||
|
||||
JSValue blobValue = globalObject->JSBlobConstructor();
|
||||
put(blobIdent, blobValue);
|
||||
JSValue blobValue = globalObject->JSBlobConstructor();
|
||||
put(blobIdent, blobValue);
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "File"_s),
|
||||
globalObject->JSDOMFileConstructor());
|
||||
put(JSC::Identifier::fromString(vm, "File"_s),
|
||||
globalObject->JSDOMFileConstructor());
|
||||
|
||||
{
|
||||
auto name = Identifier::fromString(vm, "INSPECT_MAX_BYTES"_s);
|
||||
auto value = JSC::CustomGetterSetter::create(vm, jsGetter_INSPECT_MAX_BYTES, jsSetter_INSPECT_MAX_BYTES);
|
||||
auto attributes = PropertyAttribute::DontDelete | PropertyAttribute::CustomAccessor;
|
||||
defaultObject->putDirectCustomAccessor(vm, name, value, (unsigned)attributes);
|
||||
exportNames.append(name);
|
||||
exportValues.append(value);
|
||||
__NATIVE_MODULE_ASSERT_INCR;
|
||||
}
|
||||
{
|
||||
auto name = Identifier::fromString(vm, "INSPECT_MAX_BYTES"_s);
|
||||
auto value = JSC::CustomGetterSetter::create(vm, jsGetter_INSPECT_MAX_BYTES, jsSetter_INSPECT_MAX_BYTES);
|
||||
auto attributes = PropertyAttribute::DontDelete | PropertyAttribute::CustomAccessor;
|
||||
defaultObject->putDirectCustomAccessor(vm, name, value, (unsigned)attributes);
|
||||
exportNames.append(name);
|
||||
exportValues.append(value);
|
||||
__NATIVE_MODULE_ASSERT_INCR;
|
||||
}
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "kMaxLength"_s), JSC::jsNumber(Bun::Buffer::kMaxLength));
|
||||
put(JSC::Identifier::fromString(vm, "kStringMaxLength"_s), JSC::jsNumber(Bun::Buffer::kStringMaxLength));
|
||||
put(JSC::Identifier::fromString(vm, "kMaxLength"_s), JSC::jsNumber(Bun::Buffer::kMaxLength));
|
||||
put(JSC::Identifier::fromString(vm, "kStringMaxLength"_s), JSC::jsNumber(Bun::Buffer::kStringMaxLength));
|
||||
|
||||
JSC::JSObject *constants = JSC::constructEmptyObject(lexicalGlobalObject, globalObject->objectPrototype(), 2);
|
||||
constants->putDirect(vm, JSC::Identifier::fromString(vm, "MAX_LENGTH"_s), JSC::jsNumber(Bun::Buffer::MAX_LENGTH));
|
||||
constants->putDirect(vm, JSC::Identifier::fromString(vm, "MAX_STRING_LENGTH"_s), JSC::jsNumber(Bun::Buffer::MAX_STRING_LENGTH));
|
||||
JSC::JSObject* constants = JSC::constructEmptyObject(lexicalGlobalObject, globalObject->objectPrototype(), 2);
|
||||
constants->putDirect(vm, JSC::Identifier::fromString(vm, "MAX_LENGTH"_s), JSC::jsNumber(Bun::Buffer::MAX_LENGTH));
|
||||
constants->putDirect(vm, JSC::Identifier::fromString(vm, "MAX_STRING_LENGTH"_s), JSC::jsNumber(Bun::Buffer::MAX_STRING_LENGTH));
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "constants"_s), constants);
|
||||
put(JSC::Identifier::fromString(vm, "constants"_s), constants);
|
||||
|
||||
JSC::Identifier atobI = JSC::Identifier::fromString(vm, "atob"_s);
|
||||
JSC::JSValue atobV = lexicalGlobalObject->get(globalObject, PropertyName(atobI));
|
||||
JSC::Identifier atobI = JSC::Identifier::fromString(vm, "atob"_s);
|
||||
JSC::JSValue atobV = lexicalGlobalObject->get(globalObject, PropertyName(atobI));
|
||||
|
||||
JSC::Identifier btoaI = JSC::Identifier::fromString(vm, "btoa"_s);
|
||||
JSC::JSValue btoaV = lexicalGlobalObject->get(globalObject, PropertyName(btoaI));
|
||||
JSC::Identifier btoaI = JSC::Identifier::fromString(vm, "btoa"_s);
|
||||
JSC::JSValue btoaV = lexicalGlobalObject->get(globalObject, PropertyName(btoaI));
|
||||
|
||||
put(atobI, atobV);
|
||||
put(btoaI, btoaV);
|
||||
put(atobI, atobV);
|
||||
put(btoaI, btoaV);
|
||||
|
||||
auto *transcode = InternalFunction::createFunctionThatMasqueradesAsUndefined(
|
||||
vm, globalObject, 1, "transcode"_s, jsFunctionNotImplemented);
|
||||
auto* transcode = InternalFunction::createFunctionThatMasqueradesAsUndefined(
|
||||
vm, globalObject, 1, "transcode"_s, jsFunctionNotImplemented);
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "transcode"_s), transcode);
|
||||
put(JSC::Identifier::fromString(vm, "transcode"_s), transcode);
|
||||
|
||||
auto *resolveObjectURL =
|
||||
InternalFunction::createFunctionThatMasqueradesAsUndefined(
|
||||
vm, globalObject, 1, "resolveObjectURL"_s,
|
||||
jsFunctionResolveObjectURL);
|
||||
auto* resolveObjectURL = InternalFunction::createFunctionThatMasqueradesAsUndefined(
|
||||
vm, globalObject, 1, "resolveObjectURL"_s,
|
||||
jsFunctionResolveObjectURL);
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "resolveObjectURL"_s), resolveObjectURL);
|
||||
put(JSC::Identifier::fromString(vm, "resolveObjectURL"_s), resolveObjectURL);
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "isAscii"_s),
|
||||
JSC::JSFunction::create(vm, globalObject, 1, "isAscii"_s,
|
||||
jsBufferConstructorFunction_isAscii,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
jsBufferConstructorFunction_isUtf8));
|
||||
put(JSC::Identifier::fromString(vm, "isAscii"_s),
|
||||
JSC::JSFunction::create(vm, globalObject, 1, "isAscii"_s,
|
||||
jsBufferConstructorFunction_isAscii,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
jsBufferConstructorFunction_isUtf8));
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "isUtf8"_s),
|
||||
JSC::JSFunction::create(vm, globalObject, 1, "isUtf8"_s,
|
||||
jsBufferConstructorFunction_isUtf8,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
jsBufferConstructorFunction_isUtf8));
|
||||
put(JSC::Identifier::fromString(vm, "isUtf8"_s),
|
||||
JSC::JSFunction::create(vm, globalObject, 1, "isUtf8"_s,
|
||||
jsBufferConstructorFunction_isUtf8,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
jsBufferConstructorFunction_isUtf8));
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,69 +6,72 @@
|
||||
namespace Zig {
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionProcessModuleCommonJS,
|
||||
(JSGlobalObject * globalObject,
|
||||
CallFrame *callFrame)) {
|
||||
(JSGlobalObject * globalObject,
|
||||
CallFrame* callFrame))
|
||||
{
|
||||
|
||||
return JSValue::encode(
|
||||
reinterpret_cast<Zig::GlobalObject *>(globalObject)->processObject());
|
||||
return JSValue::encode(
|
||||
reinterpret_cast<Zig::GlobalObject*>(globalObject)->processObject());
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_GETTER(jsFunctionProcessModuleCommonJSGetter,
|
||||
(JSGlobalObject * globalObject,
|
||||
JSC::EncodedJSValue thisValue,
|
||||
PropertyName propertyName)) {
|
||||
(JSGlobalObject * globalObject,
|
||||
JSC::EncodedJSValue thisValue,
|
||||
PropertyName propertyName))
|
||||
{
|
||||
|
||||
return JSValue::encode(reinterpret_cast<Zig::GlobalObject *>(globalObject)
|
||||
->processObject()
|
||||
->get(globalObject, propertyName));
|
||||
return JSValue::encode(reinterpret_cast<Zig::GlobalObject*>(globalObject)
|
||||
->processObject()
|
||||
->get(globalObject, propertyName));
|
||||
}
|
||||
|
||||
JSC_DEFINE_CUSTOM_SETTER(jsFunctionProcessModuleCommonJSSetter,
|
||||
(JSGlobalObject * globalObject,
|
||||
JSC::EncodedJSValue thisValue,
|
||||
JSC::EncodedJSValue encodedValue,
|
||||
PropertyName propertyName)) {
|
||||
VM &vm = globalObject->vm();
|
||||
(JSGlobalObject * globalObject,
|
||||
JSC::EncodedJSValue thisValue,
|
||||
JSC::EncodedJSValue encodedValue,
|
||||
PropertyName propertyName))
|
||||
{
|
||||
VM& vm = globalObject->vm();
|
||||
|
||||
return reinterpret_cast<Zig::GlobalObject *>(globalObject)
|
||||
->processObject()
|
||||
->putDirect(vm, propertyName, JSValue::decode(encodedValue), 0);
|
||||
return reinterpret_cast<Zig::GlobalObject*>(globalObject)
|
||||
->processObject()
|
||||
->putDirect(vm, propertyName, JSValue::decode(encodedValue), 0);
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_MODULE(NodeProcess) {
|
||||
JSC::VM &vm = lexicalGlobalObject->vm();
|
||||
GlobalObject *globalObject =
|
||||
reinterpret_cast<GlobalObject *>(lexicalGlobalObject);
|
||||
DEFINE_NATIVE_MODULE(NodeProcess)
|
||||
{
|
||||
JSC::VM& vm = lexicalGlobalObject->vm();
|
||||
GlobalObject* globalObject = reinterpret_cast<GlobalObject*>(lexicalGlobalObject);
|
||||
|
||||
JSC::JSObject *process = globalObject->processObject();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
if (!process->staticPropertiesReified()) {
|
||||
process->reifyAllStaticProperties(globalObject);
|
||||
if (scope.exception())
|
||||
return;
|
||||
}
|
||||
|
||||
PropertyNameArray properties(vm, PropertyNameMode::Strings,
|
||||
PrivateSymbolMode::Exclude);
|
||||
process->getPropertyNames(globalObject, properties,
|
||||
DontEnumPropertiesMode::Exclude);
|
||||
if (scope.exception())
|
||||
return;
|
||||
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(process);
|
||||
|
||||
for (auto &entry : properties) {
|
||||
exportNames.append(entry);
|
||||
auto catchScope = DECLARE_CATCH_SCOPE(vm);
|
||||
JSValue result = process->get(globalObject, entry);
|
||||
if (catchScope.exception()) {
|
||||
result = jsUndefined();
|
||||
catchScope.clearException();
|
||||
JSC::JSObject* process = globalObject->processObject();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
if (!process->staticPropertiesReified()) {
|
||||
process->reifyAllStaticProperties(globalObject);
|
||||
if (scope.exception())
|
||||
return;
|
||||
}
|
||||
|
||||
exportValues.append(result);
|
||||
}
|
||||
PropertyNameArray properties(vm, PropertyNameMode::Strings,
|
||||
PrivateSymbolMode::Exclude);
|
||||
process->getPropertyNames(globalObject, properties,
|
||||
DontEnumPropertiesMode::Exclude);
|
||||
if (scope.exception())
|
||||
return;
|
||||
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(process);
|
||||
|
||||
for (auto& entry : properties) {
|
||||
exportNames.append(entry);
|
||||
auto catchScope = DECLARE_CATCH_SCOPE(vm);
|
||||
JSValue result = process->get(globalObject, entry);
|
||||
if (catchScope.exception()) {
|
||||
result = jsUndefined();
|
||||
catchScope.clearException();
|
||||
}
|
||||
|
||||
exportValues.append(result);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
|
||||
namespace Zig {
|
||||
|
||||
DEFINE_NATIVE_MODULE(NodeStringDecoder) {
|
||||
INIT_NATIVE_MODULE(1);
|
||||
DEFINE_NATIVE_MODULE(NodeStringDecoder)
|
||||
{
|
||||
INIT_NATIVE_MODULE(1);
|
||||
|
||||
put(JSC::Identifier::fromString(vm, "StringDecoder"_s),
|
||||
globalObject->JSStringDecoder());
|
||||
put(JSC::Identifier::fromString(vm, "StringDecoder"_s),
|
||||
globalObject->JSStringDecoder());
|
||||
|
||||
RETURN_NATIVE_MODULE();
|
||||
RETURN_NATIVE_MODULE();
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
|
||||
@@ -13,19 +13,20 @@ using namespace WebCore;
|
||||
JSC_DECLARE_HOST_FUNCTION(jsFunctionTty_isatty);
|
||||
JSC_DECLARE_HOST_FUNCTION(jsFunctionNotImplementedYet);
|
||||
|
||||
DEFINE_NATIVE_MODULE(NodeTTY) {
|
||||
INIT_NATIVE_MODULE(3);
|
||||
DEFINE_NATIVE_MODULE(NodeTTY)
|
||||
{
|
||||
INIT_NATIVE_MODULE(3);
|
||||
|
||||
auto *notimpl = JSFunction::create(vm, globalObject, 0, "notimpl"_s,
|
||||
jsFunctionNotImplementedYet,
|
||||
ImplementationVisibility::Public,
|
||||
NoIntrinsic, jsFunctionNotImplementedYet);
|
||||
auto* notimpl = JSFunction::create(vm, globalObject, 0, "notimpl"_s,
|
||||
jsFunctionNotImplementedYet,
|
||||
ImplementationVisibility::Public,
|
||||
NoIntrinsic, jsFunctionNotImplementedYet);
|
||||
|
||||
putNativeFn(Identifier::fromString(vm, "isatty"_s), jsFunctionTty_isatty);
|
||||
put(Identifier::fromString(vm, "ReadStream"_s), notimpl);
|
||||
put(Identifier::fromString(vm, "WriteStream"_s), notimpl);
|
||||
putNativeFn(Identifier::fromString(vm, "isatty"_s), jsFunctionTty_isatty);
|
||||
put(Identifier::fromString(vm, "ReadStream"_s), notimpl);
|
||||
put(Identifier::fromString(vm, "WriteStream"_s), notimpl);
|
||||
|
||||
RETURN_NATIVE_MODULE();
|
||||
RETURN_NATIVE_MODULE();
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
|
||||
@@ -18,491 +18,523 @@
|
||||
|
||||
using namespace JSC;
|
||||
|
||||
#define GET_FIRST_VALUE \
|
||||
if (callframe->argumentCount() < 1) \
|
||||
return JSValue::encode(jsBoolean(false)); \
|
||||
JSValue value = callframe->uncheckedArgument(0);
|
||||
#define GET_FIRST_VALUE \
|
||||
if (callframe->argumentCount() < 1) \
|
||||
return JSValue::encode(jsBoolean(false)); \
|
||||
JSValue value = callframe->uncheckedArgument(0);
|
||||
|
||||
#define GET_FIRST_CELL \
|
||||
if (callframe->argumentCount() < 1) \
|
||||
return JSValue::encode(jsBoolean(false)); \
|
||||
JSValue value = callframe->uncheckedArgument(0); \
|
||||
if (!value.isCell()) \
|
||||
return JSValue::encode(jsBoolean(false)); \
|
||||
JSCell *cell = value.asCell();
|
||||
#define GET_FIRST_CELL \
|
||||
if (callframe->argumentCount() < 1) \
|
||||
return JSValue::encode(jsBoolean(false)); \
|
||||
JSValue value = callframe->uncheckedArgument(0); \
|
||||
if (!value.isCell()) \
|
||||
return JSValue::encode(jsBoolean(false)); \
|
||||
JSCell* cell = value.asCell();
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsExternal,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(jsBoolean(value.inherits<Bun::NapiExternal>()));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(jsBoolean(value.inherits<Bun::NapiExternal>()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsDate, (JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSDateType));
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsDate, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSDateType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsArgumentsObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
if (!value.isCell())
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
if (!value.isCell())
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
|
||||
auto type = value.asCell()->type();
|
||||
switch (type) {
|
||||
case DirectArgumentsType:
|
||||
case ScopedArgumentsType:
|
||||
case ClonedArgumentsType:
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
default:
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBigIntObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(
|
||||
jsBoolean(globalObject->bigIntObjectStructure() == cell->structure()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBooleanObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(
|
||||
jsBoolean(value.isCell() && value.asCell()->type() == BooleanObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsNumberObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(
|
||||
jsBoolean(value.isCell() && value.asCell()->type() == NumberObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsStringObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(jsBoolean(
|
||||
value.isCell() && (value.asCell()->type() == StringObjectType ||
|
||||
value.asCell()->type() == DerivedStringObjectType)));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSymbolObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
|
||||
return JSValue::encode(
|
||||
jsBoolean(globalObject->symbolObjectStructure() == cell->structure()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsNativeError,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
if (value.isCell()) {
|
||||
if (value.inherits<JSC::ErrorInstance>() ||
|
||||
value.asCell()->type() == ErrorInstanceType)
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
|
||||
VM &vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
JSObject *object = value.toObject(globalObject);
|
||||
|
||||
// node util.isError relies on toString
|
||||
// https://github.com/nodejs/node/blob/cf8c6994e0f764af02da4fa70bc5962142181bf3/doc/api/util.md#L2923
|
||||
PropertySlot slot(object, PropertySlot::InternalMethodType::VMInquiry, &vm);
|
||||
if (object->getPropertySlot(globalObject,
|
||||
vm.propertyNames->toStringTagSymbol, slot)) {
|
||||
EXCEPTION_ASSERT(!scope.exception());
|
||||
if (slot.isValue()) {
|
||||
JSValue value =
|
||||
slot.getValue(globalObject, vm.propertyNames->toStringTagSymbol);
|
||||
if (value.isString()) {
|
||||
String tag = asString(value)->value(globalObject);
|
||||
if (UNLIKELY(scope.exception()))
|
||||
scope.clearException();
|
||||
if (tag == "Error"_s)
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
}
|
||||
auto type = value.asCell()->type();
|
||||
switch (type) {
|
||||
case DirectArgumentsType:
|
||||
case ScopedArgumentsType:
|
||||
case ClonedArgumentsType:
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
default:
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
|
||||
JSValue proto = object->getPrototype(vm, globalObject);
|
||||
if (proto.isCell() && (proto.inherits<JSC::ErrorInstance>() ||
|
||||
proto.asCell()->type() == ErrorInstanceType ||
|
||||
proto.inherits<JSC::ErrorPrototype>()))
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBigIntObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(
|
||||
jsBoolean(globalObject->bigIntObjectStructure() == cell->structure()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBooleanObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(
|
||||
jsBoolean(value.isCell() && value.asCell()->type() == BooleanObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsNumberObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(
|
||||
jsBoolean(value.isCell() && value.asCell()->type() == NumberObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsStringObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(jsBoolean(
|
||||
value.isCell() && (value.asCell()->type() == StringObjectType || value.asCell()->type() == DerivedStringObjectType)));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSymbolObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
return JSValue::encode(
|
||||
jsBoolean(globalObject->symbolObjectStructure() == cell->structure()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsNativeError,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
if (value.isCell()) {
|
||||
if (value.inherits<JSC::ErrorInstance>() || value.asCell()->type() == ErrorInstanceType)
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
|
||||
VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
JSObject* object = value.toObject(globalObject);
|
||||
|
||||
// node util.isError relies on toString
|
||||
// https://github.com/nodejs/node/blob/cf8c6994e0f764af02da4fa70bc5962142181bf3/doc/api/util.md#L2923
|
||||
PropertySlot slot(object, PropertySlot::InternalMethodType::VMInquiry, &vm);
|
||||
if (object->getPropertySlot(globalObject,
|
||||
vm.propertyNames->toStringTagSymbol, slot)) {
|
||||
EXCEPTION_ASSERT(!scope.exception());
|
||||
if (slot.isValue()) {
|
||||
JSValue value = slot.getValue(globalObject, vm.propertyNames->toStringTagSymbol);
|
||||
if (value.isString()) {
|
||||
String tag = asString(value)->value(globalObject);
|
||||
if (UNLIKELY(scope.exception()))
|
||||
scope.clearException();
|
||||
if (tag == "Error"_s)
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSValue proto = object->getPrototype(vm, globalObject);
|
||||
if (proto.isCell() && (proto.inherits<JSC::ErrorInstance>() || proto.asCell()->type() == ErrorInstanceType || proto.inherits<JSC::ErrorPrototype>()))
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsRegExp,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(
|
||||
jsBoolean(value.isCell() && value.asCell()->type() == RegExpObjectType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
return JSValue::encode(
|
||||
jsBoolean(value.isCell() && value.asCell()->type() == RegExpObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsAsyncFunction,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
|
||||
auto *function = jsDynamicCast<JSFunction *>(value);
|
||||
if (!function)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
auto* function = jsDynamicCast<JSFunction*>(value);
|
||||
if (!function)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
|
||||
auto *executable = function->jsExecutable();
|
||||
if (!executable)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
auto* executable = function->jsExecutable();
|
||||
if (!executable)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
|
||||
if (executable->isAsyncGenerator()) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
if (executable->isAsyncGenerator()) {
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
auto &vm = globalObject->vm();
|
||||
auto proto = function->getPrototype(vm, globalObject);
|
||||
if (!proto.isCell()) {
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
auto& vm = globalObject->vm();
|
||||
auto proto = function->getPrototype(vm, globalObject);
|
||||
if (!proto.isCell()) {
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
|
||||
auto *protoCell = proto.asCell();
|
||||
return JSValue::encode(
|
||||
jsBoolean(protoCell->inherits<AsyncFunctionPrototype>()));
|
||||
auto* protoCell = proto.asCell();
|
||||
return JSValue::encode(
|
||||
jsBoolean(protoCell->inherits<AsyncFunctionPrototype>()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsGeneratorFunction,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_VALUE
|
||||
auto *function = jsDynamicCast<JSFunction *>(value);
|
||||
if (!function)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_VALUE
|
||||
auto* function = jsDynamicCast<JSFunction*>(value);
|
||||
if (!function)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
|
||||
auto *executable = function->jsExecutable();
|
||||
if (!executable)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
auto* executable = function->jsExecutable();
|
||||
if (!executable)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
|
||||
return JSValue::encode(
|
||||
jsBoolean(executable->isGenerator() || executable->isAsyncGenerator()));
|
||||
return JSValue::encode(
|
||||
jsBoolean(executable->isGenerator() || executable->isAsyncGenerator()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsGeneratorObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSGeneratorType ||
|
||||
cell->type() == JSAsyncGeneratorType));
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSGeneratorType || cell->type() == JSAsyncGeneratorType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsPromise,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSPromiseType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSPromiseType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsMap, (JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSMapType));
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsMap, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSMapType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSet, (JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSSetType));
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSet, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSSetType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsMapIterator,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSMapIteratorType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSMapIteratorType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSetIterator,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSSetIteratorType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSSetIteratorType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsWeakMap,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSWeakMapType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSWeakMapType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsWeakSet,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSWeakSetType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == JSWeakSetType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsArrayBuffer,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
auto *arrayBuffer = jsDynamicCast<JSArrayBuffer *>(cell);
|
||||
if (!arrayBuffer)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
return JSValue::encode(jsBoolean(!arrayBuffer->isShared()));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
auto* arrayBuffer = jsDynamicCast<JSArrayBuffer*>(cell);
|
||||
if (!arrayBuffer)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
return JSValue::encode(jsBoolean(!arrayBuffer->isShared()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsDataView,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == DataViewType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == DataViewType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsSharedArrayBuffer,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
auto *arrayBuffer = jsDynamicCast<JSArrayBuffer *>(cell);
|
||||
if (!arrayBuffer)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
return JSValue::encode(jsBoolean(arrayBuffer->isShared()));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
auto* arrayBuffer = jsDynamicCast<JSArrayBuffer*>(cell);
|
||||
if (!arrayBuffer)
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
return JSValue::encode(jsBoolean(arrayBuffer->isShared()));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsProxy, (JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == GlobalProxyType ||
|
||||
cell->type() == ProxyObjectType));
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsProxy, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == GlobalProxyType || cell->type() == ProxyObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsModuleNamespaceObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == ModuleNamespaceObjectType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == ModuleNamespaceObjectType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsAnyArrayBuffer,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
auto *arrayBuffer = jsDynamicCast<JSArrayBuffer *>(cell);
|
||||
return JSValue::encode(jsBoolean(arrayBuffer != nullptr));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
auto* arrayBuffer = jsDynamicCast<JSArrayBuffer*>(cell);
|
||||
return JSValue::encode(jsBoolean(arrayBuffer != nullptr));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBoxedPrimitive,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
switch (cell->type()) {
|
||||
case JSC::BooleanObjectType:
|
||||
case JSC::NumberObjectType:
|
||||
case JSC::StringObjectType:
|
||||
case JSC::DerivedStringObjectType:
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
switch (cell->type()) {
|
||||
case JSC::BooleanObjectType:
|
||||
case JSC::NumberObjectType:
|
||||
case JSC::StringObjectType:
|
||||
case JSC::DerivedStringObjectType:
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
|
||||
default: {
|
||||
if (cell->structure() == globalObject->symbolObjectStructure())
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
default: {
|
||||
if (cell->structure() == globalObject->symbolObjectStructure())
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
|
||||
if (cell->structure() == globalObject->bigIntObjectStructure())
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
}
|
||||
if (cell->structure() == globalObject->bigIntObjectStructure())
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
}
|
||||
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsArrayBufferView,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(
|
||||
jsBoolean(cell->type() >= Int8ArrayType && cell->type() <= DataViewType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(
|
||||
jsBoolean(cell->type() >= Int8ArrayType && cell->type() <= DataViewType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsTypedArray,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() >= Int8ArrayType &&
|
||||
cell->type() <= BigUint64ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() >= Int8ArrayType && cell->type() <= BigUint64ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsUint8Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint8ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint8ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsUint8ClampedArray,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint8ClampedArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint8ClampedArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsUint16Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint16ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint16ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsUint32Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint32ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Uint32ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsInt8Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Int8ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Int8ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsInt16Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Int16ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Int16ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsInt32Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Int32ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Int32ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsFloat16Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Float16ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Float16ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsFloat32Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Float32ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Float32ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsFloat64Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Float64ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == Float64ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBigInt64Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == BigInt64ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == BigInt64ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsBigUint64Array,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == BigUint64ArrayType));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->type() == BigUint64ArrayType));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsKeyObject,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
|
||||
if (!cell->isObject()) {
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
|
||||
auto* object = cell->getObject();
|
||||
|
||||
auto& vm = globalObject->vm();
|
||||
const auto& names = WebCore::builtinNames(vm);
|
||||
|
||||
auto scope = DECLARE_CATCH_SCOPE(vm);
|
||||
|
||||
if (auto val = object->getIfPropertyExists(globalObject,
|
||||
names.bunNativePtrPrivateName())) {
|
||||
if (val.isCell() && val.inherits<WebCore::JSCryptoKey>())
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
if (scope.exception()) {
|
||||
scope.clearException();
|
||||
}
|
||||
|
||||
if (!cell->isObject()) {
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
|
||||
auto *object = cell->getObject();
|
||||
|
||||
auto &vm = globalObject->vm();
|
||||
const auto &names = WebCore::builtinNames(vm);
|
||||
|
||||
auto scope = DECLARE_CATCH_SCOPE(vm);
|
||||
|
||||
if (auto val = object->getIfPropertyExists(globalObject,
|
||||
names.bunNativePtrPrivateName())) {
|
||||
if (val.isCell() && val.inherits<WebCore::JSCryptoKey>())
|
||||
return JSValue::encode(jsBoolean(true));
|
||||
}
|
||||
|
||||
if (scope.exception()) {
|
||||
scope.clearException();
|
||||
}
|
||||
|
||||
return JSValue::encode(jsBoolean(false));
|
||||
}
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsCryptoKey,
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame *callframe)) {
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->inherits<WebCore::JSCryptoKey>()));
|
||||
(JSC::JSGlobalObject * globalObject,
|
||||
JSC::CallFrame* callframe))
|
||||
{
|
||||
GET_FIRST_CELL
|
||||
return JSValue::encode(jsBoolean(cell->inherits<WebCore::JSCryptoKey>()));
|
||||
}
|
||||
|
||||
namespace Zig {
|
||||
DEFINE_NATIVE_MODULE(NodeUtilTypes) {
|
||||
INIT_NATIVE_MODULE(43);
|
||||
DEFINE_NATIVE_MODULE(NodeUtilTypes)
|
||||
{
|
||||
INIT_NATIVE_MODULE(43);
|
||||
|
||||
putNativeFn(Identifier::fromString(vm, "isExternal"_s), jsFunctionIsExternal);
|
||||
putNativeFn(Identifier::fromString(vm, "isDate"_s), jsFunctionIsDate);
|
||||
putNativeFn(Identifier::fromString(vm, "isArgumentsObject"_s),
|
||||
jsFunctionIsArgumentsObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isBigIntObject"_s),
|
||||
jsFunctionIsBigIntObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isBooleanObject"_s),
|
||||
jsFunctionIsBooleanObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isNumberObject"_s),
|
||||
jsFunctionIsNumberObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isStringObject"_s),
|
||||
jsFunctionIsStringObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isSymbolObject"_s),
|
||||
jsFunctionIsSymbolObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isNativeError"_s),
|
||||
jsFunctionIsNativeError);
|
||||
putNativeFn(Identifier::fromString(vm, "isRegExp"_s), jsFunctionIsRegExp);
|
||||
putNativeFn(Identifier::fromString(vm, "isAsyncFunction"_s),
|
||||
jsFunctionIsAsyncFunction);
|
||||
putNativeFn(Identifier::fromString(vm, "isGeneratorFunction"_s),
|
||||
jsFunctionIsGeneratorFunction);
|
||||
putNativeFn(Identifier::fromString(vm, "isGeneratorObject"_s),
|
||||
jsFunctionIsGeneratorObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isPromise"_s), jsFunctionIsPromise);
|
||||
putNativeFn(Identifier::fromString(vm, "isMap"_s), jsFunctionIsMap);
|
||||
putNativeFn(Identifier::fromString(vm, "isSet"_s), jsFunctionIsSet);
|
||||
putNativeFn(Identifier::fromString(vm, "isMapIterator"_s),
|
||||
jsFunctionIsMapIterator);
|
||||
putNativeFn(Identifier::fromString(vm, "isSetIterator"_s),
|
||||
jsFunctionIsSetIterator);
|
||||
putNativeFn(Identifier::fromString(vm, "isWeakMap"_s), jsFunctionIsWeakMap);
|
||||
putNativeFn(Identifier::fromString(vm, "isWeakSet"_s), jsFunctionIsWeakSet);
|
||||
putNativeFn(Identifier::fromString(vm, "isArrayBuffer"_s),
|
||||
jsFunctionIsArrayBuffer);
|
||||
putNativeFn(Identifier::fromString(vm, "isDataView"_s), jsFunctionIsDataView);
|
||||
putNativeFn(Identifier::fromString(vm, "isSharedArrayBuffer"_s),
|
||||
jsFunctionIsSharedArrayBuffer);
|
||||
putNativeFn(Identifier::fromString(vm, "isProxy"_s), jsFunctionIsProxy);
|
||||
putNativeFn(Identifier::fromString(vm, "isModuleNamespaceObject"_s),
|
||||
jsFunctionIsModuleNamespaceObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isAnyArrayBuffer"_s),
|
||||
jsFunctionIsAnyArrayBuffer);
|
||||
putNativeFn(Identifier::fromString(vm, "isBoxedPrimitive"_s),
|
||||
jsFunctionIsBoxedPrimitive);
|
||||
putNativeFn(Identifier::fromString(vm, "isArrayBufferView"_s),
|
||||
jsFunctionIsArrayBufferView);
|
||||
putNativeFn(Identifier::fromString(vm, "isTypedArray"_s),
|
||||
jsFunctionIsTypedArray);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint8Array"_s),
|
||||
jsFunctionIsUint8Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint8ClampedArray"_s),
|
||||
jsFunctionIsUint8ClampedArray);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint16Array"_s),
|
||||
jsFunctionIsUint16Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint32Array"_s),
|
||||
jsFunctionIsUint32Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isInt8Array"_s),
|
||||
jsFunctionIsInt8Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isInt16Array"_s),
|
||||
jsFunctionIsInt16Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isInt32Array"_s),
|
||||
jsFunctionIsInt32Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isFloat16Array"_s),
|
||||
jsFunctionIsFloat16Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isFloat32Array"_s),
|
||||
jsFunctionIsFloat32Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isFloat64Array"_s),
|
||||
jsFunctionIsFloat64Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isBigInt64Array"_s),
|
||||
jsFunctionIsBigInt64Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isBigUint64Array"_s),
|
||||
jsFunctionIsBigUint64Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isKeyObject"_s),
|
||||
jsFunctionIsKeyObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isCryptoKey"_s),
|
||||
jsFunctionIsCryptoKey);
|
||||
putNativeFn(Identifier::fromString(vm, "isExternal"_s), jsFunctionIsExternal);
|
||||
putNativeFn(Identifier::fromString(vm, "isDate"_s), jsFunctionIsDate);
|
||||
putNativeFn(Identifier::fromString(vm, "isArgumentsObject"_s),
|
||||
jsFunctionIsArgumentsObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isBigIntObject"_s),
|
||||
jsFunctionIsBigIntObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isBooleanObject"_s),
|
||||
jsFunctionIsBooleanObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isNumberObject"_s),
|
||||
jsFunctionIsNumberObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isStringObject"_s),
|
||||
jsFunctionIsStringObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isSymbolObject"_s),
|
||||
jsFunctionIsSymbolObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isNativeError"_s),
|
||||
jsFunctionIsNativeError);
|
||||
putNativeFn(Identifier::fromString(vm, "isRegExp"_s), jsFunctionIsRegExp);
|
||||
putNativeFn(Identifier::fromString(vm, "isAsyncFunction"_s),
|
||||
jsFunctionIsAsyncFunction);
|
||||
putNativeFn(Identifier::fromString(vm, "isGeneratorFunction"_s),
|
||||
jsFunctionIsGeneratorFunction);
|
||||
putNativeFn(Identifier::fromString(vm, "isGeneratorObject"_s),
|
||||
jsFunctionIsGeneratorObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isPromise"_s), jsFunctionIsPromise);
|
||||
putNativeFn(Identifier::fromString(vm, "isMap"_s), jsFunctionIsMap);
|
||||
putNativeFn(Identifier::fromString(vm, "isSet"_s), jsFunctionIsSet);
|
||||
putNativeFn(Identifier::fromString(vm, "isMapIterator"_s),
|
||||
jsFunctionIsMapIterator);
|
||||
putNativeFn(Identifier::fromString(vm, "isSetIterator"_s),
|
||||
jsFunctionIsSetIterator);
|
||||
putNativeFn(Identifier::fromString(vm, "isWeakMap"_s), jsFunctionIsWeakMap);
|
||||
putNativeFn(Identifier::fromString(vm, "isWeakSet"_s), jsFunctionIsWeakSet);
|
||||
putNativeFn(Identifier::fromString(vm, "isArrayBuffer"_s),
|
||||
jsFunctionIsArrayBuffer);
|
||||
putNativeFn(Identifier::fromString(vm, "isDataView"_s), jsFunctionIsDataView);
|
||||
putNativeFn(Identifier::fromString(vm, "isSharedArrayBuffer"_s),
|
||||
jsFunctionIsSharedArrayBuffer);
|
||||
putNativeFn(Identifier::fromString(vm, "isProxy"_s), jsFunctionIsProxy);
|
||||
putNativeFn(Identifier::fromString(vm, "isModuleNamespaceObject"_s),
|
||||
jsFunctionIsModuleNamespaceObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isAnyArrayBuffer"_s),
|
||||
jsFunctionIsAnyArrayBuffer);
|
||||
putNativeFn(Identifier::fromString(vm, "isBoxedPrimitive"_s),
|
||||
jsFunctionIsBoxedPrimitive);
|
||||
putNativeFn(Identifier::fromString(vm, "isArrayBufferView"_s),
|
||||
jsFunctionIsArrayBufferView);
|
||||
putNativeFn(Identifier::fromString(vm, "isTypedArray"_s),
|
||||
jsFunctionIsTypedArray);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint8Array"_s),
|
||||
jsFunctionIsUint8Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint8ClampedArray"_s),
|
||||
jsFunctionIsUint8ClampedArray);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint16Array"_s),
|
||||
jsFunctionIsUint16Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isUint32Array"_s),
|
||||
jsFunctionIsUint32Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isInt8Array"_s),
|
||||
jsFunctionIsInt8Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isInt16Array"_s),
|
||||
jsFunctionIsInt16Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isInt32Array"_s),
|
||||
jsFunctionIsInt32Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isFloat16Array"_s),
|
||||
jsFunctionIsFloat16Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isFloat32Array"_s),
|
||||
jsFunctionIsFloat32Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isFloat64Array"_s),
|
||||
jsFunctionIsFloat64Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isBigInt64Array"_s),
|
||||
jsFunctionIsBigInt64Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isBigUint64Array"_s),
|
||||
jsFunctionIsBigUint64Array);
|
||||
putNativeFn(Identifier::fromString(vm, "isKeyObject"_s),
|
||||
jsFunctionIsKeyObject);
|
||||
putNativeFn(Identifier::fromString(vm, "isCryptoKey"_s),
|
||||
jsFunctionIsCryptoKey);
|
||||
|
||||
RETURN_NATIVE_MODULE();
|
||||
RETURN_NATIVE_MODULE();
|
||||
}
|
||||
} // namespace Zig
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
namespace Zig {
|
||||
JSC::SyntheticSourceProvider::SyntheticSourceGenerator
|
||||
generateObjectModuleSourceCode(JSC::JSGlobalObject *globalObject,
|
||||
JSC::JSObject *object);
|
||||
generateObjectModuleSourceCode(JSC::JSGlobalObject* globalObject,
|
||||
JSC::JSObject* object);
|
||||
|
||||
JSC::SyntheticSourceProvider::SyntheticSourceGenerator
|
||||
generateObjectModuleSourceCodeForJSON(JSC::JSGlobalObject *globalObject,
|
||||
JSC::JSObject *object);
|
||||
generateObjectModuleSourceCodeForJSON(JSC::JSGlobalObject* globalObject,
|
||||
JSC::JSObject* object);
|
||||
|
||||
JSC::SyntheticSourceProvider::SyntheticSourceGenerator
|
||||
generateJSValueModuleSourceCode(JSC::JSGlobalObject *globalObject,
|
||||
JSC::JSValue value);
|
||||
generateJSValueModuleSourceCode(JSC::JSGlobalObject* globalObject,
|
||||
JSC::JSValue value);
|
||||
|
||||
} // namespace Zig
|
||||
} // namespace Zig
|
||||
|
||||
@@ -4,17 +4,18 @@ using namespace WebCore;
|
||||
|
||||
namespace Zig {
|
||||
inline void
|
||||
generateNativeModule_UTF8Validate(JSC::JSGlobalObject *globalObject,
|
||||
JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4> &exportNames,
|
||||
JSC::MarkedArgumentBuffer &exportValues) {
|
||||
auto &vm = globalObject->vm();
|
||||
generateNativeModule_UTF8Validate(JSC::JSGlobalObject* globalObject,
|
||||
JSC::Identifier moduleKey,
|
||||
Vector<JSC::Identifier, 4>& exportNames,
|
||||
JSC::MarkedArgumentBuffer& exportValues)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(JSC::JSFunction::create(
|
||||
vm, globalObject, 1, "utf8Validate"_s, jsBufferConstructorFunction_isUtf8,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
jsBufferConstructorFunction_isUtf8));
|
||||
exportNames.append(vm.propertyNames->defaultKeyword);
|
||||
exportValues.append(JSC::JSFunction::create(
|
||||
vm, globalObject, 1, "utf8Validate"_s, jsBufferConstructorFunction_isUtf8,
|
||||
ImplementationVisibility::Public, NoIntrinsic,
|
||||
jsBufferConstructorFunction_isUtf8));
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const bun = @import("root").bun;
|
||||
const JSC = bun.JSC;
|
||||
const Encoder = JSC.WebCore.Encoder;
|
||||
const Environment = bun.Environment;
|
||||
|
||||
pub const BufferVectorized = struct {
|
||||
pub fn fill(
|
||||
@@ -49,23 +50,33 @@ pub const BufferVectorized = struct {
|
||||
} catch return false;
|
||||
|
||||
switch (written) {
|
||||
0 => {},
|
||||
1 => @memset(buf, buf[0]),
|
||||
else => {
|
||||
var contents = buf[0..written];
|
||||
buf = buf[written..];
|
||||
|
||||
while (buf.len >= contents.len) {
|
||||
bun.copy(u8, buf, contents);
|
||||
buf = buf[contents.len..];
|
||||
contents.len *= 2;
|
||||
}
|
||||
|
||||
if (buf.len > 0) {
|
||||
bun.copy(u8, buf, contents[0..buf.len]);
|
||||
}
|
||||
0 => return true,
|
||||
1 => {
|
||||
@memset(buf, buf[0]);
|
||||
return true;
|
||||
},
|
||||
inline 4, 8, 16 => |n| if (comptime Environment.isMac) {
|
||||
const pattern = buf[0..n];
|
||||
buf = buf[pattern.len..];
|
||||
@field(bun.C, bun.fmt.comptimePrint("memset_pattern{d}", .{n}))(buf.ptr, pattern.ptr, buf.len);
|
||||
return true;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
var contents = buf[0..written];
|
||||
buf = buf[written..];
|
||||
|
||||
while (buf.len >= contents.len) {
|
||||
bun.copy(u8, buf, contents);
|
||||
buf = buf[contents.len..];
|
||||
contents.len *= 2;
|
||||
}
|
||||
|
||||
if (buf.len > 0) {
|
||||
bun.copy(u8, buf, contents[0..buf.len]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4857,21 +4857,11 @@ pub const NodeFS = struct {
|
||||
pub fn mkdirRecursiveImpl(this: *NodeFS, args: Arguments.Mkdir, comptime flavor: Flavor, comptime Ctx: type, ctx: Ctx) Maybe(Return.Mkdir) {
|
||||
_ = flavor;
|
||||
var buf: bun.OSPathBuffer = undefined;
|
||||
const path: bun.OSPathSliceZ = if (!Environment.isWindows)
|
||||
args.path.osPath(&buf)
|
||||
else brk: {
|
||||
// TODO(@paperdave): clean this up a lot.
|
||||
var joined_buf: bun.PathBuffer = undefined;
|
||||
if (std.fs.path.isAbsolute(args.path.slice())) {
|
||||
const utf8 = PosixToWinNormalizer.resolveCWDWithExternalBufZ(&joined_buf, args.path.slice()) catch
|
||||
return .{ .err = .{ .errno = @intFromEnum(C.SystemErrno.ENOMEM), .syscall = .getcwd } };
|
||||
break :brk strings.toWPath(&buf, utf8);
|
||||
} else {
|
||||
var cwd_buf: bun.PathBuffer = undefined;
|
||||
const cwd = std.posix.getcwd(&cwd_buf) catch return .{ .err = .{ .errno = @intFromEnum(C.SystemErrno.ENOMEM), .syscall = .getcwd } };
|
||||
break :brk strings.toWPath(&buf, bun.path.joinAbsStringBuf(cwd, &joined_buf, &.{args.path.slice()}, .windows));
|
||||
}
|
||||
};
|
||||
const path: bun.OSPathSliceZ = if (Environment.isWindows)
|
||||
strings.toNTPath(&buf, args.path.slice())
|
||||
else
|
||||
args.path.osPath(&buf);
|
||||
|
||||
// TODO: remove and make it always a comptime argument
|
||||
return switch (args.always_return_none) {
|
||||
inline else => |always_return_none| this.mkdirRecursiveOSPathImpl(Ctx, ctx, path, args.mode, !always_return_none),
|
||||
@@ -4921,7 +4911,12 @@ pub const NodeFS = struct {
|
||||
return .{ .result = .{ .none = {} } };
|
||||
},
|
||||
// continue
|
||||
.NOENT => {},
|
||||
.NOENT => {
|
||||
if (len == 0) {
|
||||
// no path to copy
|
||||
return .{ .err = err };
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
.result => {
|
||||
|
||||
@@ -2316,6 +2316,7 @@ pub const Expect = struct {
|
||||
|
||||
const not = this.flags.not;
|
||||
|
||||
var return_value_from_function: JSValue = .zero;
|
||||
const result_: ?JSValue = brk: {
|
||||
if (!value.jsType().isFunction()) {
|
||||
if (this.flags.promise != .none) {
|
||||
@@ -2336,8 +2337,7 @@ pub const Expect = struct {
|
||||
const prev_unhandled_pending_rejection_to_capture = vm.unhandled_pending_rejection_to_capture;
|
||||
vm.unhandled_pending_rejection_to_capture = &return_value;
|
||||
vm.onUnhandledRejection = &VirtualMachine.onQuietUnhandledRejectionHandlerCaptureValue;
|
||||
const return_value_from_function: JSValue = value.call(globalThis, .undefined, &.{}) catch |err|
|
||||
globalThis.takeException(err);
|
||||
return_value_from_function = value.call(globalThis, .undefined, &.{}) catch |err| globalThis.takeException(err);
|
||||
vm.unhandled_pending_rejection_to_capture = prev_unhandled_pending_rejection_to_capture;
|
||||
|
||||
vm.global.handleRejectedPromises();
|
||||
@@ -2628,12 +2628,13 @@ pub const Expect = struct {
|
||||
}
|
||||
|
||||
// did not throw
|
||||
const result = return_value_from_function;
|
||||
var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
|
||||
const received_line = "Received function did not throw\n";
|
||||
const received_line = "Received function did not throw\nReceived value: <red>{any}<r>\n";
|
||||
|
||||
if (expected_value.isEmpty() or expected_value.isUndefined()) {
|
||||
const signature = comptime getSignature("toThrow", "", false);
|
||||
this.throw(globalThis, signature, "\n\n" ++ received_line, .{});
|
||||
this.throw(globalThis, signature, "\n\n" ++ received_line, .{result.toFmt(&formatter)});
|
||||
return .zero;
|
||||
}
|
||||
|
||||
@@ -2641,26 +2642,26 @@ pub const Expect = struct {
|
||||
|
||||
if (expected_value.isString()) {
|
||||
const expected_fmt = "\n\nExpected substring: <green>{any}<r>\n\n" ++ received_line;
|
||||
this.throw(globalThis, signature, expected_fmt, .{expected_value.toFmt(&formatter)});
|
||||
this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) });
|
||||
return .zero;
|
||||
}
|
||||
|
||||
if (expected_value.isRegExp()) {
|
||||
const expected_fmt = "\n\nExpected pattern: <green>{any}<r>\n\n" ++ received_line;
|
||||
this.throw(globalThis, signature, expected_fmt, .{expected_value.toFmt(&formatter)});
|
||||
this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) });
|
||||
return .zero;
|
||||
}
|
||||
|
||||
if (expected_value.fastGet(globalThis, .message)) |expected_message| {
|
||||
const expected_fmt = "\n\nExpected message: <green>{any}<r>\n\n" ++ received_line;
|
||||
this.throw(globalThis, signature, expected_fmt, .{expected_message.toFmt(&formatter)});
|
||||
this.throw(globalThis, signature, expected_fmt, .{ expected_message.toFmt(&formatter), result.toFmt(&formatter) });
|
||||
return .zero;
|
||||
}
|
||||
|
||||
const expected_fmt = "\n\nExpected constructor: <green>{s}<r>\n\n" ++ received_line;
|
||||
var expected_class = ZigString.Empty;
|
||||
expected_value.getClassName(globalThis, &expected_class);
|
||||
this.throw(globalThis, signature, expected_fmt, .{expected_class});
|
||||
this.throw(globalThis, signature, expected_fmt, .{ expected_class, result.toFmt(&formatter) });
|
||||
return .zero;
|
||||
}
|
||||
pub fn toMatchSnapshot(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) JSValue {
|
||||
|
||||
@@ -888,3 +888,7 @@ pub const CLOCK_THREAD_CPUTIME_ID = 1;
|
||||
pub const netdb = @cImport({
|
||||
@cInclude("netdb.h");
|
||||
});
|
||||
|
||||
pub extern fn memset_pattern4(buf: [*]u8, pattern: [*]const u8, len: usize) void;
|
||||
pub extern fn memset_pattern8(buf: [*]u8, pattern: [*]const u8, len: usize) void;
|
||||
pub extern fn memset_pattern16(buf: [*]u8, pattern: [*]const u8, len: usize) void;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { hideFromStack } = require("internal/shared");
|
||||
|
||||
const { ArrayIsArray } = require("internal/primordials");
|
||||
const RegExpPrototypeExec = RegExp.prototype.exec;
|
||||
|
||||
const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
|
||||
@@ -28,6 +28,7 @@ function validateLinkHeaderFormat(value, name) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function validateLinkHeaderValue(hints) {
|
||||
if (typeof hints === "string") {
|
||||
validateLinkHeaderFormat(hints, "hints");
|
||||
@@ -58,8 +59,14 @@ function validateLinkHeaderValue(hints) {
|
||||
);
|
||||
}
|
||||
hideFromStack(validateLinkHeaderValue);
|
||||
// TODO: do it in NodeValidator.cpp
|
||||
function validateObject(value, name) {
|
||||
if (typeof value !== "object") throw $ERR_INVALID_ARG_TYPE(name, "object", value);
|
||||
}
|
||||
hideFromStack(validateObject);
|
||||
|
||||
export default {
|
||||
validateObject: validateObject,
|
||||
validateLinkHeaderValue: validateLinkHeaderValue,
|
||||
checkIsHttpToken: checkIsHttpToken,
|
||||
/** `(value, name, min = NumberMIN_SAFE_INTEGER, max = NumberMAX_SAFE_INTEGER)` */
|
||||
|
||||
@@ -1541,6 +1541,7 @@ function markStreamClosed(stream: Http2Stream) {
|
||||
|
||||
if ((status & StreamState.Closed) === 0) {
|
||||
stream[bunHTTP2StreamStatus] = status | StreamState.Closed;
|
||||
|
||||
markWritableDone(stream);
|
||||
}
|
||||
}
|
||||
@@ -1703,12 +1704,12 @@ class Http2Stream extends Duplex {
|
||||
if ((this[bunHTTP2StreamStatus] & StreamState.Closed) === 0) {
|
||||
const session = this[bunHTTP2Session];
|
||||
assertSession(session);
|
||||
code = code || 0;
|
||||
validateInteger(code, "code", 0, 13);
|
||||
this.rstCode = code;
|
||||
markStreamClosed(this);
|
||||
|
||||
session[bunHTTP2Native]?.rstStream(this.#id, code || 0);
|
||||
this[bunHTTP2Session] = null;
|
||||
session[bunHTTP2Native]?.rstStream(this.#id, code);
|
||||
}
|
||||
|
||||
if (typeof callback === "function") {
|
||||
@@ -1716,50 +1717,46 @@ class Http2Stream extends Duplex {
|
||||
}
|
||||
}
|
||||
_destroy(err, callback) {
|
||||
if ((this[bunHTTP2StreamStatus] & StreamState.Closed) === 0) {
|
||||
const { ending } = this._writableState;
|
||||
if (!ending) {
|
||||
// If the writable side of the Http2Stream is still open, emit the
|
||||
// 'aborted' event and set the aborted flag.
|
||||
if (!this.aborted) {
|
||||
this[kAborted] = true;
|
||||
this.emit("aborted");
|
||||
}
|
||||
const { ending } = this._writableState;
|
||||
|
||||
// at this state destroyed will be true but we need to close the writable side
|
||||
this._writableState.destroyed = false;
|
||||
this.end();
|
||||
// we now restore the destroyed flag
|
||||
this._writableState.destroyed = true;
|
||||
if (!ending) {
|
||||
// If the writable side of the Http2Stream is still open, emit the
|
||||
// 'aborted' event and set the aborted flag.
|
||||
if (!this.aborted) {
|
||||
this[kAborted] = true;
|
||||
this.emit("aborted");
|
||||
}
|
||||
// at this state destroyed will be true but we need to close the writable side
|
||||
this._writableState.destroyed = false;
|
||||
this.end();
|
||||
// we now restore the destroyed flag
|
||||
this._writableState.destroyed = true;
|
||||
}
|
||||
|
||||
const session = this[bunHTTP2Session];
|
||||
assertSession(session);
|
||||
const session = this[bunHTTP2Session];
|
||||
assertSession(session);
|
||||
|
||||
let rstCode = this.rstCode;
|
||||
if (!rstCode) {
|
||||
if (err != null) {
|
||||
if (err.code === "ABORT_ERR") {
|
||||
// Enables using AbortController to cancel requests with RST code 8.
|
||||
rstCode = NGHTTP2_CANCEL;
|
||||
} else {
|
||||
rstCode = NGHTTP2_INTERNAL_ERROR;
|
||||
}
|
||||
let rstCode = this.rstCode;
|
||||
if (!rstCode) {
|
||||
if (err != null) {
|
||||
if (err.code === "ABORT_ERR") {
|
||||
// Enables using AbortController to cancel requests with RST code 8.
|
||||
rstCode = NGHTTP2_CANCEL;
|
||||
} else {
|
||||
rstCode = this.rstCode = 0;
|
||||
rstCode = NGHTTP2_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.writableFinished) {
|
||||
markStreamClosed(this);
|
||||
|
||||
session[bunHTTP2Native]?.rstStream(this.#id, rstCode);
|
||||
this[bunHTTP2Session] = null;
|
||||
} else {
|
||||
this.once("finish", Http2Stream.#rstStream);
|
||||
rstCode = this.rstCode = 0;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (this.writableFinished) {
|
||||
markStreamClosed(this);
|
||||
|
||||
session[bunHTTP2Native]?.rstStream(this.#id, rstCode);
|
||||
this[bunHTTP2Session] = null;
|
||||
} else {
|
||||
this.once("finish", Http2Stream.#rstStream);
|
||||
}
|
||||
|
||||
callback(err);
|
||||
@@ -2153,6 +2150,7 @@ function emitStreamErrorNT(self, stream, error, destroy, destroy_self) {
|
||||
} else {
|
||||
error_instance = error;
|
||||
}
|
||||
|
||||
if (stream.readable) {
|
||||
stream.resume(); // we have a error we consume and close
|
||||
pushToStream(stream, null);
|
||||
@@ -2162,6 +2160,7 @@ function emitStreamErrorNT(self, stream, error, destroy, destroy_self) {
|
||||
else if (error_instance) {
|
||||
stream.emit("error", error_instance);
|
||||
}
|
||||
|
||||
if (destroy_self) self.destroy();
|
||||
}
|
||||
}
|
||||
@@ -2246,15 +2245,12 @@ class ServerHttp2Session extends Http2Session {
|
||||
},
|
||||
aborted(self: ServerHttp2Session, stream: ServerHttp2Stream, error: any, old_state: number) {
|
||||
if (!self || typeof stream !== "object") return;
|
||||
|
||||
stream.rstCode = constants.NGHTTP2_CANCEL;
|
||||
markStreamClosed(stream);
|
||||
// if writable and not closed emit aborted
|
||||
if (old_state != 5 && old_state != 7) {
|
||||
stream[kAborted] = true;
|
||||
stream.emit("aborted");
|
||||
}
|
||||
|
||||
self.#connections--;
|
||||
process.nextTick(emitStreamErrorNT, self, stream, error, true, self.#connections === 0 && self.#closed);
|
||||
},
|
||||
@@ -2342,9 +2338,7 @@ class ServerHttp2Session extends Http2Session {
|
||||
error(self: ServerHttp2Session, errorCode: number, lastStreamId: number, opaqueData: Buffer) {
|
||||
if (!self) return;
|
||||
const error_instance = sessionErrorFromCode(errorCode);
|
||||
self.emit("error", error_instance);
|
||||
self[bunHTTP2Socket]?.end();
|
||||
self.#parser = null;
|
||||
self.destroy(error_instance);
|
||||
},
|
||||
wantTrailers(self: ServerHttp2Session, stream: ServerHttp2Stream) {
|
||||
if (!self || typeof stream !== "object") return;
|
||||
@@ -2365,14 +2359,11 @@ class ServerHttp2Session extends Http2Session {
|
||||
if (errorCode !== 0) {
|
||||
self.#parser.emitErrorToAllStreams(errorCode);
|
||||
}
|
||||
|
||||
self[bunHTTP2Socket]?.end();
|
||||
self.#parser = null;
|
||||
self.close();
|
||||
},
|
||||
end(self: ServerHttp2Session, errorCode: number, lastStreamId: number, opaqueData: Buffer) {
|
||||
if (!self) return;
|
||||
self[bunHTTP2Socket]?.end();
|
||||
self.#parser = null;
|
||||
self.destroy();
|
||||
},
|
||||
write(self: ServerHttp2Session, buffer: Buffer) {
|
||||
if (!self) return -1;
|
||||
@@ -2390,7 +2381,12 @@ class ServerHttp2Session extends Http2Session {
|
||||
}
|
||||
|
||||
#onClose() {
|
||||
// this.destroy();
|
||||
const parser = this.#parser;
|
||||
if (parser) {
|
||||
parser.emitAbortToAllStreams();
|
||||
parser.detach();
|
||||
this.#parser = null;
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
@@ -2601,8 +2597,12 @@ class ServerHttp2Session extends Http2Session {
|
||||
this.goaway(code || constants.NGHTTP2_NO_ERROR, 0, Buffer.alloc(0));
|
||||
socket.end();
|
||||
}
|
||||
this.#parser?.emitErrorToAllStreams(code || constants.NGHTTP2_NO_ERROR);
|
||||
this.#parser = null;
|
||||
const parser = this.#parser;
|
||||
if (parser) {
|
||||
parser.emitErrorToAllStreams(code || constants.NGHTTP2_NO_ERROR);
|
||||
parser.detach();
|
||||
this.#parser = null;
|
||||
}
|
||||
this[bunHTTP2Socket] = null;
|
||||
|
||||
if (error) {
|
||||
@@ -2652,8 +2652,6 @@ class ClientHttp2Session extends Http2Session {
|
||||
},
|
||||
aborted(self: ClientHttp2Session, stream: ClientHttp2Stream, error: any, old_state: number) {
|
||||
if (!self || typeof stream !== "object") return;
|
||||
|
||||
markStreamClosed(stream);
|
||||
stream.rstCode = constants.NGHTTP2_CANCEL;
|
||||
// if writable and not closed emit aborted
|
||||
if (old_state != 5 && old_state != 7) {
|
||||
@@ -2753,9 +2751,7 @@ class ClientHttp2Session extends Http2Session {
|
||||
error(self: ClientHttp2Session, errorCode: number, lastStreamId: number, opaqueData: Buffer) {
|
||||
if (!self) return;
|
||||
const error_instance = sessionErrorFromCode(errorCode);
|
||||
self.emit("error", error_instance);
|
||||
self[bunHTTP2Socket]?.destroy();
|
||||
self.#parser = null;
|
||||
self.destroy(error_instance);
|
||||
},
|
||||
|
||||
wantTrailers(self: ClientHttp2Session, stream: ClientHttp2Stream) {
|
||||
@@ -2775,13 +2771,11 @@ class ClientHttp2Session extends Http2Session {
|
||||
if (errorCode !== 0) {
|
||||
self.#parser.emitErrorToAllStreams(errorCode);
|
||||
}
|
||||
self[bunHTTP2Socket]?.end();
|
||||
self.#parser = null;
|
||||
self.close();
|
||||
},
|
||||
end(self: ClientHttp2Session, errorCode: number, lastStreamId: number, opaqueData: Buffer) {
|
||||
if (!self) return;
|
||||
self[bunHTTP2Socket]?.end();
|
||||
self.#parser = null;
|
||||
self.destroy();
|
||||
},
|
||||
write(self: ClientHttp2Session, buffer: Buffer) {
|
||||
if (!self) return -1;
|
||||
@@ -2835,9 +2829,17 @@ class ClientHttp2Session extends Http2Session {
|
||||
}
|
||||
|
||||
#onClose() {
|
||||
const parser = this.#parser;
|
||||
if (parser) {
|
||||
parser.emitAbortToAllStreams();
|
||||
parser.detach();
|
||||
this.#parser = null;
|
||||
}
|
||||
this.close();
|
||||
this[bunHTTP2Socket] = null;
|
||||
}
|
||||
#onError(error: Error) {
|
||||
this[bunHTTP2Socket] = null;
|
||||
this.destroy(error);
|
||||
}
|
||||
#onTimeout() {
|
||||
@@ -3054,9 +3056,13 @@ class ClientHttp2Session extends Http2Session {
|
||||
this.goaway(code || constants.NGHTTP2_NO_ERROR, 0, Buffer.alloc(0));
|
||||
socket.end();
|
||||
}
|
||||
this.#parser?.emitErrorToAllStreams(code || constants.NGHTTP2_NO_ERROR);
|
||||
this[bunHTTP2Socket] = null;
|
||||
const parser = this.#parser;
|
||||
if (parser) {
|
||||
parser.emitErrorToAllStreams(code || constants.NGHTTP2_NO_ERROR);
|
||||
parser.detach();
|
||||
}
|
||||
this.#parser = null;
|
||||
this[bunHTTP2Socket] = null;
|
||||
|
||||
if (error) {
|
||||
this.emit("error", error);
|
||||
|
||||
@@ -729,7 +729,6 @@ pub fn mkdirOSPath(file_path: bun.OSPathSliceZ, flags: bun.Mode) Maybe(void) {
|
||||
return switch (Environment.os) {
|
||||
else => mkdir(file_path, flags),
|
||||
.windows => {
|
||||
assertIsValidWindowsPath(bun.OSPathChar, file_path);
|
||||
const rc = kernel32.CreateDirectoryW(file_path, null);
|
||||
|
||||
if (Maybe(void).errnoSys(
|
||||
|
||||
@@ -1520,7 +1520,7 @@ for (const [key, blob] of build.outputs) {
|
||||
}
|
||||
}
|
||||
} else if (!success) {
|
||||
if (run.exitCode) {
|
||||
if (run.exitCode != null) {
|
||||
expect([exitCode, signalCode]).toEqual([run.exitCode, undefined]);
|
||||
} else {
|
||||
throw new Error(prefix + "Runtime failed\n" + stdout!.toUnixString() + "\n" + stderr!.toUnixString());
|
||||
|
||||
@@ -8210,12 +8210,8 @@ it("should ensure read permissions of all extracted files", async () => {
|
||||
|
||||
await runBunInstall(env, package_dir);
|
||||
|
||||
expect((await stat(join(package_dir, "node_modules", "pkg-only-owner", "package.json"))).mode & 0o666).toBe(
|
||||
isWindows ? 0o666 : 0o644,
|
||||
);
|
||||
expect((await stat(join(package_dir, "node_modules", "pkg-only-owner", "src", "index.js"))).mode & 0o666).toBe(
|
||||
isWindows ? 0o666 : 0o644,
|
||||
);
|
||||
expect((await stat(join(package_dir, "node_modules", "pkg-only-owner", "package.json"))).mode & 0o444).toBe(0o444);
|
||||
expect((await stat(join(package_dir, "node_modules", "pkg-only-owner", "src", "index.js"))).mode & 0o444).toBe(0o444);
|
||||
});
|
||||
|
||||
it("should handle @scoped name that contains tilde, issue#7045", async () => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { spawnSync } from "bun";
|
||||
import { expect, it } from "bun:test";
|
||||
import * as fs from "fs";
|
||||
import { bunEnv, bunExe } from "harness";
|
||||
import { dirname, join } from "path";
|
||||
import { dirname, join, resolve } from "path";
|
||||
|
||||
it("should not log .env when quiet", async () => {
|
||||
writeDirectoryTree("/tmp/log-test-silent", {
|
||||
@@ -36,6 +36,7 @@ it("should log .env by default", async () => {
|
||||
});
|
||||
|
||||
function writeDirectoryTree(base: string, paths: Record<string, any>) {
|
||||
base = resolve(base);
|
||||
for (const path of Object.keys(paths)) {
|
||||
const content = paths[path];
|
||||
const joined = join(base, path);
|
||||
|
||||
@@ -62,6 +62,19 @@ function mkdirForce(path: string) {
|
||||
if (!existsSync(path)) mkdirSync(path, { recursive: true });
|
||||
}
|
||||
|
||||
function tmpdirTestMkdir(): string {
|
||||
const now = Date.now().toString();
|
||||
const tempdir = `${tmpdir()}/fs.test.ts/${now}/1234/hi`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
const res = mkdirSync(tempdir, { recursive: true });
|
||||
if (!res?.includes(now)) {
|
||||
expect(res).toInclude("fs.test.ts");
|
||||
}
|
||||
expect(res).not.toInclude("1234");
|
||||
expect(existsSync(tempdir)).toBe(true);
|
||||
return tempdir;
|
||||
}
|
||||
|
||||
it("fs.writeFile(1, data) should work when its inherited", async () => {
|
||||
expect([join(import.meta.dir, "fs-writeFile-1-fixture.js"), "1"]).toRun();
|
||||
});
|
||||
@@ -315,9 +328,7 @@ it("writeFileSync NOT in append SHOULD truncate the file", () => {
|
||||
|
||||
describe("copyFileSync", () => {
|
||||
it("should work for files < 128 KB", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}/1234/hi`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
const tempdir = tmpdirTestMkdir();
|
||||
|
||||
// that don't exist
|
||||
copyFileSync(import.meta.path, tempdir + "/copyFileSync.js");
|
||||
@@ -333,9 +344,7 @@ describe("copyFileSync", () => {
|
||||
});
|
||||
|
||||
it("should work for files > 128 KB ", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}-1/1234/hi`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
const tempdir = tmpdirTestMkdir();
|
||||
var buffer = new Int32Array(128 * 1024);
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
buffer[i] = i % 256;
|
||||
@@ -362,9 +371,7 @@ describe("copyFileSync", () => {
|
||||
});
|
||||
|
||||
it("FICLONE option does not error ever", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}.FICLONE/1234/hi`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
const tempdir = tmpdirTestMkdir();
|
||||
|
||||
// that don't exist
|
||||
copyFileSync(import.meta.path, tempdir + "/copyFileSync.js", fs.constants.COPYFILE_FICLONE);
|
||||
@@ -373,9 +380,7 @@ describe("copyFileSync", () => {
|
||||
});
|
||||
|
||||
it("COPYFILE_EXCL works", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}.COPYFILE_EXCL/1234/hi`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
const tempdir = tmpdirTestMkdir();
|
||||
|
||||
// that don't exist
|
||||
copyFileSync(import.meta.path, tempdir + "/copyFileSync.js", fs.constants.COPYFILE_EXCL);
|
||||
@@ -387,9 +392,7 @@ describe("copyFileSync", () => {
|
||||
if (process.platform === "linux") {
|
||||
describe("should work when copyFileRange is not available", () => {
|
||||
it("on large files", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}-1/1234/large`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
const tempdir = tmpdirTestMkdir();
|
||||
var buffer = new Int32Array(128 * 1024);
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
buffer[i] = i % 256;
|
||||
@@ -421,9 +424,7 @@ describe("copyFileSync", () => {
|
||||
});
|
||||
|
||||
it("on small files", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}-1/1234/small`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
const tempdir = tmpdirTestMkdir();
|
||||
var buffer = new Int32Array(1 * 1024);
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
buffer[i] = i % 256;
|
||||
@@ -460,12 +461,22 @@ describe("copyFileSync", () => {
|
||||
|
||||
describe("mkdirSync", () => {
|
||||
it("should create a directory", () => {
|
||||
const tempdir = `${tmpdir()}/fs.test.js/${Date.now()}.mkdirSync/1234/hi`;
|
||||
const now = Date.now().toString();
|
||||
const base = join(now, ".mkdirSync", "1234", "hi");
|
||||
const tempdir = `${tmpdir()}/${base}`;
|
||||
expect(existsSync(tempdir)).toBe(false);
|
||||
expect(tempdir.includes(mkdirSync(tempdir, { recursive: true })!)).toBe(true);
|
||||
|
||||
const res = mkdirSync(tempdir, { recursive: true });
|
||||
expect(res).toInclude(now);
|
||||
expect(res).not.toInclude(".mkdirSync");
|
||||
expect(existsSync(tempdir)).toBe(true);
|
||||
});
|
||||
|
||||
it("should throw ENOENT for empty string", () => {
|
||||
expect(() => mkdirSync("", { recursive: true })).toThrow("No such file or directory");
|
||||
expect(() => mkdirSync("")).toThrow("No such file or directory");
|
||||
});
|
||||
|
||||
it("throws for invalid options", () => {
|
||||
const path = `${tmpdir()}/${Date.now()}.rm.dir2/foo/bar`;
|
||||
|
||||
@@ -1091,10 +1102,10 @@ describe("readSync", () => {
|
||||
closeSync(fd);
|
||||
});
|
||||
|
||||
it("works with invalid fd but zero length",()=>{
|
||||
it("works with invalid fd but zero length", () => {
|
||||
expect(readSync(2147483640, Buffer.alloc(0))).toBe(0);
|
||||
expect(readSync(2147483640, Buffer.alloc(10), 0, 0, 0)).toBe(0);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it("writevSync", () => {
|
||||
@@ -2074,7 +2085,7 @@ describe("fs.ReadStream", () => {
|
||||
|
||||
describe("createWriteStream", () => {
|
||||
it("simple write stream finishes", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStream.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStream.txt`;
|
||||
const stream = createWriteStream(path);
|
||||
stream.write("Test file written successfully");
|
||||
stream.end();
|
||||
@@ -2092,7 +2103,7 @@ describe("createWriteStream", () => {
|
||||
});
|
||||
|
||||
it("writing null throws ERR_STREAM_NULL_VALUES", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamNulls.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStreamNulls.txt`;
|
||||
const stream = createWriteStream(path);
|
||||
try {
|
||||
stream.write(null);
|
||||
@@ -2103,7 +2114,7 @@ describe("createWriteStream", () => {
|
||||
});
|
||||
|
||||
it("writing null throws ERR_STREAM_NULL_VALUES (objectMode: true)", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamNulls.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStreamNulls.txt`;
|
||||
const stream = createWriteStream(path, {
|
||||
// @ts-ignore-next-line
|
||||
objectMode: true,
|
||||
@@ -2117,7 +2128,7 @@ describe("createWriteStream", () => {
|
||||
});
|
||||
|
||||
it("writing false throws ERR_INVALID_ARG_TYPE", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamFalse.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStreamFalse.txt`;
|
||||
const stream = createWriteStream(path);
|
||||
try {
|
||||
stream.write(false);
|
||||
@@ -2128,7 +2139,7 @@ describe("createWriteStream", () => {
|
||||
});
|
||||
|
||||
it("writing false throws ERR_INVALID_ARG_TYPE (objectMode: true)", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamFalse.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStreamFalse.txt`;
|
||||
const stream = createWriteStream(path, {
|
||||
// @ts-ignore-next-line
|
||||
objectMode: true,
|
||||
@@ -2142,7 +2153,7 @@ describe("createWriteStream", () => {
|
||||
});
|
||||
|
||||
it("writing in append mode should not truncate the file", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamAppend.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStreamAppend.txt`;
|
||||
const stream = createWriteStream(path, {
|
||||
// @ts-ignore-next-line
|
||||
flags: "a",
|
||||
@@ -2233,7 +2244,7 @@ describe("fs/promises", () => {
|
||||
});
|
||||
|
||||
it("writeFile", async () => {
|
||||
const path = `${tmpdir()}/fs.test.js/${Date.now()}.writeFile.txt`;
|
||||
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.writeFile.txt`;
|
||||
await writeFile(path, "File written successfully");
|
||||
expect(readFileSync(path, "utf8")).toBe("File written successfully");
|
||||
});
|
||||
@@ -2595,7 +2606,7 @@ it("fstat on a large file", () => {
|
||||
var dest: string = "",
|
||||
fd;
|
||||
try {
|
||||
dest = `${tmpdir()}/fs.test.js/${Math.trunc(Math.random() * 10000000000).toString(32)}.stat.txt`;
|
||||
dest = `${tmpdir()}/fs.test.ts/${Math.trunc(Math.random() * 10000000000).toString(32)}.stat.txt`;
|
||||
mkdirSync(dirname(dest), { recursive: true });
|
||||
const bigBuffer = new Uint8Array(1024 * 1024 * 1024);
|
||||
fd = openSync(dest, "w");
|
||||
|
||||
@@ -10,7 +10,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from
|
||||
import http2utils from "./helpers";
|
||||
import { nodeEchoServer, TLS_CERT, TLS_OPTIONS } from "./http2-helpers";
|
||||
|
||||
for (const nodeExecutable of [nodeExe()]) {
|
||||
for (const nodeExecutable of [nodeExe(), bunExe()]) {
|
||||
describe(`${path.basename(nodeExecutable)}`, () => {
|
||||
let nodeEchoServer_;
|
||||
|
||||
@@ -665,30 +665,7 @@ for (const nodeExecutable of [nodeExe()]) {
|
||||
expect(req.aborted).toBeTrue();
|
||||
expect(req.rstCode).toBe(http2.constants.NGHTTP2_CANCEL);
|
||||
});
|
||||
it("aborted event should not work when not writable but should emit error", async () => {
|
||||
const abortController = new AbortController();
|
||||
const { promise, resolve, reject } = Promise.withResolvers();
|
||||
const client = http2.connect(HTTPS_SERVER, TLS_OPTIONS);
|
||||
client.on("error", reject);
|
||||
const req = client.request({ ":path": "/" }, { signal: abortController.signal });
|
||||
req.on("aborted", reject);
|
||||
req.on("error", err => {
|
||||
if (err.code !== "ABORT_ERR") {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
req.on("end", () => {
|
||||
reject();
|
||||
client.close();
|
||||
});
|
||||
abortController.abort();
|
||||
const result = await promise;
|
||||
expect(result).toBeUndefined();
|
||||
expect(req.aborted).toBeFalse(); // will only be true when the request is in a writable state
|
||||
expect(req.rstCode).toBe(http2.constants.NGHTTP2_CANCEL);
|
||||
});
|
||||
|
||||
it("aborted event should work with aborted signal", async () => {
|
||||
const { promise, resolve, reject } = Promise.withResolvers();
|
||||
const client = http2.connect(HTTPS_SERVER, TLS_OPTIONS);
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
//#FILE: test-http2-connect-tls-with-delay.js
|
||||
//#SHA1: 8c5489e025ec14c2cc53788b27fde11a11990e42
|
||||
//-----------------
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
const http2 = require('http2');
|
||||
const tls = require('tls');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const http2 = require("http2");
|
||||
const tls = require("tls");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const serverOptions = {
|
||||
key: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent1-key.pem')),
|
||||
cert: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent1-cert.pem'))
|
||||
key: fs.readFileSync(path.join(__dirname, "..", "fixtures", "keys", "agent1-key.pem")),
|
||||
cert: fs.readFileSync(path.join(__dirname, "..", "fixtures", "keys", "agent1-cert.pem")),
|
||||
};
|
||||
|
||||
let server;
|
||||
|
||||
beforeAll((done) => {
|
||||
beforeAll(done => {
|
||||
server = http2.createSecureServer(serverOptions, (req, res) => {
|
||||
res.end();
|
||||
});
|
||||
|
||||
server.listen(0, '127.0.0.1', done);
|
||||
server.listen(0, "127.0.0.1", done);
|
||||
});
|
||||
|
||||
afterAll((done) => {
|
||||
server.close(done);
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
test('HTTP/2 connect with TLS and delay', (done) => {
|
||||
test("HTTP/2 connect with TLS and delay", done => {
|
||||
const options = {
|
||||
ALPNProtocols: ['h2'],
|
||||
host: '127.0.0.1',
|
||||
servername: 'localhost',
|
||||
ALPNProtocols: ["h2"],
|
||||
host: "127.0.0.1",
|
||||
servername: "localhost",
|
||||
port: server.address().port,
|
||||
rejectUnauthorized: false
|
||||
rejectUnauthorized: false,
|
||||
};
|
||||
|
||||
const socket = tls.connect(options, async () => {
|
||||
socket.once('readable', () => {
|
||||
const client = http2.connect(
|
||||
'https://localhost:' + server.address().port,
|
||||
{ ...options, createConnection: () => socket }
|
||||
);
|
||||
socket.once("readable", () => {
|
||||
const client = http2.connect("https://localhost:" + server.address().port, {
|
||||
...options,
|
||||
createConnection: () => socket,
|
||||
});
|
||||
|
||||
client.once('remoteSettings', () => {
|
||||
client.once("remoteSettings", () => {
|
||||
const req = client.request({
|
||||
':path': '/'
|
||||
":path": "/",
|
||||
});
|
||||
req.on('data', () => req.resume());
|
||||
req.on('end', () => {
|
||||
req.on("data", () => req.resume());
|
||||
req.on("end", () => {
|
||||
client.close();
|
||||
req.close();
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user