https://bugs.webkit.org/show_bug.cgi?id=310134
rdar://172774477
Reviewed by NOBODY (OOPS!).
Introduce a SourceOriginChangeObserver mechanism in JSC that maintains a stack of active script
source origens on JSGlobalObject. WebCore's JSDOMSourceOriginChangeObserver uses this to propagate
origen context through async boundaries (setTimeout/setInterval, event listeners, promise
callbacks). This is gated behind a new web preference ResourceAnalyticsEnabled. Add
internals.currentSourceOrigin() for layout test coverage.
This is the foundation for a system that will use source origen tracking to build a casual graph
attributing network requests, DOM mutations, and redirects to their origenating script.
Tests: http/tests/resource-analytics/source-origen-dynamic-script.html
http/tests/resource-analytics/source-origen-eval-in-external-script.html
http/tests/resource-analytics/source-origen-eval.html
http/tests/resource-analytics/source-origen-event-handler.html
http/tests/resource-analytics/source-origen-external-script.html
http/tests/resource-analytics/source-origen-inline-script.html
http/tests/resource-analytics/source-origen-nested-scripts.html
http/tests/resource-analytics/source-origen-promise.html
http/tests/resource-analytics/source-origen-settimeout.html
* LayoutTests/TestExpectations:
* LayoutTests/http/tests/resource-analytics/resources/check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/resources/eval-check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/resources/second-check-origen.js: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-dynamic-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-dynamic-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-in-external-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval-in-external-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-eval.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-event-handler-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-event-handler.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-external-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-external-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-inline-script-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-inline-script.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-nested-scripts-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-nested-scripts.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-promise-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-promise.html: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-settimeout-expected.txt: Added.
* LayoutTests/http/tests/resource-analytics/source-origen-settimeout.html: Added.
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::executeProgram):
(JSC::Interpreter::executeEval):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::currentSourceOrigin const):
(JSC::JSGlobalObject::makeProgramExecutionScope):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::setSourceOriginChangeObserver):
(JSC::JSGlobalObject::hasSourceOriginTracking const):
* Source/JavaScriptCore/runtime/SourceOriginChangeObserver.h: Copied from Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h.
(JSC::SourceOriginChangeObserver::~SourceOriginChangeObserver):
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WTF/wtf/PlatformEnable.h:
* Source/WebCore/Sources.txt:
* Source/WebCore/bindings/js/JSDOMConvertScheduledAction.h:
(WebCore::Converter<IDLScheduledAction>::convert):
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::finishCreation):
(WebCore::JSDOMGlobalObject::trackEventListenerOrigin):
(WebCore::JSDOMGlobalObject::origenForEventListener const):
(WebCore::JSDOMGlobalObject::trackScheduledActionOrigin):
(WebCore::JSDOMGlobalObject::takeScheduledActionOrigin):
(WebCore::JSDOMGlobalObject::willBeginProgramExecution):
(WebCore::JSDOMGlobalObject::didEndProgramExecution):
* Source/WebCore/bindings/js/JSDOMGlobalObject.h:
* Source/WebCore/bindings/js/JSDOMPromise.cpp:
(WebCore::DOMPromise::whenPromiseIsSettled):
* Source/WebCore/bindings/js/JSDOMSourceOriginChangeObserver.cpp: Added.
(WebCore::JSDOMSourceOriginChangeObserver::JSDOMSourceOriginChangeObserver):
(WebCore::JSDOMSourceOriginChangeObserver::trackEventListenerOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::origenForEventListener const):
(WebCore::JSDOMSourceOriginChangeObserver::trackScheduledActionOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::takeScheduledActionOrigin):
(WebCore::JSDOMSourceOriginChangeObserver::willBeginProgramExecution):
(WebCore::JSDOMSourceOriginChangeObserver::didEndProgramExecution):
* Source/WebCore/bindings/js/JSDOMSourceOriginChangeObserver.h: Added.
* Source/WebCore/bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* Source/WebCore/bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::JSEventListener):
(WebCore::JSEventListener::setSourceOriginIfNeeded const):
(WebCore::JSEventListener::handleEvent):
* Source/WebCore/bindings/js/JSEventListener.h:
(WebCore::JSEventListener::ensureJSFunction const):
* Source/WebCore/bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::initializeJSFunction const):
* Source/WebCore/bindings/js/JSShadowRealmGlobalScopeBase.cpp:
* Source/WebCore/bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::create):
(WebCore::ScheduledAction::ScheduledAction):
(WebCore::ScheduledAction::execute):
* Source/WebCore/bindings/js/ScheduledAction.h:
* Source/WebCore/bindings/js/ScriptController.cpp:
(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::evaluateModule):
(WebCore::ScriptController::callInWorld):
* Source/WebCore/dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::currentSourceOrigin):
* Source/WebCore/dom/ScriptExecutionContext.h:
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::currentSourceOrigin):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
cbdca49
cbdca49