Skip to content

Implementation of Error cause proposal #6621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 14, 2021

Conversation

MadProbe
Copy link
Contributor

Error cause proposal is stage 3.

There are no 262 tests to check against yet.

@MadProbe
Copy link
Contributor Author

@rhuanjl can you review this PR?

Copy link
Collaborator

@rhuanjl rhuanjl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Just a few things it would be good to tidy up + it should have more tests (see comments for suggestions).

{
name: "Error().cause === undefined",
body: function () {
assert.isFalse("cause" in SyntaxError(), "Error().cause should not be defined if specified by cause property of options parameter in *Error constructor");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the error message here - do you mean "Error().cause should not be defined if specified by cause property of options parameter in *Error constructor"

}
},
{
name: "Error().cause === undefined",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also have a case where we call the constructor with 1 parameter and check it has a message but not a cause.

assert.areEqual(hasCounter, 1, `hasCounter should be 1`);
assert.areEqual(getCounter, 1, `getCounter should be 1`);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add a cause with an options parameter BUT without a cause property - confirm that cause doesn't get created.

{
ScriptContext* scriptContext = function->GetScriptContext();

bool isCtorSuperCall = (callInfo.Flags & CallFlags_New) && newTarget != nullptr && !JavascriptOperators::IsUndefined(newTarget);
JavascriptString* messageString = nullptr;
Var cause = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be defined inside the if statement where it's used? it doesn't look like it's used outside of it.

@@ -65,6 +66,14 @@ namespace Js
pError->SetNotEnumerable(PropertyIds::message);
}

if (JavascriptOperators::IsObject(options) && JavascriptOperators::HasProperty(VarTo<RecyclableObject>(options), PropertyIds::cause))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use UnsafeVarTo<RecyclableObject> here as the IsObject has checked it.

(VarTo = AssertOrFailFast if this conversion is likely to be invalid; UnsafeVarTo = just do the conversion)

@MadProbe MadProbe requested a review from rhuanjl March 14, 2021 10:26
Comment on lines 102 to 107
{
name: "Cause property is not added to error if options parameter doesn't have the cause property",
body: function () {
assert.isFalse('cause' in ErrorConstructor(message, { }), `Cause property must not be added to error if options parameter doesn't have the cause property`);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also have a case where the options parameter isn't an object - maybe do one with a string and one with a number.

Other than that, looks good to merge.

<test>
<default>
<files>error_cause.js</files>
<compile-flags>-args summary -endargs</compile-flags>
Copy link
Collaborator

@rhuanjl rhuanjl Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have guessed but just an FYI this gives -args summary -endargs as extra command line arguments for the test.

Which in turn makes WScript.Arguments[0] = "summary" - so that testRunner.runTests gets called with verbose: false

The reason for doing this to set the "verbose" option of a test to false rather than having it hard coded in the test file is so when you run the test yourself the default will be verbose = true(to print out all the test cases within the file) vs when it's run here through the test runner it prints only failures + the word "pass" or "fail" at the end.

Copy link
Collaborator

@rhuanjl rhuanjl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Will merge if/when the tests pass. Thanks for the contribution.

@rhuanjl rhuanjl merged commit b992a5d into chakra-core:master Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants