Skip to content

Commit

Permalink
Merge branch 'main' into warm_node
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Mar 20, 2024
2 parents 1764879 + 2ce6451 commit 5876131
Show file tree
Hide file tree
Showing 40 changed files with 628 additions and 178 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const installDenoStep = {

const authenticateWithGoogleCloud = {
name: "Authenticate with Google Cloud",
uses: "google-github-actions/auth@v1",
uses: "google-github-actions/auth@v2",
with: {
"project_id": "denoland",
"credentials_json": "${{ secrets.GCP_SA_KEY }}",
Expand Down Expand Up @@ -510,7 +510,7 @@ const ci = {
"(github.ref == 'refs/heads/main' ||",
"startsWith(github.ref, 'refs/tags/'))",
].join("\n"),
uses: "google-github-actions/setup-gcloud@v1",
uses: "google-github-actions/setup-gcloud@v2",
with: {
project_id: "denoland",
},
Expand All @@ -525,7 +525,7 @@ const ci = {
"(github.ref == 'refs/heads/main' ||",
"startsWith(github.ref, 'refs/tags/'))",
].join("\n"),
uses: "google-github-actions/setup-gcloud@v1",
uses: "google-github-actions/setup-gcloud@v2",
env: {
CLOUDSDK_PYTHON: "${{env.pythonLocation}}\\python.exe",
},
Expand Down Expand Up @@ -1061,7 +1061,7 @@ const ci = {
authenticateWithGoogleCloud,
{
name: "Setup gcloud",
uses: "google-github-actions/setup-gcloud@v1",
uses: "google-github-actions/setup-gcloud@v2",
with: {
project_id: "denoland",
},
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ jobs:
(github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/')))
name: Authenticate with Google Cloud
uses: google-github-actions/auth@v1
uses: google-github-actions/auth@v2
with:
project_id: denoland
credentials_json: '${{ secrets.GCP_SA_KEY }}'
Expand All @@ -223,7 +223,7 @@ jobs:
github.repository == 'denoland/deno' &&
(github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/')))
uses: google-github-actions/setup-gcloud@v1
uses: google-github-actions/setup-gcloud@v2
with:
project_id: denoland
- name: Setup gcloud (windows)
Expand All @@ -234,7 +234,7 @@ jobs:
github.repository == 'denoland/deno' &&
(github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/')))
uses: google-github-actions/setup-gcloud@v1
uses: google-github-actions/setup-gcloud@v2
env:
CLOUDSDK_PYTHON: '${{env.pythonLocation}}\python.exe'
with:
Expand Down Expand Up @@ -672,14 +672,14 @@ jobs:
if: github.repository == 'denoland/deno' && github.ref == 'refs/heads/main'
steps:
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v1
uses: google-github-actions/auth@v2
with:
project_id: denoland
credentials_json: '${{ secrets.GCP_SA_KEY }}'
export_environment_variables: true
create_credentials_file: true
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v1
uses: google-github-actions/setup-gcloud@v2
with:
project_id: denoland
- name: Upload canary version file to dl.deno.land
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/bench/deno_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Deno.bench("b64_rt_short", { n: 1e6 }, () => {
const dataChunk = new Uint8Array(100);
const file = Deno.openSync("/dev/null", { write: true });
Deno.bench("write_null", { n: 5e5 }, () => {
Deno.writeSync(file.rid, dataChunk);
file.writeSync(dataChunk);
});
}

Expand Down
10 changes: 5 additions & 5 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ declare namespace Deno {
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
* );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello world"));
* file.writeSync(new TextEncoder().encode("Hello world"));
*
* // advance cursor 6 bytes
* const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.Start);
Expand All @@ -2159,7 +2159,7 @@ declare namespace Deno {
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
* );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello world"));
* file.writeSync(new TextEncoder().encode("Hello world"));
*
* // Seek 6 bytes from the start of the file
* console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.Start)); // "6"
Expand Down Expand Up @@ -2209,7 +2209,7 @@ declare namespace Deno {
* "my_file.txt",
* { read: true, write: true, create: true },
* );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* file.writeSync(new TextEncoder().encode("Hello World"));
* file.truncateSync(1);
* Deno.fsyncSync(file.rid);
* console.log(Deno.readTextFileSync("my_file.txt")); // H
Expand Down Expand Up @@ -2244,7 +2244,7 @@ declare namespace Deno {
* "my_file.txt",
* { read: true, write: true, create: true },
* );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* file.writeSync(new TextEncoder().encode("Hello World"));
* Deno.fdatasyncSync(file.rid);
* console.log(Deno.readTextFileSync("my_file.txt")); // Hello World
* ```
Expand Down Expand Up @@ -5471,7 +5471,7 @@ declare namespace Deno {
* "my_file.txt",
* { read: true, write: true, create: true }
* );
* Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
* file.writeSync(new TextEncoder().encode("Hello World"));
* Deno.ftruncateSync(file.rid, 7);
* Deno.seekSync(file.rid, 0, Deno.SeekMode.Start);
* const data = new Uint8Array(32);
Expand Down
6 changes: 3 additions & 3 deletions ext/net/01_net.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class Listener {
}
}

class Datagram {
class DatagramConn {
#rid = 0;
#addr = null;
#unref = false;
Expand Down Expand Up @@ -553,15 +553,15 @@ function createListenDatagram(udpOpFn, unixOpFn) {
args.loopback ?? false,
);
addr.transport = "udp";
return new Datagram(rid, addr);
return new DatagramConn(rid, addr);
}
case "unixpacket": {
const { 0: rid, 1: path } = unixOpFn(args.path);
const addr = {
transport: "unixpacket",
path,
};
return new Datagram(rid, addr);
return new DatagramConn(rid, addr);
}
default:
throw new TypeError(`Unsupported transport: '${transport}'`);
Expand Down
1 change: 1 addition & 0 deletions ext/node/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ deno_core::extension!(deno_node,
ops::require::op_require_package_imports_resolve<P>,
ops::require::op_require_break_on_next_statement,
ops::util::op_node_guess_handle_type,
ops::worker_threads::op_worker_threads_filename<P>,
ops::crypto::op_node_create_private_key,
ops::crypto::op_node_create_public_key,
ops::ipc::op_node_child_ipc_pipe,
Expand Down
14 changes: 8 additions & 6 deletions ext/node/ops/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use deno_core::OpState;
use deno_core::ResourceId;
use deno_core::StringOrBuffer;
use deno_core::ToJsBuffer;
use elliptic_curve::sec1::ToEncodedPoint;
use hkdf::Hkdf;
use num_bigint::BigInt;
use num_bigint_dig::BigUint;
Expand Down Expand Up @@ -739,8 +740,6 @@ pub async fn op_node_dsa_generate_async(
fn ec_generate(
named_curve: &str,
) -> Result<(ToJsBuffer, ToJsBuffer), AnyError> {
use elliptic_curve::sec1::ToEncodedPoint;

let mut rng = rand::thread_rng();
// TODO(@littledivy): Support public key point encoding.
// Default is uncompressed.
Expand Down Expand Up @@ -1054,36 +1053,38 @@ pub fn op_node_ecdh_generate_keys(
#[string] curve: &str,
#[buffer] pubbuf: &mut [u8],
#[buffer] privbuf: &mut [u8],
#[string] format: &str,
) -> Result<ResourceId, AnyError> {
let mut rng = rand::thread_rng();
let compress = format == "compressed";
match curve {
"secp256k1" => {
let privkey =
elliptic_curve::SecretKey::<k256::Secp256k1>::random(&mut rng);
let pubkey = privkey.public_key();
pubbuf.copy_from_slice(pubkey.to_sec1_bytes().as_ref());
pubbuf.copy_from_slice(pubkey.to_encoded_point(compress).as_ref());
privbuf.copy_from_slice(privkey.to_nonzero_scalar().to_bytes().as_ref());

Ok(0)
}
"prime256v1" | "secp256r1" => {
let privkey = elliptic_curve::SecretKey::<NistP256>::random(&mut rng);
let pubkey = privkey.public_key();
pubbuf.copy_from_slice(pubkey.to_sec1_bytes().as_ref());
pubbuf.copy_from_slice(pubkey.to_encoded_point(compress).as_ref());
privbuf.copy_from_slice(privkey.to_nonzero_scalar().to_bytes().as_ref());
Ok(0)
}
"secp384r1" => {
let privkey = elliptic_curve::SecretKey::<NistP384>::random(&mut rng);
let pubkey = privkey.public_key();
pubbuf.copy_from_slice(pubkey.to_sec1_bytes().as_ref());
pubbuf.copy_from_slice(pubkey.to_encoded_point(compress).as_ref());
privbuf.copy_from_slice(privkey.to_nonzero_scalar().to_bytes().as_ref());
Ok(0)
}
"secp224r1" => {
let privkey = elliptic_curve::SecretKey::<NistP224>::random(&mut rng);
let pubkey = privkey.public_key();
pubbuf.copy_from_slice(pubkey.to_sec1_bytes().as_ref());
pubbuf.copy_from_slice(pubkey.to_encoded_point(compress).as_ref());
privbuf.copy_from_slice(privkey.to_nonzero_scalar().to_bytes().as_ref());
Ok(0)
}
Expand Down Expand Up @@ -1606,6 +1607,7 @@ pub fn op_node_create_public_key(
named_curve: named_curve.to_string(),
})
}
DH_KEY_AGREEMENT_OID => Ok(AsymmetricKeyDetails::Dh),
_ => Err(type_error("Unsupported algorithm")),
}
}
1 change: 1 addition & 0 deletions ext/node/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub mod require;
pub mod util;
pub mod v8;
pub mod winerror;
pub mod worker_threads;
pub mod zlib;
4 changes: 3 additions & 1 deletion ext/node/ops/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ pub fn op_require_resolve_deno_dir(
resolver
.resolve_package_folder_from_package(
&request,
&ModuleSpecifier::from_file_path(parent_filename).unwrap(),
&ModuleSpecifier::from_file_path(&parent_filename).unwrap_or_else(|_| {
panic!("Url::from_file_path: [{:?}]", parent_filename)
}),
NodeResolutionMode::Execution,
)
.ok()
Expand Down
87 changes: 87 additions & 0 deletions ext/node/ops/worker_threads.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::url::Url;
use deno_core::OpState;
use deno_fs::FileSystemRc;
use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;

use crate::resolution;
use crate::NodePermissions;
use crate::NodeResolver;
use crate::NpmResolverRc;

fn ensure_read_permission<P>(
state: &mut OpState,
file_path: &Path,
) -> Result<(), AnyError>
where
P: NodePermissions + 'static,
{
let resolver = state.borrow::<NpmResolverRc>();
let permissions = state.borrow::<P>();
resolver.ensure_read_permission(permissions, file_path)
}

#[op2]
#[string]
pub fn op_worker_threads_filename<P>(
state: &mut OpState,
#[string] specifier: String,
) -> Result<String, AnyError>
where
P: NodePermissions + 'static,
{
if specifier.starts_with("data:") {
return Ok(specifier);
}
let url: Url = if specifier.starts_with("file:") {
Url::parse(&specifier)?
} else {
let path = PathBuf::from(&specifier);
if path.is_relative() && !specifier.starts_with('.') {
return Err(generic_error(
"Relative path entries must start with '.' or '..'",
));
}
ensure_read_permission::<P>(state, &path)?;
let fs = state.borrow::<FileSystemRc>();
let canonicalized_path =
deno_core::strip_unc_prefix(fs.realpath_sync(&path)?);
Url::from_file_path(canonicalized_path)
.map_err(|e| generic_error(format!("URL from Path-String: {:#?}", e)))?
};
let url_path = url
.to_file_path()
.map_err(|e| generic_error(format!("URL to Path-String: {:#?}", e)))?;
ensure_read_permission::<P>(state, &url_path)?;
let fs = state.borrow::<FileSystemRc>();
if !fs.exists_sync(&url_path) {
return Err(generic_error(format!("File not found [{:?}]", url_path)));
}
let node_resolver = state.borrow::<Rc<NodeResolver>>();
match node_resolver.url_to_node_resolution(url)? {
resolution::NodeResolution::Esm(u) => Ok(u.to_string()),
resolution::NodeResolution::CommonJs(u) => wrap_cjs(u),
_ => Err(generic_error("Neither ESM nor CJS")),
}
}

///
/// Wrap a CJS file-URL and the required setup in a stringified `data:`-URL
///
fn wrap_cjs(url: Url) -> Result<String, AnyError> {
let path = url
.to_file_path()
.map_err(|e| generic_error(format!("URL to Path: {:#?}", e)))?;
let filename = path.file_name().unwrap().to_string_lossy();
Ok(format!(
"data:text/javascript,import {{ createRequire }} from \"node:module\";\
const require = createRequire(\"{}\"); require(\"./{}\");",
url, filename,
))
}

0 comments on commit 5876131

Please sign in to comment.