summaryrefslogtreecommitdiff
path: root/dom/base/nsJSUtils.cpp
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2023-04-21 17:35:04 -0500
committerBrian Smith <brian@dbsoft.org>2023-04-27 13:34:55 -0500
commit914299b8ba22bb40fc30f83fe5481ebf4598ab48 (patch)
treeca0a35c7573f80c33d74b2f3f6b5bde5d5649a2e /dom/base/nsJSUtils.cpp
parente29f4488b1d8d33f3ca04531177d1c1690f57577 (diff)
downloaduxp-914299b8ba22bb40fc30f83fe5481ebf4598ab48.tar.gz
Issue #1691 - Part 8: Fix --enable-debug builds and continue dynamic module import changes.
https://bugzilla.mozilla.org/show_bug.cgi?id=1342012 Support import from timeout handlers by associating the initiating script with the compiled JSScript. Fix error message that covers all import() failures that don't throw a JS exception. https://bugzilla.mozilla.org/show_bug.cgi?id=1331662 Partial - Replace nsJSUtils::EvaluateString calls by ExecutionContext scopes. Left EvaluateString() in nsXBLProtoImplField.cpp until ExecutionContext errors can be fixed. (cherry picked from commit 22fcfc77971a9bb204df664c474681f4dcf54211)
Diffstat (limited to 'dom/base/nsJSUtils.cpp')
-rw-r--r--dom/base/nsJSUtils.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp
index 467a5b0b53..b43f94422d 100644
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -142,6 +142,7 @@ nsJSUtils::ExecutionContext::ExecutionContext(JSContext* aCx,
, mRv(NS_OK)
, mSkip(false)
, mCoerceToString(false)
+ , mEncodeBytecode(false)
#ifdef DEBUG
, mWantsReturnValue(false)
, mExpectScopeChain(false)
@@ -150,7 +151,6 @@ nsJSUtils::ExecutionContext::ExecutionContext(JSContext* aCx,
{
MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
MOZ_ASSERT(NS_IsMainThread());
- MOZ_ASSERT(nsContentUtils::IsInMicroTask());
MOZ_ASSERT(mRetValue.isUndefined());
MOZ_ASSERT(js::GetGlobalForObjectCrossCompartment(aGlobal) == aGlobal);
@@ -207,7 +207,7 @@ nsJSUtils::ExecutionContext::JoinCompile(void** aOffThreadToken)
return mRv;
}
- if (!StartIncrementalEncoding(mCx, mScript)) {
+ if (mEncodeBytecode && !StartIncrementalEncoding(mCx, mScript)) {
mSkip = true;
mRv = EvaluationExceptionToNSResult(mCx);
return mRv;
@@ -246,7 +246,7 @@ nsJSUtils::ExecutionContext::Compile(JS::CompileOptions& aCompileOptions,
return mRv;
}
- if (!StartIncrementalEncoding(mCx, mScript)) {
+ if (mEncodeBytecode && !StartIncrementalEncoding(mCx, mScript)) {
mSkip = true;
mRv = EvaluationExceptionToNSResult(mCx);
return mRv;
@@ -340,6 +340,19 @@ nsresult nsJSUtils::ExecutionContext::ExecScript() {
return NS_OK;
}
+static bool IsPromiseValue(JSContext* aCx, JS::Handle<JS::Value> aValue) {
+ if (!aValue.isObject()) {
+ return false;
+ }
+
+ JS::Rooted<JSObject*> obj(aCx, js::CheckedUnwrap(&aValue.toObject()));
+ if (!obj) {
+ return false;
+ }
+
+ return JS::IsPromiseObject(obj);
+}
+
nsresult
nsJSUtils::ExecutionContext::ExecScript(JS::MutableHandle<JS::Value> aRetValue)
{
@@ -359,6 +372,15 @@ nsJSUtils::ExecutionContext::ExecScript(JS::MutableHandle<JS::Value> aRetValue)
#ifdef DEBUG
mWantsReturnValue = false;
#endif
+ if (mCoerceToString && IsPromiseValue(mCx, aRetValue)) {
+ // We're a javascript: url and we should treat Promise return values as
+ // undefined.
+ //
+ // Once bug 1477821 is fixed this code might be able to go away, or will
+ // become enshrined in the spec, depending.
+ aRetValue.setUndefined();
+ }
+
if (mCoerceToString && !aRetValue.isUndefined()) {
JSString* str = JS::ToString(mCx, aRetValue);
if (!str) {