Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp

Issue 2777763003: Bindings: Manage the main world separately from other worlds (Closed)
Patch Set: address review comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorldTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp
index c42ceffc71f85d41876980657e66e9975b7114e8..2132012105c5b601b6c0abb7d42dc8330c181836 100644
--- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.cpp
@@ -83,10 +83,11 @@ class DOMObjectHolder : public DOMObjectHolderBase {
unsigned DOMWrapperWorld::s_numberOfNonMainWorldsInMainThread = 0;
-using WorldMap = HashMap<int,
- DOMWrapperWorld*,
- WTF::IntHash<int>,
- WTF::UnsignedWithZeroKeyHashTraits<int>>;
+// This does not contain the main world because the WorldMap needs
+// non-default hashmap traits (WTF::UnsignedWithZeroKeyHashTraits) to contain
+// it for the main world's id (0), and it may change the performance trends.
+// (see https://crbug.com/704778#c6).
+using WorldMap = HashMap<int, DOMWrapperWorld*>;
static WorldMap& worldMap() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<WorldMap>, map,
new ThreadSpecific<WorldMap>);
@@ -114,11 +115,23 @@ DOMWrapperWorld::DOMWrapperWorld(v8::Isolate* isolate,
m_worldId(worldId),
m_domDataStore(
WTF::wrapUnique(new DOMDataStore(isolate, isMainWorld()))) {
- WorldMap& map = worldMap();
- DCHECK(!map.contains(m_worldId));
- map.insert(m_worldId, this);
- if (isMainThread() && m_worldType != WorldType::Main)
- s_numberOfNonMainWorldsInMainThread++;
+ switch (m_worldType) {
+ case WorldType::Main:
+ // The main world is managed separately from worldMap(). See worldMap().
+ break;
+ case WorldType::Isolated:
+ case WorldType::GarbageCollector:
+ case WorldType::RegExp:
+ case WorldType::Testing:
+ case WorldType::Worker: {
+ WorldMap& map = worldMap();
+ DCHECK(!map.contains(m_worldId));
+ map.insert(m_worldId, this);
+ if (isMainThread())
+ s_numberOfNonMainWorldsInMainThread++;
+ break;
+ }
+ }
}
DOMWrapperWorld& DOMWrapperWorld::mainWorld() {
@@ -131,6 +144,8 @@ DOMWrapperWorld& DOMWrapperWorld::mainWorld() {
void DOMWrapperWorld::allWorldsInCurrentThread(
Vector<RefPtr<DOMWrapperWorld>>& worlds) {
+ if (isMainThread())
+ worlds.push_back(&mainWorld());
for (DOMWrapperWorld* world : worldMap().values())
worlds.push_back(world);
}
@@ -141,8 +156,6 @@ void DOMWrapperWorld::markWrappersInAllWorlds(
// Marking for worlds other than the main world.
DCHECK(ThreadState::current()->isolate());
for (DOMWrapperWorld* world : worldMap().values()) {
- if (world->isMainWorld())
- continue;
DOMDataStore& dataStore = world->domDataStore();
if (dataStore.containsWrapper(scriptWrappable))
dataStore.markWrapper(scriptWrappable);
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorldTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698