Changeset 192186 in webkit
- Timestamp:
- Nov 9, 2015, 4:19:26 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 2 deleted
- 21 edited
- 2 copied
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/TestExpectations (modified) (1 diff)
-
LayoutTests/http/tests/inspector/console/access-inspected-object-expected.txt (deleted)
-
LayoutTests/http/tests/inspector/console/access-inspected-object.html (deleted)
-
LayoutTests/http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt (added)
-
LayoutTests/http/tests/inspector/console/cross-domain-inspected-node-access.html (added)
-
Source/JavaScriptCore/CMakeLists.txt (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj (modified) (2 diffs)
-
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters (modified) (2 diffs)
-
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (modified) (7 diffs)
-
Source/JavaScriptCore/inspector/InjectedScriptHost.cpp (modified) (2 diffs)
-
Source/JavaScriptCore/inspector/InjectedScriptHost.h (modified) (2 diffs)
-
Source/JavaScriptCore/inspector/InjectedScriptManager.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/inspector/InjectedScriptManager.h (modified) (2 diffs)
-
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/inspector/JSInjectedScriptHost.h (modified) (4 diffs)
-
Source/JavaScriptCore/inspector/PerGlobalObjectWrapperWorld.cpp (copied) (copied from trunk/Source/JavaScriptCore/inspector/InjectedScriptHost.h ) (1 diff)
-
Source/JavaScriptCore/inspector/PerGlobalObjectWrapperWorld.h (copied) (copied from trunk/Source/JavaScriptCore/inspector/InjectedScriptHost.h ) (3 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/ForwardingHeaders/inspector/PerGlobalObjectWrapperWorld.h (added)
-
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (modified) (1 diff)
-
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (modified) (1 diff)
-
Source/WebCore/inspector/CommandLineAPIHost.cpp (modified) (3 diffs)
-
Source/WebCore/inspector/CommandLineAPIHost.h (modified) (4 diffs)
-
Source/WebCore/inspector/CommandLineAPIModule.cpp (modified) (2 diffs)
-
Source/WebCore/inspector/WebInjectedScriptManager.cpp (modified) (1 diff)
-
Source/WebCore/inspector/WebInjectedScriptManager.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r192182 r192186 1 2015-11-09 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: $0 stops working after navigating to a different domain 4 https://bugs.webkit.org/show_bug.cgi?id=147962 5 6 Reviewed by Brian Burg. 7 8 * TestExpectations: 9 * http/tests/inspector/console/access-inspected-object-expected.txt: Removed. 10 * http/tests/inspector/console/access-inspected-object.html: Removed. 11 * http/tests/inspector/console/cross-domain-inspected-node-access-expected.txt: Added. 12 * http/tests/inspector/console/cross-domain-inspected-node-access.html: Added. 13 Rewrite the old test with the new testing infrastructure. 14 Test this particular case of cross origin CommandLineAPI usage ($0). 15 1 16 2015-11-09 Ryan Haddad <ryanhaddad@apple.com> 2 17 -
trunk/LayoutTests/TestExpectations
r192132 r192186 121 121 122 122 # These tests will be rewritten, just skip them until that time. 123 webkit.org/b/148036 http/tests/inspector/console/ [ Skip ]124 123 webkit.org/b/148036 http/tests/inspector/css/ [ Skip ] 125 124 webkit.org/b/148036 http/tests/inspector/page/ [ Skip ] -
trunk/Source/JavaScriptCore/CMakeLists.txt
r192135 r192186 399 399 inspector/JSJavaScriptCallFramePrototype.cpp 400 400 inspector/JavaScriptCallFrame.cpp 401 inspector/PerGlobalObjectWrapperWorld.cpp 401 402 inspector/ScriptArguments.cpp 402 403 inspector/ScriptCallFrame.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r192183 r192186 1 2015-11-09 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: $0 stops working after navigating to a different domain 4 https://bugs.webkit.org/show_bug.cgi?id=147962 5 6 Reviewed by Brian Burg. 7 8 Extract the per-GlobalObject cache of JSValue wrappers for 9 InjectedScriptHost objects to be reused by WebCore for its 10 CommandLineAPIHost objects injected into multiple contexts. 11 12 * CMakeLists.txt: 13 * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj: 14 * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters: 15 * JavaScriptCore.xcodeproj/project.pbxproj: 16 Add new files. 17 18 * inspector/PerGlobalObjectWrapperWorld.h: 19 * inspector/PerGlobalObjectWrapperWorld.cpp: 20 (Inspector::PerGlobalObjectWrapperWorld::getWrapper): 21 (Inspector::PerGlobalObjectWrapperWorld::addWrapper): 22 (Inspector::PerGlobalObjectWrapperWorld::clearAllWrappers): 23 Hold a bunch of per-global-object wrappers for an object 24 that will outlive the global object. This inspector does this 25 for host objects that it exposes into scripts it injects into 26 each execution context created by the page. 27 28 * inspector/InjectedScriptHost.cpp: 29 (Inspector::InjectedScriptHost::wrapper): 30 (Inspector::InjectedScriptHost::clearAllWrappers): 31 (Inspector::InjectedScriptHost::jsWrapper): Deleted. 32 (Inspector::clearWrapperFromValue): Deleted. 33 (Inspector::InjectedScriptHost::clearWrapper): Deleted. 34 Extract and simplify the Per-GlobalObject wrapping into a class. 35 Simplify object construction as well. 36 37 * inspector/InjectedScriptHost.h: 38 * inspector/InjectedScriptManager.cpp: 39 (Inspector::InjectedScriptManager::createInjectedScript): 40 (Inspector::InjectedScriptManager::discardInjectedScripts): 41 Make discarding virtual so subclasses may also discard injected scripts. 42 43 * inspector/JSInjectedScriptHost.cpp: 44 (Inspector::JSInjectedScriptHost::JSInjectedScriptHost): 45 (Inspector::JSInjectedScriptHost::releaseImpl): Deleted. 46 (Inspector::JSInjectedScriptHost::~JSInjectedScriptHost): Deleted. 47 (Inspector::toJS): Deleted. 48 (Inspector::toJSInjectedScriptHost): Deleted. 49 * inspector/JSInjectedScriptHost.h: 50 (Inspector::JSInjectedScriptHost::create): 51 (Inspector::JSInjectedScriptHost::impl): 52 Update this code originally copied from older generated bindings to 53 be more like new generated bindings and remove some now unused code. 54 1 55 2015-11-08 Filip Pizlo <fpizlo@apple.com> 2 56 -
trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
r191905 r192186 609 609 <ClCompile Include="..\inspector\JSJavaScriptCallFramePrototype.cpp" /> 610 610 <ClCompile Include="..\inspector\JavaScriptCallFrame.cpp" /> 611 <ClCompile Include="..\inspector\PerGlobalObjectWrapperWorld.cpp" /> 611 612 <ClCompile Include="..\inspector\ScriptArguments.cpp" /> 612 613 <ClCompile Include="..\inspector\ScriptCallFrame.cpp" /> … … 1419 1420 <ClInclude Include="..\inspector\JSJavaScriptCallFramePrototype.h" /> 1420 1421 <ClInclude Include="..\inspector\JavaScriptCallFrame.h" /> 1422 <ClInclude Include="..\inspector\PerGlobalObjectWrapperWorld.h" /> 1421 1423 <ClInclude Include="..\inspector\ScriptArguments.h" /> 1422 1424 <ClInclude Include="..\inspector\ScriptBreakpoint.h" /> -
trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters
r191905 r192186 1732 1732 <Filter>inspector</Filter> 1733 1733 </ClCompile> 1734 <ClCompile Include="..\inspector\PerGlobalObjectWrapperWorld.cpp"> 1735 <Filter>inspector</Filter> 1736 </ClCompile> 1734 1737 <ClCompile Include="..\profiler\ProfilerJettisonReason.cpp"> 1735 1738 <Filter>profiler</Filter> … … 4326 4329 </ClInclude> 4327 4330 <ClInclude Include="..\inspector\JSJavaScriptCallFrame.h"> 4331 <Filter>inspector</Filter> 4332 </ClInclude> 4333 <ClInclude Include="..\inspector\PerGlobalObjectWrapperWorld.h"> 4328 4334 <Filter>inspector</Filter> 4329 4335 </ClInclude> -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r192183 r192186 1523 1523 A59455931824744700CC3843 /* JSGlobalObjectDebuggable.h in Headers */ = {isa = PBXBuildFile; fileRef = A59455911824744700CC3843 /* JSGlobalObjectDebuggable.h */; }; 1524 1524 A5945595182479EB00CC3843 /* InspectorFrontendChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = A5945594182479EB00CC3843 /* InspectorFrontendChannel.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1525 A5AB49DC1BEC8082007020FB /* PerGlobalObjectWrapperWorld.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5AB49DA1BEC8079007020FB /* PerGlobalObjectWrapperWorld.cpp */; }; 1526 A5AB49DD1BEC8086007020FB /* PerGlobalObjectWrapperWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = A5AB49DB1BEC8079007020FB /* PerGlobalObjectWrapperWorld.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1525 1527 A5B6A74D18C6DBA600F11E91 /* ConsoleClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5B6A74C18C6DBA600F11E91 /* ConsoleClient.cpp */; }; 1526 1528 A5BA15E8182340B300A82E69 /* RemoteInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = A5BA15E1182340B300A82E69 /* RemoteInspector.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1943 1945 FE0D4A061AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */; }; 1944 1946 FE0D4A091ABA2437002F54BF /* GlobalContextWithFinalizerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE0D4A071ABA2437002F54BF /* GlobalContextWithFinalizerTest.cpp */; }; 1945 FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1220261BE7F5640039E6F2 /* JITAddGenerator.h */; settings = {ASSET_TAGS = (); };};1946 FE1220281BE7F5910039E6F2 /* JITAddGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE1220251BE7F5640039E6F2 /* JITAddGenerator.cpp */; settings = {ASSET_TAGS = (); };};1947 FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1220261BE7F5640039E6F2 /* JITAddGenerator.h */; }; 1948 FE1220281BE7F5910039E6F2 /* JITAddGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE1220251BE7F5640039E6F2 /* JITAddGenerator.cpp */; }; 1947 1949 FE1C0FFD1B193E9800B53FCA /* Exception.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1C0FFC1B193E9800B53FCA /* Exception.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1948 1950 FE1C0FFF1B194FD100B53FCA /* Exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE1C0FFE1B194FD100B53FCA /* Exception.cpp */; }; … … 1956 1958 FE3913551B794F8A00EDAF71 /* LiveObjectData.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3913511B794AC900EDAF71 /* LiveObjectData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1957 1959 FE3913561B794F8F00EDAF71 /* LiveObjectList.h in Headers */ = {isa = PBXBuildFile; fileRef = FE3913531B794AC900EDAF71 /* LiveObjectList.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1958 FE4238901BE18C3C00514737 /* JITSubGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE42388F1BE18C1200514737 /* JITSubGenerator.cpp */; settings = {ASSET_TAGS = (); };};1960 FE4238901BE18C3C00514737 /* JITSubGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE42388F1BE18C1200514737 /* JITSubGenerator.cpp */; }; 1959 1961 FE4BFF2B1AD476E700088F87 /* FunctionOverrides.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE4BFF291AD476E700088F87 /* FunctionOverrides.cpp */; }; 1960 1962 FE4BFF2C1AD476E700088F87 /* FunctionOverrides.h in Headers */ = {isa = PBXBuildFile; fileRef = FE4BFF2A1AD476E700088F87 /* FunctionOverrides.h */; }; … … 3605 3607 A59455911824744700CC3843 /* JSGlobalObjectDebuggable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalObjectDebuggable.h; sourceTree = "<group>"; }; 3606 3608 A5945594182479EB00CC3843 /* InspectorFrontendChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendChannel.h; sourceTree = "<group>"; }; 3609 A5AB49DA1BEC8079007020FB /* PerGlobalObjectWrapperWorld.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerGlobalObjectWrapperWorld.cpp; sourceTree = "<group>"; }; 3610 A5AB49DB1BEC8079007020FB /* PerGlobalObjectWrapperWorld.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerGlobalObjectWrapperWorld.h; sourceTree = "<group>"; }; 3607 3611 A5B6A74C18C6DBA600F11E91 /* ConsoleClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConsoleClient.cpp; sourceTree = "<group>"; }; 3608 3612 A5BA15E1182340B300A82E69 /* RemoteInspector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteInspector.h; sourceTree = "<group>"; }; … … 6430 6434 A503FA17188E0FB000110F14 /* JSJavaScriptCallFramePrototype.cpp */, 6431 6435 A503FA18188E0FB000110F14 /* JSJavaScriptCallFramePrototype.h */, 6436 A5AB49DA1BEC8079007020FB /* PerGlobalObjectWrapperWorld.cpp */, 6437 A5AB49DB1BEC8079007020FB /* PerGlobalObjectWrapperWorld.h */, 6432 6438 A5FD0065189AFE9C00633231 /* ScriptArguments.cpp */, 6433 6439 A5FD0066189AFE9C00633231 /* ScriptArguments.h */, … … 7232 7238 A5EA70EE19F5B5C40098F5EC /* JSContextRefInspectorSupport.h in Headers */, 7233 7239 A5D2E665195E174000A518E7 /* JSContextRefInternal.h in Headers */, 7240 A5AB49DD1BEC8086007020FB /* PerGlobalObjectWrapperWorld.h in Headers */, 7234 7241 148CD1D8108CF902008163C6 /* JSContextRefPrivate.h in Headers */, 7235 7242 A72028B81797601E0098028C /* JSCTestRunnerUtils.h in Headers */, … … 8721 8728 14469DDE107EC7E700650446 /* Lookup.cpp in Sources */, 8722 8729 0F4680CC14BBB17A00BFE272 /* LowLevelInterpreter.cpp in Sources */, 8730 A5AB49DC1BEC8082007020FB /* PerGlobalObjectWrapperWorld.cpp in Sources */, 8723 8731 14B723B212D7DA46003BD5ED /* MachineStackMarker.cpp in Sources */, 8724 8732 0FEB3ECF16237F6C00AB67AD /* MacroAssembler.cpp in Sources */, -
trunk/Source/JavaScriptCore/inspector/InjectedScriptHost.cpp
r178820 r192186 27 27 #include "InjectedScriptHost.h" 28 28 29 #include "JSCInlines.h" 29 30 #include "JSInjectedScriptHost.h" 30 31 … … 37 38 } 38 39 39 JSValue InjectedScriptHost:: jsWrapper(ExecState* exec, JSGlobalObject* globalObject)40 JSValue InjectedScriptHost::wrapper(ExecState* exec, JSGlobalObject* globalObject) 40 41 { 41 auto key = std::make_pair(exec, globalObject); 42 auto it = m_wrappers.find(key); 43 if (it != m_wrappers.end()) 44 return it->value.get(); 42 JSValue value = m_wrappers.getWrapper(globalObject); 43 if (value) 44 return value; 45 45 46 JSValue jsValue = toJS(exec, globalObject, this); 47 if (!jsValue.isObject()) 48 return jsValue; 46 JSObject* prototype = JSInjectedScriptHost::createPrototype(exec->vm(), globalObject); 47 Structure* structure = JSInjectedScriptHost::createStructure(exec->vm(), globalObject, prototype); 48 JSInjectedScriptHost* injectedScriptHost = JSInjectedScriptHost::create(exec->vm(), structure, Ref<InjectedScriptHost>(*this)); 49 m_wrappers.addWrapper(globalObject, injectedScriptHost); 49 50 50 JSObject* jsObject = jsValue.toObject(exec, globalObject); 51 Strong<JSObject> wrapper(exec->vm(), jsObject); 52 m_wrappers.add(key, wrapper); 53 54 return jsValue; 55 } 56 57 static void clearWrapperFromValue(JSValue value) 58 { 59 JSInjectedScriptHost* jsInjectedScriptHost = toJSInjectedScriptHost(value); 60 ASSERT(jsInjectedScriptHost); 61 if (jsInjectedScriptHost) 62 jsInjectedScriptHost->releaseImpl(); 63 } 64 65 void InjectedScriptHost::clearWrapper(ExecState* exec, JSGlobalObject* globalObject) 66 { 67 auto key = std::make_pair(exec, globalObject); 68 clearWrapperFromValue(m_wrappers.take(key).get()); 51 return injectedScriptHost; 69 52 } 70 53 71 54 void InjectedScriptHost::clearAllWrappers() 72 55 { 73 for (auto& wrapper : m_wrappers) 74 clearWrapperFromValue(wrapper.value.get()); 75 76 m_wrappers.clear(); 56 m_wrappers.clearAllWrappers(); 77 57 } 78 58 -
trunk/Source/JavaScriptCore/inspector/InjectedScriptHost.h
r185346 r192186 28 28 29 29 #include "JSCJSValueInlines.h" 30 #include "Strong.h" 31 #include "StrongInlines.h" 30 #include "inspector/PerGlobalObjectWrapperWorld.h" 32 31 #include <wtf/HashMap.h> 33 32 #include <wtf/RefCounted.h> … … 43 42 virtual bool isHTMLAllCollection(JSC::JSValue) { return false; } 44 43 45 JSC::JSValue jsWrapper(JSC::ExecState*, JSC::JSGlobalObject*); 46 void clearWrapper(JSC::ExecState*, JSC::JSGlobalObject*); 44 JSC::JSValue wrapper(JSC::ExecState*, JSC::JSGlobalObject*); 47 45 void clearAllWrappers(); 48 46 49 47 private: 50 HashMap<std::pair<JSC::ExecState*, JSC::JSGlobalObject*>, JSC::Strong<JSC::JSObject>>m_wrappers;48 PerGlobalObjectWrapperWorld m_wrappers; 51 49 }; 52 50 -
trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp
r192064 r192186 61 61 } 62 62 63 void InjectedScriptManager::discardInjectedScripts() 64 { 65 m_injectedScriptHost->clearAllWrappers(); 66 m_idToInjectedScript.clear(); 67 m_scriptStateToId.clear(); 68 } 69 63 70 InjectedScriptHost* InjectedScriptManager::injectedScriptHost() 64 71 { … … 108 115 } 109 116 110 void InjectedScriptManager::discardInjectedScripts()111 {112 m_injectedScriptHost->clearAllWrappers();113 m_idToInjectedScript.clear();114 m_scriptStateToId.clear();115 }116 117 117 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) 118 118 { … … 152 152 153 153 MarkedArgumentBuffer args; 154 args.append(m_injectedScriptHost-> jsWrapper(scriptState, globalObject));154 args.append(m_injectedScriptHost->wrapper(scriptState, globalObject)); 155 155 args.append(globalThisValue); 156 156 args.append(jsNumber(id)); -
trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.h
r192064 r192186 55 55 56 56 virtual void disconnect(); 57 virtual void discardInjectedScripts(); 57 58 58 59 InjectedScriptHost* injectedScriptHost(); … … 63 64 int injectedScriptIdFor(JSC::ExecState*); 64 65 InjectedScript injectedScriptForObjectId(const String& objectId); 65 void discardInjectedScripts();66 66 void releaseObjectGroup(const String& objectGroup); 67 67 void clearExceptionValue(); -
trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
r187959 r192186 61 61 const ClassInfo JSInjectedScriptHost::s_info = { "InjectedScriptHost", &Base::s_info, 0, CREATE_METHOD_TABLE(JSInjectedScriptHost) }; 62 62 63 JSInjectedScriptHost::JSInjectedScriptHost(VM& vm, Structure* structure, PassRefPtr<InjectedScriptHost>impl)63 JSInjectedScriptHost::JSInjectedScriptHost(VM& vm, Structure* structure, Ref<InjectedScriptHost>&& impl) 64 64 : JSDestructibleObject(vm, structure) 65 , m_ impl(impl.leakRef())65 , m_wrapped(WTF::move(impl)) 66 66 { 67 67 } … … 82 82 JSInjectedScriptHost* thisObject = static_cast<JSInjectedScriptHost*>(cell); 83 83 thisObject->JSInjectedScriptHost::~JSInjectedScriptHost(); 84 }85 86 void JSInjectedScriptHost::releaseImpl()87 {88 if (auto impl = std::exchange(m_impl, nullptr))89 impl->deref();90 }91 92 JSInjectedScriptHost::~JSInjectedScriptHost()93 {94 releaseImpl();95 84 } 96 85 … … 485 474 } 486 475 487 JSValue toJS(ExecState* exec, JSGlobalObject* globalObject, InjectedScriptHost* impl)488 {489 if (!impl)490 return jsNull();491 492 JSObject* prototype = JSInjectedScriptHost::createPrototype(exec->vm(), globalObject);493 Structure* structure = JSInjectedScriptHost::createStructure(exec->vm(), globalObject, prototype);494 JSInjectedScriptHost* injectedScriptHost = JSInjectedScriptHost::create(exec->vm(), structure, impl);495 496 return injectedScriptHost;497 }498 499 JSInjectedScriptHost* toJSInjectedScriptHost(JSValue value)500 {501 return value.inherits(JSInjectedScriptHost::info()) ? jsCast<JSInjectedScriptHost*>(value) : nullptr;502 }503 504 476 } // namespace Inspector -
trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.h
r183025 r192186 29 29 #include "JSDestructibleObject.h" 30 30 31 namespace JSC {32 class WeakMapData;33 }34 35 31 namespace Inspector { 36 32 … … 49 45 } 50 46 51 static JSInjectedScriptHost* create(JSC::VM& vm, JSC::Structure* structure, PassRefPtr<InjectedScriptHost>impl)47 static JSInjectedScriptHost* create(JSC::VM& vm, JSC::Structure* structure, Ref<InjectedScriptHost>&& impl) 52 48 { 53 JSInjectedScriptHost* instance = new (NotNull, JSC::allocateCell<JSInjectedScriptHost>(vm.heap)) JSInjectedScriptHost(vm, structure, impl);49 JSInjectedScriptHost* instance = new (NotNull, JSC::allocateCell<JSInjectedScriptHost>(vm.heap)) JSInjectedScriptHost(vm, structure, WTF::move(impl)); 54 50 instance->finishCreation(vm); 55 51 return instance; … … 59 55 static void destroy(JSC::JSCell*); 60 56 61 InjectedScriptHost& impl() const { return *m_impl; } 62 void releaseImpl(); 57 InjectedScriptHost& impl() const { return const_cast<InjectedScriptHost&>(m_wrapped.get()); } 63 58 64 59 // Attributes. … … 81 76 82 77 private: 83 JSInjectedScriptHost(JSC::VM&, JSC::Structure*, PassRefPtr<InjectedScriptHost>); 84 ~JSInjectedScriptHost(); 78 JSInjectedScriptHost(JSC::VM&, JSC::Structure*, Ref<InjectedScriptHost>&&); 85 79 86 InjectedScriptHost* m_impl;80 Ref<InjectedScriptHost> m_wrapped; 87 81 }; 88 89 JSC::JSValue toJS(JSC::ExecState*, JSC::JSGlobalObject*, InjectedScriptHost*);90 JSInjectedScriptHost* toJSInjectedScriptHost(JSC::JSValue);91 82 92 83 } // namespace Inspector -
trunk/Source/JavaScriptCore/inspector/PerGlobalObjectWrapperWorld.cpp
r192185 r192186 24 24 */ 25 25 26 #i fndef InjectedScriptHost_h27 # define InjectedScriptHost_h26 #include "config.h" 27 #include "PerGlobalObjectWrapperWorld.h" 28 28 29 #include "JSCJSValueInlines.h" 30 #include "Strong.h" 31 #include "StrongInlines.h" 32 #include <wtf/HashMap.h> 33 #include <wtf/RefCounted.h> 29 using namespace JSC; 34 30 35 31 namespace Inspector { 36 32 37 class JS_EXPORT_PRIVATE InjectedScriptHost : public RefCounted<InjectedScriptHost> { 38 public: 39 static Ref<InjectedScriptHost> create() { return adoptRef(*new InjectedScriptHost); } 40 virtual ~InjectedScriptHost(); 33 JSValue PerGlobalObjectWrapperWorld::getWrapper(JSGlobalObject* globalObject) 34 { 35 auto it = m_wrappers.find(globalObject); 36 if (it != m_wrappers.end()) 37 return it->value.get(); 38 return JSValue(); 39 } 41 40 42 virtual JSC::JSValue subtype(JSC::ExecState*, JSC::JSValue) { return JSC::jsUndefined(); } 43 virtual bool isHTMLAllCollection(JSC::JSValue) { return false; } 41 void PerGlobalObjectWrapperWorld::addWrapper(JSGlobalObject* globalObject, JSObject* object) 42 { 43 Strong<JSObject> wrapper(globalObject->vm(), object); 44 m_wrappers.add(globalObject, wrapper); 45 } 44 46 45 JSC::JSValue jsWrapper(JSC::ExecState*, JSC::JSGlobalObject*); 46 void clearWrapper(JSC::ExecState*, JSC::JSGlobalObject*); 47 void clearAllWrappers(); 48 49 private: 50 HashMap<std::pair<JSC::ExecState*, JSC::JSGlobalObject*>, JSC::Strong<JSC::JSObject>> m_wrappers; 51 }; 47 void PerGlobalObjectWrapperWorld::clearAllWrappers() 48 { 49 m_wrappers.clear(); 50 } 52 51 53 52 } // namespace Inspector 54 55 #endif // !defined(InjectedScriptHost_h) -
trunk/Source/JavaScriptCore/inspector/PerGlobalObjectWrapperWorld.h
r192185 r192186 1 1 /* 2 * Copyright (C) 201 3Apple Inc. All rights reserved.2 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef InjectedScriptHost_h27 #define InjectedScriptHost_h26 #ifndef PerGlobalObjectWrapperWorld_h 27 #define PerGlobalObjectWrapperWorld_h 28 28 29 29 #include "JSCJSValueInlines.h" … … 31 31 #include "StrongInlines.h" 32 32 #include <wtf/HashMap.h> 33 #include <wtf/RefCounted.h>34 33 35 34 namespace Inspector { 36 35 37 class JS_EXPORT_PRIVATE InjectedScriptHost : public RefCounted<InjectedScriptHost>{36 class JS_EXPORT_PRIVATE PerGlobalObjectWrapperWorld { 38 37 public: 39 static Ref<InjectedScriptHost> create() { return adoptRef(*new InjectedScriptHost); } 40 virtual ~InjectedScriptHost(); 41 42 virtual JSC::JSValue subtype(JSC::ExecState*, JSC::JSValue) { return JSC::jsUndefined(); } 43 virtual bool isHTMLAllCollection(JSC::JSValue) { return false; } 44 45 JSC::JSValue jsWrapper(JSC::ExecState*, JSC::JSGlobalObject*); 46 void clearWrapper(JSC::ExecState*, JSC::JSGlobalObject*); 38 JSC::JSValue getWrapper(JSC::JSGlobalObject*); 39 void addWrapper(JSC::JSGlobalObject*, JSC::JSObject*); 47 40 void clearAllWrappers(); 48 41 49 42 private: 50 HashMap< std::pair<JSC::ExecState*, JSC::JSGlobalObject*>, JSC::Strong<JSC::JSObject>> m_wrappers;43 HashMap<JSC::JSGlobalObject*, JSC::Strong<JSC::JSObject>> m_wrappers; 51 44 }; 52 45 53 46 } // namespace Inspector 54 47 55 #endif // !defined( InjectedScriptHost_h)48 #endif // !defined(PerGlobalObjectWrapperWorld_h) -
trunk/Source/WebCore/ChangeLog
r192176 r192186 1 2015-11-09 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: $0 stops working after navigating to a different domain 4 https://bugs.webkit.org/show_bug.cgi?id=147962 5 6 Reviewed by Brian Burg. 7 8 Test: http/tests/inspector/console/cross-domain-inspected-node-access.html 9 10 The inspector backend injects the CommandLineAPI Source with a 11 corresponding CommandLineAPIHost into each execution context 12 created by the page (main frame, sub frames, etc). 13 14 When creating the JSValue wrapper for the CommandLineAPIHost using 15 the generated toJS(...) DOM bindings, we were using the cached 16 CommandLineAPIHost wrapper values in the single DOMWrapperWorld shared 17 across all frames. This meant that the first time the wrapper was 18 needed it was created in context A. But when needed for context B 19 it was using the wrapper created in context A. Using this wrapper 20 in context B was producing unexpected cross-origin warnings. 21 22 The solution taken here, is to create a new JSValue wrapper for 23 the CommandLineAPIHost per execution context. This way each time 24 the CommandLineAPIHost wrapper is used in a frame, it is using 25 the one created for that frame. 26 27 The C++ host object being wrapped has a lifetime equivalent to 28 the Page. It does not change in this patch. The wrapper values 29 are cleared on page navigation or when the page is closed, and 30 will be garbage collected. 31 32 * WebCore.vcxproj/WebCore.vcxproj: 33 * WebCore.vcxproj/WebCore.vcxproj.filters: 34 * ForwardingHeaders/inspector/PerGlobalObjectWrapperWorld.h: Added. 35 New forwarding header. 36 37 * inspector/CommandLineAPIHost.h: 38 * inspector/CommandLineAPIHost.cpp: 39 (WebCore::CommandLineAPIHost::CommandLineAPIHost): 40 (WebCore::CommandLineAPIHost::wrapper): 41 Cached JSValue wrappers per GlobalObject. 42 43 (WebCore::CommandLineAPIHost::clearAllWrappers): 44 Clear any wrappers we have, including the $0 value itself 45 which we weren't explicitly clearing previously. 46 47 * inspector/CommandLineAPIModule.cpp: 48 (WebCore::CommandLineAPIModule::host): 49 Simplify creating the wrapper. 50 51 * inspector/WebInjectedScriptManager.h: 52 * inspector/WebInjectedScriptManager.cpp: 53 (WebCore::WebInjectedScriptManager::discardInjectedScripts): 54 When the main frame window object clears, also clear the 55 CommandLineAPI wrappers we may have created. Also take this 56 opportunity to clear any $0 value that may have pointed 57 to a value in the previous page. 58 1 59 2015-11-09 Per Arne Vollan <peavo@outlook.com> 2 60 -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r192017 r192186 20436 20436 <ClInclude Include="..\ForwardingHeaders\inspector\InspectorProtocolTypes.h" /> 20437 20437 <ClInclude Include="..\ForwardingHeaders\inspector\InspectorValues.h" /> 20438 <ClInclude Include="..\ForwardingHeaders\inspector\PerGlobalObjectWrapperWorld.h" /> 20438 20439 <ClInclude Include="..\ForwardingHeaders\inspector\ScriptArguments.h" /> 20439 20440 <ClInclude Include="..\ForwardingHeaders\inspector\ScriptBreakpoint.h" /> -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
r192017 r192186 11783 11783 <Filter>ForwardingHeaders\inspector</Filter> 11784 11784 </ClInclude> 11785 <ClInclude Include="..\ForwardingHeaders\inspector\PerGlobalObjectWrapperWorld.h"> 11786 <Filter>ForwardingHeaders\inspector</Filter> 11787 </ClInclude> 11785 11788 <ClInclude Include="..\ForwardingHeaders\inspector\ScriptArguments.h"> 11786 11789 <Filter>ForwardingHeaders\inspector</Filter> -
trunk/Source/WebCore/inspector/CommandLineAPIHost.cpp
r189964 r192186 33 33 34 34 #include "Database.h" 35 #include "Element.h"36 #include "Frame.h"37 #include "FrameLoader.h"38 #include "HTMLFrameOwnerElement.h"39 35 #include "InspectorDOMAgent.h" 40 36 #include "InspectorDOMStorageAgent.h" 41 37 #include "InspectorDatabaseAgent.h" 42 #include <inspector/InspectorFrontendDispatchers.h> 38 #include "JSCommandLineAPIHost.h" 39 #include "JSDOMGlobalObject.h" 43 40 #include "Pasteboard.h" 44 41 #include "Storage.h" 45 #include "markup.h"46 42 #include <bindings/ScriptValue.h> 47 43 #include <inspector/InspectorValues.h> 48 44 #include <inspector/agents/InspectorAgent.h> 49 45 #include <inspector/agents/InspectorConsoleAgent.h> 46 #include <runtime/JSCInlines.h> 50 47 #include <wtf/RefPtr.h> 51 48 #include <wtf/StdLibExtras.h> 52 49 50 using namespace JSC; 53 51 using namespace Inspector; 54 52 … … 61 59 62 60 CommandLineAPIHost::CommandLineAPIHost() 63 : m_inspectorAgent(nullptr) 64 , m_consoleAgent(nullptr) 65 , m_domAgent(nullptr) 66 , m_domStorageAgent(nullptr) 67 , m_databaseAgent(nullptr) 61 : m_inspectedObject(std::make_unique<InspectableObject>()) 68 62 { 69 m_inspectedObject = std::make_unique<InspectableObject>();70 63 } 71 64 … … 144 137 } 145 138 139 JSValue CommandLineAPIHost::wrapper(ExecState* exec, JSDOMGlobalObject* globalObject) 140 { 141 JSValue value = m_wrappers.getWrapper(globalObject); 142 if (value) 143 return value; 144 145 JSObject* prototype = JSCommandLineAPIHost::createPrototype(exec->vm(), globalObject); 146 Structure* structure = JSCommandLineAPIHost::createStructure(exec->vm(), globalObject, prototype); 147 JSCommandLineAPIHost* commandLineAPIHost = JSCommandLineAPIHost::create(structure, globalObject, Ref<CommandLineAPIHost>(*this)); 148 m_wrappers.addWrapper(globalObject, commandLineAPIHost); 149 150 return commandLineAPIHost; 151 } 152 153 void CommandLineAPIHost::clearAllWrappers() 154 { 155 m_wrappers.clearAllWrappers(); 156 m_inspectedObject = std::make_unique<InspectableObject>(); 157 } 158 146 159 } // namespace WebCore -
trunk/Source/WebCore/inspector/CommandLineAPIHost.h
r180715 r192186 32 32 33 33 #include "ScriptState.h" 34 #include < runtime/ConsoleTypes.h>34 #include <inspector/PerGlobalObjectWrapperWorld.h> 35 35 #include <wtf/RefCounted.h> 36 36 #include <wtf/Vector.h> … … 39 39 namespace Deprecated { 40 40 class ScriptValue; 41 } 42 43 namespace JSC { 44 class JSValue; 41 45 } 42 46 … … 54 58 class InspectorDOMStorageAgent; 55 59 class InspectorDatabaseAgent; 60 class JSDOMGlobalObject; 56 61 class Node; 57 62 class Storage; … … 98 103 String storageIdImpl(Storage*); 99 104 105 JSC::JSValue wrapper(JSC::ExecState*, JSDOMGlobalObject*); 106 void clearAllWrappers(); 107 100 108 private: 101 109 CommandLineAPIHost(); 102 110 103 Inspector::InspectorAgent* m_inspectorAgent ;104 Inspector::InspectorConsoleAgent* m_consoleAgent ;105 InspectorDOMAgent* m_domAgent ;106 InspectorDOMStorageAgent* m_domStorageAgent ;107 InspectorDatabaseAgent* m_databaseAgent ;111 Inspector::InspectorAgent* m_inspectorAgent {nullptr}; 112 Inspector::InspectorConsoleAgent* m_consoleAgent {nullptr}; 113 InspectorDOMAgent* m_domAgent {nullptr}; 114 InspectorDOMStorageAgent* m_domStorageAgent {nullptr}; 115 InspectorDatabaseAgent* m_databaseAgent {nullptr}; 108 116 109 117 std::unique_ptr<InspectableObject> m_inspectedObject; // $0 118 Inspector::PerGlobalObjectWrapperWorld m_wrappers; 110 119 }; 111 120 -
trunk/Source/WebCore/inspector/CommandLineAPIModule.cpp
r192064 r192186 28 28 29 29 #include "CommandLineAPIModuleSource.h" 30 #include "DOMWrapperWorld.h" 31 #include "JSCommandLineAPIHost.h" 30 #include "JSDOMGlobalObject.h" 32 31 #include "WebInjectedScriptManager.h" 33 32 #include <inspector/InjectedScript.h> … … 54 53 } 55 54 56 JS C::JSValue CommandLineAPIModule::host(InjectedScriptManager* injectedScriptManager, JSC::ExecState* exec) const55 JSValue CommandLineAPIModule::host(InjectedScriptManager* injectedScriptManager, ExecState* exec) const 57 56 { 58 57 // CommandLineAPIModule should only ever be used by a WebInjectedScriptManager. 59 58 WebInjectedScriptManager* pageInjectedScriptManager = static_cast<WebInjectedScriptManager*>(injectedScriptManager); 60 59 ASSERT(pageInjectedScriptManager->commandLineAPIHost()); 60 61 61 JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()); 62 return toJS(exec, globalObject, pageInjectedScriptManager->commandLineAPIHost());62 return pageInjectedScriptManager->commandLineAPIHost()->wrapper(exec, globalObject); 63 63 } 64 64 -
trunk/Source/WebCore/inspector/WebInjectedScriptManager.cpp
r192064 r192186 48 48 } 49 49 50 void WebInjectedScriptManager::discardInjectedScripts() 51 { 52 InjectedScriptManager::discardInjectedScripts(); 53 54 m_commandLineAPIHost->clearAllWrappers(); 55 } 56 50 57 void WebInjectedScriptManager::didCreateInjectedScript(const Inspector::InjectedScript& injectedScript) 51 58 { -
trunk/Source/WebCore/inspector/WebInjectedScriptManager.h
r192064 r192186 43 43 44 44 virtual void disconnect() override; 45 virtual void discardInjectedScripts() override; 45 46 46 47 void discardInjectedScriptsFor(DOMWindow*);
Note:
See TracChangeset
for help on using the changeset viewer.