diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 5d44c2f76dd7a0..c22247b95c5402 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -903,7 +903,8 @@ bool ContextifyScript::EvalMachine(Environment* env, if (!env->can_call_into_js()) return false; if (!ContextifyScript::InstanceOf(env, args.Holder())) { - env->ThrowTypeError( + THROW_ERR_INVALID_THIS( + env, "Script methods can only be called on script instances."); return false; } diff --git a/src/node_errors.h b/src/node_errors.h index d814d78d9cf412..a47f096b43430b 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -40,6 +40,7 @@ void OnFatalError(const char* location, const char* message); V(ERR_INVALID_ARG_VALUE, TypeError) \ V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \ V(ERR_INVALID_ARG_TYPE, TypeError) \ + V(ERR_INVALID_THIS, TypeError) \ V(ERR_INVALID_TRANSFER_OBJECT, TypeError) \ V(ERR_MEMORY_ALLOCATION_FAILED, Error) \ V(ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE, Error) \ @@ -94,6 +95,7 @@ void OnFatalError(const char* location, const char* message); V(ERR_CRYPTO_UNKNOWN_DH_GROUP, "Unknown DH group") \ V(ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE, \ "Context not associated with Node.js environment") \ + V(ERR_INVALID_THIS, "Value of \"this\" is the wrong type") \ V(ERR_INVALID_TRANSFER_OBJECT, "Found invalid object in transferList") \ V(ERR_MEMORY_ALLOCATION_FAILED, "Failed to allocate memory") \ V(ERR_OSSL_EVP_INVALID_DIGEST, "Invalid digest used") \