1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-19 05:45:09 -05:00

fix: FastString v8_string() should error when cannot allocated (#27375)

Upgrades deno_core to 0.326.0
This commit is contained in:
Divy Srivastava 2024-12-16 05:51:49 -08:00 committed by GitHub
parent 7949f53cab
commit 50871b2aa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 17 deletions

17
Cargo.lock generated
View file

@ -1483,9 +1483,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_core" name = "deno_core"
version = "0.324.0" version = "0.326.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24503eda646f246aa6eb0f794909f9a857c8f05095fed66f36e0eaef92edce23" checksum = "ed157162dc5320a2b46ffeeaec24788339df0f2437cfaea78a8d82696715ad7f"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"az", "az",
@ -1493,6 +1493,7 @@ dependencies = [
"bit-set", "bit-set",
"bit-vec", "bit-vec",
"bytes", "bytes",
"capacity_builder",
"cooked-waker", "cooked-waker",
"deno_core_icudata", "deno_core_icudata",
"deno_ops", "deno_ops",
@ -2052,9 +2053,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_ops" name = "deno_ops"
version = "0.200.0" version = "0.202.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a529a2c488cd3042f12f35666569ebe5b3cf89d2b7d1cafc1a652f6d7bcc8f" checksum = "4dd8ac1af251e292388e516dd339b9a3b982a6d1e7f8644c08e34671ca39003c"
dependencies = [ dependencies = [
"proc-macro-rules", "proc-macro-rules",
"proc-macro2", "proc-macro2",
@ -6694,9 +6695,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_v8" name = "serde_v8"
version = "0.233.0" version = "0.235.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "307f176b7475480cee690c34c7118f96fe564d1f2a974bf990294b8310ae4983" checksum = "d07afd8b67b4a442ecc2823038473ac0e9e5682de93c213323b60661afdd7eb4"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"serde", "serde",
@ -8281,9 +8282,9 @@ dependencies = [
[[package]] [[package]]
name = "v8" name = "v8"
version = "130.0.1" version = "130.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c23b5c2caff00209b03a716609b275acae94b02dd3b63c4648e7232a84a8402f" checksum = "2ee0be58935708fa4d7efb970c6cf9f2d9511d24ee24246481a65b6ee167348d"
dependencies = [ dependencies = [
"bindgen", "bindgen",
"bitflags 2.6.0", "bitflags 2.6.0",

View file

@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies] [workspace.dependencies]
deno_ast = { version = "=0.44.0", features = ["transpiling"] } deno_ast = { version = "=0.44.0", features = ["transpiling"] }
deno_core = { version = "0.324.0" } deno_core = { version = "0.326.0" }
deno_bench_util = { version = "0.176.0", path = "./bench_util" } deno_bench_util = { version = "0.176.0", path = "./bench_util" }
deno_config = { version = "=0.39.3", features = ["workspace", "sync"] } deno_config = { version = "=0.39.3", features = ["workspace", "sync"] }

View file

@ -4496,6 +4496,7 @@ impl<'a> ToV8<'a> for TscRequestArray {
let method_name = deno_core::FastString::from_static(method_name) let method_name = deno_core::FastString::from_static(method_name)
.v8_string(scope) .v8_string(scope)
.unwrap()
.into(); .into();
let args = args.unwrap_or_else(|| v8::Array::new(scope, 0).into()); let args = args.unwrap_or_else(|| v8::Array::new(scope, 0).into());
let scope_url = serde_v8::to_v8(scope, self.scope) let scope_url = serde_v8::to_v8(scope, self.scope)

View file

@ -1411,19 +1411,13 @@ impl<'s> ToV8<'s> for V8MaybeStaticStr {
self, self,
scope: &mut v8::HandleScope<'s>, scope: &mut v8::HandleScope<'s>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> { ) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
// todo(https://github.com/denoland/deno_core/pull/986): remove this check
// when upgrading deno_core
const MAX_V8_STRING_LENGTH: usize = 536870888;
if self.0.len() > MAX_V8_STRING_LENGTH {
return Err(FastStringV8AllocationError);
}
Ok( Ok(
match self.0 { match self.0 {
Cow::Borrowed(text) => FastString::from_static(text), Cow::Borrowed(text) => FastString::from_static(text),
Cow::Owned(value) => value.into(), Cow::Owned(value) => value.into(),
} }
.v8_string(scope) .v8_string(scope)
.map_err(|_| FastStringV8AllocationError)?
.into(), .into(),
) )
} }

View file

@ -68,6 +68,7 @@ impl v8::ValueSerializerImpl for SerializerDelegate {
let obj = self.obj(scope); let obj = self.obj(scope);
let key = FastString::from_static("_getSharedArrayBufferId") let key = FastString::from_static("_getSharedArrayBufferId")
.v8_string(scope) .v8_string(scope)
.unwrap()
.into(); .into();
if let Some(v) = obj.get(scope, key) { if let Some(v) = obj.get(scope, key) {
if let Ok(fun) = v.try_cast::<v8::Function>() { if let Ok(fun) = v.try_cast::<v8::Function>() {
@ -89,6 +90,7 @@ impl v8::ValueSerializerImpl for SerializerDelegate {
let obj = self.obj(scope); let obj = self.obj(scope);
let key = FastString::from_static("_getDataCloneError") let key = FastString::from_static("_getDataCloneError")
.v8_string(scope) .v8_string(scope)
.unwrap()
.into(); .into();
if let Some(v) = obj.get(scope, key) { if let Some(v) = obj.get(scope, key) {
let fun = v let fun = v
@ -112,6 +114,7 @@ impl v8::ValueSerializerImpl for SerializerDelegate {
let obj = self.obj(scope); let obj = self.obj(scope);
let key = FastString::from_static("_writeHostObject") let key = FastString::from_static("_writeHostObject")
.v8_string(scope) .v8_string(scope)
.unwrap()
.into(); .into();
if let Some(v) = obj.get(scope, key) { if let Some(v) = obj.get(scope, key) {
if let Ok(v) = v.try_cast::<v8::Function>() { if let Ok(v) = v.try_cast::<v8::Function>() {
@ -240,6 +243,7 @@ impl v8::ValueDeserializerImpl for DeserializerDelegate {
let obj = v8::Local::new(scope, &self.obj); let obj = v8::Local::new(scope, &self.obj);
let key = FastString::from_static("_readHostObject") let key = FastString::from_static("_readHostObject")
.v8_string(scope) .v8_string(scope)
.unwrap()
.into(); .into();
let scope = &mut v8::AllowJavascriptExecutionScope::new(scope); let scope = &mut v8::AllowJavascriptExecutionScope::new(scope);
if let Some(v) = obj.get(scope, key) { if let Some(v) = obj.get(scope, key) {
@ -250,7 +254,8 @@ impl v8::ValueDeserializerImpl for DeserializerDelegate {
Err(_) => { Err(_) => {
let msg = let msg =
FastString::from_static("readHostObject must return an object") FastString::from_static("readHostObject must return an object")
.v8_string(scope); .v8_string(scope)
.unwrap();
let error = v8::Exception::type_error(scope, msg); let error = v8::Exception::type_error(scope, msg);
scope.throw_exception(error); scope.throw_exception(error);
return None; return None;