From 049b3235ac6aa0f7e6aceef0431ccbf6de66164d Mon Sep 17 00:00:00 2001 From: roytam1 Date: Mon, 29 Jan 2024 15:26:23 +0800 Subject: [PATCH] import changes from `dev' branch of rmottola/Arctic-Fox: - Bug 1207494 - Part 8: Remove use of expression closure from dom/identity/. r=ferjm (34fac889f8) - minor crash thing (13fe2827c2) - Bug 1243359 - initialize mScrollSeriesNumber in all ScrollWheelInput constructors. r=roc (94163d8eca) - fix misspatch (b380a7bbe4) - Bug 1207412 - Make SystemTimeConverter use TimeStamp::Now() when converting times; r=karlt (f408549605) - Bug 1212102 - Drop unnecessary assertion comparing timestamps in SystemTimeConverter; r=karlt (1efaa04b3f) - Bug 1241302 - Slightly modernize this code. r=jst (c1e97bc069) - bug 1216916 clean up when InvokeDragSessionWithImage/Selection() fails r=roc (9cdf71b717) - Bug 1231329 - run ConvertToUnscaledDevPixels if *aPresContext is valid. r=roc (d10f23633b) - Bug 1245927: Innerize before creating DOM files from the file picker. r=baku (8754128362) - Bug 1155214 - Mark nsIBidiKeyboard as builtinclass; r=mrbkap (2d00326d2b) - reorder (c3c1ba92c9) - Bug 1236566 - add override declarations for widget/windows/GfxInfo.h; r=roc (940b40ed91) - Bug 1242659: Part 1. More information on the mismatches. r=jrmuizel (78331ddad2) - Block some Radeon drivers that crash on D3D9. (bug 1213107, r=jrmuizel) (482b66d313) - Bug 1203199 - Blacklist DXVA on some older intel drivers for causing crashes. r=jrmuizel (f1827d4498) - Bug 1203199 - Fix driver range with blacklist to avoid blacklisting other OSes. (2c2d547296) - Bug 1203199 - Bustage fix. CLOSED TREE (3233d407f3) - Bug 1178385. Enable DXVA on the G45 r=ajones (3c59a58a15) - Bug 1188442 IMMHandler::GetSelection() should use static Selection instance when IME doesn't have focus and return its or mSelection's reference r=emk (5cc4b30433) - Bug 1238899 Create hidden native caret for ATOK at composing in windowless plugin r=m_kato (40ef5bb4aa) - Bug 1257919 part 1. Kill off nsIXSLTException. r=khuey (11f37643f2) - Bug 1242072 - Change implementation of BaseProxyHandler::get() to follow ES6 [[Get]] specification. r=jorendorff (094a67f284) - Bug 489636 - Add a GC u-bench test for property tree splitting via deletion; r=sfink (9282fec25f) - Bug 1257919 part 2. Make nsIException and nsIStackFrame builtinclass, so we can start using [implicit_jscontext] on them. r=khuey (0e65fb8554) - Bug 1257919 part 3. Make the various toString methods on exceptions take an explicit JSContext. r=khuey (b342fb4930) - Bug 1257919 part 4. Stop returning StackFrame instances from exceptions::CreateStack. C++ callers of GetCurrentJSStack or exceptions::CreateStack always check for null anyway, and none of them seem to want this non-JS thing. r=khuey (d34036ccf9) - Bug 1257919 part 5. Get rid of the now-unused StackFrame class. r=khuey (aa13af0dfe) - Bug 1141222 - Create ScriptError with stack from Cu.reportError. r=bholley (b83ad26aa0) - Bug 1208641 - Extract stack from DOM/XPC exception. r=bholley (e382b5f48c) - Bug 1254380 part 1. Find the relevant window when the compartment we've got is an addon sandbox compartment in AutoJSAPI exception/warning reporting code. r=bholley (4b1f6c64a9) - Bug 1250630 - remove PBackgroundTest and ifdef ENABLE_TEST blocks. r=khuey (d7b36860a3) - Bug 1250963 part 1. Change NotifyRunnable::Dispatch to not require a JSContext. r=khuey (48e03c2fc2) - Bug 1250963 part 2. Remove the unused JSContext argument of WorkerPrivate::ModifyBusyCount. r=khuey (0f5ca42be1) - Bug 1250291 part 1. Stop pretending to report exceptions in MainThreadStopSyncLoopRunnable::PostDispatch. r=khuey (6e1c81cc06) - Bug 1250291 part 2. Stop pretending to report exceptions in MainThreadWorkerSyncRunnable::PostDispatch. r=khuey (f3d846ea31) - Bug 1250291 part 3. Stop pretending to report exceptions in WorkerDebuggerRunnable::PostDispatch. r=khuey (10bc1710d1) - Bug 1250975. Stop passing a JSContext argument to WorkerRunnable::PreDispatch and its overrides. r=khuey (71ab9046f0) - Bug 1255298. Just pass through the JSContext when passing through the NotificationOptions in notification code. r=wchen (552ae8e33e) - Bug 1250185 part 2. Remove some JSContext stuff that's no longer needed in Notification code. r=khuey (20b99ef28b) - Bug 1251045 part 8. Remove the JSContext argument from some nsINotificationStorageCallback methods. r=khuey (170c4afabc) - Bug 1227015 P7 Supress unused ErrorResult exception if the worker runnable failed to dispatch. r=catalinb (23a3cc6f45) - Bug 1251045 part 3. Remove the JSContext argument of WorkerRunnable::PostDispatch and its overrides. r=khuey (6a666d1a4a) - Bug 1251045 part 2. Remove the JSContext argument of ModifyBusyCountFromWorker. r=khuey (105bc4f59e) - Bug 1252130. Remove unnecessary JSContext argument from NotificationWorkerRunnable::WorkerRunInternal. r=khuey (642727f6f6) - Bug 1252127. Remove unnecessary JSContext argument from PromiseWorkerProxy::CleanUp. r=khuey (339e1157d1) - Bug 1251045 part 1. Make it possible to dispatch a ModifyBusyCountRunnable without a JSContext. r=khuey (665c1f81b4) - Bug 1251045 part 4. Remove the JSContext argument of WorkerRunnable::Dispatch. r=khuey (6c5cdab2b7) - Bug 1250185 part 1. nsIStructuredCloneContainer.initFromBase64 doesn't need a JSContext argument. r=khuey (d63a219209) - fix (773c0393aa) - Bug 1251045 part 5. Remove the JSContext argument from WorkerPrivateParent::Freeze/Thaw. r=khuey (cd419bfd2c) - Bug 1251045 part 6. Remove the JSContext argument from some worker debugger methods that no longer need it. r=khuey (abcc437cb9) - Bug 1251045 part 7. Remove the JSContext argument from some worker methods that no longer need it. r=khuey (3ddcbca08c) - Bug 1249652 part 1. Add a method on ErrorResult to steal an exception, if any, from a JSContext. r=khuey (9c07f5044b) - Bug 1229071 - importScripts should throw the correct error result in case the loading of one of scripts fails, r=bz (cd37645d76) - Bug 1229970 Abort script loading start requests if a load has been canceled. r=khuey (a44d9128ca) - Bug 1233171 Cancel channel when ScriptLoader is aborted during service worker script load. r=khuey (3b6ceafec7) - Bug 1249351 part 1. When doing importScripts of multiple scripts in a service worker, make sure to track the cache streams per-loadinfo, instead of trying to make them all wait on the same stream. r=bkelly (e1ccea9685) - Bug 1157544 - Fix a typo in the test; r=baku (8c0bf8f504) - Bug 1249351 part 2. Clean up test_importscript.html and add multiple-url importScript() case. r=bz (52b0a31032) - Bug 1249652 part 2. ScriptExecutorRunnable::WorkerRun should immediately move JS exceptions to its ErrorResult instead of allowing them to linger on the JSContext. r=baku,khuey (f628d3c8ba) - Bug 1249652 part 3. Simplify way we handle canceling when ScriptLoaderRunnable::RunInternal fails by canceling things with its actual failure code, so we don't have to guess which failed loads are actual failures and which are just canceled via this mechanism. r=baku,khuey (388543fbc3) - Bug 1251369. Use an AutoJSAPI that reports its own exceptions around the main runloop in workers. r=khuey (28b33287cd) - Bug 1251518. Fix js::ErrorReportToString to make a bit more sense, and change worker code to not use it anyway, so it matches the mainthread code. r=bholley,terrence (a48a40de90) - Bug 1254380 part 2. Go ahead and log the stack from our exception in AutoJSAPI::ReportException even if we don't have a window. r=bholley (64532b6017) - Bug 1212328 - Clean up some JSErrorReport-related code. r=Waldo,bz (d5aa611edc) - Bug 1255192 part 1. Remove the JSContext argument of JS::ExceptionStackOrNull. r=bholley (39b631d5ad) - bug 1252687 - make the ctor for CycleCollectorStats constexpr r=mccr8 (9e8168d8ac) - Bug 1254380 part 3. Skip firing error events for mainthread out of memory exceptions via AutoJSAPI::ReportException. r=bholley (d5e4e7dc29) - Bug 1254230 kinda-fix. Make sure to never send script errors with stacks attached to the console service if the associated windows have already had FreeInnerObjects called on them. r=bholley (8c379fe0e0) - Bug 1255192 part 2. Clean up the JSContext usage around xpc::FindExceptionStackForConsoleReport now that it just needs a JSContext for rooting. r=bholley (cade862491) - Bug 1255201. Improve the stack handling in nsXPCComponents_Utils::ReportError for the DOMException case to include the stack from the DOMException. r=bholley (fc6c065284) - Bug 1257919 part 6. Make the filename getter on JSStackFrame take an explicit JSContext. r=khuey (cde115b789) - Bug 1257919 part 7. Make the name getter on JSStackFrame take an explicit JSContext. r=khuey (d7466e9eab) - Bug 1257919 part 8. Make the line/column number getters on JSStackFrame take an explicit JSContext. r=khuey (b8766b98b2) - Bug 1257919 part 9. Make the asyncCause/asyncCaller getters on JSStackFrame take an explicit JSContext. r=khuey (b776ff9c6d) - Bug 1257919 part 10. Make the caller and formattedStack getters on JSStackFrame take an explicit JSContext. r=khuey (dc4d3d9091) - Bug 1252091. Add/RemoveFeature don't need a JSContext argument. r=khuey (5be6253a67) - Bug 1252123. Remove some unnecessary JSContext arguments from worker ScriptLoader methods. r=khuey (1657a35268) - Bug 1255181. Remove AutoJSAPI::InitWithLegacyErrorReporting. r=bholley (5ee7ac506e) - Bug 1254847 part 1. Take ownership of error reporting on the AutoEntryScript in nsXPCWrappedJSClass::DelegatedQueryInterface. r=bholley (62d987b030) - make style wrong again.... (fa4e6cfbc1) - Bug 1254847 part 2. Change nsJSNPRuntime to always use AutoEntryScript and always take ownership of error reporting. r=bholley (d24cb80622) - Bug 1251655 - Remove support for JavaScript-global-constructor-prototype-alias. r=bz. (2b354ea423) - Bug 1251655 - Remove support for JavaScript-DOM-class and JavaScript-DOM-interface. r=bz. (dd6786ea57) - Bug 1251275. Switch to using an AutoEntryScript in WorkerPrivate::RunExpiredTimeouts. r=khuey (f10d1b0dec) - Bug 1072144 part 1. Just release-assert that Promise::Resolve does not fail in service worker code. It can only do that on OOM or overrecursion anyway, and overrecursion is not likely if we're coming right off a runnable. r=khuey (ba4c89a3bc) - Bug 1072144 part 2. When UnregisterWorker tries to ScheduleWorker and that throws, just suppress the exception: there is no good place to report it anyway. r=khuey (ca563ec5cd) - Bug 1072144 part 3. Hoist the exception reporting out of WorkerRunnable::PostRun into WorkerRunnable::Run and make it unconditional. r=khuey (9914acd4a6) - Bug 1252221. When GetOrCreateGlobalScope fails while trying to run a ScriptExecutorRunnable::WorkerRun, just suppress the exception, because there is no way to report it without a compartment to work with. r=khuey (abcc9df148) - Bug 1072144 part 4. Add a WorkerRunnable::PreRun so that we can move worker global creation to it and always have an AutoEntryScript by the time we're evaluating the main worker script. r=khuey (007b528868) - Bug 1251276 part 1. Change WorkerPrivate::CancelAllTimeouts to no longer call RunExpiredTimeouts. r=khuey (6b937370a1) - Bug 1251276 part 2. Remove the JSContext argument of WorkerPrivate::CancelAllTimeouts. r=khuey (336b788e03) - Bug 1251380. Change things so that WorkerPrivate::NotifyInternal (hopefully) never throws. r=khuey (1d4863f83a) - Bug 1254846. Add an AutoEntryScript constructor that takes a JSObject instead of an nsIGlobalObject, for convenience. r=bholley (693857f9b0) - Bug 1255706 part 1. Remove JSContext argument from WorkerPrivate constructor. r=khuey (0486bdb01c) - Bug 1255706 part 2. Remove JSContext argument from WorkerPrivate::Terminate. r=khuey (f0b62de092) - Bug 1257568. Remove the JSContext argument of WorkerPrivate::Kill. r=khuey (ebe7d247b5) - Bug 1252189. Remove the unnecessary JSContext argument from WorkerPrivate::FreezeInternal/ThawInternal. r=khuey (22b137b05e) - Bug 1119490 - Expose the URL constructor to WorkerDebuggerGlobalScope;r=khuey (6f4fc13e1e) - Bug 1241841 - Clear the worker's debugger event queue before destroying its context;r=khuey (a1e8dd4b2d) - Bug 1249950 - Add Performance Markers for MessagePort - patch 1 - remove non-useful 'explicit', r=smaug (8a014b53e6) - Bug 1249950 - Add Performance Markers for MessagePort - patch 2, r=smaug, r=vporof (560caf0ae1) - bug 1250486 - make the ComponentsSH ctor constexpr r=bz (1c441dbb0f) - Bug 1257032: Make files in dom/workers actually build without unification. r=baku (6ab4ae0b65) - Bug 1241522 - handle OOM in nsExpatDriver::HandleCharacterData; r=hsivonen (b652220cdc) - Bug 1219482: Replace PRLogModuleInfo with LazyLogModule in various files.r=benjamin (5fd5e8dbc8) - Bug 1238545 - Remove nsISimpleUnicharStreamFactory; r=froydnj (f0018c5b16) - Bug 1257335. Replace some AutoSafeJSContext uses with AutoJSAPI or AutoJSContext uses. r=bholley (7baf79deb7) - Bug 1247635 - Unify PostMessageRunnable and DispatchEventRunnable in MessagePort.cpp, r=smaug (df2765c215) - Bug 1250572 - Force a parent object in MessagePort/Channel and in StructuredCloneHolder, r=smaug (2a929d59d1) - Bug 1255375 - MessagePort should not leak if DispatchMessage() fails, r=smaug (0a5cdebfb0) - Bug 1251272. Remove the dead code in ReportErrorRunnable::ReportError that could fail, and make it infallible. r=khuey (89e80694d0) - Bug 1072144 part 5. Stop fiddling with compartments on the JSContext before calling PostRun in WorkerRunnable::Run. Add some documentation explaining what's going on. r=khuey (91f4bb6a7c) - Bug 1072144 part 6. Switch WorkerRunnable::Run to calling TakeOwnershipOfErrorReporting on its AutoJSAPI/AutoEntryScript and remove the remaining JS_ReportPendingException callers in worker code. r=khuey (405d9e0282) - Bug 1179548 - Close the windows opened in private browsing worker tests; r=baku (acf3430b69) - Bug 1179753 - Use pushPrefEnv more in worker tests; r=baku (4bfd949c72) - Bug 1134224 - More test for test_bug1132395.html, r=ehsan (626eb100cd) - Bug 1134224 - onerror for test_bug1132395.html, r=ehsan (147195f57e) - Bug 1207635 - get rid of dom.workers.sharedWorkers.enabled pref, r=khuey (22fe2965c6) - Bug 1252592. JS warnings should not trigger error events on shared workers. r=khuey (7f05c2c00d) - Bug 1251308; r=luke (3cbec95738) - Bug 1246838 - Handle const qualifiers and references better in Variant. r=waldo (30da6e3ebf) - Bug 1254565 - Allow passing matchers as rvalues to Variant::match. r=froydnj (1dd799fb0a) - Bug 1246841 - Allow construction of Variant values using type inference. r=waldo (6ba3e6704c) - Bug 1250666 - Forward Variant's move constructor argument correctly to the underlying variant type. r=waldo (7353a53bf0) - Bug 1252185. Remove the dead "target" variable from CloseEventRunnable::WorkerRun. r=khuey (be172da10b) - Bug 1253059: Use fallible allocation in the worker error reporter. r=baku (963222bdd4) - Bug 1253199 - MessagePort should handle the dispatching a message when the parent window is gone, r=smaug (d552e3cd9e) - Bug 1252839 - Remove some if stmt after allocation with 'new' - patch 2, r=bz (3c7eb959bc) - Bug 1252839 - Remove some if stmt after allocation with 'new' - patch 1, r=bz (85067dbfb6) - Bug 1254855. Switch AutoEntryScripts in nsDirectoryViewer to take ownership of error reporting. r=bholley (8c10532323) - Bug 1252565 part 1. Push the script environment preparer bits up from XPCJSRuntime to CycleCollectedJSRuntime, because we need them on workers to do ctypes on workers properly. r=bholley (aecf2595dd) - Bug 1252565 part 2. Make dom::WarningOnlyErrorReporter handle workers. r=bholley (f415b8868b) - Bug 1244222 - Check for function interfaces in DelegatedQueryInterface. r=bz (d213eec83c) - Bug 1254393. Take ownership of error reporting on the AutoEntryScript in nsXPCWrappedJSClass::CallMethod. r=bholley (4765b501c0) - Bug 1251769 - Remove remaining references to MOZILLA_XPCOMRT_API from mfbt. r=froydnj (236adc1d4c) - Bug 1247835 (part 0) - Minor comment and style tweaks in BinarySearch.h. r=luke. (db04793721) - Bug 1244074 - Part 1: Move SheetParsingMode to a separate file. r=dholbert (290adaadea) - Bug 1244074 - Part 2: Add HandleRefPtr for refcounting StyleSheetHandles. r=dholbert r=waldo (8549b24392) - Bug 1244068 - Part 1: Add enum to represent the style system backend type. r=dholbert (c2e53feaf2) - Bug 1244068 - Part 2: Add skeleton ServoStyleSet and a StyleSetHandle smart pointer. r=dholbert (71a5c28629) - Bug 1244068 - Part 3: Factor out nsStyleSet getting in RestyleManager/ElementRestyler. r=dholbert (9e9f4f2e80) - Bug 1245406: In ReflowBlockFrame, use Maybe<> to destroy & reconstruct a stack-allocated object, instead of an explicit call to destructor & placement 'new'. r=dbaron (d36858b818) - Bug 1244068 - Part 4: Use StyleSetHandle instead of concrete style set class in most places. r=dholbert (93f9bcf799) - Bug 1244074 - Part 3: Add skeleton ServoStyleSheet and a StyleSheetHandle smart pointer. r=dholbert (5b4fbdce38) - Bug 1195173 - Apply CSP to preloaded styles within layout/style/Loader.cpp (r=bz) (d1ba920fd3) - Bug 1245681 - Fix addOverrideStyleSheet. r=bz (64099eac73) - Bug 1244074 - Part 4: Use StyleSheetHandle instead of concrete style sheet class in most places. r=dholberti (867470ac83) - Bug 1246013 (part 1) - Store a copy of the ETLDEntry directly in DomainEntry instead of a pointer to it. r=jduell. (587b3a9fb7) - Bug 1246013 (part 2) - Change "explicit/xpcom/effective-TLD-service" path to the more sensible "explicit/network/effective-TLD-service". r=jduell. (2e0df6f28f) - Bug 1247835 (part 1) - Use binary search instead of a hash table in nsEffectiveTLDService. r=jduell. (685dae01c0) - Bug 1257121 part 1 - Use struct for passing some params of font metrics. r=jfkthame (1dfd7a7429) - Bug 1257121 part 2 - Merge nsFontMetrics::Init to the constructor and remove unused failure handling code. r=jfkthame (0cdc441511) - Bug 1257121 part 3 - Add GetInflatedFontMetricsForFrame function to simplify a common use pattern. r=jfkthame (d9630ebd1b) - Bug 1257121 part 4 - Use return value rather than out param to retur font metrics. r=jfkthame (c9a5b1d1dd) - Bug 1257121 part 5 - Make nsDeviceContext::mFontCache a RefPtr. r=jfkthame (9c53238a6a) --- accessible/base/TextAttrs.cpp | 8 +- accessible/windows/sdn/sdnTextAccessible.cpp | 4 +- caps/nsScriptSecurityManager.cpp | 2 +- chrome/nsChromeRegistry.cpp | 28 +- docshell/base/nsDocShell.cpp | 25 +- .../base/timeline/AbstractTimelineMarker.h | 10 +- docshell/base/timeline/AutoTimelineMarker.h | 4 +- .../base/timeline/CompositeTimelineMarker.h | 4 +- .../base/timeline/ConsoleTimelineMarker.h | 4 +- docshell/base/timeline/EventTimelineMarker.h | 6 +- .../base/timeline/JavascriptTimelineMarker.h | 14 +- .../base/timeline/MessagePortTimelineMarker.h | 47 ++ .../base/timeline/RestyleTimelineMarker.h | 4 +- docshell/base/timeline/TimelineMarker.h | 14 +- docshell/base/timeline/WorkerTimelineMarker.h | 6 +- docshell/base/timeline/moz.build | 1 + dom/base/Console.cpp | 90 +-- dom/base/DOMException.cpp | 69 +-- dom/base/DOMException.h | 8 +- dom/base/FileReader.cpp | 6 +- dom/base/ScriptSettings.cpp | 77 +-- dom/base/ScriptSettings.h | 31 +- dom/base/ShadowRoot.cpp | 19 +- dom/base/ShadowRoot.h | 5 +- dom/base/StructuredCloneHolder.cpp | 5 +- dom/base/WebSocket.cpp | 42 +- dom/base/moz.build | 2 - dom/base/nsContentSink.cpp | 2 +- dom/base/nsContentSink.h | 2 +- dom/base/nsContentUtils.cpp | 1 - dom/base/nsDOMClassInfo.cpp | 355 ++---------- dom/base/nsDOMClassInfo.h | 39 +- dom/base/nsDOMClassInfoID.h | 4 - dom/base/nsDOMScriptObjectFactory.cpp | 127 ---- dom/base/nsDOMScriptObjectFactory.h | 50 -- dom/base/nsDOMWindowUtils.cpp | 1 + dom/base/nsDocument.cpp | 212 ++++--- dom/base/nsDocument.h | 61 +- dom/base/nsFrameMessageManager.cpp | 28 +- dom/base/nsGlobalWindow.cpp | 22 +- dom/base/nsGlobalWindow.h | 4 - dom/base/nsHostObjectProtocolHandler.cpp | 22 +- dom/base/nsIDOMClassInfo.h | 154 ----- dom/base/nsIDOMScriptObjectFactory.h | 45 -- dom/base/nsIDocument.h | 43 +- dom/base/nsIDocumentObserver.h | 38 +- dom/base/nsIScriptNameSpaceManager.h | 9 - dom/base/nsIStyleSheetLinkingElement.h | 9 +- dom/base/nsJSEnvironment.cpp | 120 ++-- dom/base/nsJSUtils.cpp | 19 +- dom/base/nsObjectLoadingContent.cpp | 12 +- dom/base/nsPIDOMWindow.h | 14 + dom/base/nsScriptLoader.cpp | 3 +- dom/base/nsScriptNameSpaceManager.cpp | 245 +------- dom/base/nsScriptNameSpaceManager.h | 32 +- dom/base/nsStructuredCloneContainer.cpp | 3 +- dom/base/nsStyleLinkElement.cpp | 32 +- dom/base/nsStyleLinkElement.h | 17 +- dom/base/nsXMLHttpRequest.cpp | 8 +- dom/bindings/BindingUtils.cpp | 16 + dom/bindings/Bindings.conf | 9 +- dom/bindings/CallbackObject.cpp | 6 +- dom/bindings/Codegen.py | 66 +++ dom/bindings/Configuration.py | 2 + dom/bindings/ErrorResult.h | 20 +- dom/bindings/Exceptions.cpp | 339 ++++------- dom/bindings/Exceptions.h | 8 +- dom/bindings/mozwebidlcodegen/__init__.py | 2 + dom/bindings/parser/WebIDL.py | 7 + .../common/BluetoothReplyRunnable.cpp | 4 +- dom/broadcastchannel/BroadcastChannel.cpp | 5 +- .../test_broadcastchannel_sharedWorker.html | 2 +- dom/cache/Feature.cpp | 4 +- dom/canvas/CanvasRenderingContext2D.cpp | 60 +- dom/canvas/ImageBitmap.cpp | 4 +- dom/canvas/WebGLContextLossHandler.cpp | 4 +- dom/datastore/DataStoreDB.cpp | 12 +- dom/events/ContentEventHandler.cpp | 17 +- dom/events/EventStateManager.cpp | 5 +- dom/fetch/Fetch.cpp | 20 +- dom/html/ImageDocument.cpp | 1 - dom/html/nsGenericHTMLElement.cpp | 4 +- dom/html/nsHTMLDocument.cpp | 24 +- dom/html/nsHTMLDocument.h | 7 +- dom/icc/Icc.cpp | 7 +- dom/identity/DOMIdentity.jsm | 8 +- dom/indexedDB/ActorsChild.cpp | 10 +- dom/indexedDB/IDBRequest.cpp | 10 +- dom/indexedDB/IDBTransaction.cpp | 7 +- .../base/nsIStructuredCloneContainer.idl | 3 +- .../notification/nsINotificationStorage.idl | 2 - dom/ipc/ContentChild.cpp | 5 +- dom/ipc/ContentParent.cpp | 145 +---- dom/mathml/nsMathMLElement.cpp | 4 +- dom/media/MediaPermissionGonk.cpp | 7 +- dom/messagechannel/MessageChannel.cpp | 23 +- dom/messagechannel/MessageChannel.h | 12 +- dom/messagechannel/MessagePort.cpp | 176 +++--- dom/messagechannel/MessagePort.h | 13 +- dom/notification/Notification.cpp | 115 ++-- dom/notification/Notification.h | 15 +- dom/plugins/base/nsJSNPRuntime.cpp | 331 ++++++----- dom/promise/Promise.cpp | 18 +- dom/promise/PromiseWorkerProxy.h | 8 +- dom/push/PushManager.cpp | 20 +- .../csp/file_child-src_worker-redirect.html | 2 +- dom/svg/SVGContentUtils.cpp | 5 +- dom/svg/SVGDocument.cpp | 26 +- dom/svg/SVGSVGElement.cpp | 3 +- dom/system/gonk/AudioManager.cpp | 3 +- dom/system/gonk/AutoMounterSetting.cpp | 4 +- dom/system/gonk/SystemWorkerManager.cpp | 10 +- dom/system/gonk/SystemWorkerManager.h | 4 +- dom/time/DateCacheCleaner.cpp | 1 - dom/webidl/ProfileTimelineMarker.webidl | 8 + dom/webidl/SharedWorker.webidl | 3 +- dom/webidl/URL.webidl | 2 +- dom/webidl/URLSearchParams.webidl | 2 +- dom/workers/DataStore.cpp | 10 +- dom/workers/RegisterBindings.cpp | 17 + dom/workers/RuntimeService.cpp | 176 ++---- dom/workers/ScriptLoader.cpp | 232 ++++++-- dom/workers/ScriptLoader.h | 9 +- dom/workers/ServiceWorkerClient.cpp | 3 + dom/workers/ServiceWorkerClients.cpp | 36 +- dom/workers/ServiceWorkerContainer.cpp | 1 + dom/workers/ServiceWorkerEvents.cpp | 8 +- dom/workers/ServiceWorkerManagerParent.cpp | 6 - dom/workers/ServiceWorkerManagerService.cpp | 1 + dom/workers/ServiceWorkerPrivate.cpp | 84 ++- dom/workers/ServiceWorkerPrivate.h | 3 + dom/workers/ServiceWorkerRegistrar.cpp | 1 + dom/workers/ServiceWorkerRegistration.cpp | 36 +- dom/workers/ServiceWorkerScriptCache.cpp | 2 + dom/workers/ServiceWorkerScriptCache.h | 2 + dom/workers/ServiceWorkerWindowClient.cpp | 9 +- dom/workers/SharedWorker.cpp | 1 + dom/workers/WorkerDebuggerManager.h | 1 + dom/workers/WorkerPrivate.cpp | 546 ++++++++++-------- dom/workers/WorkerPrivate.h | 89 +-- dom/workers/WorkerRunnable.cpp | 168 +++--- dom/workers/WorkerRunnable.h | 80 +-- dom/workers/WorkerScope.cpp | 20 +- dom/workers/WorkerScope.h | 5 +- dom/workers/XMLHttpRequest.cpp | 137 +++-- dom/workers/nsIWorkerDebugger.idl | 3 +- dom/workers/test/bug1132395_sharedWorker.js | 5 + .../serviceworkers/importscript_worker.js | 18 +- .../test/serviceworkers/lorem_script.js | 8 + dom/workers/test/serviceworkers/mochitest.ini | 1 + .../serviceworkers/test_privateBrowsing.html | 16 +- dom/workers/test/sharedWorker_sharedWorker.js | 5 + dom/workers/test/test_404.html | 2 +- dom/workers/test/test_bug1036484.html | 2 +- dom/workers/test/test_bug1132395.html | 25 +- dom/workers/test/test_bug949946.html | 13 +- .../test/test_consoleSharedWorkers.html | 5 +- dom/workers/test/test_loadError.html | 11 +- dom/workers/test/test_multi_sharedWorker.html | 9 - .../test_multi_sharedWorker_lifetimes.html | 16 +- dom/workers/test/test_recursion.html | 2 +- dom/workers/test/test_sharedWorker.html | 74 ++- .../test/test_sharedWorker_lifetime.html | 20 +- ..._sharedWorker_performance_user_timing.html | 17 +- dom/workers/test/test_sharedWorker_ports.html | 37 +- .../test_sharedWorker_privateBrowsing.html | 15 +- dom/workers/test/test_simpleThread.html | 2 +- dom/workers/test/test_throwingOnerror.html | 2 +- .../test/test_webSocket_sharedWorker.html | 17 +- dom/xbl/nsBindingManager.cpp | 3 +- dom/xbl/nsBindingManager.h | 7 +- dom/xbl/nsXBLDocumentInfo.cpp | 1 - dom/xbl/nsXBLPrototypeBinding.cpp | 30 +- dom/xbl/nsXBLPrototypeBinding.h | 15 +- dom/xbl/nsXBLPrototypeHandler.cpp | 1 - dom/xbl/nsXBLPrototypeResources.cpp | 30 +- dom/xbl/nsXBLPrototypeResources.h | 13 +- dom/xbl/nsXBLResourceLoader.cpp | 9 +- dom/xbl/nsXBLResourceLoader.h | 2 +- dom/xml/nsXMLContentSink.cpp | 2 +- dom/xml/nsXMLContentSink.h | 2 +- dom/xslt/moz.build | 1 - dom/xslt/nsIXSLTException.idl | 21 - dom/xslt/nsIXSLTProcessor.idl | 6 - dom/xslt/xslt/txMozillaXMLOutput.cpp | 2 +- dom/xslt/xslt/txMozillaXMLOutput.h | 2 +- dom/xul/XULDocument.cpp | 8 +- dom/xul/XULDocument.h | 5 +- dom/xul/nsXULElement.cpp | 43 +- dom/xul/nsXULPrototypeCache.cpp | 4 +- dom/xul/nsXULPrototypeDocument.cpp | 1 - editor/libeditor/nsEditor.cpp | 4 +- editor/libeditor/nsEditor.h | 6 +- editor/libeditor/nsHTMLEditor.cpp | 72 ++- editor/libeditor/nsHTMLEditor.h | 14 +- editor/libeditor/nsStyleSheetTxns.cpp | 11 +- editor/libeditor/nsStyleSheetTxns.h | 13 +- editor/nsIEditorStyleSheets.idl | 22 - extensions/auth/nsAuth.h | 2 +- extensions/auth/nsAuthFactory.cpp | 3 +- extensions/gio/nsGIOProtocolHandler.cpp | 4 +- .../pref/autoconfig/src/nsAutoConfig.cpp | 2 +- .../autoconfig/src/nsJSConfigTriggers.cpp | 10 +- .../pref/autoconfig/src/nsReadConfig.cpp | 4 +- gfx/layers/apz/util/ActiveElementManager.cpp | 4 +- gfx/src/nsDeviceContext.cpp | 105 +--- gfx/src/nsDeviceContext.h | 16 +- gfx/src/nsFontMetrics.cpp | 53 +- gfx/src/nsFontMetrics.h | 27 +- hal/Hal.cpp | 7 +- hal/HalLog.h | 2 +- ipc/chromium/src/base/logging.cc | 12 +- ipc/chromium/src/base/logging.h | 4 +- ipc/glue/BackgroundParent.h | 6 + ipc/glue/BackgroundParentImpl.cpp | 8 +- ipc/testshell/TestShellParent.cpp | 4 +- ipc/testshell/XPCShellEnvironment.cpp | 28 +- js/ipc/WrapperAnswer.cpp | 6 +- js/src/asmjs/Wasm.cpp | 8 +- js/src/builtin/TestingFunctions.cpp | 4 +- .../benchmarks/propertyTreeSplitting.js | 25 + js/src/devtools/gc-ubench/index.html | 1 + js/src/frontend/TokenStream.cpp | 26 +- js/src/jit-test/tests/wasm/basic.js | 2 + js/src/jsapi.cpp | 74 ++- js/src/jsapi.h | 72 ++- js/src/jscntxt.cpp | 34 +- js/src/jsexn.cpp | 109 ++-- js/src/jsfriendapi.h | 7 - js/src/proxy/BaseProxyHandler.cpp | 67 ++- js/src/shell/OSObject.cpp | 2 +- js/src/shell/js.cpp | 4 +- js/src/vm/Stack.cpp | 15 + js/src/vm/Stack.h | 1 + js/xpconnect/idl/nsIXPConnect.idl | 1 + js/xpconnect/idl/xpccomponents.idl | 1 + js/xpconnect/idl/xpcexception.idl | 2 +- js/xpconnect/loader/mozJSComponentLoader.cpp | 8 +- js/xpconnect/loader/mozJSSubScriptLoader.cpp | 2 +- js/xpconnect/src/Sandbox.cpp | 4 +- js/xpconnect/src/XPCComponents.cpp | 75 ++- js/xpconnect/src/XPCConvert.cpp | 30 +- js/xpconnect/src/XPCJSRuntime.cpp | 22 - js/xpconnect/src/XPCLog.cpp | 7 +- js/xpconnect/src/XPCShellImpl.cpp | 2 +- js/xpconnect/src/XPCWrappedJSClass.cpp | 40 +- js/xpconnect/src/nsXPConnect.cpp | 44 +- js/xpconnect/src/xpcprivate.h | 8 +- js/xpconnect/src/xpcpublic.h | 26 + js/xpconnect/tests/unit/test_bug641378.js | 46 -- js/xpconnect/tests/unit/xpcshell.ini | 1 - js/xpconnect/wrappers/XrayWrapper.cpp | 2 +- layout/base/PositionedEventTargeting.cpp | 5 +- layout/base/RestyleManager.cpp | 65 ++- layout/base/RestyleManager.h | 4 + layout/base/nsCSSFrameConstructor.cpp | 27 +- layout/base/nsCaret.cpp | 5 +- layout/base/nsDocumentViewer.cpp | 58 +- layout/base/nsFrameManagerBase.h | 1 - layout/base/nsIDocumentViewerPrint.h | 10 +- layout/base/nsIPresShell.h | 15 +- layout/base/nsLayoutUtils.cpp | 46 +- layout/base/nsLayoutUtils.h | 30 +- layout/base/nsPresContext.cpp | 47 +- layout/base/nsPresContext.h | 2 +- layout/base/nsPresShell.cpp | 105 ++-- layout/base/nsPresShell.h | 17 +- layout/base/nsStyleSheetService.cpp | 54 +- layout/base/nsStyleSheetService.h | 14 +- layout/build/nsLayoutModule.cpp | 5 - layout/forms/nsButtonFrameRenderer.cpp | 5 +- layout/forms/nsColorControlFrame.cpp | 3 +- layout/forms/nsComboboxControlFrame.cpp | 5 +- layout/forms/nsGfxButtonControlFrame.cpp | 3 +- layout/forms/nsHTMLButtonControlFrame.cpp | 1 - layout/forms/nsListControlFrame.cpp | 13 +- layout/forms/nsMeterFrame.cpp | 13 +- layout/forms/nsNumberControlFrame.cpp | 2 + layout/forms/nsProgressFrame.cpp | 7 +- layout/forms/nsRangeFrame.cpp | 5 +- layout/forms/nsTextControlFrame.cpp | 15 +- layout/generic/MathMLTextRunFactory.cpp | 19 +- layout/generic/TextOverflow.cpp | 15 +- layout/generic/nsBRFrame.cpp | 5 +- layout/generic/nsBlockFrame.cpp | 52 +- layout/generic/nsBlockFrame.h | 9 +- layout/generic/nsBulletFrame.cpp | 15 +- layout/generic/nsFirstLetterFrame.cpp | 3 +- layout/generic/nsFrameSetFrame.cpp | 5 +- layout/generic/nsGfxScrollFrame.cpp | 5 +- layout/generic/nsHTMLReflowState.cpp | 6 +- layout/generic/nsImageFrame.cpp | 8 +- layout/generic/nsInlineFrame.cpp | 2 + layout/generic/nsLineLayout.cpp | 10 +- layout/generic/nsPageFrame.cpp | 11 +- layout/generic/nsTextFrame.cpp | 20 +- layout/inspector/inDOMUtils.cpp | 14 +- layout/mathml/nsMathMLChar.cpp | 32 +- layout/mathml/nsMathMLContainerFrame.cpp | 10 +- layout/mathml/nsMathMLFrame.cpp | 9 +- layout/mathml/nsMathMLFrame.h | 10 +- layout/mathml/nsMathMLTokenFrame.cpp | 6 +- layout/mathml/nsMathMLmencloseFrame.cpp | 5 +- layout/mathml/nsMathMLmfencedFrame.cpp | 10 +- layout/mathml/nsMathMLmfracFrame.cpp | 5 +- layout/mathml/nsMathMLmmultiscriptsFrame.cpp | 5 +- layout/mathml/nsMathMLmoFrame.cpp | 10 +- layout/mathml/nsMathMLmrootFrame.cpp | 10 +- layout/mathml/nsMathMLmtableFrame.cpp | 11 +- layout/mathml/nsMathMLmunderoverFrame.cpp | 5 +- layout/printing/nsPrintEngine.cpp | 6 +- layout/printing/nsPrintObject.h | 1 - layout/style/CSSRuleList.h | 3 +- layout/style/CSSStyleSheet.cpp | 13 +- layout/style/CSSStyleSheet.h | 35 +- layout/style/CounterStyleManager.cpp | 20 +- layout/style/FontFaceSet.cpp | 2 +- layout/style/FontFaceSet.h | 2 +- layout/style/HandleRefPtr.h | 107 ++++ layout/style/Loader.cpp | 329 ++++++----- layout/style/Loader.h | 33 +- layout/style/ServoStyleSet.cpp | 191 ++++++ layout/style/ServoStyleSet.h | 112 ++++ layout/style/ServoStyleSheet.cpp | 152 +++++ layout/style/ServoStyleSheet.h | 68 +++ layout/style/SheetParsingMode.h | 43 ++ layout/style/StyleAnimationValue.cpp | 4 +- layout/style/StyleBackendType.h | 23 + layout/style/StyleSetHandle.h | 212 +++++++ layout/style/StyleSetHandleInlines.h | 241 ++++++++ layout/style/StyleSheetHandle.h | 196 +++++++ layout/style/StyleSheetHandleInlines.h | 204 +++++++ layout/style/moz.build | 11 + layout/style/nsAnimationManager.cpp | 20 +- layout/style/nsComputedDOMStyle.cpp | 12 +- layout/style/nsFontFaceUtils.cpp | 6 +- layout/style/nsICSSLoaderObserver.h | 13 +- layout/style/nsLayoutStylesheetCache.cpp | 277 ++++----- layout/style/nsLayoutStylesheetCache.h | 105 ++-- layout/style/nsMediaFeatures.cpp | 3 + layout/style/nsRuleNode.cpp | 32 +- layout/style/nsStyleContext.cpp | 11 +- layout/style/nsStyleSet.cpp | 36 +- layout/style/nsStyleSet.h | 14 +- layout/style/nsTransitionManager.cpp | 5 +- layout/tables/nsTableFrame.cpp | 3 +- layout/xul/nsListBoxBodyFrame.cpp | 12 +- layout/xul/nsSplitterFrame.cpp | 3 +- layout/xul/nsTextBoxFrame.cpp | 16 +- layout/xul/tree/nsTreeBodyFrame.cpp | 20 +- layout/xul/tree/nsTreeStyleCache.cpp | 8 +- mfbt/Assertions.h | 4 +- mfbt/BinarySearch.h | 18 +- mfbt/RefCounted.h | 1 - mfbt/Types.h | 2 +- mfbt/Variant.h | 166 +++++- mfbt/tests/TestVariant.cpp | 10 + modules/libjar/nsJARChannel.cpp | 5 +- modules/libpref/init/all.js | 3 - netwerk/base/ProxyAutoConfig.cpp | 2 +- netwerk/dns/nsEffectiveTLDService.cpp | 54 +- netwerk/dns/nsEffectiveTLDService.h | 99 ++-- netwerk/dns/prepare_tlds.py | 11 +- parser/htmlparser/nsExpatDriver.cpp | 27 +- rdf/base/nsCompositeDataSource.cpp | 4 +- rdf/base/nsInMemoryDataSource.cpp | 7 +- rdf/base/nsRDFContentSink.cpp | 7 +- rdf/base/nsRDFService.cpp | 5 +- rdf/base/nsRDFXMLDataSource.cpp | 6 +- security/sandbox/linux/glue/SandboxCrash.cpp | 12 +- storage/VacuumManager.cpp | 2 +- storage/mozStorageAsyncStatement.cpp | 2 +- storage/mozStorageConnection.cpp | 5 +- storage/mozStoragePrivateHelpers.cpp | 2 +- storage/mozStorageStatement.cpp | 2 +- testing/profiles/prefs_general.js | 3 - .../WorkerUtils/importScripts/002.html.ini | 5 - .../ctypes/tests/chrome/test_ctypes.xul | 4 +- toolkit/components/satchel/FormHistory.jsm | 18 +- .../satchel/test/unit/test_history_api.js | 59 +- toolkit/components/telemetry/Histograms.json | 17 + toolkit/content/finddialog.js | 22 +- uriloader/base/nsURILoader.cpp | 5 - widget/GfxInfoX11.h | 1 + widget/InputData.cpp | 1 + widget/MouseEvents.h | 2 +- widget/SystemTimeConverter.h | 12 +- widget/nsBaseClipboard.cpp | 26 +- widget/nsBaseClipboard.h | 4 +- widget/nsBaseDragService.cpp | 24 +- widget/nsBaseFilePicker.cpp | 4 +- widget/nsIBidiKeyboard.idl | 2 +- widget/nsIWidget.h | 16 +- widget/windows/GfxInfo.cpp | 21 +- widget/windows/GfxInfo.h | 48 +- widget/windows/IMMHandler.cpp | 44 +- widget/windows/IMMHandler.h | 25 +- xpcom/base/CycleCollectedJSRuntime.cpp | 35 ++ xpcom/base/CycleCollectedJSRuntime.h | 6 + xpcom/base/nsIException.idl | 16 +- xpcom/build/XPCOM.h | 1 - xpcom/io/moz.build | 1 - xpcom/io/nsISimpleUnicharStreamFactory.idl | 26 - xpcom/io/nsUnicharInputStream.h | 1 - xpfe/appshell/nsAppShellService.cpp | 5 - xpfe/appshell/nsChromeTreeOwner.cpp | 2 - xpfe/appshell/nsWindowMediator.cpp | 2 - xpfe/appshell/nsXULWindow.cpp | 6 - .../directory/nsDirectoryViewer.cpp | 5 +- 409 files changed, 6475 insertions(+), 5328 deletions(-) create mode 100644 docshell/base/timeline/MessagePortTimelineMarker.h delete mode 100644 dom/base/nsDOMScriptObjectFactory.cpp delete mode 100644 dom/base/nsDOMScriptObjectFactory.h delete mode 100644 dom/base/nsIDOMScriptObjectFactory.h create mode 100644 dom/workers/test/serviceworkers/lorem_script.js delete mode 100644 dom/xslt/nsIXSLTException.idl create mode 100644 js/src/devtools/gc-ubench/benchmarks/propertyTreeSplitting.js delete mode 100644 js/xpconnect/tests/unit/test_bug641378.js create mode 100644 layout/style/HandleRefPtr.h create mode 100644 layout/style/ServoStyleSet.cpp create mode 100644 layout/style/ServoStyleSet.h create mode 100644 layout/style/ServoStyleSheet.cpp create mode 100644 layout/style/ServoStyleSheet.h create mode 100644 layout/style/SheetParsingMode.h create mode 100644 layout/style/StyleBackendType.h create mode 100644 layout/style/StyleSetHandle.h create mode 100644 layout/style/StyleSetHandleInlines.h create mode 100644 layout/style/StyleSheetHandle.h create mode 100644 layout/style/StyleSheetHandleInlines.h delete mode 100644 testing/web-platform/meta/workers/interfaces/WorkerUtils/importScripts/002.html.ini delete mode 100644 xpcom/io/nsISimpleUnicharStreamFactory.idl diff --git a/accessible/base/TextAttrs.cpp b/accessible/base/TextAttrs.cpp index cf108d0c39..6acc803029 100644 --- a/accessible/base/TextAttrs.cpp +++ b/accessible/base/TextAttrs.cpp @@ -460,8 +460,8 @@ bool TextAttrsMgr::FontFamilyTextAttr:: GetFontFamily(nsIFrame* aFrame, nsString& aFamily) { - RefPtr fm; - nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm)); + RefPtr fm = + nsLayoutUtils::GetFontMetricsForFrame(aFrame, 1.0f); gfxFontGroup* fontGroup = fm->GetThebesFontGroup(); gfxFont* font = fontGroup->GetFirstValidFont(); @@ -618,8 +618,8 @@ TextAttrsMgr::FontWeightTextAttr:: { // nsFont::width isn't suitable here because it's necessary to expose real // value of font weight (used font might not have some font weight values). - RefPtr fm; - nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm)); + RefPtr fm = + nsLayoutUtils::GetFontMetricsForFrame(aFrame, 1.0f); gfxFontGroup *fontGroup = fm->GetThebesFontGroup(); gfxFont *font = fontGroup->GetFirstValidFont(); diff --git a/accessible/windows/sdn/sdnTextAccessible.cpp b/accessible/windows/sdn/sdnTextAccessible.cpp index 9bc7500e8b..b51caf44ed 100644 --- a/accessible/windows/sdn/sdnTextAccessible.cpp +++ b/accessible/windows/sdn/sdnTextAccessible.cpp @@ -179,8 +179,8 @@ sdnTextAccessible::get_fontFamily(BSTR __RPC_FAR* aFontFamily) if (!frame) return E_FAIL; - RefPtr fm; - nsLayoutUtils::GetFontMetricsForFrame(frame, getter_AddRefs(fm)); + RefPtr fm = + nsLayoutUtils::GetFontMetricsForFrame(frame, 1.0f); const nsString& name = fm->GetThebesFontGroup()->GetFirstValidFont()->GetName(); diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 1a881981be..6bb13ebcb0 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -465,7 +465,7 @@ nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(JSContext *cx) unsigned lineNum = 0; NS_NAMED_LITERAL_STRING(scriptSample, "call to eval() or related function blocked by CSP"); - JS::UniqueChars scriptFilename; + JS::AutoFilename scriptFilename; if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum)) { if (const char *file = scriptFilename.get()) { CopyUTF8toUTF16(nsDependentCString(file), fileName); diff --git a/chrome/nsChromeRegistry.cpp b/chrome/nsChromeRegistry.cpp index 1eb35372f0..b4c8b3063d 100644 --- a/chrome/nsChromeRegistry.cpp +++ b/chrome/nsChromeRegistry.cpp @@ -17,7 +17,6 @@ #include "nsString.h" #include "nsQueryObject.h" -#include "mozilla/CSSStyleSheet.h" #include "mozilla/dom/URL.h" #include "nsIConsoleService.h" #include "nsIDocument.h" @@ -30,12 +29,14 @@ #include "nsIScriptError.h" #include "nsIWindowMediator.h" #include "nsIPrefService.h" +#include "mozilla/StyleSheetHandle.h" +#include "mozilla/StyleSheetHandleInlines.h" nsChromeRegistry* nsChromeRegistry::gChromeRegistry; // DO NOT use namespace mozilla; it'll break due to a naming conflict between // mozilla::TextRange and a TextRange in OSX headers. -using mozilla::CSSStyleSheet; +using mozilla::StyleSheetHandle; using mozilla::dom::IsChromeURI; //////////////////////////////////////////////////////////////////////////////// @@ -414,19 +415,18 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) nsCOMPtr shell = document->GetShell(); if (shell) { // Reload only the chrome URL agent style sheets. - nsTArray> agentSheets; + nsTArray agentSheets; rv = shell->GetAgentStyleSheets(agentSheets); NS_ENSURE_SUCCESS(rv, rv); - nsTArray> newAgentSheets; - for (CSSStyleSheet* sheet : agentSheets) { + nsTArray newAgentSheets; + for (StyleSheetHandle sheet : agentSheets) { nsIURI* uri = sheet->GetSheetURI(); if (IsChromeURI(uri)) { // Reload the sheet. - RefPtr newSheet; - rv = document->LoadChromeSheetSync(uri, true, - getter_AddRefs(newSheet)); + StyleSheetHandle::RefPtr newSheet; + rv = document->LoadChromeSheetSync(uri, true, &newSheet); if (NS_FAILED(rv)) return rv; if (newSheet) { rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; @@ -446,27 +446,27 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) int32_t count = document->GetNumberOfStyleSheets(); // Build an array of style sheets we need to reload. - nsTArray> oldSheets(count); - nsTArray> newSheets(count); + nsTArray oldSheets(count); + nsTArray newSheets(count); // Iterate over the style sheets. for (int32_t i = 0; i < count; i++) { // Get the style sheet - CSSStyleSheet* styleSheet = document->GetStyleSheetAt(i); + StyleSheetHandle styleSheet = document->GetStyleSheetAt(i); oldSheets.AppendElement(styleSheet); } // Iterate over our old sheets and kick off a sync load of the new // sheet if and only if it's a chrome URL. - for (CSSStyleSheet* sheet : oldSheets) { + for (StyleSheetHandle sheet : oldSheets) { nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr; if (uri && IsChromeURI(uri)) { // Reload the sheet. - RefPtr newSheet; + StyleSheetHandle::RefPtr newSheet; // XXX what about chrome sheets that have a title or are disabled? This // only works by sheer dumb luck. - document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet)); + document->LoadChromeSheetSync(uri, false, &newSheet); // Even if it's null, we put in in there. newSheets.AppendElement(newSheet); } else { diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d27ccd7487..3c4c7c4f85 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -264,9 +264,9 @@ static uint32_t gValidateOrigin = 0xffffffff; #define NS_EVENT_STARVATION_DELAY_HINT 2000 #ifdef DEBUG -static PRLogModuleInfo* gDocShellLog; +static mozilla::LazyLogModule gDocShellLog("nsDocShell"); #endif -static PRLogModuleInfo* gDocShellLeakLog; +static mozilla::LazyLogModule gDocShellLeakLog("nsDocShellLeak");; const char kBrandBundleURL[] = "chrome://branding/locale/brand.properties"; const char kAppstringsBundleURL[] = "chrome://global/locale/appstrings.properties"; @@ -816,17 +816,7 @@ nsDocShell::nsDocShell() CallGetService(NS_URIFIXUP_CONTRACTID, &sURIFixup); } -#ifdef DEBUG - if (!gDocShellLog) { - gDocShellLog = PR_NewLogModule("nsDocShell"); - } -#endif - if (!gDocShellLeakLog) { - gDocShellLeakLog = PR_NewLogModule("nsDocShellLeak"); - } - if (gDocShellLeakLog) { - MOZ_LOG(gDocShellLeakLog, LogLevel::Debug, ("DOCSHELL %p created\n", this)); - } + MOZ_LOG(gDocShellLeakLog, LogLevel::Debug, ("DOCSHELL %p created\n", this)); #ifdef DEBUG // We're counting the number of |nsDocShells| to help find leaks @@ -885,8 +875,6 @@ nsDocShell::Init() NS_ASSERTION(mLoadGroup, "Something went wrong!"); mContentListener = new nsDSURIContentListener(this); - NS_ENSURE_TRUE(mContentListener, NS_ERROR_OUT_OF_MEMORY); - rv = mContentListener->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -894,7 +882,6 @@ nsDocShell::Init() // ref to us... use an InterfaceRequestorProxy to do this. nsCOMPtr proxy = new InterfaceRequestorProxy(static_cast(this)); - NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY); mLoadGroup->SetNotificationCallbacks(proxy); rv = nsDocLoader::AddDocLoaderAsChildOfRoot(this); @@ -1661,7 +1648,6 @@ NS_IMETHODIMP nsDocShell::CreateLoadInfo(nsIDocShellLoadInfo** aLoadInfo) { nsDocShellLoadInfo* loadInfo = new nsDocShellLoadInfo(); - NS_ENSURE_TRUE(loadInfo, NS_ERROR_OUT_OF_MEMORY); nsCOMPtr localRef(loadInfo); localRef.forget(aLoadInfo); @@ -2619,10 +2605,6 @@ nsDocShell::GetDocShellEnumerator(int32_t aItemType, int32_t aDirection, docShellEnum = new nsDocShellBackwardsEnumerator; } - if (!docShellEnum) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsresult rv = docShellEnum->SetEnumDocShellType(aItemType); if (NS_FAILED(rv)) { return rv; @@ -6553,7 +6535,6 @@ nsDocShell::RefreshURI(nsIURI* aURI, } nsRefreshTimer* refreshTimer = new nsRefreshTimer(); - NS_ENSURE_TRUE(refreshTimer, NS_ERROR_OUT_OF_MEMORY); uint32_t busyFlags = 0; GetBusyFlags(&busyFlags); diff --git a/docshell/base/timeline/AbstractTimelineMarker.h b/docshell/base/timeline/AbstractTimelineMarker.h index 5fde6631da..516b44eb0b 100644 --- a/docshell/base/timeline/AbstractTimelineMarker.h +++ b/docshell/base/timeline/AbstractTimelineMarker.h @@ -30,12 +30,12 @@ private: void operator=(const AbstractTimelineMarker& aOther) = delete; public: - explicit AbstractTimelineMarker(const char* aName, - MarkerTracingType aTracingType); + AbstractTimelineMarker(const char* aName, + MarkerTracingType aTracingType); - explicit AbstractTimelineMarker(const char* aName, - const TimeStamp& aTime, - MarkerTracingType aTracingType); + AbstractTimelineMarker(const char* aName, + const TimeStamp& aTime, + MarkerTracingType aTracingType); virtual ~AbstractTimelineMarker(); diff --git a/docshell/base/timeline/AutoTimelineMarker.h b/docshell/base/timeline/AutoTimelineMarker.h index e8a335a60d..47bb25046a 100644 --- a/docshell/base/timeline/AutoTimelineMarker.h +++ b/docshell/base/timeline/AutoTimelineMarker.h @@ -38,8 +38,8 @@ class MOZ_RAII AutoTimelineMarker RefPtr mDocShell; public: - explicit AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName - MOZ_GUARD_OBJECT_NOTIFIER_PARAM); + AutoTimelineMarker(nsIDocShell* aDocShell, + const char* aName MOZ_GUARD_OBJECT_NOTIFIER_PARAM); ~AutoTimelineMarker(); AutoTimelineMarker(const AutoTimelineMarker& aOther) = delete; diff --git a/docshell/base/timeline/CompositeTimelineMarker.h b/docshell/base/timeline/CompositeTimelineMarker.h index 571f5d7a30..45faefbd62 100644 --- a/docshell/base/timeline/CompositeTimelineMarker.h +++ b/docshell/base/timeline/CompositeTimelineMarker.h @@ -15,8 +15,8 @@ namespace mozilla { class CompositeTimelineMarker : public TimelineMarker { public: - explicit CompositeTimelineMarker(const TimeStamp& aTime, - MarkerTracingType aTracingType) + CompositeTimelineMarker(const TimeStamp& aTime, + MarkerTracingType aTracingType) : TimelineMarker("Composite", aTime, aTracingType) { // Even though these markers end up being created on the main thread in the diff --git a/docshell/base/timeline/ConsoleTimelineMarker.h b/docshell/base/timeline/ConsoleTimelineMarker.h index 3903649495..f397830c2d 100644 --- a/docshell/base/timeline/ConsoleTimelineMarker.h +++ b/docshell/base/timeline/ConsoleTimelineMarker.h @@ -15,8 +15,8 @@ namespace mozilla { class ConsoleTimelineMarker : public TimelineMarker { public: - explicit ConsoleTimelineMarker(const nsAString& aCause, - MarkerTracingType aTracingType) + ConsoleTimelineMarker(const nsAString& aCause, + MarkerTracingType aTracingType) : TimelineMarker("ConsoleTime", aTracingType) , mCause(aCause) { diff --git a/docshell/base/timeline/EventTimelineMarker.h b/docshell/base/timeline/EventTimelineMarker.h index 74dfb5e5c0..095bc528e9 100644 --- a/docshell/base/timeline/EventTimelineMarker.h +++ b/docshell/base/timeline/EventTimelineMarker.h @@ -15,9 +15,9 @@ namespace mozilla { class EventTimelineMarker : public TimelineMarker { public: - explicit EventTimelineMarker(const nsAString& aType, - uint16_t aPhase, - MarkerTracingType aTracingType) + EventTimelineMarker(const nsAString& aType, + uint16_t aPhase, + MarkerTracingType aTracingType) : TimelineMarker("DOMEvent", aTracingType) , mType(aType) , mPhase(aPhase) diff --git a/docshell/base/timeline/JavascriptTimelineMarker.h b/docshell/base/timeline/JavascriptTimelineMarker.h index 124dc82612..0214857d39 100644 --- a/docshell/base/timeline/JavascriptTimelineMarker.h +++ b/docshell/base/timeline/JavascriptTimelineMarker.h @@ -17,13 +17,13 @@ namespace mozilla { class JavascriptTimelineMarker : public TimelineMarker { public: - explicit JavascriptTimelineMarker(const char* aReason, - const char16_t* aFunctionName, - const char16_t* aFileName, - uint32_t aLineNumber, - MarkerTracingType aTracingType, - JS::Handle aAsyncStack, - JS::Handle aAsyncCause) + JavascriptTimelineMarker(const char* aReason, + const char16_t* aFunctionName, + const char16_t* aFileName, + uint32_t aLineNumber, + MarkerTracingType aTracingType, + JS::Handle aAsyncStack, + JS::Handle aAsyncCause) : TimelineMarker("Javascript", aTracingType, MarkerStackRequest::NO_STACK) , mCause(NS_ConvertUTF8toUTF16(aReason)) , mFunctionName(aFunctionName) diff --git a/docshell/base/timeline/MessagePortTimelineMarker.h b/docshell/base/timeline/MessagePortTimelineMarker.h new file mode 100644 index 0000000000..f578cf128b --- /dev/null +++ b/docshell/base/timeline/MessagePortTimelineMarker.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_MessagePortTimelineMarker_h_ +#define mozilla_MessagePortTimelineMarker_h_ + +#include "TimelineMarker.h" +#include "mozilla/dom/ProfileTimelineMarkerBinding.h" + +namespace mozilla { + +class MessagePortTimelineMarker : public TimelineMarker +{ +public: + MessagePortTimelineMarker(dom::ProfileTimelineMessagePortOperationType aOperationType, + MarkerTracingType aTracingType) + : TimelineMarker("MessagePort", aTracingType, MarkerStackRequest::NO_STACK) + , mOperationType(aOperationType) + {} + + virtual UniquePtr Clone() override + { + MessagePortTimelineMarker* clone = + new MessagePortTimelineMarker(mOperationType, GetTracingType()); + clone->SetCustomTime(GetTime()); + return UniquePtr(clone); + } + + virtual void AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker) override + { + TimelineMarker::AddDetails(aCx, aMarker); + + if (GetTracingType() == MarkerTracingType::START) { + aMarker.mMessagePortOperation.Construct(mOperationType); + } + } + +private: + dom::ProfileTimelineMessagePortOperationType mOperationType; +}; + +} // namespace mozilla + +#endif /* mozilla_MessagePortTimelineMarker_h_ */ diff --git a/docshell/base/timeline/RestyleTimelineMarker.h b/docshell/base/timeline/RestyleTimelineMarker.h index fcc37b05d8..71055b08e5 100644 --- a/docshell/base/timeline/RestyleTimelineMarker.h +++ b/docshell/base/timeline/RestyleTimelineMarker.h @@ -15,8 +15,8 @@ namespace mozilla { class RestyleTimelineMarker : public TimelineMarker { public: - explicit RestyleTimelineMarker(nsRestyleHint aRestyleHint, - MarkerTracingType aTracingType) + RestyleTimelineMarker(nsRestyleHint aRestyleHint, + MarkerTracingType aTracingType) : TimelineMarker("Styles", aTracingType) { if (aRestyleHint) { diff --git a/docshell/base/timeline/TimelineMarker.h b/docshell/base/timeline/TimelineMarker.h index 468d95d9c1..2e0b4dd021 100644 --- a/docshell/base/timeline/TimelineMarker.h +++ b/docshell/base/timeline/TimelineMarker.h @@ -18,14 +18,14 @@ namespace mozilla { class TimelineMarker : public AbstractTimelineMarker { public: - explicit TimelineMarker(const char* aName, - MarkerTracingType aTracingType, - MarkerStackRequest aStackRequest = MarkerStackRequest::STACK); + TimelineMarker(const char* aName, + MarkerTracingType aTracingType, + MarkerStackRequest aStackRequest = MarkerStackRequest::STACK); - explicit TimelineMarker(const char* aName, - const TimeStamp& aTime, - MarkerTracingType aTracingType, - MarkerStackRequest aStackRequest = MarkerStackRequest::STACK); + TimelineMarker(const char* aName, + const TimeStamp& aTime, + MarkerTracingType aTracingType, + MarkerStackRequest aStackRequest = MarkerStackRequest::STACK); virtual void AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker) override; virtual JSObject* GetStack() override; diff --git a/docshell/base/timeline/WorkerTimelineMarker.h b/docshell/base/timeline/WorkerTimelineMarker.h index 2b2b695003..b6b3692707 100644 --- a/docshell/base/timeline/WorkerTimelineMarker.h +++ b/docshell/base/timeline/WorkerTimelineMarker.h @@ -15,8 +15,8 @@ namespace mozilla { class WorkerTimelineMarker : public TimelineMarker { public: - explicit WorkerTimelineMarker(ProfileTimelineWorkerOperationType aOperationType, - MarkerTracingType aTracingType) + WorkerTimelineMarker(dom::ProfileTimelineWorkerOperationType aOperationType, + MarkerTracingType aTracingType) : TimelineMarker("Worker", aTracingType, MarkerStackRequest::NO_STACK) , mOperationType(aOperationType) {} @@ -38,7 +38,7 @@ public: } private: - ProfileTimelineWorkerOperationType mOperationType; + dom::ProfileTimelineWorkerOperationType mOperationType; }; } // namespace mozilla diff --git a/docshell/base/timeline/moz.build b/docshell/base/timeline/moz.build index 69f126596e..da330dbe2a 100644 --- a/docshell/base/timeline/moz.build +++ b/docshell/base/timeline/moz.build @@ -14,6 +14,7 @@ EXPORTS.mozilla += [ 'JavascriptTimelineMarker.h', 'LayerTimelineMarker.h', 'MarkersStorage.h', + 'MessagePortTimelineMarker.h', 'ObservedDocShell.h', 'RestyleTimelineMarker.h', 'TimelineConsumers.h', diff --git a/dom/base/Console.cpp b/dom/base/Console.cpp index 0e7fde7f14..b45580b1e5 100644 --- a/dom/base/Console.cpp +++ b/dom/base/Console.cpp @@ -298,7 +298,7 @@ public: return false; } - if (NS_WARN_IF(!mWorkerPrivate->AddFeature(cx, this))) { + if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) { return false; } @@ -360,7 +360,7 @@ private: mRunnable->ReleaseData(); mRunnable->mConsole = nullptr; - aWorkerPrivate->RemoveFeature(aCx, mRunnable); + aWorkerPrivate->RemoveFeature(mRunnable); return true; } @@ -371,7 +371,7 @@ private: RefPtr runnable = new ConsoleReleaseRunnable(mWorkerPrivate, this); - runnable->Dispatch(nullptr); + runnable->Dispatch(); } void @@ -1033,64 +1033,58 @@ Console::NoopMethod() static nsresult -StackFrameToStackEntry(nsIStackFrame* aStackFrame, - ConsoleStackEntry& aStackEntry, - uint32_t aLanguage) +StackFrameToStackEntry(JSContext* aCx, nsIStackFrame* aStackFrame, + ConsoleStackEntry& aStackEntry) { MOZ_ASSERT(aStackFrame); - nsresult rv = aStackFrame->GetFilename(aStackEntry.mFilename); + nsresult rv = aStackFrame->GetFilename(aCx, aStackEntry.mFilename); NS_ENSURE_SUCCESS(rv, rv); int32_t lineNumber; - rv = aStackFrame->GetLineNumber(&lineNumber); + rv = aStackFrame->GetLineNumber(aCx, &lineNumber); NS_ENSURE_SUCCESS(rv, rv); aStackEntry.mLineNumber = lineNumber; int32_t columnNumber; - rv = aStackFrame->GetColumnNumber(&columnNumber); + rv = aStackFrame->GetColumnNumber(aCx, &columnNumber); NS_ENSURE_SUCCESS(rv, rv); aStackEntry.mColumnNumber = columnNumber; - rv = aStackFrame->GetName(aStackEntry.mFunctionName); + rv = aStackFrame->GetName(aCx, aStackEntry.mFunctionName); NS_ENSURE_SUCCESS(rv, rv); nsString cause; - rv = aStackFrame->GetAsyncCause(cause); + rv = aStackFrame->GetAsyncCause(aCx, cause); NS_ENSURE_SUCCESS(rv, rv); if (!cause.IsEmpty()) { aStackEntry.mAsyncCause.Construct(cause); } - aStackEntry.mLanguage = aLanguage; + aStackEntry.mLanguage = nsIProgrammingLanguage::JAVASCRIPT; return NS_OK; } static nsresult -ReifyStack(nsIStackFrame* aStack, nsTArray& aRefiedStack) +ReifyStack(JSContext* aCx, nsIStackFrame* aStack, + nsTArray& aRefiedStack) { nsCOMPtr stack(aStack); while (stack) { - uint32_t language; - nsresult rv = stack->GetLanguage(&language); + ConsoleStackEntry& data = *aRefiedStack.AppendElement(); + nsresult rv = StackFrameToStackEntry(aCx, stack, data); NS_ENSURE_SUCCESS(rv, rv); - if (language == nsIProgrammingLanguage::JAVASCRIPT) { - ConsoleStackEntry& data = *aRefiedStack.AppendElement(); - rv = StackFrameToStackEntry(stack, data, language); - NS_ENSURE_SUCCESS(rv, rv); - } - nsCOMPtr caller; - rv = stack->GetCaller(getter_AddRefs(caller)); + rv = stack->GetCaller(aCx, getter_AddRefs(caller)); NS_ENSURE_SUCCESS(rv, rv); if (!caller) { - rv = stack->GetAsyncCaller(getter_AddRefs(caller)); + rv = stack->GetAsyncCaller(aCx, getter_AddRefs(caller)); NS_ENSURE_SUCCESS(rv, rv); } stack.swap(caller); @@ -1129,46 +1123,22 @@ Console::Method(JSContext* aCx, MethodName aMethodName, DEFAULT_MAX_STACKTRACE_DEPTH : 1; nsCOMPtr stack = CreateStack(aCx, maxDepth); - if (!stack) { - return; + if (stack) { + callData->mTopStackFrame.emplace(); + nsresult rv = StackFrameToStackEntry(aCx, stack, + *callData->mTopStackFrame); + if (NS_FAILED(rv)) { + return; + } } - // Walk up to the first JS stack frame and save it if we find it. - do { - uint32_t language; - nsresult rv = stack->GetLanguage(&language); - if (NS_FAILED(rv)) { - return; - } - - if (language == nsIProgrammingLanguage::JAVASCRIPT) { - callData->mTopStackFrame.emplace(); - nsresult rv = StackFrameToStackEntry(stack, - *callData->mTopStackFrame, - language); - if (NS_FAILED(rv)) { - return; - } - - break; - } - - nsCOMPtr caller; - rv = stack->GetCaller(getter_AddRefs(caller)); - if (NS_FAILED(rv)) { - return; - } - - stack.swap(caller); - } while (stack); - if (NS_IsMainThread()) { callData->mStack = stack; } else { // nsIStackFrame is not threadsafe, so we need to snapshot it now, // before we post our runnable to the main thread. callData->mReifiedStack.emplace(); - nsresult rv = ReifyStack(stack, *callData->mReifiedStack); + nsresult rv = ReifyStack(aCx, stack, *callData->mReifiedStack); if (NS_WARN_IF(NS_FAILED(rv))) { return; } @@ -1301,7 +1271,7 @@ LazyStackGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) nsIStackFrame* stack = reinterpret_cast(v.toPrivate()); nsTArray reifiedStack; - nsresult rv = ReifyStack(stack, reifiedStack); + nsresult rv = ReifyStack(aCx, stack, reifiedStack); if (NS_FAILED(rv)) { Throw(aCx, rv); return false; @@ -1333,12 +1303,14 @@ Console::ProcessCallData(ConsoleCallData* aData, JS::Handle aGlobal, frame = *aData->mTopStackFrame; } - AutoSafeJSContext cx; + AutoJSAPI jsapi; + if (!jsapi.Init(aGlobal)) { + return; + } + JSContext* cx = jsapi.cx(); ClearException ce(cx); RootedDictionary event(cx); - JSAutoCompartment ac(cx, aGlobal); - event.mID.Construct(); event.mInnerID.Construct(); diff --git a/dom/base/DOMException.cpp b/dom/base/DOMException.cpp index a035a4f98f..99587382c6 100644 --- a/dom/base/DOMException.cpp +++ b/dom/base/DOMException.cpp @@ -216,37 +216,7 @@ Exception::Exception(const nsACString& aMessage, sEverMadeOneFromFactory = true; } - nsCOMPtr location; - if (aLocation) { - location = aLocation; - } else { - location = GetCurrentJSStack(); - // it is legal for there to be no active JS stack, if C++ code - // is operating on a JS-implemented interface pointer without - // having been called in turn by JS. This happens in the JS - // component loader, and will become more common as additional - // components are implemented in JS. - } - // We want to trim off any leading native 'dataless' frames - if (location) { - while (1) { - uint32_t language; - int32_t lineNumber; - if (NS_FAILED(location->GetLanguage(&language)) || - language == nsIProgrammingLanguage::JAVASCRIPT || - NS_FAILED(location->GetLineNumber(&lineNumber)) || - lineNumber) { - break; - } - nsCOMPtr caller; - if (NS_FAILED(location->GetCaller(getter_AddRefs(caller))) || !caller) { - break; - } - location = caller; - } - } - - Initialize(aMessage, aResult, aName, location, aData); + Initialize(aMessage, aResult, aName, aLocation, aData); } Exception::Exception() @@ -336,12 +306,12 @@ Exception::GetName(nsACString& aName) } NS_IMETHODIMP -Exception::GetFilename(nsAString& aFilename) +Exception::GetFilename(JSContext* aCx, nsAString& aFilename) { NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); if (mLocation) { - return mLocation->GetFilename(aFilename); + return mLocation->GetFilename(aCx, aFilename); } aFilename.Assign(mFilename); @@ -349,14 +319,14 @@ Exception::GetFilename(nsAString& aFilename) } NS_IMETHODIMP -Exception::GetLineNumber(uint32_t *aLineNumber) +Exception::GetLineNumber(JSContext* aCx, uint32_t *aLineNumber) { NS_ENSURE_ARG_POINTER(aLineNumber); NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); if (mLocation) { int32_t lineno; - nsresult rv = mLocation->GetLineNumber(&lineno); + nsresult rv = mLocation->GetLineNumber(aCx, &lineno); *aLineNumber = lineno; return rv; } @@ -398,7 +368,7 @@ Exception::GetData(nsISupports** aData) } NS_IMETHODIMP -Exception::ToString(nsACString& _retval) +Exception::ToString(JSContext* aCx, nsACString& _retval) { NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); @@ -411,7 +381,7 @@ Exception::ToString(nsACString& _retval) if (mLocation) { // we need to free this if it does not fail - nsresult rv = mLocation->ToString(location); + nsresult rv = mLocation->ToString(aCx, location); NS_ENSURE_SUCCESS(rv, rv); } @@ -452,12 +422,11 @@ Exception::Initialize(const nsACString& aMessage, nsresult aResult, if (aLocation) { mLocation = aLocation; } else { - nsresult rv; - nsXPConnect* xpc = nsXPConnect::XPConnect(); - rv = xpc->GetCurrentJSStack(getter_AddRefs(mLocation)); - if (NS_FAILED(rv)) { - return rv; - } + mLocation = GetCurrentJSStack(); + // it is legal for there to be no active JS stack, if C++ code + // is operating on a JS-implemented interface pointer without + // having been called in turn by JS. This happens in the JS + // component loader. } mData = aData; @@ -503,11 +472,11 @@ Exception::GetName(nsString& retval) } uint32_t -Exception::LineNumber() const +Exception::LineNumber(JSContext* aCx) const { if (mLocation) { int32_t lineno; - if (NS_SUCCEEDED(mLocation->GetLineNumber(&lineno))) { + if (NS_SUCCEEDED(mLocation->GetLineNumber(aCx, &lineno))) { return lineno; } return 0; @@ -537,21 +506,21 @@ Exception::GetData() const } void -Exception::GetStack(nsAString& aStack, ErrorResult& aRv) const +Exception::GetStack(JSContext* aCx, nsAString& aStack, ErrorResult& aRv) const { if (mLocation) { - aRv = mLocation->GetFormattedStack(aStack); + aRv = mLocation->GetFormattedStack(aCx, aStack); } } void -Exception::Stringify(nsString& retval) +Exception::Stringify(JSContext* aCx, nsString& retval) { nsCString str; #ifdef DEBUG DebugOnly rv = #endif - ToString(str); + ToString(aCx, str); MOZ_ASSERT(NS_SUCCEEDED(rv)); CopyUTF8toUTF16(str, retval); } @@ -590,7 +559,7 @@ DOMException::GetCode(uint16_t* aCode) } NS_IMETHODIMP -DOMException::ToString(nsACString& aReturn) +DOMException::ToString(JSContext* aCx, nsACString& aReturn) { aReturn.Truncate(); diff --git a/dom/base/DOMException.h b/dom/base/DOMException.h index 0ad1a1f0c0..1c11d52fee 100644 --- a/dom/base/DOMException.h +++ b/dom/base/DOMException.h @@ -78,7 +78,7 @@ public: // The XPCOM GetFilename does the right thing. It might throw, but we want to // return an empty filename in that case anyway, instead of throwing. - uint32_t LineNumber() const; + uint32_t LineNumber(JSContext* aCx) const; uint32_t ColumnNumber() const; @@ -86,9 +86,9 @@ public: already_AddRefed GetData() const; - void GetStack(nsAString& aStack, ErrorResult& aRv) const; + void GetStack(JSContext* aCx, nsAString& aStack, ErrorResult& aRv) const; - void Stringify(nsString& retval); + void Stringify(JSContext* aCx, nsString& retval); // XPCOM factory ctor. Exception(); @@ -131,7 +131,7 @@ public: NS_DECL_NSIDOMDOMEXCEPTION // nsIException overrides - NS_IMETHOD ToString(nsACString& aReturn) override; + NS_IMETHOD ToString(JSContext* aCx, nsACString& aReturn) override; // nsWrapperCache overrides virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) diff --git a/dom/base/FileReader.cpp b/dom/base/FileReader.cpp index cabda2fe97..9fcb11194d 100644 --- a/dom/base/FileReader.cpp +++ b/dom/base/FileReader.cpp @@ -701,7 +701,7 @@ nsresult FileReader::IncreaseBusyCounter() { if (mWorkerPrivate && mBusyCount++ == 0 && - !mWorkerPrivate->AddFeature(mWorkerPrivate->GetJSContext(), this)) { + !mWorkerPrivate->AddFeature(this)) { return NS_ERROR_FAILURE; } @@ -713,7 +713,7 @@ FileReader::DecreaseBusyCounter() { MOZ_ASSERT_IF(mWorkerPrivate, mBusyCount); if (mWorkerPrivate && --mBusyCount == 0) { - mWorkerPrivate->RemoveFeature(mWorkerPrivate->GetJSContext(), this); + mWorkerPrivate->RemoveFeature(this); } } @@ -742,7 +742,7 @@ FileReader::Shutdown() } if (mWorkerPrivate && mBusyCount != 0) { - mWorkerPrivate->RemoveFeature(mWorkerPrivate->GetJSContext(), this); + mWorkerPrivate->RemoveFeature(this); mWorkerPrivate = nullptr; mBusyCount = 0; } diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index ef1e036e00..96119210b4 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -347,9 +347,10 @@ AutoJSAPI::InitInternal(JSObject* aGlobal, JSContext* aCx, bool aIsMainThread) mAutoNullableCompartment.emplace(mCx, aGlobal); } + JSRuntime* rt = JS_GetRuntime(aCx); + mOldErrorReporter.emplace(JS_GetErrorReporter(rt)); + if (aIsMainThread) { - JSRuntime* rt = JS_GetRuntime(aCx); - mOldErrorReporter.emplace(JS_GetErrorReporter(rt)); JS_SetErrorReporter(rt, xpc::SystemErrorReporter); } } @@ -410,14 +411,6 @@ AutoJSAPI::Init(JSObject* aObject) return Init(xpc::NativeGlobal(aObject)); } -bool -AutoJSAPI::InitWithLegacyErrorReporting(nsIGlobalObject* aGlobalObject) -{ - MOZ_ASSERT(NS_IsMainThread()); - - return Init(aGlobalObject, FindJSContext(aGlobalObject)); -} - bool AutoJSAPI::Init(nsPIDOMWindow* aWindow, JSContext* aCx) { @@ -442,18 +435,6 @@ AutoJSAPI::Init(nsGlobalWindow* aWindow) return Init(static_cast(aWindow)); } -bool -AutoJSAPI::InitWithLegacyErrorReporting(nsPIDOMWindow* aWindow) -{ - return InitWithLegacyErrorReporting(static_cast(aWindow)); -} - -bool -AutoJSAPI::InitWithLegacyErrorReporting(nsGlobalWindow* aWindow) -{ - return InitWithLegacyErrorReporting(static_cast(aWindow)); -} - // Even with autoJSAPIOwnsErrorReporting, the JS engine still sends warning // reports to the JSErrorReporter as soon as they are generated. These go // directly to the console, so we can handle them easily here. @@ -463,11 +444,30 @@ AutoJSAPI::InitWithLegacyErrorReporting(nsGlobalWindow* aWindow) void WarningOnlyErrorReporter(JSContext* aCx, const char* aMessage, JSErrorReport* aRep) { - MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(JSREPORT_IS_WARNING(aRep->flags)); + if (!NS_IsMainThread()) { + // Reporting a warning on workers is a bit complicated because we have to + // climb our parent chain until we get to the main thread. So go ahead and + // just go through the worker ReportError codepath here. + // + // That said, it feels like we should be able to short-circuit things a bit + // here by posting an appropriate runnable to the main thread directly... + // Worth looking into sometime. + workers::WorkerPrivate* worker = workers::GetWorkerPrivateFromContext(aCx); + MOZ_ASSERT(worker); + + worker->ReportError(aCx, aMessage, aRep); + return; + } RefPtr xpcReport = new xpc::ErrorReport(); - nsPIDOMWindow* win = xpc::CurrentWindowOrNull(aCx); + nsGlobalWindow* win = xpc::CurrentWindowOrNull(aCx); + if (!win) { + // We run addons in a separate privileged compartment, but if we're in an + // addon compartment we should log warnings to the console of the associated + // DOM Window. + win = xpc::AddonWindowOrNull(JS::CurrentGlobalOrNull(aCx)); + } xpcReport->Init(aRep, aMessage, nsContentUtils::IsCallerChrome(), win ? win->WindowID() : 0); xpcReport->LogToConsole(); @@ -482,13 +482,7 @@ AutoJSAPI::TakeOwnershipOfErrorReporting() JSRuntime *rt = JS_GetRuntime(cx()); mOldAutoJSAPIOwnsErrorReporting = JS::ContextOptionsRef(cx()).autoJSAPIOwnsErrorReporting(); JS::ContextOptionsRef(cx()).setAutoJSAPIOwnsErrorReporting(true); - // Workers have their own error reporting mechanism which deals with warnings - // as well, so don't change the worker error reporter for now. Once we switch - // all of workers to TakeOwnershipOfErrorReporting(), we will just make the - // default worker error reporter assert that it only sees warnings. - if (mIsMainThread) { - JS_SetErrorReporter(rt, WarningOnlyErrorReporter); - } + JS_SetErrorReporter(rt, WarningOnlyErrorReporter); } void @@ -518,14 +512,22 @@ AutoJSAPI::ReportException() if (StealException(&exn) && jsReport.init(cx(), exn)) { if (mIsMainThread) { RefPtr xpcReport = new xpc::ErrorReport(); + nsCOMPtr win = xpc::WindowGlobalOrNull(errorGlobal); + if (!win) { + // We run addons in a separate privileged compartment, but they still + // expect to trigger the onerror handler of their associated DOM Window. + win = xpc::AddonWindowOrNull(errorGlobal); + } xpcReport->Init(jsReport.report(), jsReport.message(), nsContentUtils::IsCallerChrome(), win ? win->WindowID() : 0); - if (win) { + if (win && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) { DispatchScriptErrorEvent(win, JS_GetRuntime(cx()), xpcReport, exn); } else { - xpcReport->LogToConsole(); + JS::Rooted stack(cx(), + xpc::FindExceptionStackForConsoleReport(win, exn)); + xpcReport->LogToConsoleWithStack(stack); } } else { // On a worker, we just use the worker error reporting mechanism and don't @@ -545,6 +547,7 @@ AutoJSAPI::ReportException() } } else { NS_WARNING("OOMed while acquiring uncaught exception from JSAPI"); + ClearException(); } } @@ -588,6 +591,14 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, } } +AutoEntryScript::AutoEntryScript(JSObject* aObject, + const char *aReason, + bool aIsMainThread, + JSContext* aCx) + : AutoEntryScript(xpc::NativeGlobal(aObject), aReason, aIsMainThread, aCx) +{ +} + AutoEntryScript::~AutoEntryScript() { // GC when we pop a script entry point. This is a useful heuristic that helps diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index 9a8f7f1ade..4bbb5adaec 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -221,12 +221,20 @@ public: // This uses the SafeJSContext (or worker equivalent), and enters a null // compartment, so that the consumer is forced to select a compartment to // enter before manipulating objects. + // + // This variant will ensure that any errors reported by this AutoJSAPI as it + // comes off the stack will not fire error events or be associated with any + // particular web-visible global. void Init(); // This uses the SafeJSContext (or worker equivalent), and enters the // compartment of aGlobalObject. // If aGlobalObject or its associated JS global are null then it returns // false and use of cx() will cause an assertion. + // + // If aGlobalObject represents a web-visible global, errors reported by this + // AutoJSAPI as it comes off the stack will fire the relevant error events and + // show up in the corresponding web console. bool Init(nsIGlobalObject* aGlobalObject); // This is a helper that grabs the native global associated with aObject and @@ -237,18 +245,12 @@ public: // If aGlobalObject or its associated JS global are null then it returns // false and use of cx() will cause an assertion. // If aCx is null it will cause an assertion. + // + // If aGlobalObject represents a web-visible global, errors reported by this + // AutoJSAPI as it comes off the stack will fire the relevant error events and + // show up in the corresponding web console. bool Init(nsIGlobalObject* aGlobalObject, JSContext* aCx); - // This may only be used on the main thread. - // This attempts to use the JSContext associated with aGlobalObject, otherwise - // it uses the SafeJSContext. It then enters the compartment of aGlobalObject. - // This means that existing error reporting mechanisms that use the JSContext - // to find the JSErrorReporter should still work as before. - // We should be able to remove this around bug 981198. - // If aGlobalObject or its associated JS global are null then it returns - // false and use of cx() will cause an assertion. - bool InitWithLegacyErrorReporting(nsIGlobalObject* aGlobalObject); - // Convenience functions to take an nsPIDOMWindow* or nsGlobalWindow*, // when it is more easily available than an nsIGlobalObject. bool Init(nsPIDOMWindow* aWindow); @@ -257,9 +259,6 @@ public: bool Init(nsGlobalWindow* aWindow); bool Init(nsGlobalWindow* aWindow, JSContext* aCx); - bool InitWithLegacyErrorReporting(nsPIDOMWindow* aWindow); - bool InitWithLegacyErrorReporting(nsGlobalWindow* aWindow); - JSContext* cx() const { MOZ_ASSERT(mCx, "Must call Init before using an AutoJSAPI"); MOZ_ASSERT_IF(mIsMainThread, CxPusherIsStackTop()); @@ -346,6 +345,12 @@ public: // Note: aCx is mandatory off-main-thread. JSContext* aCx = nullptr); + AutoEntryScript(JSObject* aObject, // Any object from the relevant global + const char *aReason, + bool aIsMainThread = NS_IsMainThread(), + // Note: aCx is mandatory off-main-thread. + JSContext* aCx = nullptr); + ~AutoEntryScript(); void SetWebIDLCallerPrincipal(nsIPrincipal *aPrincipal) { diff --git a/dom/base/ShadowRoot.cpp b/dom/base/ShadowRoot.cpp index ed60e55ae2..120aeb34d2 100644 --- a/dom/base/ShadowRoot.cpp +++ b/dom/base/ShadowRoot.cpp @@ -17,6 +17,8 @@ #include "mozilla/dom/HTMLContentElement.h" #include "mozilla/dom/HTMLShadowElement.h" #include "nsXBLPrototypeBinding.h" +#include "mozilla/StyleSheetHandle.h" +#include "mozilla/StyleSheetHandleInlines.h" using namespace mozilla; using namespace mozilla::dom; @@ -130,7 +132,7 @@ ShadowRoot::StyleSheetChanged() } void -ShadowRoot::InsertSheet(CSSStyleSheet* aSheet, +ShadowRoot::InsertSheet(StyleSheetHandle aSheet, nsIContent* aLinkingContent) { nsCOMPtr @@ -148,8 +150,8 @@ ShadowRoot::InsertSheet(CSSStyleSheet* aSheet, break; } - nsINode* sheetOwnerNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode(); - if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwnerNode)) { + nsINode* sheetOwningNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode(); + if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) { mProtoBinding->InsertStyleSheetAt(i, aSheet); break; } @@ -161,7 +163,7 @@ ShadowRoot::InsertSheet(CSSStyleSheet* aSheet, } void -ShadowRoot::RemoveSheet(CSSStyleSheet* aSheet) +ShadowRoot::RemoveSheet(StyleSheetHandle aSheet) { mProtoBinding->RemoveStyleSheet(aSheet); @@ -752,7 +754,14 @@ ShadowRootStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound) return nullptr; } - return mShadowRoot->mProtoBinding->StyleSheetAt(aIndex); + // XXXheycam Return null until ServoStyleSheet implements the right + // DOM interfaces. + StyleSheetHandle sheet = mShadowRoot->mProtoBinding->StyleSheetAt(aIndex); + if (sheet->IsServo()) { + NS_ERROR("stylo: can't return ServoStyleSheets to script yet"); + return nullptr; + } + return sheet->AsGecko(); } uint32_t diff --git a/dom/base/ShadowRoot.h b/dom/base/ShadowRoot.h index a2b71244c5..cbf4cfb088 100644 --- a/dom/base/ShadowRoot.h +++ b/dom/base/ShadowRoot.h @@ -9,6 +9,7 @@ #include "mozilla/dom/DocumentFragment.h" #include "mozilla/dom/StyleSheetList.h" +#include "mozilla/StyleSheetHandle.h" #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" #include "nsTHashtable.h" @@ -45,8 +46,8 @@ public: void AddToIdTable(Element* aElement, nsIAtom* aId); void RemoveFromIdTable(Element* aElement, nsIAtom* aId); - void InsertSheet(CSSStyleSheet* aSheet, nsIContent* aLinkingContent); - void RemoveSheet(CSSStyleSheet* aSheet); + void InsertSheet(StyleSheetHandle aSheet, nsIContent* aLinkingContent); + void RemoveSheet(StyleSheetHandle aSheet); bool ApplyAuthorStyles(); void SetApplyAuthorStyles(bool aApplyAuthorStyles); StyleSheetList* StyleSheets(); diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 3540a00adc..f0da538093 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -295,6 +295,7 @@ StructuredCloneHolder::Read(nsISupports* aParent, { MOZ_ASSERT_IF(mSupportedContext == SameProcessSameThread, mCreationThread == NS_GetCurrentThread()); + MOZ_ASSERT(aParent); mozilla::AutoRestore guard(mParent); mParent = aParent; @@ -1044,9 +1045,11 @@ StructuredCloneHolder::CustomReadTransferHandler(JSContext* aCx, MOZ_ASSERT(aExtraData < mPortIdentifiers.Length()); const MessagePortIdentifier& portIdentifier = mPortIdentifiers[aExtraData]; + nsCOMPtr global = do_QueryInterface(mParent); + ErrorResult rv; RefPtr port = - MessagePort::Create(mParent, portIdentifier, rv); + MessagePort::Create(global, portIdentifier, rv); if (NS_WARN_IF(rv.Failed())) { return false; } diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index 972e0aa77a..d8a47bc8d1 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -1258,7 +1258,7 @@ WebSocket::Constructor(const GlobalObject& aGlobal, } unsigned lineno, column; - JS::UniqueChars file; + JS::AutoFilename file; if (!JS::DescribeScriptedCaller(aGlobal.Context(), &file, &lineno, &column)) { NS_WARNING("Failed to get line number and filename in workers."); @@ -1493,7 +1493,7 @@ WebSocketImpl::Init(JSContext* aCx, MOZ_ASSERT(aCx); unsigned lineno, column; - JS::UniqueChars file; + JS::AutoFilename file; if (JS::DescribeScriptedCaller(aCx, &file, &lineno, &column)) { mScriptFile = file.get(); mScriptLine = lineno; @@ -2148,8 +2148,7 @@ WebSocketImpl::RegisterFeature() MOZ_ASSERT(!mWorkerFeature); mWorkerFeature = new WebSocketWorkerFeature(this); - JSContext* cx = GetCurrentThreadJSContext(); - if (!mWorkerPrivate->AddFeature(cx, mWorkerFeature)) { + if (!mWorkerPrivate->AddFeature(mWorkerFeature)) { NS_WARNING("Failed to register a feature."); mWorkerFeature = nullptr; return false; @@ -2170,8 +2169,7 @@ WebSocketImpl::UnregisterFeature() mWorkerPrivate->AssertIsOnWorkerThread(); MOZ_ASSERT(mWorkerFeature); - JSContext* cx = GetCurrentThreadJSContext(); - mWorkerPrivate->RemoveFeature(cx, mWorkerFeature); + mWorkerPrivate->RemoveFeature(mWorkerFeature); mWorkerFeature = nullptr; mWorkerPrivate = nullptr; @@ -2525,20 +2523,21 @@ public: { } - bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) + bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override { aWorkerPrivate->AssertIsOnWorkerThread(); - aWorkerPrivate->ModifyBusyCountFromWorker(aCx, true); + aWorkerPrivate->ModifyBusyCountFromWorker(true); return !NS_FAILED(mImpl->CancelInternal()); } - void PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult) + void PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, + bool aRunResult) override { - aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false); + aWorkerPrivate->ModifyBusyCountFromWorker(false); } bool - PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) + PreDispatch(WorkerPrivate* aWorkerPrivate) override { // We don't call WorkerRunnable::PreDispatch because it would assert the // wrong thing about which thread we're on. @@ -2547,8 +2546,7 @@ public: } void - PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate, - bool aDispatchResult) + PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override { // We don't call WorkerRunnable::PostDispatch because it would assert the // wrong thing about which thread we're on. @@ -2571,7 +2569,7 @@ WebSocketImpl::Cancel(nsresult aStatus) MOZ_ASSERT(mWorkerPrivate); RefPtr runnable = new CancelRunnable(mWorkerPrivate, this); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { return NS_ERROR_FAILURE; } @@ -2695,10 +2693,10 @@ public: { } - bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) + bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override { aWorkerPrivate->AssertIsOnWorkerThread(); - aWorkerPrivate->ModifyBusyCountFromWorker(aCx, true); + aWorkerPrivate->ModifyBusyCountFromWorker(true); // No messages when disconnected. if (mWebSocketImpl->mDisconnectingOrDisconnected) { @@ -2709,13 +2707,14 @@ public: return !NS_FAILED(mEvent->Run()); } - void PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult) + void PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, + bool aRunResult) override { - aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false); + aWorkerPrivate->ModifyBusyCountFromWorker(false); } bool - PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) + PreDispatch(WorkerPrivate* aWorkerPrivate) override { // We don't call WorkerRunnable::PreDispatch because it would assert the // wrong thing about which thread we're on. We're on whichever thread the @@ -2725,8 +2724,7 @@ public: } void - PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate, - bool aDispatchResult) + PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override { // We don't call WorkerRunnable::PreDispatch because it would assert the // wrong thing about which thread we're on. We're on whichever thread the @@ -2772,7 +2770,7 @@ WebSocketImpl::Dispatch(already_AddRefed&& aEvent, uint32_t aFlags) RefPtr event = new WorkerRunnableDispatcher(this, mWorkerPrivate, event_ref.forget()); - if (!event->Dispatch(nullptr)) { + if (!event->Dispatch()) { return NS_ERROR_FAILURE; } diff --git a/dom/base/moz.build b/dom/base/moz.build index a1e8aba519..039f513920 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -92,7 +92,6 @@ EXPORTS += [ 'nsIDocumentInlines.h', 'nsIDocumentObserver.h', 'nsIDOMClassInfo.h', - 'nsIDOMScriptObjectFactory.h', 'nsIGlobalObject.h', 'nsImageLoadingContent.h', 'nsIMutationObserver.h', @@ -276,7 +275,6 @@ UNIFIED_SOURCES += [ 'nsDOMClassInfo.cpp', 'nsDOMMutationObserver.cpp', 'nsDOMNavigationTiming.cpp', - 'nsDOMScriptObjectFactory.cpp', 'nsDOMSerializer.cpp', 'nsDOMTokenList.cpp', 'nsDOMWindowList.cpp', diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp index 51052013c0..6d0d84bd26 100644 --- a/dom/base/nsContentSink.cpp +++ b/dom/base/nsContentSink.cpp @@ -213,7 +213,7 @@ nsContentSink::Init(nsIDocument* aDoc, } NS_IMETHODIMP -nsContentSink::StyleSheetLoaded(CSSStyleSheet* aSheet, +nsContentSink::StyleSheetLoaded(StyleSheetHandle aSheet, bool aWasAlternate, nsresult aStatus) { diff --git a/dom/base/nsContentSink.h b/dom/base/nsContentSink.h index e65c6f7eda..a5b1e2ab7c 100644 --- a/dom/base/nsContentSink.h +++ b/dom/base/nsContentSink.h @@ -85,7 +85,7 @@ class nsContentSink : public nsICSSLoaderObserver, NS_DECL_NSITIMERCALLBACK // nsICSSLoaderObserver - NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet, + NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet, bool aWasAlternate, nsresult aStatus) override; diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 742d66a006..d79c2ab071 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -117,7 +117,6 @@ #include "nsIDOMHTMLInputElement.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIDOMWindowUtils.h" #include "nsIDOMXULCommandEvent.h" #include "nsIDragService.h" diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 97657971fd..8d26a41ec1 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -26,6 +26,7 @@ #include "nscore.h" #include "nsDOMClassInfo.h" +#include "nsIDOMClassInfo.h" #include "nsCRT.h" #include "nsCRTGlue.h" #include "nsICategoryManager.h" @@ -117,8 +118,6 @@ using namespace mozilla; using namespace mozilla::dom; -static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); - // NOTE: DEFAULT_SCRIPTABLE_FLAGS and DOM_DEFAULT_SCRIPTABLE_FLAGS // are defined in nsIDOMClassInfo.h. @@ -149,7 +148,7 @@ static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); _chromeOnly, _allowXBL) \ { #_class, \ nullptr, \ - { _helper::doCreate }, \ + _helper::doCreate, \ nullptr, \ nullptr, \ nullptr, \ @@ -335,9 +334,13 @@ nsDOMClassInfo::GetNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj) } nsresult -nsDOMClassInfo::DefineStaticJSVals(JSContext *cx) +nsDOMClassInfo::DefineStaticJSVals() { -#define SET_JSID_TO_STRING(_id, _cx, _str) \ + AutoJSAPI jsapi; + jsapi.Init(xpc::UnprivilegedJunkScope()); + JSContext* cx = jsapi.cx(); + +#define SET_JSID_TO_STRING(_id, _cx, _str) \ if (JSString *str = ::JS_AtomizeAndPinString(_cx, _str)) \ _id = INTERNED_STRING_TO_JSID(_cx, str); \ else \ @@ -361,15 +364,6 @@ nsDOMClassInfo::nsDOMClassInfo(nsDOMClassInfoData* aData) : mData(aData) { } -nsDOMClassInfo::~nsDOMClassInfo() -{ - if (IS_EXTERNAL(mData->mCachedClassInfo)) { - // Some compilers don't like delete'ing a const nsDOMClassInfo* - nsDOMClassInfoData* data = const_cast(mData); - delete static_cast(data); - } -} - NS_IMPL_ADDREF(nsDOMClassInfo) NS_IMPL_RELEASE(nsDOMClassInfo) @@ -457,58 +451,6 @@ nsDOMClassInfo::RegisterClassProtos(int32_t aClassInfoID) return NS_OK; } -// static -nsresult -nsDOMClassInfo::RegisterExternalClasses() -{ - nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); - NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED); - - nsCOMPtr registrar; - nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(registrar)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr cm = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr e; - rv = cm->EnumerateCategory(JAVASCRIPT_DOM_CLASS, getter_AddRefs(e)); - NS_ENSURE_SUCCESS(rv, rv); - - nsXPIDLCString contractId; - nsAutoCString categoryEntry; - nsCOMPtr entry; - - while (NS_SUCCEEDED(e->GetNext(getter_AddRefs(entry)))) { - nsCOMPtr category(do_QueryInterface(entry)); - - if (!category) { - NS_WARNING("Category entry not an nsISupportsCString!"); - continue; - } - - rv = category->GetData(categoryEntry); - - cm->GetCategoryEntry(JAVASCRIPT_DOM_CLASS, categoryEntry.get(), - getter_Copies(contractId)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCID *cid; - rv = registrar->ContractIDToCID(contractId, &cid); - if (NS_FAILED(rv)) { - NS_WARNING("Bad contract id registered with the script namespace manager"); - continue; - } - - rv = nameSpaceManager->RegisterExternalClassName(categoryEntry.get(), *cid); - free(cid); - NS_ENSURE_SUCCESS(rv, rv); - } - - return nameSpaceManager->RegisterExternalInterfaces(true); -} - #define _DOM_CLASSINFO_MAP_BEGIN(_class, _ifptr, _has_class_if) \ { \ nsDOMClassInfoData &d = sClassInfoData[eDOMClassInfo_##_class##_id]; \ @@ -571,8 +513,6 @@ nsDOMClassInfo::Init() nsCOMPtr elt = new nsEventListenerThisTranslator(); sXPConnect->SetFunctionThisTranslator(NS_GET_IID(nsIDOMEventListener), elt); - AutoSafeJSContext cx; - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(DOMPrototype, nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_END @@ -719,7 +659,7 @@ nsDOMClassInfo::Init() #ifdef DEBUG for (size_t i = 0; i < eDOMClassInfoIDCount; i++) { - if (!sClassInfoData[i].u.mConstructorFptr || + if (!sClassInfoData[i].mConstructorFptr || sClassInfoData[i].mDebugID != i) { MOZ_CRASH("Class info data out of sync, you forgot to update " "nsDOMClassInfo.h and nsDOMClassInfo.cpp! Fix this, " @@ -736,7 +676,7 @@ nsDOMClassInfo::Init() #endif // Initialize static JSString's - DefineStaticJSVals(cx); + DefineStaticJSVals(); int32_t i; @@ -754,8 +694,6 @@ nsDOMClassInfo::Init() RegisterClassProtos(i); } - RegisterExternalClasses(); - sIsInitialized = true; return NS_OK; @@ -987,41 +925,6 @@ nsDOMClassInfo::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx, return NS_ERROR_UNEXPECTED; } -static nsresult -GetExternalClassInfo(nsScriptNameSpaceManager *aNameSpaceManager, - const nsAString &aName, - const nsGlobalNameStruct *aStruct, - const nsGlobalNameStruct **aResult) -{ - NS_ASSERTION(aStruct->mType == - nsGlobalNameStruct::eTypeExternalClassInfoCreator, - "Wrong type!"); - - nsresult rv; - nsCOMPtr creator(do_CreateInstance(aStruct->mCID, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr sof(do_GetService(kDOMSOF_CID)); - NS_ENSURE_TRUE(sof, NS_ERROR_FAILURE); - - rv = creator->RegisterDOMCI(NS_ConvertUTF16toUTF8(aName).get(), sof); - NS_ENSURE_SUCCESS(rv, rv); - - const nsGlobalNameStruct *name_struct = aNameSpaceManager->LookupName(aName); - if (name_struct && - name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - *aResult = name_struct; - } - else { - NS_ERROR("Couldn't get the DOM ClassInfo data."); - - *aResult = nullptr; - } - - return NS_OK; -} - - static nsresult ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx, JS::Handle obj, const char16_t *name, @@ -1155,48 +1058,20 @@ NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID) if (!sClassInfoData[aID].mCachedClassInfo) { nsDOMClassInfoData& data = sClassInfoData[aID]; - data.mCachedClassInfo = data.u.mConstructorFptr(&data); + data.mCachedClassInfo = data.mConstructorFptr(&data); NS_ENSURE_TRUE(data.mCachedClassInfo, nullptr); NS_ADDREF(data.mCachedClassInfo); } - NS_ASSERTION(!IS_EXTERNAL(sClassInfoData[aID].mCachedClassInfo), - "This is bad, internal class marked as external!"); - return sClassInfoData[aID].mCachedClassInfo; } -// static -nsIClassInfo * -nsDOMClassInfo::GetClassInfoInstance(nsDOMClassInfoData* aData) -{ - NS_ASSERTION(IS_EXTERNAL(aData->mCachedClassInfo) - || !aData->mCachedClassInfo, - "This is bad, external class marked as internal!"); - - if (!aData->mCachedClassInfo) { - if (aData->u.mExternalConstructorFptr) { - aData->mCachedClassInfo = - aData->u.mExternalConstructorFptr(aData->mName); - } else { - aData->mCachedClassInfo = nsDOMGenericSH::doCreate(aData); - } - NS_ENSURE_TRUE(aData->mCachedClassInfo, nullptr); - - NS_ADDREF(aData->mCachedClassInfo); - aData->mCachedClassInfo = MARK_EXTERNAL(aData->mCachedClassInfo); - } - - return GET_CLEAN_CI_PTR(aData->mCachedClassInfo); -} - - // static void nsDOMClassInfo::ShutDown() { - if (sClassInfoData[0].u.mConstructorFptr) { + if (sClassInfoData[0].mConstructorFptr) { uint32_t i; for (i = 0; i < eDOMClassInfoIDCount; i++) { @@ -1223,12 +1098,10 @@ BaseStubConstructor(nsIWeakReference* aWeakOwner, nsCOMPtr native; if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { rv = NS_ERROR_NOT_AVAILABLE; - } else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) { - native = do_CreateInstance(name_struct->mCID, &rv); - } else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) { - native = do_CreateInstance(name_struct->mAlias->mCID, &rv); } else { - native = do_CreateInstance(*name_struct->mData->mConstructorCID, &rv); + MOZ_ASSERT(name_struct->mType == + nsGlobalNameStruct::eTypeExternalConstructor); + native = do_CreateInstance(name_struct->mCID, &rv); } if (NS_FAILED(rv)) { NS_ERROR("Failed to create the object"); @@ -1300,7 +1173,6 @@ protected: public: static nsresult Create(const char16_t* aName, - const nsDOMClassInfoData* aData, const nsGlobalNameStruct* aNameStruct, nsPIDOMWindow* aOwner, nsDOMConstructor** aResult); @@ -1356,25 +1228,9 @@ private: return NS_OK; } - static bool IsConstructable(const nsDOMClassInfoData *aData) - { - if (IS_EXTERNAL(aData->mCachedClassInfo)) { - const nsExternalDOMClassInfoData* data = - static_cast(aData); - return data->mConstructorCID != nullptr; - } - - return false; - } static bool IsConstructable(const nsGlobalNameStruct *aNameStruct) { - return - (aNameStruct->mType == nsGlobalNameStruct::eTypeClassConstructor && - IsConstructable(&sClassInfoData[aNameStruct->mDOMClassInfoID])) || - (aNameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo && - IsConstructable(aNameStruct->mData)) || - aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructor || - aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias; + return aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructor; } const char16_t* mClassName; @@ -1385,7 +1241,6 @@ private: //static nsresult nsDOMConstructor::Create(const char16_t* aName, - const nsDOMClassInfoData* aData, const nsGlobalNameStruct* aNameStruct, nsPIDOMWindow* aOwner, nsDOMConstructor** aResult) @@ -1406,9 +1261,7 @@ nsDOMConstructor::Create(const char16_t* aName, return NS_ERROR_DOM_SECURITY_ERR; } - bool constructable = aNameStruct ? - IsConstructable(aNameStruct) : - IsConstructable(aData); + bool constructable = aNameStruct && IsConstructable(aNameStruct); *aResult = new nsDOMConstructor(aName, constructable, currentInner); NS_ADDREF(*aResult); @@ -1540,9 +1393,7 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper, return NS_OK; } - if (name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor && - name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo && - name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructorAlias) { + if (name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor) { // Doesn't have DOM interfaces. return NS_OK; } @@ -1556,59 +1407,27 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper, return NS_OK; } - nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); - NS_ASSERTION(nameSpaceManager, "Can't get namespace manager?"); - const nsIID *class_iid; - if (class_name_struct->mType == nsGlobalNameStruct::eTypeInterface || - class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) { + if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) { class_iid = &class_name_struct->mIID; } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { class_iid = sClassInfoData[class_name_struct->mDOMClassInfoID].mProtoChainInterface; - } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - class_iid = class_name_struct->mData->mProtoChainInterface; - } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) { - const nsGlobalNameStruct* alias_struct = - nameSpaceManager->GetConstructorProto(class_name_struct); - if (!alias_struct) { - NS_ERROR("Couldn't get constructor prototype."); - return NS_ERROR_UNEXPECTED; - } - - if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { - class_iid = - sClassInfoData[alias_struct->mDOMClassInfoID].mProtoChainInterface; - } else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - class_iid = alias_struct->mData->mProtoChainInterface; - } else { - NS_ERROR("Expected eTypeClassConstructor or eTypeExternalClassInfo."); - return NS_ERROR_UNEXPECTED; - } } else { *bp = false; return NS_OK; } - if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) { - name_struct = nameSpaceManager->GetConstructorProto(name_struct); - if (!name_struct) { - NS_ERROR("Couldn't get constructor prototype."); - return NS_ERROR_UNEXPECTED; - } - } - - NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor || - name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo, + NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor, "The constructor was set up with a struct of the wrong type."); - const nsDOMClassInfoData *ci_data = nullptr; + const nsDOMClassInfoData *ci_data; if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor && name_struct->mDOMClassInfoID >= 0) { ci_data = &sClassInfoData[name_struct->mDOMClassInfoID]; - } else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - ci_data = name_struct->mData; + } else { + ci_data = nullptr; } nsCOMPtr @@ -1652,14 +1471,11 @@ nsDOMConstructor::ResolveInterfaceConstants(JSContext *cx, JS::Handle return NS_ERROR_UNEXPECTED; const nsIID *class_iid; - if (class_name_struct->mType == nsGlobalNameStruct::eTypeInterface || - class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) { + if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) { class_iid = &class_name_struct->mIID; } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { class_iid = sClassInfoData[class_name_struct->mDOMClassInfoID].mProtoChainInterface; - } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - class_iid = class_name_struct->mData->mProtoChainInterface; } else { return NS_OK; } @@ -1686,23 +1502,15 @@ GetXPCProto(nsIXPConnect *aXPConnect, JSContext *cx, nsGlobalWindow *aWin, const nsGlobalNameStruct *aNameStruct, JS::MutableHandle aProto) { - NS_ASSERTION(aNameStruct->mType == - nsGlobalNameStruct::eTypeClassConstructor || - aNameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo, + NS_ASSERTION(aNameStruct->mType == nsGlobalNameStruct::eTypeClassConstructor, "Wrong type!"); - nsCOMPtr ci; - if (aNameStruct->mType == nsGlobalNameStruct::eTypeClassConstructor) { - int32_t id = aNameStruct->mDOMClassInfoID; - MOZ_ASSERT(id >= 0, "Negative DOM classinfo?!?"); + int32_t id = aNameStruct->mDOMClassInfoID; + MOZ_ASSERT(id >= 0, "Negative DOM classinfo?!?"); - nsDOMClassInfoID ci_id = (nsDOMClassInfoID)id; + nsDOMClassInfoID ci_id = (nsDOMClassInfoID)id; - ci = NS_GetDOMClassInfoInstance(ci_id); - } - else { - ci = nsDOMClassInfo::GetClassInfoInstance(aNameStruct->mData); - } + nsCOMPtr ci = NS_GetDOMClassInfoInstance(ci_id); NS_ENSURE_TRUE(ci, NS_ERROR_UNEXPECTED); nsresult rv = @@ -1730,7 +1538,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx, "Wrong type or missing ci_data!"); RefPtr constructor; - nsresult rv = nsDOMConstructor::Create(name, ci_data, name_struct, aWin, + nsresult rv = nsDOMConstructor::Create(name, name_struct, aWin, getter_AddRefs(constructor)); NS_ENSURE_SUCCESS(rv, rv); @@ -1883,8 +1691,7 @@ OldBindingConstructorEnabled(const nsGlobalNameStruct *aStruct, nsGlobalWindow *aWin, JSContext *cx) { MOZ_ASSERT(aStruct->mType == nsGlobalNameStruct::eTypeProperty || - aStruct->mType == nsGlobalNameStruct::eTypeClassConstructor || - aStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo); + aStruct->mType == nsGlobalNameStruct::eTypeClassConstructor); // Don't expose chrome only constructors to content windows. if (aStruct->mChromeOnly) { @@ -1915,17 +1722,8 @@ nsWindowSH::NameStructEnabled(JSContext* aCx, nsGlobalWindow *aWin, const nsGlobalNameStruct& aNameStruct) { const nsGlobalNameStruct* nameStruct = &aNameStruct; - if (nameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) { - nsresult rv = GetExternalClassInfo(GetNameSpaceManager(), aName, nameStruct, - &nameStruct); - if (NS_FAILED(rv) || !nameStruct) { - return false; - } - } - return (nameStruct->mType != nsGlobalNameStruct::eTypeProperty && - nameStruct->mType != nsGlobalNameStruct::eTypeClassConstructor && - nameStruct->mType != nsGlobalNameStruct::eTypeExternalClassInfo) || + nameStruct->mType != nsGlobalNameStruct::eTypeClassConstructor) || OldBindingConstructorEnabled(nameStruct, aWin, aCx); } @@ -1995,16 +1793,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, nsresult rv = NS_OK; - if (name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) { - rv = GetExternalClassInfo(nameSpaceManager, name, name_struct, - &name_struct); - if (NS_FAILED(rv) || !name_struct) { - return rv; - } - } - if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding || - name_struct->mType == nsGlobalNameStruct::eTypeInterface || name_struct->mType == nsGlobalNameStruct::eTypeClassProto || name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { // Lookup new DOM bindings. @@ -2096,45 +1885,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, } } - if (name_struct->mType == nsGlobalNameStruct::eTypeInterface) { - // We're resolving a name of a DOM interface for which there is no - // direct DOM class, create a constructor object... - RefPtr constructor; - rv = nsDOMConstructor::Create(class_name, - nullptr, - name_struct, - static_cast(aWin), - getter_AddRefs(constructor)); - NS_ENSURE_SUCCESS(rv, rv); - - JS::Rooted v(cx); - js::AssertSameCompartment(cx, obj); - rv = nsContentUtils::WrapNative(cx, constructor, - &NS_GET_IID(nsIDOMDOMConstructor), &v, - false); - NS_ENSURE_SUCCESS(rv, rv); - - JS::Rooted class_obj(cx, &v.toObject()); - - // ... and define the constants from the DOM interface on that - // constructor object. - - { - JSAutoCompartment ac(cx, class_obj); - rv = DefineInterfaceConstants(cx, class_obj, &name_struct->mIID); - NS_ENSURE_SUCCESS(rv, rv); - } - - if (!JS_WrapValue(cx, &v)) { - return NS_ERROR_UNEXPECTED; - } - - FillPropertyDescriptor(desc, obj, 0, v); - return NS_OK; - } - - if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor || - name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { + if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { if (!OldBindingConstructorEnabled(name_struct, aWin, cx)) { return NS_OK; } @@ -2158,15 +1909,9 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, // This is the Xray case. Look up the constructor object for this // prototype. - const nsDOMClassInfoData *ci_data; - if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { - ci_data = &sClassInfoData[name_struct->mDOMClassInfoID]; - } else { - ci_data = name_struct->mData; - } - return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj, - class_name, ci_data, + class_name, + &sClassInfoData[name_struct->mDOMClassInfoID], name_struct, nameSpaceManager, dot_prototype, desc); } @@ -2179,37 +1924,9 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, name_struct, nameSpaceManager, nullptr, desc); } - if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) { - const nsGlobalNameStruct *alias_struct = - nameSpaceManager->GetConstructorProto(name_struct); - NS_ENSURE_TRUE(alias_struct, NS_ERROR_UNEXPECTED); - - // We need to use the XPConnect prototype for the DOM class that this - // constructor is an alias for (for example for Image we need the prototype - // for HTMLImageElement). - JS::Rooted dot_prototype(cx); - rv = GetXPCProto(nsDOMClassInfo::sXPConnect, cx, aWin, alias_struct, - &dot_prototype); - NS_ENSURE_SUCCESS(rv, rv); - MOZ_ASSERT(dot_prototype); - - const nsDOMClassInfoData *ci_data; - if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) { - ci_data = &sClassInfoData[alias_struct->mDOMClassInfoID]; - } else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - ci_data = alias_struct->mData; - } else { - return NS_ERROR_UNEXPECTED; - } - - return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj, - class_name, ci_data, - name_struct, nameSpaceManager, nullptr, desc); - } - if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) { RefPtr constructor; - rv = nsDOMConstructor::Create(class_name, nullptr, name_struct, + rv = nsDOMConstructor::Create(class_name, name_struct, static_cast(aWin), getter_AddRefs(constructor)); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 032046cad0..4286330bb7 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -8,9 +8,9 @@ #define nsDOMClassInfo_h___ #include "mozilla/Attributes.h" +#include "nsDOMClassInfoID.h" #include "nsIXPCScriptable.h" #include "nsIScriptGlobalObject.h" -#include "nsIDOMScriptObjectFactory.h" #include "js/Id.h" #include "nsIXPConnect.h" @@ -32,13 +32,9 @@ struct nsDOMClassInfoData { const char *mName; const char16_t *mNameUTF16; - union { - nsDOMClassInfoConstructorFnc mConstructorFptr; - nsDOMClassInfoExternalConstructorFnc mExternalConstructorFptr; - } u; + nsDOMClassInfoConstructorFnc mConstructorFptr; - nsIClassInfo *mCachedClassInfo; // low bit is set to 1 if external, - // so be sure to mask if necessary! + nsIClassInfo *mCachedClassInfo; const nsIID *mProtoChainInterface; const nsIID **mInterfaces; uint32_t mScriptableFlags : 31; // flags must not use more than 31 bits! @@ -51,19 +47,6 @@ struct nsDOMClassInfoData #endif }; -struct nsExternalDOMClassInfoData : public nsDOMClassInfoData -{ - const nsCID *mConstructorCID; -}; - - -// To be used with the nsDOMClassInfoData::mCachedClassInfo pointer. -// The low bit is set when we created a generic helper for an external -// (which holds on to the nsDOMClassInfoData). -#define GET_CLEAN_CI_PTR(_ptr) (nsIClassInfo*)(uintptr_t(_ptr) & ~0x1) -#define MARK_EXTERNAL(_ptr) (nsIClassInfo*)(uintptr_t(_ptr) | 0x1) -#define IS_EXTERNAL(_ptr) (uintptr_t(_ptr) & 0x1) - class nsWindowSH; class nsDOMClassInfo : public nsXPCClassInfo @@ -71,7 +54,7 @@ class nsDOMClassInfo : public nsXPCClassInfo friend class nsWindowSH; protected: - virtual ~nsDOMClassInfo(); + virtual ~nsDOMClassInfo() {}; public: explicit nsDOMClassInfo(nsDOMClassInfoData* aData); @@ -82,17 +65,6 @@ public: NS_DECL_NSICLASSINFO - // Helper method that returns a *non* refcounted pointer to a - // helper. So please note, don't release this pointer, if you do, - // you better make sure you've addreffed before release. - // - // Whaaaaa! I wanted to name this method GetClassInfo, but nooo, - // some of Microsoft devstudio's headers #defines GetClassInfo to - // GetClassInfoA so I can't, those $%#@^! bastards!!! What gives - // them the right to do that? - - static nsIClassInfo* GetClassInfoInstance(nsDOMClassInfoData* aData); - static nsresult Init(); static void ShutDown(); @@ -134,12 +106,11 @@ protected: } static nsresult RegisterClassProtos(int32_t aDOMClassInfoID); - static nsresult RegisterExternalClasses(); static nsIXPConnect *sXPConnect; // nsIXPCScriptable code - static nsresult DefineStaticJSVals(JSContext *cx); + static nsresult DefineStaticJSVals(); static bool sIsInitialized; diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 5ffa08faa4..1ef6451b43 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -60,10 +60,6 @@ NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID); } \ } else -#else - -// See nsIDOMClassInfo.h - #endif // MOZILLA_INTERNAL_API #endif // nsDOMClassInfoID_h__ diff --git a/dom/base/nsDOMScriptObjectFactory.cpp b/dom/base/nsDOMScriptObjectFactory.cpp deleted file mode 100644 index fba307ad30..0000000000 --- a/dom/base/nsDOMScriptObjectFactory.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * This Original Code has been modified by IBM Corporation. - * Modifications made by IBM described herein are - * Copyright (c) International Business Machines - * Corporation, 2000 - * - * Modifications to Mozilla code or documentation - * identified per MPL Section 3.3 - * - * Date Modified by Description of modification - * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink - * use in OS2 - */ - -#include "nsDOMScriptObjectFactory.h" -#include "nsScriptNameSpaceManager.h" -#include "nsIObserverService.h" -#include "nsJSEnvironment.h" -#include "nsGlobalWindow.h" -#include "nsCRT.h" -#ifdef MOZ_XUL -#include "nsXULPrototypeCache.h" -#endif -#include "nsThreadUtils.h" - -using mozilla::dom::GetNameSpaceManager; - -nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() -{ - nsCOMPtr observerService = - mozilla::services::GetObserverService(); - if (observerService) { - observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); - } - -} - -NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory) - NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory) - NS_INTERFACE_MAP_ENTRY(nsIObserver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory) -NS_INTERFACE_MAP_END - - -NS_IMPL_ADDREF(nsDOMScriptObjectFactory) -NS_IMPL_RELEASE(nsDOMScriptObjectFactory) - -NS_IMETHODIMP_(nsISupports *) -nsDOMScriptObjectFactory::GetClassInfoInstance(nsDOMClassInfoID aID) -{ - return NS_GetDOMClassInfoInstance(aID); -} - -NS_IMETHODIMP_(nsISupports *) -nsDOMScriptObjectFactory::GetExternalClassInfoInstance(const nsAString& aName) -{ - nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); - NS_ENSURE_TRUE(nameSpaceManager, nullptr); - - const nsGlobalNameStruct *globalStruct = nameSpaceManager->LookupName(aName); - if (globalStruct) { - if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) { - nsresult rv; - nsCOMPtr creator(do_CreateInstance(globalStruct->mCID, &rv)); - NS_ENSURE_SUCCESS(rv, nullptr); - - rv = creator->RegisterDOMCI(NS_ConvertUTF16toUTF8(aName).get(), this); - NS_ENSURE_SUCCESS(rv, nullptr); - - globalStruct = nameSpaceManager->LookupName(aName); - NS_ENSURE_TRUE(globalStruct, nullptr); - - NS_ASSERTION(globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo, - "The classinfo data for this class didn't get registered."); - } - if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - return nsDOMClassInfo::GetClassInfoInstance(globalStruct->mData); - } - } - return nullptr; -} - -NS_IMETHODIMP -nsDOMScriptObjectFactory::Observe(nsISupports *aSubject, - const char *aTopic, - const char16_t *someData) -{ - if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { -#ifdef MOZ_XUL - // Flush the XUL cache since it holds JS roots, and we're about to - // start the final GC. - nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); - - if (cache) - cache->Flush(); -#endif - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName, - nsDOMClassInfoExternalConstructorFnc aConstructorFptr, - const nsIID *aProtoChainInterface, - const nsIID **aInterfaces, - uint32_t aScriptableFlags, - bool aHasClassInterface, - const nsCID *aConstructorCID) -{ - nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager(); - NS_ENSURE_TRUE(nameSpaceManager, NS_ERROR_NOT_INITIALIZED); - - return nameSpaceManager->RegisterDOMCIData(aName, - aConstructorFptr, - aProtoChainInterface, - aInterfaces, - aScriptableFlags, - aHasClassInterface, - aConstructorCID); -} diff --git a/dom/base/nsDOMScriptObjectFactory.h b/dom/base/nsDOMScriptObjectFactory.h deleted file mode 100644 index ed12d1c3f5..0000000000 --- a/dom/base/nsDOMScriptObjectFactory.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * This Original Code has been modified by IBM Corporation. - * Modifications made by IBM described herein are - * Copyright (c) International Business Machines - * Corporation, 2000 - * - * Modifications to Mozilla code or documentation - * identified per MPL Section 3.3 - * - * Date Modified by Description of modification - * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink - * use in OS2 - */ - -#include "nsIDOMScriptObjectFactory.h" -#include "nsIObserver.h" -#include "mozilla/Attributes.h" - -class nsDOMScriptObjectFactory final : public nsIDOMScriptObjectFactory, - public nsIObserver -{ - ~nsDOMScriptObjectFactory() {} - -public: - nsDOMScriptObjectFactory(); - - NS_DECL_ISUPPORTS - - // nsIObserver - NS_DECL_NSIOBSERVER - - // nsIDOMScriptObjectFactory - NS_IMETHOD_(nsISupports *) GetClassInfoInstance(nsDOMClassInfoID aID) override; - NS_IMETHOD_(nsISupports *) GetExternalClassInfoInstance(const nsAString& aName) override; - - NS_IMETHOD RegisterDOMClassInfo(const char *aName, - nsDOMClassInfoExternalConstructorFnc aConstructorFptr, - const nsIID *aProtoChainInterface, - const nsIID **aInterfaces, - uint32_t aScriptableFlags, - bool aHasClassInterface, - const nsCID *aConstructorCID) override; -}; - diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 74bec69b6d..00af743e0a 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -108,6 +108,7 @@ #include "mozilla/css/ImageLoader.h" #include "mozilla/layers/APZCTreeManager.h" // for layers::ZoomToRectBehavior #include "mozilla/dom/Promise.h" +#include "mozilla/CSSStyleSheet.h" #ifdef XP_WIN #undef GetClassName diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 22e19397cd..efef3265dc 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -243,6 +243,10 @@ #include "gfxVR.h" #include "gfxPrefs.h" #include "nsISupportsPrimitives.h" +#include "mozilla/StyleSetHandle.h" +#include "mozilla/StyleSetHandleInlines.h" +#include "mozilla/StyleSheetHandle.h" +#include "mozilla/StyleSheetHandleInlines.h" #include "nsISpeculativeConnect.h" @@ -729,10 +733,16 @@ nsDOMStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound) } aFound = true; - CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(aIndex); + StyleSheetHandle sheet = mDocument->GetStyleSheetAt(aIndex); NS_ASSERTION(sheet, "Must have a sheet"); - return static_cast(sheet); + // XXXheycam Return null until ServoStyleSheet implements the right DOM + // interfaces. + if (sheet->IsServo()) { + NS_ERROR("stylo: can't return a ServoStyleSheet to the DOM yet"); + return nullptr; + } + return sheet->AsGecko(); } void @@ -742,7 +752,7 @@ nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode) } void -nsDOMStyleSheetList::StyleSheetAdded(CSSStyleSheet* aStyleSheet, +nsDOMStyleSheetList::StyleSheetAdded(StyleSheetHandle aStyleSheet, bool aDocumentSheet) { if (aDocumentSheet && -1 != mLength) { @@ -751,7 +761,7 @@ nsDOMStyleSheetList::StyleSheetAdded(CSSStyleSheet* aStyleSheet, } void -nsDOMStyleSheetList::StyleSheetRemoved(CSSStyleSheet* aStyleSheet, +nsDOMStyleSheetList::StyleSheetRemoved(StyleSheetHandle aStyleSheet, bool aDocumentSheet) { if (aDocumentSheet && -1 != mLength) { @@ -1318,9 +1328,14 @@ nsDOMStyleSheetSetList::EnsureFresh() int32_t count = mDocument->GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(index); + StyleSheetHandle sheet = mDocument->GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); - sheet->GetTitle(title); + // XXXheycam ServoStyleSheets don't expose their title yet. + if (sheet->IsServo()) { + NS_ERROR("stylo: ServoStyleSets don't expose their title yet"); + continue; + } + sheet->AsGecko()->GetTitle(title); if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) { return; } @@ -1600,7 +1615,7 @@ nsDocument::~nsDocument() mCachedRootElement = nullptr; // Let the stylesheets know we're going away - for (CSSStyleSheet* sheet : mStyleSheets) { + for (StyleSheetHandle sheet : mStyleSheets) { sheet->SetOwningDocument(nullptr); } if (mAttrStyleSheet) { @@ -2279,7 +2294,7 @@ void nsDocument::RemoveDocStyleSheetsFromStyleSets() { // The stylesheets should forget us - for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { + for (StyleSheetHandle sheet : Reversed(mStyleSheets)) { sheet->SetOwningDocument(nullptr); if (sheet->IsApplicable()) { @@ -2294,11 +2309,11 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets() void nsDocument::RemoveStyleSheetsFromStyleSets( - nsTArray>& aSheets, + nsTArray& aSheets, SheetType aType) { // The stylesheets should forget us - for (CSSStyleSheet* sheet : Reversed(aSheets)) { + for (StyleSheetHandle sheet : Reversed(aSheets)) { sheet->SetOwningDocument(nullptr); if (sheet->IsApplicable()) { @@ -2364,24 +2379,24 @@ nsDocument::ResetStylesheetsToURI(nsIURI* aURI) } static void -AppendSheetsToStyleSet(nsStyleSet* aStyleSet, - const nsTArray>& aSheets, +AppendSheetsToStyleSet(StyleSetHandle aStyleSet, + const nsTArray& aSheets, SheetType aType) { - for (CSSStyleSheet* sheet : Reversed(aSheets)) { + for (StyleSheetHandle sheet : Reversed(aSheets)) { aStyleSet->AppendStyleSheet(aType, sheet); } } void -nsDocument::FillStyleSet(nsStyleSet* aStyleSet) +nsDocument::FillStyleSet(StyleSetHandle aStyleSet) { NS_PRECONDITION(aStyleSet, "Must have a style set"); NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0, "Style set already has document sheets?"); - for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { + for (StyleSheetHandle sheet : Reversed(mStyleSheets)) { if (sheet->IsApplicable()) { aStyleSet->AddDocStyleSheet(sheet, this); } @@ -2389,13 +2404,13 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet) nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); if (sheetService) { - for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) { + for (StyleSheetHandle sheet : *sheetService->AuthorStyleSheets()) { aStyleSet->AppendStyleSheet(SheetType::Doc, sheet); } } // Iterate backwards to maintain order - for (CSSStyleSheet* sheet : Reversed(mOnDemandBuiltInUASheets)) { + for (StyleSheetHandle sheet : Reversed(mOnDemandBuiltInUASheets)) { if (sheet->IsApplicable()) { aStyleSet->PrependStyleSheet(SheetType::Agent, sheet); } @@ -3721,7 +3736,7 @@ nsDocument::TryChannelCharset(nsIChannel *aChannel, already_AddRefed nsDocument::CreateShell(nsPresContext* aContext, nsViewManager* aViewManager, - nsStyleSet* aStyleSet) + StyleSetHandle aStyleSet) { // Don't add anything here. Add it to |doCreateShell| instead. // This exists so that subclasses can pass other values for the 4th @@ -3731,7 +3746,7 @@ nsDocument::CreateShell(nsPresContext* aContext, nsViewManager* aViewManager, already_AddRefed nsDocument::doCreateShell(nsPresContext* aContext, - nsViewManager* aViewManager, nsStyleSet* aStyleSet) + nsViewManager* aViewManager, StyleSetHandle aStyleSet) { NS_ASSERTION(!mPresShell, "We have a presshell already!"); @@ -4048,7 +4063,7 @@ nsDocument::RemoveChildAt(uint32_t aIndex, bool aNotify) } void -nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) +nsDocument::EnsureOnDemandBuiltInUASheet(StyleSheetHandle aSheet) { if (mOnDemandBuiltInUASheets.Contains(aSheet)) { return; @@ -4059,7 +4074,7 @@ nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) } void -nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) +nsDocument::AddOnDemandBuiltInUASheet(StyleSheetHandle aSheet) { MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet)); @@ -4088,20 +4103,20 @@ nsDocument::GetNumberOfStyleSheets() const return mStyleSheets.Length(); } -CSSStyleSheet* +StyleSheetHandle nsDocument::GetStyleSheetAt(int32_t aIndex) const { - return mStyleSheets.SafeElementAt(aIndex, nullptr); + return mStyleSheets.SafeElementAt(aIndex, StyleSheetHandle()); } int32_t -nsDocument::GetIndexOfStyleSheet(CSSStyleSheet* aSheet) const +nsDocument::GetIndexOfStyleSheet(StyleSheetHandle aSheet) const { return mStyleSheets.IndexOf(aSheet); } void -nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet) +nsDocument::AddStyleSheetToStyleSets(StyleSheetHandle aSheet) { nsCOMPtr shell = GetShell(); if (shell) { @@ -4114,7 +4129,11 @@ nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet) className##Init init; \ init.mBubbles = true; \ init.mCancelable = true; \ - init.mStylesheet = aSheet; \ + /* XXXheycam ServoStyleSheet doesn't implement DOM interfaces yet */ \ + if (aSheet->IsServo()) { \ + NS_ERROR("stylo: can't dispatch events for ServoStyleSheets yet"); \ + } \ + init.mStylesheet = aSheet->IsGecko() ? aSheet->AsGecko() : nullptr; \ init.memberName = argName; \ \ RefPtr event = \ @@ -4128,7 +4147,7 @@ nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet) } while (0); void -nsDocument::NotifyStyleSheetAdded(CSSStyleSheet* aSheet, bool aDocumentSheet) +nsDocument::NotifyStyleSheetAdded(StyleSheetHandle aSheet, bool aDocumentSheet) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (aSheet, aDocumentSheet)); @@ -4141,7 +4160,7 @@ nsDocument::NotifyStyleSheetAdded(CSSStyleSheet* aSheet, bool aDocumentSheet) } void -nsDocument::NotifyStyleSheetRemoved(CSSStyleSheet* aSheet, bool aDocumentSheet) +nsDocument::NotifyStyleSheetRemoved(StyleSheetHandle aSheet, bool aDocumentSheet) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (aSheet, aDocumentSheet)); @@ -4154,7 +4173,7 @@ nsDocument::NotifyStyleSheetRemoved(CSSStyleSheet* aSheet, bool aDocumentSheet) } void -nsDocument::AddStyleSheet(CSSStyleSheet* aSheet) +nsDocument::AddStyleSheet(StyleSheetHandle aSheet) { NS_PRECONDITION(aSheet, "null arg"); mStyleSheets.AppendElement(aSheet); @@ -4168,7 +4187,7 @@ nsDocument::AddStyleSheet(CSSStyleSheet* aSheet) } void -nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet) +nsDocument::RemoveStyleSheetFromStyleSets(StyleSheetHandle aSheet) { nsCOMPtr shell = GetShell(); if (shell) { @@ -4177,10 +4196,10 @@ nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet) } void -nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet) +nsDocument::RemoveStyleSheet(StyleSheetHandle aSheet) { NS_PRECONDITION(aSheet, "null arg"); - RefPtr sheet = aSheet; // hold ref so it won't die too soon + StyleSheetHandle::RefPtr sheet = aSheet; // hold ref so it won't die too soon if (!mStyleSheets.RemoveElement(aSheet)) { NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found"); @@ -4199,8 +4218,8 @@ nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet) } void -nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, - nsTArray>& aNewSheets) +nsDocument::UpdateStyleSheets(nsTArray& aOldSheets, + nsTArray& aNewSheets) { BeginUpdate(UPDATE_STYLE); @@ -4209,7 +4228,7 @@ nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, "The lists must be the same length!"); int32_t count = aOldSheets.Length(); - RefPtr oldSheet; + StyleSheetHandle::RefPtr oldSheet; int32_t i; for (i = 0; i < count; ++i) { oldSheet = aOldSheets[i]; @@ -4220,7 +4239,7 @@ nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, RemoveStyleSheet(oldSheet); // This does the right notifications // Now put the new one in its place. If it's null, just ignore it. - CSSStyleSheet* newSheet = aNewSheets[i]; + StyleSheetHandle newSheet = aNewSheets[i]; if (newSheet) { mStyleSheets.InsertElementAt(oldIndex, newSheet); newSheet->SetOwningDocument(this); @@ -4236,7 +4255,7 @@ nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, } void -nsDocument::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex) +nsDocument::InsertStyleSheetAt(StyleSheetHandle aSheet, int32_t aIndex) { NS_PRECONDITION(aSheet, "null ptr"); @@ -4253,7 +4272,7 @@ nsDocument::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex) void -nsDocument::SetStyleSheetApplicableState(CSSStyleSheet* aSheet, +nsDocument::SetStyleSheetApplicableState(StyleSheetHandle aSheet, bool aApplicable) { NS_PRECONDITION(aSheet, "null arg"); @@ -4319,7 +4338,7 @@ ConvertAdditionalSheetType(nsIDocument::additionalSheetType aType) } static int32_t -FindSheet(const nsTArray>& aSheets, nsIURI* aSheetURI) +FindSheet(const nsTArray& aSheets, nsIURI* aSheetURI) { for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) { bool bEqual; @@ -4363,9 +4382,8 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType, MOZ_CRASH("impossible value for aType"); } - RefPtr sheet; - nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, - getter_AddRefs(sheet)); + StyleSheetHandle::RefPtr sheet; + nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet); NS_ENSURE_SUCCESS(rv, rv); sheet->SetOwningDocument(this); @@ -4375,7 +4393,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType, } nsresult -nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, CSSStyleSheet* aSheet) +nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, StyleSheetHandle aSheet) { if (mAdditionalSheets[aType].Contains(aSheet)) return NS_ERROR_INVALID_ARG; @@ -4404,11 +4422,11 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet { MOZ_ASSERT(aSheetURI); - nsTArray>& sheets = mAdditionalSheets[aType]; + nsTArray& sheets = mAdditionalSheets[aType]; int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI); if (i >= 0) { - RefPtr sheetRef = sheets[i]; + StyleSheetHandle::RefPtr sheetRef = sheets[i]; sheets.RemoveElementAt(i); BeginUpdate(UPDATE_STYLE); @@ -4430,10 +4448,10 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet } } -CSSStyleSheet* +StyleSheetHandle nsDocument::FirstAdditionalAuthorSheet() { - return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, nullptr); + return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, StyleSheetHandle()); } nsIGlobalObject* @@ -5173,7 +5191,7 @@ nsDocument::DocumentStatesChanged(EventStates aStateMask) } void -nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet, +nsDocument::StyleRuleChanged(StyleSheetHandle aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleChanged, (aSheet)); @@ -5187,7 +5205,7 @@ nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet, } void -nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet, +nsDocument::StyleRuleAdded(StyleSheetHandle aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleAdded, (aSheet)); @@ -5202,7 +5220,7 @@ nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet, } void -nsDocument::StyleRuleRemoved(CSSStyleSheet* aSheet, +nsDocument::StyleRuleRemoved(StyleSheetHandle aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleRemoved, (aSheet)); @@ -6443,17 +6461,23 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet) int32_t count = GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - CSSStyleSheet* sheet = GetStyleSheetAt(index); + StyleSheetHandle sheet = GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); + // XXXheycam Make this work with ServoStyleSheets. + if (sheet->IsServo()) { + NS_ERROR("stylo: can't handle alternate ServoStyleSheets yet"); + continue; + } + bool disabled; - sheet->GetDisabled(&disabled); + sheet->AsGecko()->GetDisabled(&disabled); if (disabled) { // Disabled sheets don't affect the currently selected set continue; } - sheet->GetTitle(title); + sheet->AsGecko()->GetTitle(title); if (aSheetSet.IsEmpty()) { aSheetSet = title; @@ -6557,11 +6581,18 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet, int32_t count = GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - CSSStyleSheet* sheet = GetStyleSheetAt(index); + StyleSheetHandle sheet = GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); - sheet->GetTitle(title); + + // XXXheycam Make this work with ServoStyleSheets. + if (sheet->IsServo()) { + NS_ERROR("stylo: can't handle alternate ServoStyleSheets yet"); + continue; + } + + sheet->AsGecko()->GetTitle(title); if (!title.IsEmpty()) { - sheet->SetEnabled(title.Equals(aSheetSet)); + sheet->AsGecko()->SetEnabled(title.Equals(aSheetSet)); } } if (aUpdateCSSLoader) { @@ -9804,7 +9835,7 @@ class StubCSSLoaderObserver final : public nsICSSLoaderObserver { ~StubCSSLoaderObserver() {} public: NS_IMETHOD - StyleSheetLoaded(CSSStyleSheet*, bool, nsresult) override + StyleSheetLoaded(StyleSheetHandle, bool, nsresult) override { return NS_OK; } @@ -9833,12 +9864,12 @@ nsDocument::PreloadStyle(nsIURI* uri, const nsAString& charset, nsresult nsDocument::LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet, - CSSStyleSheet** sheet) + mozilla::StyleSheetHandle::RefPtr* aSheet) { css::SheetParsingMode mode = isAgentSheet ? css::eAgentSheetFeatures : css::eAuthorSheetFeatures; - return CSSLoader()->LoadSheetSync(uri, mode, isAgentSheet, sheet); + return CSSLoader()->LoadSheetSync(uri, mode, isAgentSheet, aSheet); } class nsDelayedEventDispatcher : public nsRunnable @@ -10164,28 +10195,38 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) int32_t sheetsCount = GetNumberOfStyleSheets(); for (int32_t i = 0; i < sheetsCount; ++i) { - RefPtr sheet = GetStyleSheetAt(i); + StyleSheetHandle::RefPtr sheet = GetStyleSheetAt(i); if (sheet) { if (sheet->IsApplicable()) { - RefPtr clonedSheet = - sheet->Clone(nullptr, nullptr, clonedDoc, nullptr); - NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!"); - if (clonedSheet) { - clonedDoc->AddStyleSheet(clonedSheet); + // XXXheycam Need to make ServoStyleSheet cloning work. + if (sheet->IsGecko()) { + RefPtr clonedSheet = + sheet->AsGecko()->Clone(nullptr, nullptr, clonedDoc, nullptr); + NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!"); + if (clonedSheet) { + clonedDoc->AddStyleSheet(clonedSheet); + } + } else { + NS_ERROR("stylo: ServoStyleSheet doesn't support cloning"); } } } } // Iterate backwards to maintain order - for (CSSStyleSheet* sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) { + for (StyleSheetHandle sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) { if (sheet) { if (sheet->IsApplicable()) { - RefPtr clonedSheet = - sheet->Clone(nullptr, nullptr, clonedDoc, nullptr); - NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!"); - if (clonedSheet) { - clonedDoc->AddOnDemandBuiltInUASheet(clonedSheet); + // XXXheycam Need to make ServoStyleSheet cloning work. + if (sheet->IsGecko()) { + RefPtr clonedSheet = + sheet->AsGecko()->Clone(nullptr, nullptr, clonedDoc, nullptr); + NS_WARN_IF_FALSE(clonedSheet, "Cloning a stylesheet didn't work!"); + if (clonedSheet) { + clonedDoc->AddOnDemandBuiltInUASheet(clonedSheet); + } + } else { + NS_ERROR("stylo: ServoStyleSheet doesn't support cloning"); } } } @@ -12316,7 +12357,7 @@ nsDocument::OnAppThemeChanged() } for (int32_t i = 0; i < GetNumberOfStyleSheets(); i++) { - RefPtr sheet = GetStyleSheetAt(i); + StyleSheetHandle::RefPtr sheet = GetStyleSheetAt(i); if (!sheet) { continue; } @@ -12683,12 +12724,12 @@ nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const } static size_t -SizeOfOwnedSheetArrayExcludingThis(const nsTArray>& aSheets, +SizeOfOwnedSheetArrayExcludingThis(const nsTArray& aSheets, MallocSizeOf aMallocSizeOf) { size_t n = 0; n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); - for (CSSStyleSheet* sheet : aSheets) { + for (StyleSheetHandle sheet : aSheets) { if (!sheet->GetOwningDocument()) { // Avoid over-reporting shared sheets. continue; @@ -13269,8 +13310,15 @@ nsIDocument::FlushUserFontSet() if (gfxPlatform::GetPlatform()->DownloadableFontsEnabled()) { nsTArray rules; nsIPresShell* shell = GetShell(); - if (shell && !shell->StyleSet()->AppendFontFaceRules(rules)) { - return; + if (shell) { + // XXXheycam ServoStyleSets don't support exposing @font-face rules yet. + if (shell->StyleSet()->IsGecko()) { + if (!shell->StyleSet()->AsGecko()->AppendFontFaceRules(rules)) { + return; + } + } else { + NS_ERROR("stylo: ServoStyleSets cannot handle @font-face rules yet"); + } } bool changed = false; @@ -13353,6 +13401,18 @@ nsIDocument::ReportHasScrollLinkedEffect() "ScrollLinkedEffectFound2"); } +mozilla::StyleBackendType +nsIDocument::GetStyleBackendType() const +{ + if (!mPresShell) { +#ifdef MOZ_STYLO + NS_WARNING("GetStyleBackendType() called on document without a pres shell"); +#endif + return StyleBackendType::Gecko; + } + return mPresShell->StyleSet()->BackendType(); +} + Selection* nsIDocument::GetSelection(ErrorResult& aRv) { diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 0f715f7d65..770c7cf204 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -44,7 +44,7 @@ #include "nsGkAtoms.h" #include "nsIApplicationCache.h" #include "nsIApplicationCacheContainer.h" -#include "nsStyleSet.h" +#include "mozilla/StyleSetHandle.h" #include "PLDHashTable.h" #include "nsAttrAndChildArray.h" #include "nsDOMAttributeMap.h" @@ -748,9 +748,10 @@ public: * its presentation context (presentation contexts must not be * shared among multiple presentation shells). */ - virtual already_AddRefed CreateShell(nsPresContext* aContext, - nsViewManager* aViewManager, - nsStyleSet* aStyleSet) override; + virtual already_AddRefed CreateShell( + nsPresContext* aContext, + nsViewManager* aViewManager, + mozilla::StyleSetHandle aStyleSet) override; virtual void DeleteShell() override; virtual nsresult GetAllowPlugins(bool* aAllowPlugins) override; @@ -768,36 +769,36 @@ public: virtual Element* FindContentForSubDocument(nsIDocument *aDocument) const override; virtual Element* GetRootElementInternal() const override; - virtual void EnsureOnDemandBuiltInUASheet(mozilla::CSSStyleSheet* aSheet) override; + virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheetHandle aSheet) override; /** * Get the (document) style sheets owned by this document. * These are ordered, highest priority last */ virtual int32_t GetNumberOfStyleSheets() const override; - virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const override; - virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const override; - virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) override; - virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) override; + virtual mozilla::StyleSheetHandle GetStyleSheetAt(int32_t aIndex) const override; + virtual int32_t GetIndexOfStyleSheet(mozilla::StyleSheetHandle aSheet) const override; + virtual void AddStyleSheet(mozilla::StyleSheetHandle aSheet) override; + virtual void RemoveStyleSheet(mozilla::StyleSheetHandle aSheet) override; virtual void UpdateStyleSheets( - nsTArray>& aOldSheets, - nsTArray>& aNewSheets) override; - virtual void AddStyleSheetToStyleSets(mozilla::CSSStyleSheet* aSheet); - virtual void RemoveStyleSheetFromStyleSets(mozilla::CSSStyleSheet* aSheet); + nsTArray& aOldSheets, + nsTArray& aNewSheets) override; + virtual void AddStyleSheetToStyleSets(mozilla::StyleSheetHandle aSheet); + virtual void RemoveStyleSheetFromStyleSets(mozilla::StyleSheetHandle aSheet); - virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, + virtual void InsertStyleSheetAt(mozilla::StyleSheetHandle aSheet, int32_t aIndex) override; - virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, + virtual void SetStyleSheetApplicableState(mozilla::StyleSheetHandle aSheet, bool aApplicable) override; virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) override; virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, - mozilla::CSSStyleSheet* aSheet) override; + mozilla::StyleSheetHandle aSheet) override; virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) override; - virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() override; + virtual mozilla::StyleSheetHandle FirstAdditionalAuthorSheet() override; virtual nsIChannel* GetChannel() const override { return mChannel; @@ -857,11 +858,11 @@ public: virtual void DocumentStatesChanged( mozilla::EventStates aStateMask) override; - virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet, mozilla::css::Rule* aStyleRule) override; - virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet, mozilla::css::Rule* aStyleRule) override; - virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet, mozilla::css::Rule* aStyleRule) override; virtual void FlushPendingNotifications(mozFlushType aType) override; @@ -933,7 +934,7 @@ public: void ReportUseCounters(); private: - void AddOnDemandBuiltInUASheet(mozilla::CSSStyleSheet* aSheet); + void AddOnDemandBuiltInUASheet(mozilla::StyleSheetHandle aSheet); nsRadioGroupStruct* GetRadioGroupInternal(const nsAString& aName) const; void SendToConsole(nsCOMArray& aMessages); @@ -1115,7 +1116,7 @@ public: const nsAString& aIntegrity) override; virtual nsresult LoadChromeSheetSync(nsIURI* uri, bool isAgentSheet, - mozilla::CSSStyleSheet** sheet) override; + mozilla::StyleSheetHandle::RefPtr* aSheet) override; virtual nsISupports* GetCurrentContentSink() override; @@ -1485,14 +1486,14 @@ public: protected: already_AddRefed doCreateShell(nsPresContext* aContext, nsViewManager* aViewManager, - nsStyleSet* aStyleSet); + mozilla::StyleSetHandle aStyleSet); void RemoveDocStyleSheetsFromStyleSets(); void RemoveStyleSheetsFromStyleSets( - nsTArray>& aSheets, + nsTArray& aSheets, mozilla::SheetType aType); void ResetStylesheetsToURI(nsIURI* aURI); - void FillStyleSet(nsStyleSet* aStyleSet); + void FillStyleSet(mozilla::StyleSetHandle aStyleSet); // Return whether all the presshells for this document are safe to flush bool IsSafeToFlush() const; @@ -1538,9 +1539,9 @@ protected: // EndLoad() has already happened. nsWeakPtr mWeakSink; - nsTArray> mStyleSheets; - nsTArray> mOnDemandBuiltInUASheets; - nsTArray> mAdditionalSheets[AdditionalSheetTypeCount]; + nsTArray mStyleSheets; + nsTArray mOnDemandBuiltInUASheets; + nsTArray mAdditionalSheets[AdditionalSheetTypeCount]; // Array of observers nsTObserverArray mObservers; @@ -1719,8 +1720,8 @@ private: friend class nsUnblockOnloadEvent; // Recomputes the visibility state but doesn't set the new value. mozilla::dom::VisibilityState GetVisibilityState() const; - void NotifyStyleSheetAdded(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); - void NotifyStyleSheetRemoved(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); + void NotifyStyleSheetAdded(mozilla::StyleSheetHandle aSheet, bool aDocumentSheet); + void NotifyStyleSheetRemoved(mozilla::StyleSheetHandle aSheet, bool aDocumentSheet); void PostUnblockOnloadEvent(); void DoUnblockOnload(); diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 2bbbea66dc..7f730e083a 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -11,6 +11,7 @@ #include "AppProcessChecker.h" #include "ContentChild.h" #include "nsContentUtils.h" +#include "nsDOMClassInfoID.h" #include "nsError.h" #include "nsIXPConnect.h" #include "jsapi.h" @@ -1102,16 +1103,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, continue; } - // Note - The ergonomics here will get a lot better with bug 971673: - // - // AutoEntryScript aes; - // if (!aes.Init(wrappedJS->GetJSObject())) { - // continue; - // } - // JSContext* cx = aes.cx(); - nsIGlobalObject* nativeGlobal = - xpc::NativeGlobal(js::GetGlobalForObjectCrossCompartment(wrappedJS->GetJSObject())); - AutoEntryScript aes(nativeGlobal, "message manager handler"); + AutoEntryScript aes(wrappedJS->GetJSObject(), "message manager handler"); aes.TakeOwnershipOfErrorReporting(); JSContext* cx = aes.cx(); JS::Rooted object(cx, wrappedJS->GetJSObject()); @@ -1655,7 +1647,6 @@ void nsMessageManagerScriptExecutor::Shutdown() { if (sCachedScripts) { - AutoSafeJSContext cx; NS_ASSERTION(sCachedScripts != nullptr, "Need cached scripts"); for (auto iter = sCachedScripts->Iter(); !iter.Done(); iter.Next()) { delete iter.Data(); @@ -1694,8 +1685,7 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL, JS::Rooted global(rt, mGlobal->GetJSObject()); if (global) { - AutoEntryScript aes(xpc::NativeGlobal(global), - "message manager script load"); + AutoEntryScript aes(global, "message manager script load"); aes.TakeOwnershipOfErrorReporting(); JSContext* cx = aes.cx(); if (script) { @@ -1772,12 +1762,13 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript( JS::SourceBufferHolder::GiveOwnership); if (dataStringBuf && dataStringLength > 0) { - AutoSafeJSContext cx; // Compile the script in the compilation scope instead of the current global // to avoid keeping the current compartment alive. - JS::Rooted global(cx, xpc::CompilationScope()); - - JSAutoCompartment ac(cx, global); + AutoJSAPI jsapi; + if (!jsapi.Init(xpc::CompilationScope())) { + return; + } + JSContext* cx = jsapi.cx(); JS::CompileOptions options(cx, JSVERSION_LATEST); options.setFileAndLine(url.get(), 1); options.setNoScriptRval(true); @@ -1816,8 +1807,7 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript( const nsAString& aURL, bool aRunInGlobalScope) { - AutoSafeJSContext cx; - JS::Rooted script(cx); + JS::Rooted script(nsContentUtils::RootingCx()); TryCacheLoadAndCompileScript(aURL, aRunInGlobalScope, true, &script); } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 1c61a4b533..c6267fef1e 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -615,6 +615,7 @@ nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindow *aOuterWindow) mMayHavePaintEventListener(false), mMayHaveTouchEventListener(false), mMayHaveMouseEnterLeaveEventListener(false), mMayHavePointerEnterLeaveEventListener(false), + mInnerObjectsFreed(false), mIsModalContentWindow(false), mIsActive(false), mIsBackground(false), mAudioMuted(false), mAudioVolume(1.0), mAudioCaptured(false), @@ -1155,7 +1156,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow) #endif mShowFocusRingForContent(false), mFocusByKeyOccurred(false), - mInnerObjectsFreed(false), mHasGamepad(false), #ifdef MOZ_GAMEPAD mHasSeenGamepadInput(false), @@ -3413,9 +3413,9 @@ nsGlobalWindow::DefineArgumentsProperty(nsIArray *aArguments) nsIScriptContext *ctx = GetOuterWindowInternal()->mContext; NS_ENSURE_TRUE(aArguments && ctx, NS_ERROR_NOT_INITIALIZED); - AutoJSContext cx; - JS::Rooted obj(cx, GetWrapperPreserveColor()); + JS::Rooted obj(nsContentUtils::RootingCx(), + GetWrapperPreserveColor()); return ctx->SetProperty(obj, "arguments", aArguments); } @@ -4057,7 +4057,9 @@ nsGlobalWindow::GetMozSelfSupport(ErrorResult& aError) return mMozSelfSupport; } - AutoSafeJSContext cx; + // We're called from JS and want to use out existing JSContext (and, + // importantly, its compartment!) here. + AutoJSContext cx; GlobalObject global(cx, FastGetGlobalJSObject()); mMozSelfSupport = MozSelfSupport::Constructor(global, cx, aError); return mMozSelfSupport; @@ -6214,8 +6216,13 @@ nsGlobalWindow::DispatchResizeEvent(const CSSIntSize& aSize) return false; } - AutoSafeJSContext cx; + // We don't init the AutoJSAPI with ourselves because we don't want it + // reporting errors to our onerror handlers. + AutoJSAPI jsapi; + jsapi.Init(); + JSContext* cx = jsapi.cx(); JSAutoCompartment ac(cx, GetWrapperPreserveColor()); + DOMWindowResizeEventDetail detail; detail.mWidth = aSize.width; detail.mHeight = aSize.height; @@ -9130,8 +9137,7 @@ nsGlobalWindow::NotifyDOMWindowThawed(nsGlobalWindow* aWindow) { JSObject* nsGlobalWindow::GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey) { - AutoSafeJSContext cx; - JS::Rooted handler(cx); + JS::Rooted handler(nsContentUtils::RootingCx()); if (mCachedXBLPrototypeHandlers) { mCachedXBLPrototypeHandlers->Get(aKey, handler.address()); } @@ -11242,7 +11248,7 @@ nsGlobalWindow::ShowSlowScriptDialog() } // Check if we should offer the option to debug - JS::UniqueChars filename; + JS::AutoFilename filename; unsigned lineno; bool hasFrame = JS::DescribeScriptedCaller(cx, &filename, &lineno); diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 8871eb7fce..2d05643cdf 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -1680,10 +1680,6 @@ protected: // should be displayed. bool mFocusByKeyOccurred : 1; - // Ensure that a call to ResumeTimeouts() after FreeInnerObjects() does nothing. - // This member is only used by inner windows. - bool mInnerObjectsFreed : 1; - // Inner windows only. // Indicates whether this window wants gamepad input events bool mHasGamepad : 1; diff --git a/dom/base/nsHostObjectProtocolHandler.cpp b/dom/base/nsHostObjectProtocolHandler.cpp index d5e4843fb6..c98a35f1e4 100644 --- a/dom/base/nsHostObjectProtocolHandler.cpp +++ b/dom/base/nsHostObjectProtocolHandler.cpp @@ -7,6 +7,7 @@ #include "nsHostObjectProtocolHandler.h" #include "DOMMediaStream.h" +#include "mozilla/dom/Exceptions.h" #include "mozilla/dom/File.h" #include "mozilla/dom/MediaSource.h" #include "mozilla/LoadInfo.h" @@ -200,11 +201,7 @@ class BlobURLsReporter final : public nsIMemoryReporter return; } - nsresult rv; - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - nsCOMPtr frame; - rv = xpc->GetCurrentJSStack(getter_AddRefs(frame)); - NS_ENSURE_SUCCESS_VOID(rv); + nsCOMPtr frame = dom::GetCurrentJSStack(maxFrames); nsAutoCString origin; nsCOMPtr principalURI; @@ -213,12 +210,17 @@ class BlobURLsReporter final : public nsIMemoryReporter principalURI->GetPrePath(origin); } - for (uint32_t i = 0; i < maxFrames && frame; ++i) { + // If we got a frame, we better have a current JSContext. This is cheating + // a bit; ideally we'd have our caller pass in a JSContext, or have + // GetCurrentJSStack() hand out the JSContext it found. + JSContext* cx = frame ? nsContentUtils::GetCurrentJSContext() : nullptr; + + for (uint32_t i = 0; frame; ++i) { nsString fileNameUTF16; int32_t lineNumber = 0; - frame->GetFilename(fileNameUTF16); - frame->GetLineNumber(&lineNumber); + frame->GetFilename(cx, fileNameUTF16); + frame->GetLineNumber(cx, &lineNumber); if (!fileNameUTF16.IsEmpty()) { NS_ConvertUTF16toUTF8 fileName(fileNameUTF16); @@ -245,8 +247,10 @@ class BlobURLsReporter final : public nsIMemoryReporter stack += ")/"; } - rv = frame->GetCaller(getter_AddRefs(frame)); + nsCOMPtr caller; + nsresult rv = frame->GetCaller(cx, getter_AddRefs(caller)); NS_ENSURE_SUCCESS_VOID(rv); + caller.swap(frame); } } diff --git a/dom/base/nsIDOMClassInfo.h b/dom/base/nsIDOMClassInfo.h index fa1b330ea8..90c65c1243 100644 --- a/dom/base/nsIDOMClassInfo.h +++ b/dom/base/nsIDOMClassInfo.h @@ -7,12 +7,7 @@ #ifndef nsIDOMClassInfo_h___ #define nsIDOMClassInfo_h___ -#include "nsIClassInfoImpl.h" -#include "nsDOMClassInfoID.h" #include "nsIXPCScriptable.h" -#include "nsIServiceManager.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsDOMCID.h" #define DOM_BASE_SCRIPTABLE_FLAGS \ (nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY | \ @@ -32,153 +27,4 @@ nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY) - -#ifdef MOZILLA_INTERNAL_API - -// See nsDOMClassInfoID.h - -#else - -#define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class) \ - if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ - aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ - static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ - \ - nsresult rv; \ - nsCOMPtr sof(do_GetService(kDOMSOF_CID, \ - &rv)); \ - if (NS_FAILED(rv)) { \ - *aInstancePtr = nullptr; \ - return rv; \ - } \ - \ - foundInterface = \ - sof->GetClassInfoInstance(eDOMClassInfo_##_class##_id); \ - } else - -#endif /* MOZILLA_INTERNAL_API */ - -// Looks up the nsIClassInfo for a class name registered with the -// nsScriptNamespaceManager. Remember to release NS_CLASSINFO_NAME(_class) -// (eg. when your module unloads). -#define NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(_class) \ - if (aIID.Equals(NS_GET_IID(nsIClassInfo)) || \ - aIID.Equals(NS_GET_IID(nsXPCClassInfo))) { \ - extern nsISupports *NS_CLASSINFO_NAME(_class); \ - if (NS_CLASSINFO_NAME(_class)) { \ - foundInterface = NS_CLASSINFO_NAME(_class); \ - } else { \ - static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \ - \ - nsresult rv; \ - nsCOMPtr sof(do_GetService(kDOMSOF_CID, \ - &rv)); \ - if (NS_FAILED(rv)) { \ - *aInstancePtr = nullptr; \ - return rv; \ - } \ - \ - foundInterface = \ - sof->GetExternalClassInfoInstance(NS_LITERAL_STRING(#_class)); \ - \ - if (foundInterface) { \ - NS_CLASSINFO_NAME(_class) = foundInterface; \ - NS_CLASSINFO_NAME(_class)->AddRef(); \ - } \ - } \ - } else - - -#define NS_DECL_DOM_CLASSINFO(_class) \ - nsISupports *NS_CLASSINFO_NAME(_class) = nullptr; - -// {891a7b01-1b61-11d6-a7f2-f690b638899c} -#define NS_IDOMCI_EXTENSION_IID \ -{ 0x891a7b01, 0x1b61, 0x11d6, \ -{ 0xa7, 0xf2, 0xf6, 0x90, 0xb6, 0x38, 0x89, 0x9c } } - -class nsIDOMScriptObjectFactory; - -class nsIDOMCIExtension : public nsISupports { -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMCI_EXTENSION_IID) - - NS_IMETHOD RegisterDOMCI(const char* aName, - nsIDOMScriptObjectFactory* aDOMSOFactory) = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMCIExtension, NS_IDOMCI_EXTENSION_IID) - -#define NS_DOMCI_EXTENSION_NAME(_module) ns##_module##DOMCIExtension -#define NS_DOMCI_EXTENSION_CONSTRUCTOR(_module) \ - ns##_module##DOMCIExtensionConstructor -#define NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(_extension) \ - NS_GENERIC_FACTORY_CONSTRUCTOR(_extension) - -#define NS_DOMCI_EXTENSION(_module) \ -class NS_DOMCI_EXTENSION_NAME(_module) : public nsIDOMCIExtension \ -{ \ -public: \ - NS_DOMCI_EXTENSION_NAME(_module)(); \ - virtual ~NS_DOMCI_EXTENSION_NAME(_module)(); \ - \ - NS_DECL_ISUPPORTS \ - \ - NS_IMETHOD RegisterDOMCI(const char* aName, \ - nsIDOMScriptObjectFactory* aDOMSOFactory); \ -}; \ - \ -NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(NS_DOMCI_EXTENSION_NAME(_module)) \ - \ -NS_DOMCI_EXTENSION_NAME(_module)::NS_DOMCI_EXTENSION_NAME(_module)() \ -{ \ -} \ - \ -NS_DOMCI_EXTENSION_NAME(_module)::~NS_DOMCI_EXTENSION_NAME(_module)() \ -{ \ -} \ - \ -NS_IMPL_ISUPPORTS(NS_DOMCI_EXTENSION_NAME(_module), nsIDOMCIExtension) \ - \ -NS_IMETHODIMP \ -NS_DOMCI_EXTENSION_NAME(_module)::RegisterDOMCI(const char* aName, \ - nsIDOMScriptObjectFactory* aDOMSOFactory) \ -{ - -#define NS_DOMCI_EXTENSION_ENTRY_BEGIN(_class) \ - if (nsCRT::strcmp(aName, #_class) == 0) { \ - static const nsIID* interfaces[] = { - -#define NS_DOMCI_EXTENSION_ENTRY_INTERFACE(_interface) \ - &NS_GET_IID(_interface), - -// Don't forget to register the primary interface (_proto) in the -// JAVASCRIPT_DOM_INTERFACE category, or prototypes for this class -// won't work (except if the interface name starts with nsIDOM). -#define NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, _proto, _hasclassif, \ - _constructorcid) \ - nullptr \ - }; \ - aDOMSOFactory->RegisterDOMClassInfo(#_class, nullptr, _proto, \ - interfaces, \ - DOM_DEFAULT_SCRIPTABLE_FLAGS, \ - _hasclassif, _constructorcid); \ - return NS_OK; \ - } - -#define NS_DOMCI_EXTENSION_ENTRY_END(_class, _proto, _hasclassif, \ - _constructorcid) \ - NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, &NS_GET_IID(_proto), \ - _hasclassif, _constructorcid) - -#define NS_DOMCI_EXTENSION_ENTRY_END_NO_PRIMARY_IF(_class, _hasclassif, \ - _constructorcid) \ - NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, nullptr, _hasclassif, \ - _constructorcid) - -#define NS_DOMCI_EXTENSION_END \ - return NS_ERROR_FAILURE; \ -} - - #endif /* nsIDOMClassInfo_h___ */ diff --git a/dom/base/nsIDOMScriptObjectFactory.h b/dom/base/nsIDOMScriptObjectFactory.h deleted file mode 100644 index a29cef1fe6..0000000000 --- a/dom/base/nsIDOMScriptObjectFactory.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef nsIDOMScriptObjectFactory_h__ -#define nsIDOMScriptObjectFactory_h__ - -#include "nsISupports.h" -#include "nsIDOMClassInfo.h" -#include "nsString.h" - -#define NS_IDOM_SCRIPT_OBJECT_FACTORY_IID \ -{ 0x2a50e17c, 0x46ff, 0x4150, \ - { 0xbb, 0x46, 0xd8, 0x07, 0xb3, 0x36, 0xde, 0xab } } - -typedef nsXPCClassInfo* (*nsDOMClassInfoExternalConstructorFnc) - (const char* aName); - -class nsIDOMScriptObjectFactory : public nsISupports { -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOM_SCRIPT_OBJECT_FACTORY_IID) - - NS_IMETHOD_(nsISupports *) GetClassInfoInstance(nsDOMClassInfoID aID) = 0; - NS_IMETHOD_(nsISupports *) GetExternalClassInfoInstance(const nsAString& aName) = 0; - - // Register the info for an external class. aName must be static - // data, it will not be deleted by the DOM code. aProtoChainInterface - // must be registered in the JAVASCRIPT_DOM_INTERFACE category, or - // prototypes for this class won't work (except if the interface - // name starts with nsIDOM). - NS_IMETHOD RegisterDOMClassInfo(const char *aName, - nsDOMClassInfoExternalConstructorFnc aConstructorFptr, - const nsIID *aProtoChainInterface, - const nsIID **aInterfaces, - uint32_t aScriptableFlags, - bool aHasClassInterface, - const nsCID *aConstructorCID) = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMScriptObjectFactory, - NS_IDOM_SCRIPT_OBJECT_FACTORY_IID) - -#endif /* nsIDOMScriptObjectFactory_h__ */ diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index d493932218..5e760652ed 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -35,6 +35,8 @@ #include "nsClassHashtable.h" #include "prclist.h" #include "mozilla/CORSMode.h" +#include "mozilla/StyleBackendType.h" +#include "mozilla/StyleSheetHandle.h" #include // for member class gfxUserFontSet; @@ -81,7 +83,6 @@ class nsPresContext; class nsRange; class nsScriptLoader; class nsSMILAnimationController; -class nsStyleSet; class nsTextNode; class nsWindowSizes; class nsDOMCaretPosition; @@ -94,6 +95,7 @@ class CSSStyleSheet; class ErrorResult; class EventStates; class PendingAnimationTracker; +class StyleSetHandle; class SVGAttrAnimationRuleProcessor; template class OwningNonNull; @@ -682,9 +684,10 @@ public: * method is responsible for calling BeginObservingDocument() on the * presshell if the presshell should observe document mutations. */ - virtual already_AddRefed CreateShell(nsPresContext* aContext, - nsViewManager* aViewManager, - nsStyleSet* aStyleSet) = 0; + virtual already_AddRefed CreateShell( + nsPresContext* aContext, + nsViewManager* aViewManager, + mozilla::StyleSetHandle aStyleSet) = 0; virtual void DeleteShell() = 0; nsIPresShell* GetShell() const @@ -929,7 +932,7 @@ public: * TODO We can get rid of the whole concept of delayed loading if we fix * bug 77999. */ - virtual void EnsureOnDemandBuiltInUASheet(mozilla::CSSStyleSheet* aSheet) = 0; + virtual void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheetHandle aSheet) = 0; /** * Get the number of (document) stylesheets @@ -945,7 +948,7 @@ public: * @return the stylesheet at aIndex. Null if aIndex is out of range. * @throws no exceptions */ - virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0; + virtual mozilla::StyleSheetHandle GetStyleSheetAt(int32_t aIndex) const = 0; /** * Insert a sheet at a particular spot in the stylesheet list (zero-based) @@ -954,7 +957,7 @@ public: * adjusted for the "special" sheets. * @throws no exceptions */ - virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, + virtual void InsertStyleSheetAt(mozilla::StyleSheetHandle aSheet, int32_t aIndex) = 0; /** @@ -963,7 +966,7 @@ public: * @param aSheet the sheet to get the index of * @return aIndex the index of the sheet in the full list */ - virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const = 0; + virtual int32_t GetIndexOfStyleSheet(mozilla::StyleSheetHandle aSheet) const = 0; /** * Replace the stylesheets in aOldSheets with the stylesheets in @@ -974,24 +977,24 @@ public: * will simply be removed. */ virtual void UpdateStyleSheets( - nsTArray>& aOldSheets, - nsTArray>& aNewSheets) = 0; + nsTArray& aOldSheets, + nsTArray& aNewSheets) = 0; /** * Add a stylesheet to the document */ - virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; + virtual void AddStyleSheet(mozilla::StyleSheetHandle aSheet) = 0; /** * Remove a stylesheet from the document */ - virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; + virtual void RemoveStyleSheet(mozilla::StyleSheetHandle aSheet) = 0; /** * Notify the document that the applicable state of the sheet changed * and that observers should be notified and style sets updated */ - virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, + virtual void SetStyleSheetApplicableState(mozilla::StyleSheetHandle aSheet, bool aApplicable) = 0; enum additionalSheetType { @@ -1004,10 +1007,10 @@ public: virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) = 0; virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, - mozilla::CSSStyleSheet* aSheet) = 0; + mozilla::StyleSheetHandle aSheet) = 0; virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) = 0; - virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() = 0; + virtual mozilla::StyleSheetHandle FirstAdditionalAuthorSheet() = 0; /** * Get this document's CSSLoader. This is guaranteed to not return null. @@ -1016,6 +1019,8 @@ public: return mCSSLoader; } + mozilla::StyleBackendType GetStyleBackendType() const; + /** * Get this document's StyleImageLoader. This is guaranteed to not return null. */ @@ -1310,11 +1315,11 @@ public: // Observation hooks for style data to propagate notifications // to document observers - virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; - virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; - virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; /** @@ -2137,7 +2142,7 @@ public: * DO NOT USE FOR UNTRUSTED CONTENT. */ virtual nsresult LoadChromeSheetSync(nsIURI* aURI, bool aIsAgentSheet, - mozilla::CSSStyleSheet** aSheet) = 0; + mozilla::StyleSheetHandle::RefPtr* aSheet) = 0; /** * Returns true if the locale used for the document specifies a direction of diff --git a/dom/base/nsIDocumentObserver.h b/dom/base/nsIDocumentObserver.h index 5d6d2542a2..0aed2a7cca 100644 --- a/dom/base/nsIDocumentObserver.h +++ b/dom/base/nsIDocumentObserver.h @@ -7,6 +7,7 @@ #define nsIDocumentObserver_h___ #include "mozilla/EventStates.h" +#include "mozilla/StyleSheetHandle.h" #include "nsISupports.h" #include "nsIMutationObserver.h" @@ -14,7 +15,6 @@ class nsIContent; class nsIDocument; namespace mozilla { -class CSSStyleSheet; namespace css { class Rule; } // namespace css @@ -100,7 +100,7 @@ public: * @param aDocumentSheet True if sheet is in document's style sheet list, * false if sheet is not (i.e., UA or user sheet) */ - virtual void StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleSheetAdded(mozilla::StyleSheetHandle aStyleSheet, bool aDocumentSheet) = 0; /** @@ -113,7 +113,7 @@ public: * @param aDocumentSheet True if sheet is in document's style sheet list, * false if sheet is not (i.e., UA or user sheet) */ - virtual void StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, + virtual void StyleSheetRemoved(mozilla::StyleSheetHandle aStyleSheet, bool aDocumentSheet) = 0; /** @@ -125,7 +125,7 @@ public: * * @param aStyleSheet the StyleSheet that has changed state */ - virtual void StyleSheetApplicableStateChanged(mozilla::CSSStyleSheet* aStyleSheet) = 0; + virtual void StyleSheetApplicableStateChanged(mozilla::StyleSheetHandle aStyleSheet) = 0; /** * A StyleRule has just been modified within a style sheet. @@ -136,7 +136,7 @@ public: * * @param aStyleSheet the StyleSheet that contians the rule */ - virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) = 0; + virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet) = 0; /** * A StyleRule has just been added to a style sheet. @@ -147,7 +147,7 @@ public: * * @param aStyleSheet the StyleSheet that has been modified */ - virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) = 0; + virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet) = 0; /** * A StyleRule has just been removed from a style sheet. @@ -158,7 +158,7 @@ public: * * @param aStyleSheet the StyleSheet that has been modified */ - virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) = 0; + virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) @@ -186,25 +186,25 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) mozilla::EventStates aStateMask) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ - virtual void StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, \ + virtual void StyleSheetAdded(mozilla::StyleSheetHandle aStyleSheet, \ bool aDocumentSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ - virtual void StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, \ + virtual void StyleSheetRemoved(mozilla::StyleSheetHandle aStyleSheet, \ bool aDocumentSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ virtual void StyleSheetApplicableStateChanged( \ - mozilla::CSSStyleSheet* aStyleSheet) override; + mozilla::StyleSheetHandle aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ - virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) override; + virtual void StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ - virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) override; + virtual void StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ - virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) override; + virtual void StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER \ NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ @@ -262,29 +262,29 @@ NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \ void \ -_class::StyleSheetAdded(mozilla::CSSStyleSheet* aStyleSheet, \ +_class::StyleSheetAdded(mozilla::StyleSheetHandle aStyleSheet, \ bool aDocumentSheet) \ { \ } \ void \ -_class::StyleSheetRemoved(mozilla::CSSStyleSheet* aStyleSheet, \ +_class::StyleSheetRemoved(mozilla::StyleSheetHandle aStyleSheet, \ bool aDocumentSheet) \ { \ } \ void \ -_class::StyleSheetApplicableStateChanged(mozilla::CSSStyleSheet* aStyleSheet) \ +_class::StyleSheetApplicableStateChanged(mozilla::StyleSheetHandle aStyleSheet) \ { \ } \ void \ -_class::StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet) \ +_class::StyleRuleChanged(mozilla::StyleSheetHandle aStyleSheet) \ { \ } \ void \ -_class::StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet) \ +_class::StyleRuleAdded(mozilla::StyleSheetHandle aStyleSheet) \ { \ } \ void \ -_class::StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet) \ +_class::StyleRuleRemoved(mozilla::StyleSheetHandle aStyleSheet) \ { \ } diff --git a/dom/base/nsIScriptNameSpaceManager.h b/dom/base/nsIScriptNameSpaceManager.h index c2ea3eb70d..9a5b5146c6 100644 --- a/dom/base/nsIScriptNameSpaceManager.h +++ b/dom/base/nsIScriptNameSpaceManager.h @@ -10,9 +10,6 @@ #define JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY \ "JavaScript-global-constructor" -#define JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY \ - "JavaScript-global-constructor-prototype-alias" - #define JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY \ "JavaScript-global-property" @@ -23,10 +20,4 @@ #define JAVASCRIPT_NAVIGATOR_PROPERTY_CATEGORY \ "JavaScript-navigator-property" -#define JAVASCRIPT_DOM_CLASS \ - "JavaScript-DOM-class" - -#define JAVASCRIPT_DOM_INTERFACE \ - "JavaScript-DOM-interface" - #endif /* nsIScriptNameSpaceManager_h__ */ diff --git a/dom/base/nsIStyleSheetLinkingElement.h b/dom/base/nsIStyleSheetLinkingElement.h index 77eaebf609..d6c2440169 100644 --- a/dom/base/nsIStyleSheetLinkingElement.h +++ b/dom/base/nsIStyleSheetLinkingElement.h @@ -8,6 +8,7 @@ #include "nsISupports.h" +#include "mozilla/StyleSheetHandle.h" class nsICSSLoaderObserver; class nsIURI; @@ -16,10 +17,6 @@ class nsIURI; { 0xa8b79f3b, 0x9d18, 0x4f9c, \ { 0xb1, 0xaa, 0x8c, 0x9b, 0x1b, 0xaa, 0xac, 0xad } } -namespace mozilla { -class CSSStyleSheet; -} // namespace mozilla - class nsIStyleSheetLinkingElement : public nsISupports { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID) @@ -31,14 +28,14 @@ public: * @param aStyleSheet the style sheet associated with this * element. */ - NS_IMETHOD SetStyleSheet(mozilla::CSSStyleSheet* aStyleSheet) = 0; + NS_IMETHOD SetStyleSheet(mozilla::StyleSheetHandle aStyleSheet) = 0; /** * Used to obtain the style sheet linked in by this element. * * @return the style sheet associated with this element. */ - NS_IMETHOD_(mozilla::CSSStyleSheet*) GetStyleSheet() = 0; + NS_IMETHOD_(mozilla::StyleSheetHandle) GetStyleSheet() = 0; /** * Initialize the stylesheet linking element. If aDontLoadStyle is diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index d1f4f9e610..2c833f7dbc 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -52,6 +52,8 @@ #include "nsGlobalWindow.h" #include "nsScriptNameSpaceManager.h" #include "mozilla/AutoRestore.h" +#include "mozilla/dom/DOMException.h" +#include "mozilla/dom/DOMExceptionBinding.h" #include "mozilla/dom/ErrorEvent.h" #include "nsAXPCNativeCallContext.h" #include "mozilla/CycleCollectedJSRuntime.h" @@ -223,6 +225,59 @@ ProcessNameForCollectorLog() "default" : "content"; } +namespace xpc { + +// This handles JS Exceptions (via ExceptionStackOrNull), as well as DOM and XPC +// Exceptions. +// +// Note that the returned object is _not_ wrapped into the compartment of +// exceptionValue. +JSObject* +FindExceptionStackForConsoleReport(nsPIDOMWindow* win, + JS::HandleValue exceptionValue) +{ + if (!exceptionValue.isObject()) { + return nullptr; + } + + if (win && win->InnerObjectsFreed()) { + // Pretend like we have no stack, so we don't end up keeping the global + // alive via the stack. + return nullptr; + } + + JSContext* cx = nsContentUtils::RootingCxForThread(); + JS::RootedObject exceptionObject(cx, &exceptionValue.toObject()); + JSObject* stackObject = ExceptionStackOrNull(exceptionObject); + if (stackObject) { + return stackObject; + } + + // It is not a JS Exception, try DOM Exception. + RefPtr exception; + UNWRAP_OBJECT(DOMException, exceptionObject, exception); + if (!exception) { + // Not a DOM Exception, try XPC Exception. + UNWRAP_OBJECT(Exception, exceptionObject, exception); + if (!exception) { + return nullptr; + } + } + + nsCOMPtr stack = exception->GetLocation(); + if (!stack) { + return nullptr; + } + JS::RootedValue value(cx); + stack->GetNativeSavedFrame(&value); + if (value.isObject()) { + return &value.toObject(); + } + return nullptr; +} + +} /* namespace xpc */ + static PRTime GetCollectionTimeDelta() { @@ -381,8 +436,10 @@ public: nsEventStatus status = nsEventStatus_eIgnore; nsPIDOMWindow* win = mWindow; MOZ_ASSERT(win); + MOZ_ASSERT(NS_IsMainThread()); // First, notify the DOM that we have a script error, but only if // our window is still the current inner. + JSContext* rootingCx = nsContentUtils::RootingCx(); if (win->IsCurrentInnerWindow() && win->GetDocShell() && !sHandlingScriptError) { AutoRestore recursionGuard(sHandlingScriptError); sHandlingScriptError = true; @@ -390,8 +447,7 @@ public: RefPtr presContext; win->GetDocShell()->GetPresContext(getter_AddRefs(presContext)); - ThreadsafeAutoJSContext cx; - RootedDictionary init(cx); + RootedDictionary init(rootingCx); init.mCancelable = true; init.mFilename = mReport->mFileName; init.mBubbles = true; @@ -418,20 +474,9 @@ public: } if (status != nsEventStatus_eConsumeNoDefault) { - if (mError.isObject()) { - AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(mError.toObjectOrNull()))) { - mReport->LogToConsole(); - return NS_OK; - } - JSContext* cx = jsapi.cx(); - JS::Rooted exObj(cx, mError.toObjectOrNull()); - JS::RootedObject stack(cx, ExceptionStackOrNull(cx, exObj)); - mReport->LogToConsoleWithStack(stack); - } else { - mReport->LogToConsole(); - } - + JS::Rooted stack(rootingCx, + xpc::FindExceptionStackForConsoleReport(win, mError)); + mReport->LogToConsoleWithStack(stack); } return NS_OK; @@ -509,14 +554,9 @@ SystemErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) if (!win || JSREPORT_IS_WARNING(xpcReport->mFlags) || report->errorNumber == JSMSG_OUT_OF_MEMORY) { - if (exception.isObject()) { - JS::RootedObject exObj(cx, exception.toObjectOrNull()); - JSAutoCompartment ac(cx, exObj); - JS::RootedObject stackVal(cx, ExceptionStackOrNull(cx, exObj)); - xpcReport->LogToConsoleWithStack(stackVal); - } else { - xpcReport->LogToConsole(); - } + JS::Rooted stack(cx, + xpc::FindExceptionStackForConsoleReport(win, exception)); + xpcReport->LogToConsoleWithStack(stack); return; } @@ -799,15 +839,15 @@ nsresult nsJSContext::SetProperty(JS::Handle aTarget, const char* aPropName, nsISupports* aArgs) { AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.InitWithLegacyErrorReporting(GetGlobalObject()))) { + if (NS_WARN_IF(!jsapi.Init(GetGlobalObject()))) { return NS_ERROR_FAILURE; } - MOZ_ASSERT(jsapi.cx() == mContext, - "AutoJSAPI should have found our own JSContext*"); + jsapi.TakeOwnershipOfErrorReporting(); + JSContext* cx = jsapi.cx(); - JS::AutoValueVector args(mContext); + JS::AutoValueVector args(cx); - JS::Rooted global(mContext, GetWindowProxy()); + JS::Rooted global(cx, GetWindowProxy()); nsresult rv = ConvertSupportsTojsvals(aArgs, global, args); NS_ENSURE_SUCCESS(rv, rv); @@ -815,17 +855,17 @@ nsJSContext::SetProperty(JS::Handle aTarget, const char* aPropName, n // got the arguments, now attach them. for (uint32_t i = 0; i < args.length(); ++i) { - if (!JS_WrapValue(mContext, args[i])) { + if (!JS_WrapValue(cx, args[i])) { return NS_ERROR_FAILURE; } } - JS::Rooted array(mContext, ::JS_NewArrayObject(mContext, args)); + JS::Rooted array(cx, ::JS_NewArrayObject(cx, args)); if (!array) { return NS_ERROR_FAILURE; } - return JS_DefineProperty(mContext, aTarget, aPropName, array, 0) ? NS_OK : NS_ERROR_FAILURE; + return JS_DefineProperty(cx, aTarget, aPropName, array, 0) ? NS_OK : NS_ERROR_FAILURE; } nsresult @@ -1400,6 +1440,11 @@ TimeUntilNow(TimeStamp start) struct CycleCollectorStats { + MOZ_CONSTEXPR CycleCollectorStats() : + mMaxGCDuration(0), mRanSyncForgetSkippable(false), mSuspected(0), + mMaxSkippableDuration(0), mMaxSliceTime(0), mMaxSliceTimeSinceClear(0), + mTotalSliceTime(0), mAnyLockedOut(false), mExtraForgetSkippableCalls(0) {} + void Init() { Clear(); @@ -2527,8 +2572,6 @@ AsmJSCacheOpenEntryForWrite(JS::Handle aGlobal, aSize, aMemory, aHandle); } -static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); - void nsJSContext::EnsureStatics() { @@ -2663,15 +2706,6 @@ nsJSContext::EnsureStatics() obs->AddObserver(observer, "quit-application", false); obs->AddObserver(observer, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); - // Bug 907848 - We need to explicitly get the nsIDOMScriptObjectFactory - // service in order to force its constructor to run, which registers a - // shutdown observer. It would be nice to make this more explicit and less - // side-effect-y. - nsCOMPtr factory = do_GetService(kDOMScriptObjectFactoryCID); - if (!factory) { - MOZ_CRASH(); - } - sIsInitialized = true; } diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index 1bc9d9f92d..3ab855c8dd 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -37,7 +37,7 @@ bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsACString& aFilename, uint32_t* aLineno, uint32_t* aColumn) { - JS::UniqueChars filename; + JS::AutoFilename filename; if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, aColumn)) { return false; } @@ -50,7 +50,7 @@ bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsAString& aFilename, uint32_t* aLineno, uint32_t* aColumn) { - JS::UniqueChars filename; + JS::AutoFilename filename; if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, aColumn)) { return false; } @@ -83,19 +83,8 @@ nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(JSContext *aContext) if (!aContext) return 0; - uint64_t innerWindowID = 0; - - JSObject *jsGlobal = JS::CurrentGlobalOrNull(aContext); - if (jsGlobal) { - nsIScriptGlobalObject *scriptGlobal = GetStaticScriptGlobal(jsGlobal); - if (scriptGlobal) { - nsCOMPtr win = do_QueryInterface(scriptGlobal); - if (win) - innerWindowID = win->WindowID(); - } - } - - return innerWindowID; + nsGlobalWindow* win = xpc::CurrentWindowOrNull(aContext); + return win ? win->WindowID() : 0; } nsresult diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 178976cf72..7100eeccfb 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -3581,11 +3581,15 @@ nsObjectLoadingContent::TeardownProtoChain() nsCOMPtr thisContent = do_QueryInterface(static_cast(this)); - // Use the safe JSContext here as we're not always able to find the - // JSContext associated with the NPP any more. - AutoSafeJSContext cx; + NS_ENSURE_TRUE_VOID(thisContent->GetWrapper()); + + // We don't init the AutoJSAPI with our wrapper because we don't want it + // reporting errors to our window's onerror listeners. + AutoJSAPI jsapi; + jsapi.Init(); + JSContext* cx = jsapi.cx(); JS::Rooted obj(cx, thisContent->GetWrapper()); - NS_ENSURE_TRUE(obj, /* void */); + MOZ_ASSERT(obj); JS::Rooted proto(cx); JSAutoCompartment ac(cx, obj); diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 75a068fe18..fd1083d220 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -539,6 +539,14 @@ public: mMayHavePointerEnterLeaveEventListener = true; } + /** + * Check whether this has had inner objects freed. + */ + bool InnerObjectsFreed() const + { + return mInnerObjectsFreed; + } + virtual JSObject* GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey) = 0; virtual void CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey, @@ -829,6 +837,12 @@ protected: bool mMayHaveMouseEnterLeaveEventListener; bool mMayHavePointerEnterLeaveEventListener; + // Used to detect whether we have called FreeInnerObjects() (e.g. to ensure + // that a call to ResumeTimeouts() after FreeInnerObjects() does nothing). + // This member is only used by inner windows. + bool mInnerObjectsFreed; + + // This variable is used on both inner and outer windows (and they // should match). bool mIsModalContentWindow; diff --git a/dom/base/nsScriptLoader.cpp b/dom/base/nsScriptLoader.cpp index 14208be43e..dc8870c24a 100644 --- a/dom/base/nsScriptLoader.cpp +++ b/dom/base/nsScriptLoader.cpp @@ -849,9 +849,10 @@ nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest) } AutoJSAPI jsapi; - if (!jsapi.InitWithLegacyErrorReporting(globalObject)) { + if (!jsapi.Init(globalObject)) { return NS_ERROR_FAILURE; } + jsapi.TakeOwnershipOfErrorReporting(); JSContext* cx = jsapi.cx(); JS::Rooted global(cx, globalObject->GetGlobalJSObject()); diff --git a/dom/base/nsScriptNameSpaceManager.cpp b/dom/base/nsScriptNameSpaceManager.cpp index 42a0f53fb5..d4e78c4935 100644 --- a/dom/base/nsScriptNameSpaceManager.cpp +++ b/dom/base/nsScriptNameSpaceManager.cpp @@ -61,21 +61,6 @@ GlobalNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry) // An entry is being cleared, let the key (nsString) do its own // cleanup. e->mKey.~nsString(); - if (e->mGlobalName.mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - nsIClassInfo* ci = GET_CLEAN_CI_PTR(e->mGlobalName.mData->mCachedClassInfo); - - // If we constructed an internal helper, we'll let the helper delete - // the nsDOMClassInfoData structure, if not we do it here. - if (!ci || e->mGlobalName.mData->u.mExternalConstructorFptr) { - delete e->mGlobalName.mData; - } - - // Release our pointer to the helper. - NS_IF_RELEASE(ci); - } - else if (e->mGlobalName.mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) { - delete e->mGlobalName.mAlias; - } // This will set e->mGlobalName.mType to // nsGlobalNameStruct::eTypeNotInitialized @@ -151,21 +136,6 @@ nsScriptNameSpaceManager::RemoveFromHash(PLDHashTable *aTable, aTable->Remove(aKey); } -nsGlobalNameStruct* -nsScriptNameSpaceManager::GetConstructorProto(const nsGlobalNameStruct* aStruct) -{ - NS_ASSERTION(aStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias, - "This function only works on constructor aliases!"); - if (!aStruct->mAlias->mProto) { - auto proto = static_cast - (mGlobalNames.Search(&aStruct->mAlias->mProtoName)); - if (proto) { - aStruct->mAlias->mProto = &proto->mGlobalName; - } - } - return aStruct->mAlias->mProto; -} - nsresult nsScriptNameSpaceManager::FillHash(nsICategoryManager *aCategoryManager, const char *aCategory) @@ -187,116 +157,6 @@ nsScriptNameSpaceManager::FillHash(nsICategoryManager *aCategoryManager, } -nsresult -nsScriptNameSpaceManager::RegisterExternalInterfaces(bool aAsProto) -{ - nsresult rv; - nsCOMPtr cm = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr - iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); - NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE); - - nsCOMPtr enumerator; - rv = cm->EnumerateCategory(JAVASCRIPT_DOM_INTERFACE, - getter_AddRefs(enumerator)); - NS_ENSURE_SUCCESS(rv, rv); - - nsXPIDLCString IID_string; - nsAutoCString category_entry; - const char* if_name; - nsCOMPtr entry; - nsCOMPtr if_info; - bool found_old, dom_prefix; - - while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { - nsCOMPtr category(do_QueryInterface(entry)); - - if (!category) { - NS_WARNING("Category entry not an nsISupportsCString!"); - - continue; - } - - rv = category->GetData(category_entry); - NS_ENSURE_SUCCESS(rv, rv); - - rv = cm->GetCategoryEntry(JAVASCRIPT_DOM_INTERFACE, category_entry.get(), - getter_Copies(IID_string)); - NS_ENSURE_SUCCESS(rv, rv); - - nsIID primary_IID; - if (!primary_IID.Parse(IID_string) || - primary_IID.Equals(NS_GET_IID(nsISupports))) { - NS_ERROR("Invalid IID registered with the script namespace manager!"); - continue; - } - - iim->GetInfoForIID(&primary_IID, getter_AddRefs(if_info)); - - while (if_info) { - const nsIID *iid; - if_info->GetIIDShared(&iid); - NS_ENSURE_TRUE(iid, NS_ERROR_UNEXPECTED); - - if (iid->Equals(NS_GET_IID(nsISupports))) { - break; - } - - if_info->GetNameShared(&if_name); - dom_prefix = (strncmp(if_name, NS_DOM_INTERFACE_PREFIX, - sizeof(NS_DOM_INTERFACE_PREFIX) - 1) == 0); - - const char* name; - if (dom_prefix) { - name = if_name + sizeof(NS_DOM_INTERFACE_PREFIX) - 1; - } else { - name = if_name + sizeof(NS_INTERFACE_PREFIX) - 1; - } - - if (aAsProto) { - RegisterClassProto(name, iid, &found_old); - } else { - RegisterInterface(name, iid, &found_old); - } - - if (found_old) { - break; - } - - nsCOMPtr tmp(if_info); - tmp->GetParent(getter_AddRefs(if_info)); - } - } - - return NS_OK; -} - -nsresult -nsScriptNameSpaceManager::RegisterInterface(const char* aIfName, - const nsIID *aIfIID, - bool* aFoundOld) -{ - *aFoundOld = false; - - nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aIfName); - NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); - - if (s->mType != nsGlobalNameStruct::eTypeNotInitialized && - s->mType != nsGlobalNameStruct::eTypeNewDOMBinding) { - *aFoundOld = true; - - return NS_OK; - } - - s->mType = nsGlobalNameStruct::eTypeInterface; - s->mIID = *aIfIID; - - return NS_OK; -} - nsresult nsScriptNameSpaceManager::Init() { @@ -304,9 +164,6 @@ nsScriptNameSpaceManager::Init() nsresult rv = NS_OK; - rv = RegisterExternalInterfaces(false); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr cm = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -389,8 +246,7 @@ nsScriptNameSpaceManager::RegisterClassName(const char *aClassName, } NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized || - s->mType == nsGlobalNameStruct::eTypeNewDOMBinding || - s->mType == nsGlobalNameStruct::eTypeInterface, + s->mType == nsGlobalNameStruct::eTypeNewDOMBinding, "Whaaa, JS environment name clash!"); s->mType = nsGlobalNameStruct::eTypeClassConstructor; @@ -414,8 +270,7 @@ nsScriptNameSpaceManager::RegisterClassProto(const char *aClassName, NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); if (s->mType != nsGlobalNameStruct::eTypeNotInitialized && - s->mType != nsGlobalNameStruct::eTypeNewDOMBinding && - s->mType != nsGlobalNameStruct::eTypeInterface) { + s->mType != nsGlobalNameStruct::eTypeNewDOMBinding) { *aFoundOld = true; return NS_OK; @@ -427,77 +282,6 @@ nsScriptNameSpaceManager::RegisterClassProto(const char *aClassName, return NS_OK; } -nsresult -nsScriptNameSpaceManager::RegisterExternalClassName(const char *aClassName, - nsCID& aCID) -{ - nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aClassName); - NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); - - // If an external constructor is already defined with aClassName we - // won't overwrite it. - - if (s->mType == nsGlobalNameStruct::eTypeExternalConstructor) { - return NS_OK; - } - - NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized || - s->mType == nsGlobalNameStruct::eTypeNewDOMBinding || - s->mType == nsGlobalNameStruct::eTypeInterface, - "Whaaa, JS environment name clash!"); - - s->mType = nsGlobalNameStruct::eTypeExternalClassInfoCreator; - s->mCID = aCID; - - return NS_OK; -} - -nsresult -nsScriptNameSpaceManager::RegisterDOMCIData(const char *aName, - nsDOMClassInfoExternalConstructorFnc aConstructorFptr, - const nsIID *aProtoChainInterface, - const nsIID **aInterfaces, - uint32_t aScriptableFlags, - bool aHasClassInterface, - const nsCID *aConstructorCID) -{ - const char16_t* className; - nsGlobalNameStruct *s = AddToHash(&mGlobalNames, aName, &className); - NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); - - // If an external constructor is already defined with aClassName we - // won't overwrite it. - - if (s->mType == nsGlobalNameStruct::eTypeClassConstructor || - s->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - return NS_OK; - } - - // XXX Should we bail out here? - NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized || - s->mType == nsGlobalNameStruct::eTypeNewDOMBinding || - s->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator, - "Someone tries to register classinfo data for a class that isn't new or external!"); - - s->mData = new nsExternalDOMClassInfoData; - s->mType = nsGlobalNameStruct::eTypeExternalClassInfo; - s->mData->mName = aName; - s->mData->mNameUTF16 = className; - if (aConstructorFptr) - s->mData->u.mExternalConstructorFptr = aConstructorFptr; - else - // null constructor will cause us to use nsDOMGenericSH::doCreate - s->mData->u.mExternalConstructorFptr = nullptr; - s->mData->mCachedClassInfo = nullptr; - s->mData->mProtoChainInterface = aProtoChainInterface; - s->mData->mInterfaces = aInterfaces; - s->mData->mScriptableFlags = aScriptableFlags; - s->mData->mHasClassInterface = aHasClassInterface; - s->mData->mConstructorCID = aConstructorCID; - - return NS_OK; -} - nsresult nsScriptNameSpaceManager::OperateCategoryEntryHash(nsICategoryManager* aCategoryManager, const char* aCategory, @@ -591,31 +375,6 @@ nsScriptNameSpaceManager::OperateCategoryEntryHash(nsICategoryManager* aCategory nsCID cid = *cidPtr; free(cidPtr); - if (type == nsGlobalNameStruct::eTypeExternalConstructor) { - nsXPIDLCString constructorProto; - rv = aCategoryManager->GetCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, - categoryEntry.get(), - getter_Copies(constructorProto)); - if (NS_SUCCEEDED(rv)) { - nsGlobalNameStruct *s = AddToHash(&mGlobalNames, categoryEntry.get()); - NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); - - if (s->mType == nsGlobalNameStruct::eTypeNotInitialized || - s->mType == nsGlobalNameStruct::eTypeNewDOMBinding) { - s->mAlias = new nsGlobalNameStruct::ConstructorAlias; - s->mType = nsGlobalNameStruct::eTypeExternalConstructorAlias; - s->mChromeOnly = false; - s->mAlias->mCID = cid; - AppendASCIItoUTF16(constructorProto, s->mAlias->mProtoName); - s->mAlias->mProto = nullptr; - } else { - NS_WARNING("Global script name not overwritten!"); - } - - return NS_OK; - } - } - nsGlobalNameStruct *s = AddToHash(table, categoryEntry.get()); NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY); diff --git a/dom/base/nsScriptNameSpaceManager.h b/dom/base/nsScriptNameSpaceManager.h index 38d099f9ae..e38a8018d1 100644 --- a/dom/base/nsScriptNameSpaceManager.h +++ b/dom/base/nsScriptNameSpaceManager.h @@ -36,25 +36,14 @@ struct nsGlobalNameStruct { - struct ConstructorAlias - { - nsCID mCID; - nsString mProtoName; - nsGlobalNameStruct* mProto; - }; - enum nametype { eTypeNotInitialized, eTypeNewDOMBinding, - eTypeInterface, eTypeProperty, eTypeNavigatorProperty, eTypeExternalConstructor, eTypeClassConstructor, eTypeClassProto, - eTypeExternalClassInfoCreator, - eTypeExternalClassInfo, - eTypeExternalConstructorAlias } mType; // mChromeOnly is only used for structs that define non-WebIDL things @@ -65,9 +54,7 @@ struct nsGlobalNameStruct union { int32_t mDOMClassInfoID; // eTypeClassConstructor - nsIID mIID; // eTypeInterface, eTypeClassProto - nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo - ConstructorAlias* mAlias; // eTypeExternalConstructorAlias + nsIID mIID; // eTypeClassProto nsCID mCID; // All other types except eTypeNewDOMBinding }; @@ -137,23 +124,6 @@ public: const nsIID *aConstructorProtoIID, bool *aFoundOld); - nsresult RegisterExternalInterfaces(bool aAsProto); - - nsresult RegisterExternalClassName(const char *aClassName, - nsCID& aCID); - - // Register the info for an external class. aName must be static - // data, it will not be deleted by the DOM code. - nsresult RegisterDOMCIData(const char *aName, - nsDOMClassInfoExternalConstructorFnc aConstructorFptr, - const nsIID *aProtoChainInterface, - const nsIID **aInterfaces, - uint32_t aScriptableFlags, - bool aHasClassInterface, - const nsCID *aConstructorCID); - - nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct); - void RegisterDefineDOMInterface(const nsAFlatString& aName, mozilla::dom::DefineInterface aDefineDOMInterface, mozilla::dom::ConstructorEnabled* aConstructorEnabled); diff --git a/dom/base/nsStructuredCloneContainer.cpp b/dom/base/nsStructuredCloneContainer.cpp index 430bfe3b3e..7f676b335e 100644 --- a/dom/base/nsStructuredCloneContainer.cpp +++ b/dom/base/nsStructuredCloneContainer.cpp @@ -58,8 +58,7 @@ nsStructuredCloneContainer::InitFromJSVal(JS::Handle aData, NS_IMETHODIMP nsStructuredCloneContainer::InitFromBase64(const nsAString &aData, - uint32_t aFormatVersion, - JSContext* aCx) + uint32_t aFormatVersion) { if (DataLength()) { return NS_ERROR_FAILURE; diff --git a/dom/base/nsStyleLinkElement.cpp b/dom/base/nsStyleLinkElement.cpp index 56fc539ef3..a1527eaf1b 100644 --- a/dom/base/nsStyleLinkElement.cpp +++ b/dom/base/nsStyleLinkElement.cpp @@ -12,7 +12,8 @@ #include "nsStyleLinkElement.h" -#include "mozilla/CSSStyleSheet.h" +#include "mozilla/StyleSheetHandle.h" +#include "mozilla/StyleSheetHandleInlines.h" #include "mozilla/css/Loader.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/FragmentOrElement.h" @@ -67,7 +68,7 @@ nsStyleLinkElement::Traverse(nsCycleCollectionTraversalCallback &cb) } NS_IMETHODIMP -nsStyleLinkElement::SetStyleSheet(CSSStyleSheet* aStyleSheet) +nsStyleLinkElement::SetStyleSheet(StyleSheetHandle aStyleSheet) { if (mStyleSheet) { mStyleSheet->SetOwningNode(nullptr); @@ -84,7 +85,7 @@ nsStyleLinkElement::SetStyleSheet(CSSStyleSheet* aStyleSheet) return NS_OK; } -NS_IMETHODIMP_(CSSStyleSheet*) +NS_IMETHODIMP_(StyleSheetHandle) nsStyleLinkElement::GetStyleSheet() { return mStyleSheet; @@ -316,8 +317,15 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument, return NS_OK; } - Element* oldScopeElement = - mStyleSheet ? mStyleSheet->GetScopeElement() : nullptr; + // XXXheycam ServoStyleSheets do not support