The Wayback Machine - https://web.archive.org/web/20220321052725/https://github.com/SeleniumHQ/selenium/pull/6785
Skip to content
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

make isPromise() return boolean value for null and undefined cases #6785

Merged
merged 8 commits into from Apr 7, 2021

Conversation

Jayasankar-m
Copy link
Contributor

@Jayasankar-m Jayasankar-m commented Dec 24, 2018

  • By placing an X in the preceding checkbox, I verify that I have signed the Contributor License Agreement

  • Currently isPromise() returns non boolean for the cases like following
    isPromise(null) // returns null
    isPromise(undefined) // returns undefined

  • Modified to return boolean value explicitly for the cases mentioned above


This change is Reviewable

Copy link
Contributor

@martin770 martin770 left a comment

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @Jayasankar-m)


javascript/node/selenium-webdriver/lib/promise.js, line 38 at r1 (raw file):

    // Use array notation so the Closure compiler does not obfuscate away our
    // contract.
    return value != null

!!value to coerce the value to a boolean (instead of value != null)

Also, you should update the tests since they currently do nothing...

/test/lib/promise_test.js -- remove lines 59&60, replace with this test:

it('isPromise', () => {
const v = () => {};
const x = new Promise(v, v);
const p = createRejectedPromise('reject');
assert.equal(true, promise.isPromise(x));
assert.equal(true, promise.isPromise(p));
assert.equal(false, promise.isPromise(0));
assert.equal(false, promise.isPromise(false));
assert.equal(false, promise.isPromise(true));
assert.equal(false, promise.isPromise(null));
assert.equal(false, promise.isPromise(undefined));
assert.equal(false, promise.isPromise(''));
assert.equal(false, promise.isPromise('promise'));
assert.equal(false, promise.isPromise(v));
});

Copy link
Contributor

@martin770 martin770 left a comment

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Jayasankar-m)


javascript/node/selenium-webdriver/lib/promise.js, line 38 at r1 (raw file):

Previously, martin770 (James Martin) wrote…

!!value to coerce the value to a boolean (instead of value != null)

Also, you should update the tests since they currently do nothing...

/test/lib/promise_test.js -- remove lines 59&60, replace with this test:

it('isPromise', () => {
const v = () => {};
const x = new Promise(v, v);
const p = createRejectedPromise('reject');
assert.equal(true, promise.isPromise(x));
assert.equal(true, promise.isPromise(p));
assert.equal(false, promise.isPromise(0));
assert.equal(false, promise.isPromise(false));
assert.equal(false, promise.isPromise(true));
assert.equal(false, promise.isPromise(null));
assert.equal(false, promise.isPromise(undefined));
assert.equal(false, promise.isPromise(''));
assert.equal(false, promise.isPromise('promise'));
assert.equal(false, promise.isPromise(v));
});

In fact, you can completely remove the value && part and just have:

        return (typeof value === 'object' || typeof value === 'function')
        && typeof value['then'] === 'function';

And it will still pass all of those tests.

Copy link
Contributor Author

@Jayasankar-m Jayasankar-m left a comment

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @martin770)


javascript/node/selenium-webdriver/lib/promise.js, line 38 at r1 (raw file):

Previously, martin770 (James Martin) wrote…

In fact, you can completely remove the value && part and just have:

        return (typeof value === 'object' || typeof value === 'function')
        && typeof value['then'] === 'function';

And it will still pass all of those tests.

Done.
Updated as per review comments

Copy link
Contributor

@martin770 martin770 left a comment

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@CLAassistant
Copy link

@CLAassistant CLAassistant commented Nov 23, 2019

CLA assistant check
All committers have signed the CLA.

@diemol diemol closed this Jul 12, 2020
@diemol diemol reopened this Jul 12, 2020
@diemol diemol changed the base branch from master to trunk Jul 12, 2020
@diemol
Copy link
Member

@diemol diemol commented Apr 7, 2021

@Jayasankar-m, would you like to continue with this PR?

@Jayasankar-m
Copy link
Contributor Author

@Jayasankar-m Jayasankar-m commented Apr 7, 2021

@Jayasankar-m, would you like to continue with this PR?

@diemol I guess all the required changes are already there in PR. Just needs to merge.
Let me know if anything is missing

@diemol
Copy link
Member

@diemol diemol commented Apr 7, 2021

@Jayasankar-m, there are merge conflicts, could you please have a look?

@sonarcloud
Copy link

@sonarcloud sonarcloud bot commented Apr 7, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@Jayasankar-m
Copy link
Contributor Author

@Jayasankar-m Jayasankar-m commented Apr 7, 2021

@Jayasankar-m, there are merge conflicts, could you please have a look?

@diemol it seems fix to the issue was made by another commit.
The tests written for this are included in the PR

diemol
diemol approved these changes Apr 7, 2021
Copy link
Member

@diemol diemol left a comment

You are right, a recent PR merge fixed this. I will merge the test, thank you.

@diemol diemol merged commit e9ba4e3 into SeleniumHQ:trunk Apr 7, 2021
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants