Repository: denoland/deno_core (rust)

Issue:
`op2`: String exceeding max length should throw `TypeError`, not `Error`

Pull request description:
fix(ops): use type_error everywhere
Fixes #177 

Patch:
diff --git a/ops/op2/dispatch_slow.rs b/ops/op2/dispatch_slow.rs
index ef8add3..b7662c6 100644
--- a/ops/op2/dispatch_slow.rs
+++ b/ops/op2/dispatch_slow.rs
@@ -726,7 +726,7 @@ fn throw_type_error_string(
     #maybe_scope
     // TODO(mmastrac): This might be allocating too much, even if it's on the error path
     let msg = #deno_core::v8::String::new(&mut #scope, &format!("{}", #deno_core::anyhow::Error::from(#message))).unwrap();
-    let exc = #deno_core::v8::Exception::error(&mut #scope, msg);
+    let exc = #deno_core::v8::Exception::type_error(&mut #scope, msg);
     #scope.throw_exception(exc);
     return;
   }))
@@ -746,7 +746,7 @@ fn throw_type_error_static_string(
   Ok(gs_quote!(generator_state(deno_core, scope) => {
     #maybe_scope
     let msg = #deno_core::v8::String::new_from_one_byte(&mut #scope, #message.as_bytes(), #deno_core::v8::NewStringType::Normal).unwrap();
-    let exc = #deno_core::v8::Exception::error(&mut #scope, msg);
+    let exc = #deno_core::v8::Exception::type_error(&mut #scope, msg);
     #scope.throw_exception(exc);
     return;
   }))


Test patch:
diff --git a/ops/op2/test_cases/async/async_jsbuffer.out b/ops/op2/test_cases/async/async_jsbuffer.out
index 3600e6d..85b5473 100644
--- a/ops/op2/test_cases/async/async_jsbuffer.out
+++ b/ops/op2/test_cases/async/async_jsbuffer.out
@@ -51,7 +51,7 @@ impl op_async_v8_buffer {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
@@ -78,7 +78,7 @@ impl op_async_v8_buffer {
                             &format!("{}", deno_core::anyhow::Error::from(rv_err)),
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
diff --git a/ops/op2/test_cases/sync/buffers.out b/ops/op2/test_cases/sync/buffers.out
index 3694e2a..0e5d053 100644
--- a/ops/op2/test_cases/sync/buffers.out
+++ b/ops/op2/test_cases/sync/buffers.out
@@ -75,7 +75,7 @@ impl op_buffers {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
@@ -96,7 +96,7 @@ impl op_buffers {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
@@ -164,7 +164,7 @@ impl op_buffers_option {
                                 deno_core::v8::NewStringType::Normal,
                             )
                             .unwrap();
-                        let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                        let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                         scope.throw_exception(exc);
                         return;
                     }
@@ -190,7 +190,7 @@ impl op_buffers_option {
                                 deno_core::v8::NewStringType::Normal,
                             )
                             .unwrap();
-                        let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                        let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                         scope.throw_exception(exc);
                         return;
                     }
diff --git a/ops/op2/test_cases/sync/buffers_copy.out b/ops/op2/test_cases/sync/buffers_copy.out
index fbae008..e1a27fa 100644
--- a/ops/op2/test_cases/sync/buffers_copy.out
+++ b/ops/op2/test_cases/sync/buffers_copy.out
@@ -85,7 +85,7 @@ impl op_buffers {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
@@ -106,7 +106,7 @@ impl op_buffers {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
@@ -127,7 +127,7 @@ impl op_buffers {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
diff --git a/ops/op2/test_cases/sync/serde_v8.out b/ops/op2/test_cases/sync/serde_v8.out
index 1a3adf9..b96e0e4 100644
--- a/ops/op2/test_cases/sync/serde_v8.out
+++ b/ops/op2/test_cases/sync/serde_v8.out
@@ -40,7 +40,7 @@ impl op_serde_v8 {
                             &format!("{}", deno_core::anyhow::Error::from(arg0_err)),
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
@@ -61,7 +61,7 @@ impl op_serde_v8 {
                         &format!("{}", deno_core::anyhow::Error::from(rv_err)),
                     )
                     .unwrap();
-                let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                 scope.throw_exception(exc);
                 return;
             }
diff --git a/ops/op2/test_cases/sync/string_onebyte.out b/ops/op2/test_cases/sync/string_onebyte.out
index 71d04d0..7c00236 100644
--- a/ops/op2/test_cases/sync/string_onebyte.out
+++ b/ops/op2/test_cases/sync/string_onebyte.out
@@ -64,7 +64,7 @@ impl op_string_onebyte {
                             deno_core::v8::NewStringType::Normal,
                         )
                         .unwrap();
-                    let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                    let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                     scope.throw_exception(exc);
                     return;
                 }
diff --git a/ops/op2/test_cases/sync/string_option_return.out b/ops/op2/test_cases/sync/string_option_return.out
index 1dc204d..f69234a 100644
--- a/ops/op2/test_cases/sync/string_option_return.out
+++ b/ops/op2/test_cases/sync/string_option_return.out
@@ -47,7 +47,7 @@ impl op_string_return {
                         &format!("{}", deno_core::anyhow::Error::from(rv_err)),
                     )
                     .unwrap();
-                let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                 scope.throw_exception(exc);
                 return;
             }
diff --git a/ops/op2/test_cases/sync/string_return.out b/ops/op2/test_cases/sync/string_return.out
index 58995a4..40d3564 100644
--- a/ops/op2/test_cases/sync/string_return.out
+++ b/ops/op2/test_cases/sync/string_return.out
@@ -36,7 +36,7 @@ impl op_string_return {
                         &format!("{}", deno_core::anyhow::Error::from(rv_err)),
                     )
                     .unwrap();
-                let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                 scope.throw_exception(exc);
                 return;
             }
@@ -86,7 +86,7 @@ impl op_string_return_ref {
                         &format!("{}", deno_core::anyhow::Error::from(rv_err)),
                     )
                     .unwrap();
-                let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                 scope.throw_exception(exc);
                 return;
             }
@@ -136,7 +136,7 @@ impl op_string_return_cow {
                         &format!("{}", deno_core::anyhow::Error::from(rv_err)),
                     )
                     .unwrap();
-                let exc = deno_core::v8::Exception::error(&mut scope, msg);
+                let exc = deno_core::v8::Exception::type_error(&mut scope, msg);
                 scope.throw_exception(exc);
                 return;
             }