tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2865881fa7e4d4eefb39837af6dc522db52d00d8
parent 0dc61042220487712e3a7cdb9b7278177b1d1b40
Author: Yoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Date:   Tue, 11 Nov 2025 08:20:48 +0000

Bug 1979050 - Part 1: Patch. r=arai

Differential Revision: https://phabricator.services.mozilla.com/D271970

Diffstat:
Mjs/loader/ImportMap.cpp | 23+++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/js/loader/ImportMap.cpp b/js/loader/ImportMap.cpp @@ -9,6 +9,7 @@ #include "js/Array.h" // IsArrayObject #include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_* #include "js/JSON.h" // JS_ParseJSON +#include "js/PropertyDescriptor.h" // JS::PropertyDescriptor #include "LoadedScript.h" #include "ModuleLoaderBase.h" // ScriptLoaderInterface #include "nsContentUtils.h" @@ -371,6 +372,21 @@ static UniquePtr<IntegrityMap> NormalizeIntegrity( return normalized; } +static bool GetOwnProperty(JSContext* aCx, Handle<JSObject*> aObj, + const char* aName, MutableHandle<Value> aValueOut) { + JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc(aCx); + if (!JS_GetOwnPropertyDescriptor(aCx, aObj, aName, &desc)) { + return false; + } + + if (desc.isNothing()) { + return true; + } + MOZ_ASSERT(!desc->isAccessorDescriptor()); + aValueOut.set(desc->value()); + return true; +} + // https://html.spec.whatwg.org/multipage/webappapis.html#parse-an-import-map-string // static UniquePtr<ImportMap> ImportMap::ParseString( @@ -417,7 +433,7 @@ UniquePtr<ImportMap> ImportMap::ParseString( RootedObject parsedObj(aCx, &parsedVal.toObject()); RootedValue importsVal(aCx); - if (!JS_GetProperty(aCx, parsedObj, "imports", &importsVal)) { + if (!GetOwnProperty(aCx, parsedObj, "imports", &importsVal)) { return nullptr; } @@ -453,7 +469,7 @@ UniquePtr<ImportMap> ImportMap::ParseString( } RootedValue scopesVal(aCx); - if (!JS_GetProperty(aCx, parsedObj, "scopes", &scopesVal)) { + if (!GetOwnProperty(aCx, parsedObj, "scopes", &scopesVal)) { return nullptr; } @@ -489,7 +505,7 @@ UniquePtr<ImportMap> ImportMap::ParseString( } RootedValue integrityVal(aCx); - if (!JS_GetProperty(aCx, parsedObj, "integrity", &integrityVal)) { + if (!GetOwnProperty(aCx, parsedObj, "integrity", &integrityVal)) { return nullptr; } @@ -583,7 +599,6 @@ static mozilla::Result<nsCOMPtr<nsIURI>, ResolveError> ResolveImportsMatch( const SpecifierMap* aSpecifierMap) { // Step 1. For each specifierKey → resolutionResult of specifierMap, for (auto&& [specifierKey, resolutionResult] : *aSpecifierMap) { - nsAutoString specifier{aNormalizedSpecifier}; nsCString asURL = aAsURL ? aAsURL->GetSpecOrDefault() : EmptyCString(); // Step 1.1. If specifierKey is normalizedSpecifier, then: