Bug 1468789 - Part 1: Add window id inside realm creation options. r=jandem,bzbarsky
authorNazım Can Altınova <canaltinova@gmail.com>
Thu, 14 Nov 2019 12:26:25 +0000
changeset 502163 0c93e34bc1f3b2e56d53a48ff6d6c09b083c8bba
parent 502162 53c096b278f5888d8b7590786628b0634a80ed2f
child 502164 1c3c775faf994b0cb12be28fc5afca9f444569af
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, bzbarsky
bugs1468789
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1468789 - Part 1: Add window id inside realm creation options. r=jandem,bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D51859
dom/bindings/BindingUtils.cpp
dom/bindings/BindingUtils.h
dom/workers/WorkerScope.cpp
dom/workers/WorkerScope.h
js/public/RealmOptions.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -36,17 +36,16 @@
 #include "nsUTF8Utils.h"
 #include "WorkerPrivate.h"
 #include "WorkerRunnable.h"
 #include "WrapperFactory.h"
 #include "xpcprivate.h"
 #include "XrayWrapper.h"
 #include "nsPrintfCString.h"
 #include "mozilla/Sprintf.h"
-#include "nsGlobalWindow.h"
 #include "nsReadableUtils.h"
 
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/CustomElementRegistry.h"
 #include "mozilla/dom/DeprecationReportBody.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/HTMLObjectElement.h"
@@ -3237,16 +3236,26 @@ bool CreateGlobalOptionsWithXPConnect::P
   SiteIdentifier site;
   nsresult rv = BasePrincipal::Cast(principal)->GetSiteIdentifier(site);
   NS_ENSURE_SUCCESS(rv, false);
 
   xpc::RealmPrivate::Init(aGlobal, site);
   return true;
 }
 
+uint64_t GetWindowID(void* aGlobal) { return 0; }
+
+uint64_t GetWindowID(nsGlobalWindowInner* aGlobal) {
+  return aGlobal->WindowID();
+}
+
+uint64_t GetWindowID(DedicatedWorkerGlobalScope* aGlobal) {
+  return aGlobal->WindowID();
+}
+
 #ifdef DEBUG
 void AssertReturnTypeMatchesJitinfo(const JSJitInfo* aJitInfo,
                                     JS::Handle<JS::Value> aValue) {
   switch (aJitInfo->returnType()) {
     case JSVAL_TYPE_UNKNOWN:
       // Any value is good.
       break;
     case JSVAL_TYPE_DOUBLE:
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -49,16 +49,17 @@ class nsGenericHTMLElement;
 
 namespace mozilla {
 
 enum UseCounter : int16_t;
 
 namespace dom {
 class CustomElementReactionsStack;
 class MessageManagerGlobal;
+class DedicatedWorkerGlobalScope;
 template <typename KeyType, typename ValueType>
 class Record;
 class WindowProxyHolder;
 
 nsresult UnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src,
                        const nsIID& iid, void** ppArg);
 
 /** Convert a jsval to an XPCOM pointer. Caller must not assume that src will
@@ -2807,29 +2808,35 @@ struct CreateGlobalOptions : Conditional
 
 template <>
 struct CreateGlobalOptions<nsGlobalWindowInner>
     : public CreateGlobalOptionsWithXPConnect {
   static constexpr ProtoAndIfaceCache::Kind ProtoAndIfaceCacheKind =
       ProtoAndIfaceCache::WindowLike;
 };
 
+uint64_t GetWindowID(void* aGlobal);
+uint64_t GetWindowID(nsGlobalWindowInner* aGlobal);
+uint64_t GetWindowID(DedicatedWorkerGlobalScope* aGlobal);
+
 // The return value is true if we created and successfully performed our part of
 // the setup for the global, false otherwise.
 //
 // Typically this method's caller will want to ensure that
 // xpc::InitGlobalObjectOptions is called before, and xpc::InitGlobalObject is
 // called after, this method, to ensure that this global object and its
 // compartment are consistent with other global objects.
 template <class T, ProtoHandleGetter GetProto>
 bool CreateGlobal(JSContext* aCx, T* aNative, nsWrapperCache* aCache,
                   const JSClass* aClass, JS::RealmOptions& aOptions,
                   JSPrincipals* aPrincipal, bool aInitStandardClasses,
                   JS::MutableHandle<JSObject*> aGlobal) {
-  aOptions.creationOptions().setTrace(CreateGlobalOptions<T>::TraceGlobal);
+  aOptions.creationOptions()
+      .setTrace(CreateGlobalOptions<T>::TraceGlobal)
+      .setProfilerRealmID(GetWindowID(aNative));
   xpc::SetPrefableRealmOptions(aOptions);
 
   aGlobal.set(JS_NewGlobalObject(aCx, aClass, aPrincipal,
                                  JS::DontFireOnNewGlobalHook, aOptions));
   if (!aGlobal) {
     NS_WARNING("Failed to create global");
     return false;
   }
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -575,16 +575,20 @@ WorkerGlobalScope::GetOrCreateServiceWor
       GetServiceWorkerRegistration(aDescriptor);
   if (!ref) {
     ref = ServiceWorkerRegistration::CreateForWorker(mWorkerPrivate, this,
                                                      aDescriptor);
   }
   return ref.forget();
 }
 
+uint64_t WorkerGlobalScope::WindowID() const {
+  return mWorkerPrivate->WindowID();
+}
+
 void WorkerGlobalScope::FirstPartyStorageAccessGranted() {
   // Reset the IndexedDB factory.
   mIndexedDB = nullptr;
 
   // Reset DOM Cache
   mCacheStorage = nullptr;
 }
 
--- a/dom/workers/WorkerScope.h
+++ b/dom/workers/WorkerScope.h
@@ -223,16 +223,18 @@ class WorkerGlobalScope : public DOMEven
 
   RefPtr<mozilla::dom::ServiceWorkerRegistration> GetServiceWorkerRegistration(
       const ServiceWorkerRegistrationDescriptor& aDescriptor) const override;
 
   RefPtr<mozilla::dom::ServiceWorkerRegistration>
   GetOrCreateServiceWorkerRegistration(
       const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
 
+  uint64_t WindowID() const;
+
   void FirstPartyStorageAccessGranted();
 };
 
 class DedicatedWorkerGlobalScope final : public WorkerGlobalScope {
   const nsString mName;
 
   ~DedicatedWorkerGlobalScope() {}
 
--- a/js/public/RealmOptions.h
+++ b/js/public/RealmOptions.h
@@ -175,23 +175,30 @@ class JS_PUBLIC_API RealmCreationOptions
   // https://w3c.github.io/webappsec-secure-contexts/
   // https://bugzilla.mozilla.org/show_bug.cgi?id=1162772#c34
   bool secureContext() const { return secureContext_; }
   RealmCreationOptions& setSecureContext(bool flag) {
     secureContext_ = flag;
     return *this;
   }
 
+  uint64_t profilerRealmID() const { return profilerRealmID_; }
+  RealmCreationOptions& setProfilerRealmID(uint64_t id) {
+    profilerRealmID_ = id;
+    return *this;
+  }
+
  private:
   JSTraceOp traceGlobal_ = nullptr;
   CompartmentSpecifier compSpec_ = CompartmentSpecifier::NewCompartmentAndZone;
   union {
     Compartment* comp_;
     Zone* zone_;
   };
+  uint64_t profilerRealmID_ = 0;
   bool invisibleToDebugger_ = false;
   bool mergeable_ = false;
   bool preserveJitCode_ = false;
   bool cloneSingletons_ = false;
   bool sharedMemoryAndAtomics_ = false;
   bool streams_ = false;
   bool readableByteStreams_ = false;
   bool byobStreamReaders_ = false;