Skip to content
File

Blob: patches/v8/0012-Update-illegal-invocation-error-message-in-v8.patch

4.2 KB
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: James M Snell <jasnell@gmail.com>
3Date: Tue, 9 Jul 2024 08:37:05 -0700
4Subject: Update illegal invocation error message in v8
5 
6Signed-off-by: James M Snell <jsnell@cloudflare.com>
7 
8diff --git a/src/common/message-template.h b/src/common/message-template.h
9index 03d61c6130d8b3e082200599771f683536b6ac12..85e1f080247e598e94dfef776bb40bebb1aec453 100644
10--- a/src/common/message-template.h
11+++ b/src/common/message-template.h
12@@ -125,7 +125,11 @@ namespace internal {
13 "First argument to % must not be a regular expression") \
14 T(FunctionBind, "Bind must be called on a function") \
15 T(GeneratorRunning, "Generator is already running") \
16- T(IllegalInvocation, "Illegal invocation") \
17+ T(IllegalInvocation, \
18+ "Illegal invocation: function called with incorrect `this` reference. " \
19+ "See " \
20+ "https://developers.cloudflare.com/workers/observability/errors/" \
21+ "#illegal-invocation-errors for details.") \
22 T(ImmutablePrototypeSet, \
23 "Immutable prototype object '%' cannot have their prototype set") \
24 T(ImportAttributesDuplicateKey, "Import attribute has duplicate key '%'") \
25diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
26index def78150b205855608f4fe475ecc6e9af5ba20b9..949aa3a74d2233d09061b1ca15dc6a0d8feed554 100644
27--- a/test/cctest/test-api.cc
28+++ b/test/cctest/test-api.cc
29@@ -223,6 +223,17 @@ THREADED_TEST(IsolateOfContext) {
30 CHECK(isolate->IsCurrent());
31 }
32
33+static bool ExceptionStartsWithIllegalInvocation(v8::Isolate* isolate,
34+ v8::TryCatch& try_catch) {
35+ v8::Local<v8::String> error_text =
36+ try_catch.Exception()
37+ ->ToString(isolate->GetCurrentContext())
38+ .ToLocalChecked();
39+ const char* prefix = "TypeError: Illegal invocation";
40+ return strncmp(prefix, *v8::String::Utf8Value(isolate, error_text),
41+ strlen(prefix)) == 0;
42+}
43+
44 static void TestSignatureLooped(const char* operation, Local<Value> receiver,
45 v8::Isolate* isolate) {
46 auto source = v8::base::OwnedVector<char>::NewForOverwrite(200);
47@@ -240,12 +251,7 @@ static void TestSignatureLooped(const char* operation, Local<Value> receiver,
48 if (!expected_to_throw) {
49 CHECK_EQ(10, signature_callback_count);
50 } else {
51- CHECK(v8_str("TypeError: Illegal invocation")
52- ->Equals(isolate->GetCurrentContext(),
53- try_catch.Exception()
54- ->ToString(isolate->GetCurrentContext())
55- .ToLocalChecked())
56- .FromJust());
57+ CHECK(ExceptionStartsWithIllegalInvocation(isolate, try_catch));
58 }
59 signature_expected_receiver_global.Reset();
60 }
61@@ -272,12 +278,7 @@ static void TestSignatureOptimized(const char* operation, Local<Value> receiver,
62 if (!expected_to_throw) {
63 CHECK_EQ(3, signature_callback_count);
64 } else {
65- CHECK(v8_str("TypeError: Illegal invocation")
66- ->Equals(isolate->GetCurrentContext(),
67- try_catch.Exception()
68- ->ToString(isolate->GetCurrentContext())
69- .ToLocalChecked())
70- .FromJust());
71+ CHECK(ExceptionStartsWithIllegalInvocation(isolate, try_catch));
72 }
73 signature_expected_receiver_global.Reset();
74 }
75diff --git a/test/mjsunit/ic-megadom-3.js b/test/mjsunit/ic-megadom-3.js
76index f7a7634e7e11845e4b364fcc6942f1170b9ee8da..e811f9e04d60f7a2eaf3a5a48e3c09d23a7c854d 100644
77--- a/test/mjsunit/ic-megadom-3.js
78+++ b/test/mjsunit/ic-megadom-3.js
79@@ -42,7 +42,7 @@ function test() {
80 load(new d8.dom.EventTarget());
81 } catch (err) {
82 assertInstanceof(err, TypeError);
83- assertEquals("Illegal invocation", err.message, 'Error message');
84+ assertTrue(err.message.startsWith("Illegal invocation"), 'Error message');
85 }
86
87 return result;