Skip to content

Commit

Permalink
[JSC] Implement Error#cause
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=223302

Reviewed by Yusuke Suzuki.

JSTests:

Add tests. test262 doesn't currently have any, but the spec is exceedingly simple anyway.

* stress/error-cause.js: Added.

Source/JavaScriptCore:

This patch implements the Error.prototype.cause proposal, which reached Stage 3 at last week's TC39 meeting:
https://github.com/tc39/proposal-error-cause

This very simple proposal allows to one reference the "error that caused this one" in a cascading scenario.
It does so by adding an options bag parameter to the Error, _NativeError_, and AggregateError constructors.
If it is an object with a `cause` property, the property will be used; if not, nothing happens at all.

* API/JSObjectRef.cpp:
(JSObjectMakeError):
* runtime/AggregateError.cpp:
(JSC::AggregateError::finishCreation):
(JSC::AggregateError::create):
* runtime/AggregateError.h:
* runtime/AggregateErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/CommonIdentifiers.h:
* runtime/Error.cpp:
(JSC::createError):
(JSC::createEvalError):
(JSC::createRangeError):
(JSC::createReferenceError):
(JSC::createSyntaxError):
(JSC::createTypeError):
(JSC::createURIError):
(JSC::createGetterTypeError):
* runtime/ErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::create):
(JSC::ErrorInstance::finishCreation):
* runtime/ErrorInstance.h:
(JSC::ErrorInstance::create):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/NativeErrorConstructor.cpp:
(JSC::NativeErrorConstructor<errorType>::constructImpl):
(JSC::NativeErrorConstructor<errorType>::callImpl):
* runtime/NullSetterFunction.cpp:
(JSC::NullSetterFunctionInternal::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/JSWebAssemblyCompileError.cpp:
(JSC::JSWebAssemblyCompileError::create):
* wasm/js/JSWebAssemblyLinkError.cpp:
(JSC::JSWebAssemblyLinkError::create):
* wasm/js/JSWebAssemblyRuntimeError.cpp:
(JSC::JSWebAssemblyRuntimeError::create):
* wasm/js/WebAssemblyCompileErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyLinkErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):


Canonical link: https://commits.webkit.org/235397@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@274552 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rkirsling committed Mar 17, 2021
1 parent 97be8b9 commit b03c4f4
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 43 deletions.
11 changes: 11 additions & 0 deletions JSTests/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2021-03-16 Ross Kirsling <[email protected]>

[JSC] Implement Error#cause
https://bugs.webkit.org/show_bug.cgi?id=223302

Reviewed by Yusuke Suzuki.

Add tests. test262 doesn't currently have any, but the spec is exceedingly simple anyway.

* stress/error-cause.js: Added.

2021-03-16 Saam Barati <[email protected]>

Object allocation sinking phase should prioritize materializations with no dependencies before materializations with no reverse dependencies
Expand Down
26 changes: 26 additions & 0 deletions JSTests/stress/error-cause.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`expected ${expected} but got ${actual}`);
}

const errorConstructors = [Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError];
const constructError = (E, ...args) => E === AggregateError ? new E([], '', ...args) : new E('', ...args);

for (const E of errorConstructors) {
shouldBe(constructError(E).cause, undefined);
shouldBe(constructError(E, undefined).cause, undefined);
shouldBe(constructError(E, null).cause, undefined);
shouldBe(constructError(E, true).cause, undefined);
shouldBe(constructError(E, 3).cause, undefined);
shouldBe(constructError(E, 'hi').cause, undefined);
shouldBe(constructError(E, {}).cause, undefined);

shouldBe(constructError(E, { cause: undefined }).cause, undefined);
shouldBe(constructError(E, { cause: null }).cause, null);
shouldBe(constructError(E, { cause: true }).cause, true);
shouldBe(constructError(E, { cause: 3 }).cause, 3);
shouldBe(constructError(E, { cause: 'hi' }).cause, 'hi');

const cause = new Error();
shouldBe(constructError(E, { cause }).cause, cause);
}
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/API/JSObjectRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSVa
auto scope = DECLARE_CATCH_SCOPE(vm);

