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

Build SpiderMonkey from mozilla-central #367

Merged
merged 44 commits into from
Jul 10, 2024

Conversation

Xmader
Copy link
Member

@Xmader Xmader commented Jun 19, 2024

Switching to mozilla-central from the ESR versions could save us from bugs that were solved several months ago in upstream SpiderMonkey tip but haven't been backported to ESR.

In order to make the target version consistent,
the mozilla-central commit hash to be used is stored in the mozcentral.version file.

Switching to mozilla-central from the ESR versions could save us from bugs that were solved several months ago in upstream SpiderMonkey tip but haven't been backported to ESR.

The mozilla-central commit hash to be used is stored in the `mozcentral.version` file.
@Xmader Xmader requested a review from wesgarland June 19, 2024 04:37
Xmader added 16 commits June 19, 2024 04:44
…K version

The latest version of SpiderMonkey on macOS requires at least Xcode SDK 14.4, but none is available on Github Actions runner's macOS 13 image.
See https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#installed-sdks

ERROR: SDK version "13.3" is too old. Please upgrade to at least 14.4. Try updating your system Xcode.
…macOS SDK version"

The hacky solution doesn't work.

This reverts commit e4c37db.
…DK in 126 alpha

Using the commit for mozilla-central tag `FIREFOX_NIGHTLY_125_END`
Using the commit for mozilla-central tag `FIREFOX_NIGHTLY_120_END`
Using the commit for mozilla-central tag `FIREFOX_NIGHTLY_115_END`
@Xmader Xmader added this to the v1.0.0 milestone Jun 19, 2024
Xmader added 9 commits June 20, 2024 06:54
…he use of `JS::ColumnNumberOneOrigin` class after upgrading SpiderMonkey to mozilla-central tip
…iningStopped` virtual method after upgrading SpiderMonkey to mozilla-central tip
…rapped in a `mozilla::UniquePtr` instead of passing it directly to the function
… (`mozilla::UniquePtr<char[], ...>`) instead of a pure `char[]` after upgrading SpiderMonkey to mozilla-central tip
…resent on `JS::RealmCreationOptions` after upgrading SpiderMonkey to mozilla-central tip
Probably due to a bug in the build system, we could not use `JS::Prefs::setAtStartup_weakrefs(true);` or `JS::Prefs::setAtStartup_experimental_iterator_helpers(true);`:
```
undefined symbol: _ZN2JS5Prefs9weakrefs_E
```

Further more, the file `js/PrefsGenerated.h` does not get copied into the installation location of SpiderMonkey, but stays in `/js/src/_build/js/public/PrefsGenerated.h`.
…UTF8CharsZ` instead of a pure `char*` after upgrading SpiderMonkey to mozilla-central tip
@Xmader
Copy link
Member Author

Xmader commented Jun 20, 2024

Windows build is disabled for now

Fixed in 3883b62

@Xmader
Copy link
Member Author

Xmader commented Jul 2, 2024

TODO

@Xmader Xmader marked this pull request as ready for review July 2, 2024 22:04
@philippedistributive philippedistributive requested review from philippedistributive and removed request for wesgarland July 8, 2024 16:16
@@ -78,6 +78,11 @@ void runJobs(JSContext *cx) override;
*/
bool empty() const override;

/**
* @return true if the job queue stops draining, which results in `empty()` being false after `runJobs()`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @return true if the job queue stops draining, which results in `empty()` being false after `runJobs()`.
* @return true if the job queue stopped draining, which results in `empty()` being false after `runJobs()`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't understand why you'll need to change this.
Is this grammatically incorrect?

Copy link
Collaborator

Choose a reason for hiding this comment

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

indeed, yes, "stops" refers to the present or future, whereas "stopped" refers to the past

setup.sh Outdated Show resolved Hide resolved
sed -i'' -e 's/shared_lib = self._pretty_path(libdef.output_path, backend_file)/shared_lib = libdef.lib_name/' ./python/mozbuild/mozbuild/backend/recursivemake.py
sed -i'' -e 's/if version < Version(mac_sdk_min_version())/if False/' ./build/moz.configure/toolchain.configure # do not verify the macOS SDK version as the required version is not available on Github Actions runner
sed -i'' -e 's/return JS::GetWeakRefsEnabled() == JS::WeakRefSpecifier::Disabled/return false/' ./js/src/vm/GlobalObject.cpp # forcibly enable FinalizationRegistry
sed -i'' -e 's/return !IsIteratorHelpersEnabled()/return false/' ./js/src/vm/GlobalObject.cpp # forcibly enable iterator helpers
Copy link
Collaborator

Choose a reason for hiding this comment

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

@caleb-distributive is this truly needed? Doesn't the switch in PyInit_pythonmonkey cover this?

Copy link
Member Author

@Xmader Xmader Jul 10, 2024

Choose a reason for hiding this comment

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

See the commit message in 42e3f53

@@ -276,7 +276,7 @@ JSObject *ExceptionType::toJsError(JSContext *cx, PyObject *exceptionValue, PyOb
JS::RootedString filename(cx, JS_NewStringCopyZ(cx, PyUnicode_AsUTF8(fileName)));
JS::RootedString message(cx, JS_NewStringCopyZ(cx, msgStream.str().c_str()));
// stack argument cannot be passed in as a string anymore (deprecated), and could not find a proper example using the new argument type
if (!JS::CreateError(cx, JSExnType::JSEXN_ERR, nullptr, filename, lineno, 0, nullptr, message, JS::NothingHandleValue, &rval)) {
if (!JS::CreateError(cx, JSExnType::JSEXN_ERR, nullptr, filename, lineno, JS::ColumnNumberOneOrigin(1), nullptr, message, JS::NothingHandleValue, &rval)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why no longer 0?

Copy link
Member Author

@Xmader Xmader Jul 10, 2024

Choose a reason for hiding this comment

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

JS::ColumnNumberOneOrigin(1)

One Origin

Copy link
Member Author

Choose a reason for hiding this comment

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

JS::CreateError()'s function signature changed to CreateError(..., JS::ColumnNumberOneOrigin column,...)

See https://hg.mozilla.org/mozilla-central/file/d25c9bd/js/public/ErrorReport.h#l537

Copy link
Member Author

Choose a reason for hiding this comment

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

}

bool JobQueue::isDrainingStopped() const {
// TODO (Tom Tang): implement this by detecting if the Python event-loop is still running
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the specific challenge in implementing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would have to modify the internal implementation of Python's asyncio event-loop.

@@ -549,8 +550,6 @@ PyMODINIT_FUNC PyInit_pythonmonkey(void)

JS::RealmCreationOptions creationOptions = JS::RealmCreationOptions();
JS::RealmBehaviors behaviours = JS::RealmBehaviors();
creationOptions.setWeakRefsEnabled(JS::WeakRefSpecifier::EnabledWithoutCleanupSome); // enable FinalizationRegistry
creationOptions.setIteratorHelpersEnabled(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@caleb-distributive please double-check with change above: why is this new way better?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -1098,7 +1098,8 @@ class Counter {
assert (False)
except Exception as e:
assert str(type(e)) == "<class 'pythonmonkey.SpiderMonkeyError'>"
assert str(e).__contains__("TypeError: this is null")
assert "TypeError:" in str(e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this better?

Copy link
Member Author

@Xmader Xmader Jul 10, 2024

Choose a reason for hiding this comment

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

in is a basic operator in Python syntax.
https://realpython.com/python-in-operator/#strings

Copy link
Member Author

Choose a reason for hiding this comment

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

__contains__ is the magic method for user-defined classes to implement the in operator, which shouldn't be used directly.

https://docs.python.org/3/reference/expressions.html#membership-test-details

For the string and bytes types, x in y is True if and only if x is a substring of y. An equivalent test is y.find(x) != -1. Empty strings are always considered to be a substring of any other string, so "" in "abc" will return True.

For user-defined classes which define the __contains__() method, x in y returns True if y.__contains__(x) returns a true value, and False otherwise.

@Xmader
Copy link
Member Author

Xmader commented Jul 10, 2024

@philippedistributive 53af133

setWeakRefsEnabled and setIteratorHelpersEnabled both no longer exist on JS::RealmCreationOptions - they moved to SpiderMonkey/Firefox prefs
(See https://hg.mozilla.org/mozilla-central/file/d25c9bd/modules/libpref/init/StaticPrefList.yaml#l7803).

@philippedistributive philippedistributive merged commit f8f1b2c into main Jul 10, 2024
29 checks passed
@philippedistributive philippedistributive deleted the Xmader/chore/moz-central branch July 10, 2024 19:00
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.

Build the spidermonkey bundle from mozilla-central instead of using the ESR
2 participants