]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/SymbolTable.cpp
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / runtime / SymbolTable.cpp
index 8c5a00b0376548dcc963fbb62911e6a4774c36e4..f60c86ac914e83cfaab5fe340479bec8210f641a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -10,7 +10,7 @@
  * 2.  Redistributions in binary form must reproduce the above copyright
  *     notice, this list of conditions and the following disclaimer in the
  *     documentation and/or other materials provided with the distribution.
- * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
  *     its contributors may be used to endorse or promote products derived
  *     from this software without specific prior written permission.
  *
 #include "config.h"
 #include "SymbolTable.h"
 
+#include "JSDestructibleObject.h"
+#include "JSCInlines.h"
+#include "SlotVisitorInlines.h"
+#include "VariableWatchpointSetInlines.h"
+
 namespace JSC {
 
-const ClassInfo SharedSymbolTable::s_info = { "SharedSymbolTable", 0, 0, 0, CREATE_METHOD_TABLE(SharedSymbolTable) };
+const ClassInfo SymbolTable::s_info = { "SymbolTable", 0, 0, 0, CREATE_METHOD_TABLE(SymbolTable) };
 
 SymbolTableEntry& SymbolTableEntry::copySlow(const SymbolTableEntry& other)
 {
@@ -42,10 +47,10 @@ SymbolTableEntry& SymbolTableEntry::copySlow(const SymbolTableEntry& other)
     return *this;
 }
 
-void SharedSymbolTable::destroy(JSCell* cell)
+void SymbolTable::destroy(JSCell* cell)
 {
-    SharedSymbolTable* thisObject = jsCast<SharedSymbolTable*>(cell);
-    thisObject->SharedSymbolTable::~SharedSymbolTable();
+    SymbolTable* thisObject = jsCast<SymbolTable*>(cell);
+    thisObject->SymbolTable::~SymbolTable();
 }
 
 void SymbolTableEntry::freeFatEntrySlow()
@@ -54,41 +59,33 @@ void SymbolTableEntry::freeFatEntrySlow()
     delete fatEntry();
 }
 
-bool SymbolTableEntry::couldBeWatched()
+JSValue SymbolTableEntry::inferredValue()
 {
     if (!isFat())
-        return false;
-    WatchpointSet* watchpoints = fatEntry()->m_watchpoints.get();
-    if (!watchpoints)
-        return false;
-    return watchpoints->isStillValid();
+        return JSValue();
+    return fatEntry()->m_watchpoints->inferredValue();
 }
 
-void SymbolTableEntry::attemptToWatch()
+void SymbolTableEntry::prepareToWatch(SymbolTable* symbolTable)
 {
     FatEntry* entry = inflate();
-    if (!entry->m_watchpoints)
-        entry->m_watchpoints = adoptRef(new WatchpointSet(InitializedWatching));
-}
-
-bool* SymbolTableEntry::addressOfIsWatched()
-{
-    ASSERT(couldBeWatched());
-    return fatEntry()->m_watchpoints->addressOfIsWatched();
+    if (entry->m_watchpoints)
+        return;
+    entry->m_watchpoints = adoptRef(new VariableWatchpointSet(*symbolTable));
 }
 
 void SymbolTableEntry::addWatchpoint(Watchpoint* watchpoint)
 {
-    ASSERT(couldBeWatched());
     fatEntry()->m_watchpoints->add(watchpoint);
 }
 
-void SymbolTableEntry::notifyWriteSlow()
+void SymbolTableEntry::notifyWriteSlow(VM& vm, JSValue value)
 {
-    WatchpointSet* watchpoints = fatEntry()->m_watchpoints.get();
+    VariableWatchpointSet* watchpoints = fatEntry()->m_watchpoints.get();
     if (!watchpoints)
         return;
-    watchpoints->notifyWrite();
+    
+    watchpoints->notifyWrite(vm, value);
 }
 
 SymbolTableEntry::FatEntry* SymbolTableEntry::inflateSlow()
@@ -98,5 +95,71 @@ SymbolTableEntry::FatEntry* SymbolTableEntry::inflateSlow()
     return entry;
 }
 
+SymbolTable::SymbolTable(VM& vm)
+    : JSCell(vm, vm.symbolTableStructure.get())
+    , m_parameterCountIncludingThis(0)
+    , m_usesNonStrictEval(false)
+    , m_captureStart(0)
+    , m_captureEnd(0)
+    , m_functionEnteredOnce(ClearWatchpoint)
+{
+}
+
+SymbolTable::~SymbolTable() { }
+
+void SymbolTable::visitChildren(JSCell* thisCell, SlotVisitor& visitor)
+{
+    SymbolTable* thisSymbolTable = jsCast<SymbolTable*>(thisCell);
+    if (!thisSymbolTable->m_watchpointCleanup) {
+        thisSymbolTable->m_watchpointCleanup =
+            std::make_unique<WatchpointCleanup>(thisSymbolTable);
+    }
+    
+    visitor.addUnconditionalFinalizer(thisSymbolTable->m_watchpointCleanup.get());
+}
+
+SymbolTable::WatchpointCleanup::WatchpointCleanup(SymbolTable* symbolTable)
+    : m_symbolTable(symbolTable)
+{
+}
+
+SymbolTable::WatchpointCleanup::~WatchpointCleanup() { }
+
+void SymbolTable::WatchpointCleanup::finalizeUnconditionally()
+{
+    Map::iterator iter = m_symbolTable->m_map.begin();
+    Map::iterator end = m_symbolTable->m_map.end();
+    for (; iter != end; ++iter) {
+        if (VariableWatchpointSet* set = iter->value.watchpointSet())
+            set->finalizeUnconditionally();
+    }
+}
+
+SymbolTable* SymbolTable::cloneCapturedNames(VM& vm)
+{
+    SymbolTable* result = SymbolTable::create(vm);
+    
+    result->m_parameterCountIncludingThis = m_parameterCountIncludingThis;
+    result->m_usesNonStrictEval = m_usesNonStrictEval;
+    result->m_captureStart = m_captureStart;
+    result->m_captureEnd = m_captureEnd;
+
+    for (auto iter = m_map.begin(), end = m_map.end(); iter != end; ++iter) {
+        if (!isCaptured(iter->value.getIndex()))
+            continue;
+        result->m_map.add(
+            iter->key,
+            SymbolTableEntry(iter->value.getIndex(), iter->value.getAttributes()));
+    }
+    
+    if (m_slowArguments) {
+        result->m_slowArguments = std::make_unique<SlowArgument[]>(parameterCount());
+        for (unsigned i = parameterCount(); i--;)
+            result->m_slowArguments[i] = m_slowArguments[i];
+    }
+    
+    return result;
+}
+
 } // namespace JSC