JSValue message = argumentCount ? toJS(globalObject, arguments[0]) : jsUndefined();
JSValue options = argumentCount > 1 ? toJS(globalObject, arguments[1]) : jsUndefined();
Structure* errorStructure = globalObject->errorStructure();
JSObject* result = ErrorInstance::create(globalObject, errorStructure, message);
JSObject* result = ErrorInstance::create(globalObject, errorStructure, message, options);

if (handleExceptionIfNeeded(scope, ctx, exception) == ExceptionStatus::DidThrow)
result = nullptr;
Expand Down
59 changes: 59 additions & 0 deletions Source/JavaScriptCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
2021-03-16 Ross Kirsling <[email protected]>

[JSC] Implement Error#cause
https://bugs.webkit.org/show_bug.cgi?id=223302

Reviewed by Yusuke Suzuki.

This patch implements the Error.prototype.cause proposal, which reached Stage 3 at last week's TC39 meeting:
https://github.com/tc39/proposal-error-cause

This very simple proposal allows to one reference the "error that caused this one" in a cascading scenario.
It does so by adding an options bag parameter to the Error, _NativeError_, and AggregateError constructors.
If it is an object with a `cause` property, the property will be used; if not, nothing happens at all.

* API/JSObjectRef.cpp:
(JSObjectMakeError):
* runtime/AggregateError.cpp:
(JSC::AggregateError::finishCreation):
(JSC::AggregateError::create):
* runtime/AggregateError.h:
* runtime/AggregateErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/CommonIdentifiers.h:
* runtime/Error.cpp:
(JSC::createError):
(JSC::createEvalError):
(JSC::createRangeError):
(JSC::createReferenceError):
(JSC::createSyntaxError):
(JSC::createTypeError):
(JSC::createURIError):
(JSC::createGetterTypeError):
* runtime/ErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::create):
(JSC::ErrorInstance::finishCreation):
* runtime/ErrorInstance.h:
(JSC::ErrorInstance::create):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/NativeErrorConstructor.cpp:
(JSC::NativeErrorConstructor<errorType>::constructImpl):
(JSC::NativeErrorConstructor<errorType>::callImpl):
* runtime/NullSetterFunction.cpp:
(JSC::NullSetterFunctionInternal::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/JSWebAssemblyCompileError.cpp:
(JSC::JSWebAssemblyCompileError::create):
* wasm/js/JSWebAssemblyLinkError.cpp:
(JSC::JSWebAssemblyLinkError::create):
* wasm/js/JSWebAssemblyRuntimeError.cpp:
(JSC::JSWebAssemblyRuntimeError::create):
* wasm/js/WebAssemblyCompileErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyLinkErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

2021-03-16 Saam Barati <[email protected]>

Object allocation sinking phase should prioritize materializations with no dependencies before materializations with no reverse dependencies
Expand Down
18 changes: 9 additions & 9 deletions Source/JavaScriptCore/runtime/AggregateError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ AggregateError::AggregateError(VM& vm, Structure* structure)
{
}

void AggregateError::finishCreation(VM& vm, JSGlobalObject* globalObject, const MarkedArgumentBuffer& errors, const String& message, SourceAppender appender, RuntimeType type, bool useCurrentFrame)
void AggregateError::finishCreation(VM& vm, JSGlobalObject* globalObject, const MarkedArgumentBuffer& errors, const String& message, JSValue cause, SourceAppender appender, RuntimeType type, bool useCurrentFrame)
{
Base::finishCreation(vm, globalObject, message, appender, type, useCurrentFrame);
Base::finishCreation(vm, globalObject, message, cause, appender, type, useCurrentFrame);
ASSERT(inherits(vm, info()));

auto scope = DECLARE_THROW_SCOPE(vm);
putDirect(vm, vm.propertyNames->errors, constructArray(globalObject, static_cast<ArrayAllocationProfile*>(nullptr), errors), static_cast<unsigned>(PropertyAttribute::DontEnum));
RETURN_IF_EXCEPTION(scope, void());
}

AggregateError* AggregateError::create(JSGlobalObject* globalObject, VM& vm, Structure* structure, JSValue errors, JSValue message, SourceAppender appender, RuntimeType type, bool useCurrentFrame)
AggregateError* AggregateError::create(JSGlobalObject* globalObject, VM& vm, Structure* structure, JSValue errors, JSValue message, JSValue options, SourceAppender appender, RuntimeType type, bool useCurrentFrame)
{
auto scope = DECLARE_THROW_SCOPE(vm);

String messageString;
if (!message.isUndefined()) {
messageString = message.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
}
String messageString = message.isUndefined() ? String() : message.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);

JSValue cause = !options.isObject() ? jsUndefined() : options.get(globalObject, vm.propertyNames->cause);
RETURN_IF_EXCEPTION(scope, nullptr);

MarkedArgumentBuffer errorsList;
forEachInIterable(globalObject, errors, [&] (VM&, JSGlobalObject*, JSValue nextValue) {
Expand All @@ -68,7 +68,7 @@ AggregateError* AggregateError::create(JSGlobalObject* globalObject, VM& vm, Str
});
RETURN_IF_EXCEPTION(scope, nullptr);

RELEASE_AND_RETURN(scope, create(globalObject, vm, structure, errorsList, messageString, appender, type, useCurrentFrame));
RELEASE_AND_RETURN(scope, create(globalObject, vm, structure, errorsList, messageString, cause, appender, type, useCurrentFrame));
}

} // namespace JSC
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/runtime/AggregateError.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class AggregateError final : public ErrorInstance {
return Structure::create(vm, globalObject, prototype, TypeInfo(ErrorInstanceType, StructureFlags), info());
}

