Skip to content

Commit

Permalink
fix: FastString v8_string() should error when cannot allocated (#27375)
Browse files Browse the repository at this point in the history
Upgrades deno_core to 0.326.0
  • Loading branch information
littledivy authored Dec 16, 2024
1 parent 7949f53 commit 50871b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
17 changes: 9 additions & 8 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
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_config = { version = "=0.39.3", features = ["workspace", "sync"] }
Expand Down
1 change: 1 addition & 0 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4496,6 +4496,7 @@ impl<'a> ToV8<'a> for TscRequestArray {

let method_name = deno_core::FastString::from_static(method_name)
.v8_string(scope)
.unwrap()
.into();
let args = args.unwrap_or_else(|| v8::Array::new(scope, 0).into());
let scope_url = serde_v8::to_v8(scope, self.scope)
Expand Down
8 changes: 1 addition & 7 deletions ext/fs/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,19 +1411,13 @@ impl<'s> ToV8<'s> for V8MaybeStaticStr {
self,
scope: &mut v8::HandleScope<'s>,
) -> 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(
match self.0 {
Cow::Borrowed(text) => FastString::from_static(text),
Cow::Owned(value) => value.into(),
}
.v8_string(scope)
.map_err(|_| FastStringV8AllocationError)?
.into(),
)
}
Expand Down
7 changes: 6 additions & 1 deletion ext/node/ops/v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl v8::ValueSerializerImpl for SerializerDelegate {
let obj = self.obj(scope);
let key = FastString::from_static("_getSharedArrayBufferId")
.v8_string(scope)
.unwrap()
.into();
if let Some(v) = obj.get(scope, key) {
if let Ok(fun) = v.try_cast::<v8::Function>() {
Expand All @@ -89,6 +90,7 @@ impl v8::ValueSerializerImpl for SerializerDelegate {
let obj = self.obj(scope);
let key = FastString::from_static("_getDataCloneError")
.v8_string(scope)
.unwrap()
.into();
if let Some(v) = obj.get(scope, key) {
let fun = v
Expand All @@ -112,6 +114,7 @@ impl v8::ValueSerializerImpl for SerializerDelegate {
let obj = self.obj(scope);
let key = FastString::from_static("_writeHostObject")
.v8_string(scope)
.unwrap()
.into();
if let Some(v) = obj.get(scope, key) {
if let Ok(v) = v.try_cast::<v8::Function>() {
Expand Down Expand Up @@ -240,6 +243,7 @@ impl v8::ValueDeserializerImpl for DeserializerDelegate {
let obj = v8::Local::new(scope, &self.obj);
let key = FastString::from_static("_readHostObject")
.v8_string(scope)
.unwrap()
.into();
let scope = &mut v8::AllowJavascriptExecutionScope::new(scope);
if let Some(v) = obj.get(scope, key) {
Expand All @@ -250,7 +254,8 @@ impl v8::ValueDeserializerImpl for DeserializerDelegate {
Err(_) => {
let msg =
FastString::from_static("readHostObject must return an object")
.v8_string(scope);
.v8_string(scope)
.unwrap();
let error = v8::Exception::type_error(scope, msg);
scope.throw_exception(error);
return None;
Expand Down

0 comments on commit 50871b2

Please sign in to comment.