From 74129c4bed17cf5df892ff5af7a835511bb789ba Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Wed, 15 May 2024 13:52:21 +0000 Subject: [PATCH 01/10] fix: panic, unwrap to unwrap_or --- core/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/error.rs b/core/error.rs index 6d8a3aa00..2e6f2a5e3 100644 --- a/core/error.rs +++ b/core/error.rs @@ -444,7 +444,7 @@ impl JsError { // Convert them into Vec let mut frames: Vec = match frames_v8 { - Some(frames_v8) => serde_v8::from_v8(scope, frames_v8.into()).unwrap(), + Some(frames_v8) => serde_v8::from_v8(scope, frames_v8.into()).unwrap_or(Vec::new()), None => vec![], }; let mut source_line = None; From e90685e5dc2ee6fd59d0f0496deae4828e93dd5f Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Fri, 17 May 2024 23:54:22 +0000 Subject: [PATCH 02/10] test: add error_variable_is_not_defined --- .../error_variable_is_not_defined.out | 2 ++ .../error_variable_is_not_defined.ts | 11 +++++++++++ testing/lib.rs | 1 + 3 files changed, 14 insertions(+) create mode 100644 testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out create mode 100644 testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts diff --git a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out new file mode 100644 index 000000000..4281bbdde --- /dev/null +++ b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out @@ -0,0 +1,2 @@ +[ERR] ReferenceError: variable is not defined +[ERR] at test:///integration/error_variable_is_not_defined/error_variable_is_not_defined.ts:11:1 diff --git a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts new file mode 100644 index 000000000..e913fe482 --- /dev/null +++ b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts @@ -0,0 +1,11 @@ +// This test refers to the issue. +// https://github.com/denoland/deno_core/issues/744 + +// Using `Object.prototype.__defineSetter__()`, +// When converting from `serde_v8::from_v8` to `Vec`, +// Panic is caused by `unwrap_failed`. +Object.prototype.__defineSetter__(0, function () {}); + +// Test that JavaScript syntax error statements are output with no panic +// For example, `ReferenceError: variable is not defined`. +variable; diff --git a/testing/lib.rs b/testing/lib.rs index 159c76e13..e9e5066e0 100644 --- a/testing/lib.rs +++ b/testing/lib.rs @@ -61,6 +61,7 @@ integration_test!( error_ext_stack, error_with_stack, error_without_stack, + error_variable_is_not_defined, main_module_handler, module_types, pending_unref_op_tla, From 86a08e1f212ee82f83baed59613313acd98cd149 Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Mon, 20 May 2024 13:11:00 +0000 Subject: [PATCH 03/10] fix: run cargo fmt --- core/error.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/error.rs b/core/error.rs index 2e6f2a5e3..eecb08ffe 100644 --- a/core/error.rs +++ b/core/error.rs @@ -444,7 +444,9 @@ impl JsError { // Convert them into Vec let mut frames: Vec = match frames_v8 { - Some(frames_v8) => serde_v8::from_v8(scope, frames_v8.into()).unwrap_or(Vec::new()), + Some(frames_v8) => { + serde_v8::from_v8(scope, frames_v8.into()).unwrap_or(Vec::new()) + } None => vec![], }; let mut source_line = None; From a4e9f135bcb08e5d8678ff55fa0b551e8bc06424 Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Tue, 21 May 2024 23:49:41 +0000 Subject: [PATCH 04/10] add copyright for lint --- .../error_variable_is_not_defined.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts index e913fe482..37b10b103 100644 --- a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts +++ b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts @@ -1,3 +1,5 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + // This test refers to the issue. // https://github.com/denoland/deno_core/issues/744 From 5286cde78703d5274db22d5d21a8a5561b3f140e Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Wed, 22 May 2024 00:19:00 +0000 Subject: [PATCH 05/10] fix: Err line --- .../error_variable_is_not_defined.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out index 4281bbdde..6c8751d35 100644 --- a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out +++ b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out @@ -1,2 +1,2 @@ [ERR] ReferenceError: variable is not defined -[ERR] at test:///integration/error_variable_is_not_defined/error_variable_is_not_defined.ts:11:1 +[ERR] at test:///integration/error_variable_is_not_defined/error_variable_is_not_defined.ts:13:1 From a20b70bd5807e89f531d1b3aa845a1bb3b49d0e0 Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Thu, 23 May 2024 14:11:15 +0000 Subject: [PATCH 06/10] change ArrayPrototypePush to a custom implementation --- core/00_primordials.js | 13 +++++++++++++ core/error.rs | 4 +--- .../error_internal_method_set.out | 2 ++ .../error_internal_method_set.ts} | 5 +---- .../error_variable_is_not_defined.out | 2 -- testing/lib.rs | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 testing/integration/error_internal_method_set/error_internal_method_set.out rename testing/integration/{error_variable_is_not_defined/error_variable_is_not_defined.ts => error_internal_method_set/error_internal_method_set.ts} (55%) delete mode 100644 testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out diff --git a/core/00_primordials.js b/core/00_primordials.js index 1afbb0552..e1d947d16 100644 --- a/core/00_primordials.js +++ b/core/00_primordials.js @@ -487,6 +487,19 @@ }, ); + primordials.ArrayPrototypePush = (thisArray, ...variableArgs) => { + const args = [...variableArgs]; + for (let i = 0; i < args.length; i++) { + ObjectDefineProperty(thisArray, thisArray.length, { + value: args[i], + enumerable: true, + writable: true, + configurable: true, + }); + } + return thisArray.length; + }; + primordials.ArrayPrototypeToString = (thisArray) => ArrayPrototypeJoin(thisArray); diff --git a/core/error.rs b/core/error.rs index eecb08ffe..6d8a3aa00 100644 --- a/core/error.rs +++ b/core/error.rs @@ -444,9 +444,7 @@ impl JsError { // Convert them into Vec let mut frames: Vec = match frames_v8 { - Some(frames_v8) => { - serde_v8::from_v8(scope, frames_v8.into()).unwrap_or(Vec::new()) - } + Some(frames_v8) => serde_v8::from_v8(scope, frames_v8.into()).unwrap(), None => vec![], }; let mut source_line = None; diff --git a/testing/integration/error_internal_method_set/error_internal_method_set.out b/testing/integration/error_internal_method_set/error_internal_method_set.out new file mode 100644 index 000000000..10d9cc1ed --- /dev/null +++ b/testing/integration/error_internal_method_set/error_internal_method_set.out @@ -0,0 +1,2 @@ +[ERR] ReferenceError: variable is not defined +[ERR] at test:///integration/error_internal_method_set/error_internal_method_set.ts:10:1 diff --git a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts b/testing/integration/error_internal_method_set/error_internal_method_set.ts similarity index 55% rename from testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts rename to testing/integration/error_internal_method_set/error_internal_method_set.ts index 37b10b103..9a5d61910 100644 --- a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.ts +++ b/testing/integration/error_internal_method_set/error_internal_method_set.ts @@ -3,11 +3,8 @@ // This test refers to the issue. // https://github.com/denoland/deno_core/issues/744 -// Using `Object.prototype.__defineSetter__()`, -// When converting from `serde_v8::from_v8` to `Vec`, -// Panic is caused by `unwrap_failed`. Object.prototype.__defineSetter__(0, function () {}); -// Test that JavaScript syntax error statements are output with no panic +// Need to dare to make errors. // For example, `ReferenceError: variable is not defined`. variable; diff --git a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out b/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out deleted file mode 100644 index 6c8751d35..000000000 --- a/testing/integration/error_variable_is_not_defined/error_variable_is_not_defined.out +++ /dev/null @@ -1,2 +0,0 @@ -[ERR] ReferenceError: variable is not defined -[ERR] at test:///integration/error_variable_is_not_defined/error_variable_is_not_defined.ts:13:1 diff --git a/testing/lib.rs b/testing/lib.rs index e9e5066e0..73de145f8 100644 --- a/testing/lib.rs +++ b/testing/lib.rs @@ -59,9 +59,9 @@ integration_test!( error_rejection_catch, error_rejection_order, error_ext_stack, + error_internal_method_set, error_with_stack, error_without_stack, - error_variable_is_not_defined, main_module_handler, module_types, pending_unref_op_tla, From e245e3b40d39ae3b8a413a407bd8c9478a93cd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BA=E3=81=93?= <73634265+peko-thunder@users.noreply.github.com> Date: Fri, 24 May 2024 09:47:25 +0900 Subject: [PATCH 07/10] fix: Removed unneeded array copy. Co-authored-by: ud2 --- core/00_primordials.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/00_primordials.js b/core/00_primordials.js index e1d947d16..afdf7e338 100644 --- a/core/00_primordials.js +++ b/core/00_primordials.js @@ -487,8 +487,7 @@ }, ); - primordials.ArrayPrototypePush = (thisArray, ...variableArgs) => { - const args = [...variableArgs]; + primordials.ArrayPrototypePush = (thisArray, ...args) => { for (let i = 0; i < args.length; i++) { ObjectDefineProperty(thisArray, thisArray.length, { value: args[i], From 05054fc57bce746ac88832268fe6675eaa959bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BA=E3=81=93?= <73634265+peko-thunder@users.noreply.github.com> Date: Fri, 24 May 2024 09:53:28 +0900 Subject: [PATCH 08/10] fix: `ObjectDefineProperty` disallows access to `get` and `set` of `prototype`. Co-authored-by: ud2 --- core/00_primordials.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/00_primordials.js b/core/00_primordials.js index afdf7e338..910958f7c 100644 --- a/core/00_primordials.js +++ b/core/00_primordials.js @@ -490,6 +490,7 @@ primordials.ArrayPrototypePush = (thisArray, ...args) => { for (let i = 0; i < args.length; i++) { ObjectDefineProperty(thisArray, thisArray.length, { + __proto__: null, value: args[i], enumerable: true, writable: true, From 6ef614030b1bdbbf2699218068cf23330987cb3a Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Fri, 24 May 2024 00:57:50 +0000 Subject: [PATCH 09/10] Revert to because of possible panic. --- core/error.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/error.rs b/core/error.rs index 6d8a3aa00..eecb08ffe 100644 --- a/core/error.rs +++ b/core/error.rs @@ -444,7 +444,9 @@ impl JsError { // Convert them into Vec let mut frames: Vec = match frames_v8 { - Some(frames_v8) => serde_v8::from_v8(scope, frames_v8.into()).unwrap(), + Some(frames_v8) => { + serde_v8::from_v8(scope, frames_v8.into()).unwrap_or(Vec::new()) + } None => vec![], }; let mut source_line = None; From 347693f4b13de342eb324e5cc1b04c8d4ef8a816 Mon Sep 17 00:00:00 2001 From: peko-thunder Date: Sun, 26 May 2024 13:14:40 +0000 Subject: [PATCH 10/10] fix: add ts-nocheck for tsc lint --- .../error_internal_method_set/error_internal_method_set.out | 2 +- .../error_internal_method_set/error_internal_method_set.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/integration/error_internal_method_set/error_internal_method_set.out b/testing/integration/error_internal_method_set/error_internal_method_set.out index 10d9cc1ed..4d41d3ee1 100644 --- a/testing/integration/error_internal_method_set/error_internal_method_set.out +++ b/testing/integration/error_internal_method_set/error_internal_method_set.out @@ -1,2 +1,2 @@ [ERR] ReferenceError: variable is not defined -[ERR] at test:///integration/error_internal_method_set/error_internal_method_set.ts:10:1 +[ERR] at test:///integration/error_internal_method_set/error_internal_method_set.ts:11:1 diff --git a/testing/integration/error_internal_method_set/error_internal_method_set.ts b/testing/integration/error_internal_method_set/error_internal_method_set.ts index 9a5d61910..c44697cac 100644 --- a/testing/integration/error_internal_method_set/error_internal_method_set.ts +++ b/testing/integration/error_internal_method_set/error_internal_method_set.ts @@ -1,4 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// @ts-nocheck: For error validation // This test refers to the issue. // https://github.com/denoland/deno_core/issues/744