static AggregateError* create(JSGlobalObject* globalObject, VM& vm, Structure* structure, const MarkedArgumentBuffer& errors, const String& message, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true)
static AggregateError* create(JSGlobalObject* globalObject, VM& vm, Structure* structure, const MarkedArgumentBuffer& errors, const String& message, JSValue cause, SourceAppender appender = nullptr, RuntimeType type = TypeNothing, bool useCurrentFrame = true)
{
auto* instance = new (NotNull, allocateCell<AggregateError>(vm.heap)) AggregateError(vm, structure);
instance->finishCreation(vm, globalObject, errors, message, appender, type, useCurrentFrame);
instance->finishCreation(vm, globalObject, errors, message, cause, appender, type, useCurrentFrame);
return instance;
}

static AggregateError* create(JSGlobalObject*, VM&, Structure*, JSValue errors, JSValue message, SourceAppender = nullptr, RuntimeType = TypeNothing, bool useCurrentFrame = true);
static AggregateError* create(JSGlobalObject*, VM&, Structure*, JSValue errors, JSValue message, JSValue options, SourceAppender = nullptr, RuntimeType = TypeNothing, bool useCurrentFrame = true);

void finishCreation(VM&, JSGlobalObject*, const MarkedArgumentBuffer& errors, const String& message, SourceAppender = nullptr, RuntimeType = TypeNothing, bool useCurrentFrame = true);
void finishCreation(VM&, JSGlobalObject*, const MarkedArgumentBuffer& errors, const String& message, JSValue cause, SourceAppender = nullptr, RuntimeType = TypeNothing, bool useCurrentFrame = true);

private:
explicit AggregateError(VM&, Structure*);
Expand Down
6 changes: 4 additions & 2 deletions Source/JavaScriptCore/runtime/AggregateErrorConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ JSC_DEFINE_HOST_FUNCTION(callAggregateErrorConstructor, (JSGlobalObject* globalO
VM& vm = globalObject->vm();
JSValue errors = callFrame->argument(0);
JSValue message = callFrame->argument(1);
JSValue options = callFrame->argument(2);
Structure* errorStructure = globalObject->errorStructure(ErrorType::AggregateError);
return JSValue::encode(AggregateError::create(globalObject, vm, errorStructure, errors, message, nullptr, TypeNothing, false));
return JSValue::encode(AggregateError::create(globalObject, vm, errorStructure, errors, message, options, nullptr, TypeNothing, false));
}

JSC_DEFINE_HOST_FUNCTION(constructAggregateErrorConstructor, (JSGlobalObject* globalObject, CallFrame* callFrame))
Expand All @@ -70,13 +71,14 @@ JSC_DEFINE_HOST_FUNCTION(constructAggregateErrorConstructor, (JSGlobalObject* gl
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue errors = callFrame->argument(0);
JSValue message = callFrame->argument(1);
JSValue options = callFrame->argument(2);

JSObject* newTarget = asObject(callFrame->newTarget());
Structure* errorStructure = JSC_GET_DERIVED_STRUCTURE(vm, errorStructureWithErrorType<ErrorType::AggregateError>, newTarget, callFrame->jsCallee());
RETURN_IF_EXCEPTION(scope, { });
ASSERT(errorStructure);

RELEASE_AND_RETURN(scope, JSValue::encode(AggregateError::create(globalObject, vm, errorStructure, errors, message, nullptr, TypeNothing, false)));
RELEASE_AND_RETURN(scope, JSValue::encode(AggregateError::create(globalObject, vm, errorStructure, errors, message, options, nullptr, TypeNothing, false)));
}

} // namespace JSC
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/CommonIdentifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
macro(callee) \
macro(caller) \
macro(caseFirst) \
macro(cause) \
macro(clear) \
macro(collation) \
macro(column) \
Expand Down
16 changes: 8 additions & 8 deletions Source/JavaScriptCore/runtime/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,37 @@ namespace JSC {
JSObject* createError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(), message, appender, TypeNothing, ErrorType::Error, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(), message, jsUndefined(), appender, TypeNothing, ErrorType::Error, true);
}

JSObject* createEvalError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::EvalError), message, appender, TypeNothing, ErrorType::EvalError, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::EvalError), message, jsUndefined(), appender, TypeNothing, ErrorType::EvalError, true);
}

JSObject* createRangeError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::RangeError), message, appender, TypeNothing, ErrorType::RangeError, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::RangeError), message, jsUndefined(), appender, TypeNothing, ErrorType::RangeError, true);
}

JSObject* createReferenceError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::ReferenceError), message, appender, TypeNothing, ErrorType::ReferenceError, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::ReferenceError), message, jsUndefined(), appender, TypeNothing, ErrorType::ReferenceError, true);
}

JSObject* createSyntaxError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::SyntaxError), message, appender, TypeNothing, ErrorType::SyntaxError, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::SyntaxError), message, jsUndefined(), appender, TypeNothing, ErrorType::SyntaxError, true);
}

JSObject* createTypeError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender, RuntimeType type)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::TypeError), message, appender, type, ErrorType::TypeError, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::TypeError), message, jsUndefined(), appender, type, ErrorType::TypeError, true);
}

JSObject* createNotEnoughArgumentsError(JSGlobalObject* globalObject, ErrorInstance::SourceAppender appender)
Expand All @@ -76,7 +76,7 @@ JSObject* createNotEnoughArgumentsError(JSGlobalObject* globalObject, ErrorInsta
JSObject* createURIError(JSGlobalObject* globalObject, const String& message, ErrorInstance::SourceAppender appender)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::URIError), message, appender, TypeNothing, ErrorType::URIError, true);
return ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::URIError), message, jsUndefined(), appender, TypeNothing, ErrorType::URIError, true);
}

JSObject* createError(JSGlobalObject* globalObject, ErrorType errorType, const String& message)
Expand Down Expand Up @@ -113,7 +113,7 @@ JSObject* createError(JSGlobalObject* globalObject, ErrorTypeWithExtension error
JSObject* createGetterTypeError(JSGlobalObject* globalObject, const String& message)
{
ASSERT(!message.isEmpty());
auto* error = ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::TypeError), message, nullptr, TypeNothing, ErrorType::TypeError);
auto* error = ErrorInstance::create(globalObject, globalObject->vm(), globalObject->errorStructure(ErrorType::TypeError), message, jsUndefined(), nullptr, TypeNothing, ErrorType::TypeError);
error->setNativeGetterTypeError();
return error;
}
Expand Down
6 changes: 4 additions & 2 deletions Source/JavaScriptCore/runtime/ErrorConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ JSC_DEFINE_HOST_FUNCTION(constructErrorConstructor, (JSGlobalObject* globalObjec
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue message = callFrame->argument(0);
JSValue options = callFrame->argument(1);

JSObject* newTarget = asObject(callFrame->newTarget());
Structure* errorStructure = JSC_GET_DERIVED_STRUCTURE(vm, errorStructure, newTarget, callFrame->jsCallee());
RETURN_IF_EXCEPTION(scope, { });

RELEASE_AND_RETURN(scope, JSValue::encode(ErrorInstance::create(globalObject, errorStructure, message, nullptr, TypeNothing, ErrorType::Error, false)));
RELEASE_AND_RETURN(scope, JSValue::encode(ErrorInstance::create(globalObject, errorStructure, message, options, nullptr, TypeNothing, ErrorType::Error, false)));
}

JSC_DEFINE_HOST_FUNCTION(callErrorConstructor, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
JSValue message = callFrame->argument(0);
JSValue options = callFrame->argument(1);
Structure* errorStructure = globalObject->errorStructure();
return JSValue::encode(ErrorInstance::create(globalObject, errorStructure, message, nullptr, TypeNothing, ErrorType::Error, false));
return JSValue::encode(ErrorInstance::create(globalObject, errorStructure, message, options, nullptr, TypeNothing, ErrorType::Error, false));
}

bool ErrorConstructor::put(JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
Expand Down
14 changes: 11 additions & 3 deletions Source/JavaScriptCore/runtime/ErrorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ ErrorInstance::ErrorInstance(VM& vm, Structure* structure, ErrorType errorType)
{
}

ErrorInstance* ErrorInstance::create(JSGlobalObject* globalObject, Structure* structure, JSValue message, SourceAppender appender, RuntimeType type, ErrorType errorType, bool useCurrentFrame)
ErrorInstance* ErrorInstance::create(JSGlobalObject* globalObject, Structure* structure, JSValue message, JSValue options, SourceAppender appender, RuntimeType type, ErrorType errorType, bool useCurrentFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

String messageString = message.isUndefined() ? String() : message.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
return create(globalObject, vm, structure, messageString, appender, type, errorType, useCurrentFrame);

JSValue cause = !options.isObject() ? jsUndefined() : options.get(globalObject, vm.propertyNames->cause);
RETURN_IF_EXCEPTION(scope, nullptr);

return create(globalObject, vm, structure, messageString, cause, appender, type, errorType, useCurrentFrame);
}

static String appendSourceToErrorMessage(CallFrame* callFrame, ErrorInstance* exception, BytecodeIndex bytecodeIndex, const String& message)
Expand Down Expand Up @@ -105,7 +110,7 @@ static String appendSourceToErrorMessage(CallFrame* callFrame, ErrorInstance* ex
return appender(message, codeBlock->source().provider()->getRange(start, stop).toString(), type, ErrorInstance::FoundApproximateSource);
}

void ErrorInstance::finishCreation(VM& vm, JSGlobalObject* globalObject, const String& message, SourceAppender appender, RuntimeType type, bool useCurrentFrame)
void ErrorInstance::finishCreation(VM& vm, JSGlobalObject* globalObject, const String& message, JSValue cause, SourceAppender appender, RuntimeType type, bool useCurrentFrame)
{
Base::finishCreation(vm);
ASSERT(inherits(vm, info()));
Expand All @@ -131,6 +136,9 @@ void ErrorInstance::finishCreation(VM& vm, JSGlobalObject* globalObject, const S

if (!messageWithSource.isNull())
putDirect(vm, vm.propertyNames->message, jsString(vm, messageWithSource), static_cast<unsigned>(PropertyAttribute::DontEnum));

if (!cause.isUndefined())
putDirect(vm, vm.propertyNames->cause, cause, static_cast<unsigned>(PropertyAttribute::DontEnum));
}

// Based on ErrorPrototype's errorProtoFuncToString(), but is modified to
Expand Down
Loading

0 comments on commit b03c4f4

Please sign in to comment.