Title: [126962] trunk/Source
Revision
126962
Author
[email protected]
Date
2012-08-28 23:40:09 -0700 (Tue, 28 Aug 2012)

Log Message

Added JSScope::objectInScope(), and refactored callers to use it
https://bugs.webkit.org/show_bug.cgi?id=95281

Reviewed by Gavin Barraclough.

../_javascript_Core: 

This is a step toward removing ScopeChainNode. We need a layer of
indirection so that 'with' scopes can proxy for an object.
JSScope::objectInScope() will be that layer.

* bytecode/EvalCodeCache.h:
(JSC::EvalCodeCache::tryGet):
(JSC::EvalCodeCache::getSlow):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::resolve):
(JSC::BytecodeGenerator::resolveConstDecl): . vs ->

* interpreter/Interpreter.cpp:
(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::execute):
* runtime/JSScope.cpp:
(JSC::JSScope::resolve):
(JSC::JSScope::resolveSkip):
(JSC::JSScope::resolveGlobalDynamic):
(JSC::JSScope::resolveBase):
(JSC::JSScope::resolveWithBase):
(JSC::JSScope::resolveWithThis): Added JSScope::objectAtScope() calls.

* runtime/JSScope.h:
(JSScope):
(JSC::JSScope::objectAtScope):
(JSC):
(ScopeChainIterator):
(JSC::ScopeChainIterator::ScopeChainIterator):
(JSC::ScopeChainIterator::get):
(JSC::ScopeChainIterator::operator->):
(JSC::ScopeChainIterator::operator++):
(JSC::ScopeChainIterator::operator==):
(JSC::ScopeChainIterator::operator!=):
(JSC::ScopeChainNode::begin):
(JSC::ScopeChainNode::end): I moved ScopeChainIterator to this file
to resolve a circular #include problem. Eventually, I'll probably rename
it to JSScope::iterator, so I think it belongs here.

* runtime/ScopeChain.cpp:
(JSC::ScopeChainNode::print):
(JSC::ScopeChainNode::localDepth): . vs ->

* runtime/ScopeChain.h:
(ScopeChainNode): I made the 'object' data member private because it's
no longer safe to access -- you need to call JSScope::objectAtScope()
instead.

The JITs need to be friends because of the private declaration.

Subtly, JIT/LLInt code is correct without any changes because JIT/LLInt
code never compiles direct access to a with scope.

../WebCore: 

* bindings/js/JSJavaScriptCallFrameCustom.cpp:
(WebCore::JSJavaScriptCallFrame::scopeChain):
(WebCore::JSJavaScriptCallFrame::scopeType):

../WebKit/mac: 

* WebView/WebScriptDebugDelegate.mm:
(-[WebScriptCallFrame scopeChain]):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (126961 => 126962)


--- trunk/Source/_javascript_Core/ChangeLog	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-08-29 06:40:09 UTC (rev 126962)
@@ -1,3 +1,62 @@
+2012-08-28  Geoffrey Garen  <[email protected]>
+
+        Added JSScope::objectInScope(), and refactored callers to use it
+        https://bugs.webkit.org/show_bug.cgi?id=95281
+
+        Reviewed by Gavin Barraclough.
+
+        This is a step toward removing ScopeChainNode. We need a layer of
+        indirection so that 'with' scopes can proxy for an object.
+        JSScope::objectInScope() will be that layer.
+
+        * bytecode/EvalCodeCache.h:
+        (JSC::EvalCodeCache::tryGet):
+        (JSC::EvalCodeCache::getSlow):
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::resolve):
+        (JSC::BytecodeGenerator::resolveConstDecl): . vs ->
+
+        * interpreter/Interpreter.cpp:
+        (JSC::Interpreter::unwindCallFrame):
+        (JSC::Interpreter::execute):
+        * runtime/JSScope.cpp:
+        (JSC::JSScope::resolve):
+        (JSC::JSScope::resolveSkip):
+        (JSC::JSScope::resolveGlobalDynamic):
+        (JSC::JSScope::resolveBase):
+        (JSC::JSScope::resolveWithBase):
+        (JSC::JSScope::resolveWithThis): Added JSScope::objectAtScope() calls.
+
+        * runtime/JSScope.h:
+        (JSScope):
+        (JSC::JSScope::objectAtScope):
+        (JSC):
+        (ScopeChainIterator):
+        (JSC::ScopeChainIterator::ScopeChainIterator):
+        (JSC::ScopeChainIterator::get):
+        (JSC::ScopeChainIterator::operator->):
+        (JSC::ScopeChainIterator::operator++):
+        (JSC::ScopeChainIterator::operator==):
+        (JSC::ScopeChainIterator::operator!=):
+        (JSC::ScopeChainNode::begin):
+        (JSC::ScopeChainNode::end): I moved ScopeChainIterator to this file
+        to resolve a circular #include problem. Eventually, I'll probably rename
+        it to JSScope::iterator, so I think it belongs here.
+
+        * runtime/ScopeChain.cpp:
+        (JSC::ScopeChainNode::print):
+        (JSC::ScopeChainNode::localDepth): . vs ->
+
+        * runtime/ScopeChain.h:
+        (ScopeChainNode): I made the 'object' data member private because it's
+        no longer safe to access -- you need to call JSScope::objectAtScope()
+        instead.
+
+        The JITs need to be friends because of the private declaration.
+
+        Subtly, JIT/LLInt code is correct without any changes because JIT/LLInt
+        code never compiles direct access to a with scope.
+
 2012-08-28  Mark Lam  <[email protected]>
 
         Adding support for adding LLInt opcode extensions.  This will be needed

Modified: trunk/Source/_javascript_Core/bytecode/EvalCodeCache.h (126961 => 126962)


--- trunk/Source/_javascript_Core/bytecode/EvalCodeCache.h	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/bytecode/EvalCodeCache.h	2012-08-29 06:40:09 UTC (rev 126962)
@@ -47,7 +47,7 @@
     public:
         EvalExecutable* tryGet(bool inStrictContext, const UString& evalSource, ScopeChainNode* scopeChain)
         {
-            if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject())
+            if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && scopeChain->begin()->isVariableObject())
                 return m_cacheMap.get(evalSource.impl()).get();
             return 0;
         }
@@ -59,7 +59,7 @@
             if (exceptionValue)
                 return 0;
             
-            if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && m_cacheMap.size() < maxCacheEntries)
+            if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && scopeChain->begin()->isVariableObject() && m_cacheMap.size() < maxCacheEntries)
                 m_cacheMap.set(evalSource.impl(), WriteBarrier<EvalExecutable>(exec->globalData(), owner, evalExecutable));
             
             return evalExecutable;

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (126961 => 126962)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2012-08-29 06:40:09 UTC (rev 126962)
@@ -1272,7 +1272,7 @@
     size_t depthOfFirstScopeWithDynamicChecks = 0;
     unsigned flags = 0;
     for (; iter != end; ++iter, ++depth) {
-        JSObject* currentScope = iter->get();
+        JSObject* currentScope = iter.get();
         if (!currentScope->isVariableObject()) {
             flags |= ResolveResult::DynamicFlag;
             break;
@@ -1310,7 +1310,7 @@
     }
 
     // Can't locate the property but we're able to avoid a few lookups.
-    JSObject* scope = iter->get();
+    JSObject* scope = iter.get();
     // Step over the function's activation, if it needs one. At this point we
     // know there is no dynamic scope in the function itself, so this is safe to
     // do.
@@ -1341,7 +1341,7 @@
     ScopeChainIterator end = scopeChain()->end();
     size_t depth = 0;
     for (; iter != end; ++iter, ++depth) {
-        JSObject* currentScope = iter->get();
+        JSObject* currentScope = iter.get();
         if (!currentScope->isVariableObject())
             continue;
         JSSymbolTableObject* currentVariableObject = jsCast<JSSymbolTableObject*>(currentScope);

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (126961 => 126962)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2012-08-29 06:40:09 UTC (rev 126962)
@@ -465,11 +465,11 @@
             oldCodeBlock->createActivation(callFrame);
             scopeChain = callFrame->scopeChain();
         }
-        while (!scopeChain->object->inherits(&JSActivation::s_info))
+        while (!JSScope::objectAtScope(scopeChain)->inherits(&JSActivation::s_info))
             scopeChain = scopeChain->pop();
 
         callFrame->setScopeChain(scopeChain);
-        JSActivation* activation = asActivation(scopeChain->object.get());
+        JSActivation* activation = asActivation(JSScope::objectAtScope(scopeChain));
         activation->tearOff(*scopeChain->globalData);
         if (JSValue arguments = callFrame->uncheckedR(unmodifiedArgumentsRegister(oldCodeBlock->argumentsRegister())).jsValue())
             asArguments(arguments)->didTearOffActivation(callFrame->globalData(), activation);
@@ -1285,8 +1285,8 @@
     JSObject* variableObject;
     for (ScopeChainNode* node = scopeChain; ; node = node->next.get()) {
         ASSERT(node);
-        if (node->object->isVariableObject() && !node->object->isNameScopeObject()) {
-            variableObject = jsCast<JSSymbolTableObject*>(node->object.get());
+        if (JSScope::objectAtScope(node)->isVariableObject() && !JSScope::objectAtScope(node)->isNameScopeObject()) {
+            variableObject = jsCast<JSSymbolTableObject*>(JSScope::objectAtScope(node));
             break;
         }
     }

Modified: trunk/Source/_javascript_Core/runtime/JSScope.cpp (126961 => 126962)


--- trunk/Source/_javascript_Core/runtime/JSScope.cpp	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/runtime/JSScope.cpp	2012-08-29 06:40:09 UTC (rev 126962)
@@ -57,7 +57,7 @@
     ASSERT(scopeChain);
 
     do {
-        JSObject* scope = scopeChain->object.get();
+        JSObject* scope = JSScope::objectAtScope(scopeChain);
         PropertySlot slot(scope);
         if (scope->getPropertySlot(callFrame, identifier, slot))
             return slot.getValue(callFrame, identifier);
@@ -85,7 +85,7 @@
     }
 
     do {
-        JSObject* scope = scopeChain->object.get();
+        JSObject* scope = JSScope::objectAtScope(scopeChain);
         PropertySlot slot(scope);
         if (scope->getPropertySlot(callFrame, identifier, slot))
             return slot.getValue(callFrame, identifier);
@@ -140,7 +140,7 @@
             scopeChain = scopeChain->next.get();
     }
     while (skip--) {
-        JSObject* scope = scopeChain->object.get();
+        JSObject* scope = JSScope::objectAtScope(scopeChain);
         if (!scope->hasCustomProperties())
             continue;
 
@@ -163,7 +163,7 @@
     ASSERT(scopeChain);
 
     do {
-        JSObject* scope = scopeChain->object.get();
+        JSObject* scope = JSScope::objectAtScope(scopeChain);
 
         PropertySlot slot(scope);
         if (!scope->getPropertySlot(callFrame, identifier, slot))
@@ -184,7 +184,7 @@
     ASSERT(scopeChain);
 
     do {
-        JSObject* scope = scopeChain->object.get();
+        JSObject* scope = JSScope::objectAtScope(scopeChain);
 
         PropertySlot slot(scope);
         if (!scope->getPropertySlot(callFrame, identifier, slot))
@@ -207,7 +207,7 @@
     ASSERT(scopeChain);
 
     do {
-        JSObject* scope = scopeChain->object.get();
+        JSObject* scope = JSScope::objectAtScope(scopeChain);
 
         PropertySlot slot(scope);
         if (!scope->getPropertySlot(callFrame, identifier, slot))

Modified: trunk/Source/_javascript_Core/runtime/JSScope.h (126961 => 126962)


--- trunk/Source/_javascript_Core/runtime/JSScope.h	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/runtime/JSScope.h	2012-08-29 06:40:09 UTC (rev 126962)
@@ -34,6 +34,8 @@
 public:
     typedef JSNonFinalObject Base;
 
+    static JSObject* objectAtScope(ScopeChainNode*);
+
     static JSValue resolve(CallFrame*, const Identifier&);
     static JSValue resolveSkip(CallFrame*, const Identifier&, int skip);
     static JSValue resolveGlobal(
@@ -65,6 +67,42 @@
 {
 }
 
+inline JSObject* JSScope::objectAtScope(ScopeChainNode* scopeChain)
+{
+    return scopeChain->object.get();
+}
+
+class ScopeChainIterator {
+public:
+    ScopeChainIterator(ScopeChainNode* node)
+        : m_node(node)
+    {
+    }
+
+    JSObject* get() const { return JSScope::objectAtScope(m_node); }
+    JSObject* operator->() const { return JSScope::objectAtScope(m_node); }
+
+    ScopeChainIterator& operator++() { m_node = m_node->next.get(); return *this; }
+
+    // postfix ++ intentionally omitted
+
+    bool operator==(const ScopeChainIterator& other) const { return m_node == other.m_node; }
+    bool operator!=(const ScopeChainIterator& other) const { return m_node != other.m_node; }
+
+private:
+    ScopeChainNode* m_node;
+};
+
+inline ScopeChainIterator ScopeChainNode::begin()
+{
+    return ScopeChainIterator(this); 
+}
+
+inline ScopeChainIterator ScopeChainNode::end()
+{ 
+    return ScopeChainIterator(0); 
+}
+
 } // namespace JSC
 
 #endif // JSScope_h

Modified: trunk/Source/_javascript_Core/runtime/ScopeChain.cpp (126961 => 126962)


--- trunk/Source/_javascript_Core/runtime/ScopeChain.cpp	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/runtime/ScopeChain.cpp	2012-08-29 06:40:09 UTC (rev 126962)
@@ -37,7 +37,7 @@
 {
     ScopeChainIterator scopeEnd = end();
     for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) {
-        JSObject* o = scopeIter->get();
+        JSObject* o = scopeIter.get();
         PropertyNameArray propertyNames(globalObject->globalExec());
         o->methodTable()->getPropertyNames(o, globalObject->globalExec(), propertyNames, ExcludeDontEnumProperties);
         PropertyNameArray::const_iterator propEnd = propertyNames.end();
@@ -60,7 +60,7 @@
     int scopeDepth = 0;
     ScopeChainIterator iter = this->begin();
     ScopeChainIterator end = this->end();
-    while (!(*iter)->inherits(&JSActivation::s_info)) {
+    while (!iter->inherits(&JSActivation::s_info)) {
         ++iter;
         if (iter == end)
             break;

Modified: trunk/Source/_javascript_Core/runtime/ScopeChain.h (126961 => 126962)


--- trunk/Source/_javascript_Core/runtime/ScopeChain.h	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/_javascript_Core/runtime/ScopeChain.h	2012-08-29 06:40:09 UTC (rev 126962)
@@ -71,7 +71,9 @@
         
         JSGlobalData* globalData;
         WriteBarrier<ScopeChainNode> next;
+    private:
         WriteBarrier<JSObject> object;
+    public:
         WriteBarrier<JSGlobalObject> globalObject;
         WriteBarrier<JSObject> globalThis;
 
@@ -93,6 +95,10 @@
 
     private:
         friend class LLIntOffsetsExtractor;
+        friend class ScopeChainIterator;
+        friend class JSScope;
+        friend class DFG::SpeculativeJIT;
+        friend class JIT;
         
         static const unsigned StructureFlags = OverridesVisitChildren;
     };
@@ -109,37 +115,6 @@
         return next.get();
     }
 
-    class ScopeChainIterator {
-    public:
-        ScopeChainIterator(ScopeChainNode* node)
-            : m_node(node)
-        {
-        }
-
-        WriteBarrier<JSObject> const & operator*() const { return m_node->object; }
-        WriteBarrier<JSObject> const * operator->() const { return &(operator*()); }
-    
-        ScopeChainIterator& operator++() { m_node = m_node->next.get(); return *this; }
-
-        // postfix ++ intentionally omitted
-
-        bool operator==(const ScopeChainIterator& other) const { return m_node == other.m_node; }
-        bool operator!=(const ScopeChainIterator& other) const { return m_node != other.m_node; }
-
-    private:
-        ScopeChainNode* m_node;
-    };
-
-    inline ScopeChainIterator ScopeChainNode::begin()
-    {
-        return ScopeChainIterator(this); 
-    }
-
-    inline ScopeChainIterator ScopeChainNode::end()
-    { 
-        return ScopeChainIterator(0); 
-    }
-
     ALWAYS_INLINE JSGlobalData& ExecState::globalData() const
     {
         ASSERT(scopeChain()->globalData);

Modified: trunk/Source/WebCore/ChangeLog (126961 => 126962)


--- trunk/Source/WebCore/ChangeLog	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/WebCore/ChangeLog	2012-08-29 06:40:09 UTC (rev 126962)
@@ -1,3 +1,14 @@
+2012-08-28  Geoffrey Garen  <[email protected]>
+
+        Added JSScope::objectInScope(), and refactored callers to use it
+        https://bugs.webkit.org/show_bug.cgi?id=95281
+
+        Reviewed by Gavin Barraclough.
+
+        * bindings/js/JSJavaScriptCallFrameCustom.cpp:
+        (WebCore::JSJavaScriptCallFrame::scopeChain):
+        (WebCore::JSJavaScriptCallFrame::scopeType):
+
 2012-08-28  Andrei Bucur  <[email protected]>
 
         Layout Test fast/repaint/japanese-rl-selection-repaint-in-regions.html is failing after r126304

Modified: trunk/Source/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp (126961 => 126962)


--- trunk/Source/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp	2012-08-29 06:40:09 UTC (rev 126962)
@@ -86,7 +86,7 @@
 
     MarkedArgumentBuffer list;
     do {
-        list.append(iter->get());
+        list.append(iter.get());
         ++iter;
     } while (iter != end);
 
@@ -107,7 +107,7 @@
 
     bool foundLocalScope = false;
     for (ScopeChainIterator iter = scopeChain->begin(); iter != end; ++iter) {
-        JSObject* scope = iter->get();
+        JSObject* scope = iter.get();
         if (scope->isActivationObject()) {
             if (!foundLocalScope) {
                 // First activation object is local scope, each successive activation object is closure.

Modified: trunk/Source/WebKit/mac/ChangeLog (126961 => 126962)


--- trunk/Source/WebKit/mac/ChangeLog	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/WebKit/mac/ChangeLog	2012-08-29 06:40:09 UTC (rev 126962)
@@ -1,3 +1,13 @@
+2012-08-28  Geoffrey Garen  <[email protected]>
+
+        Added JSScope::objectInScope(), and refactored callers to use it
+        https://bugs.webkit.org/show_bug.cgi?id=95281
+
+        Reviewed by Gavin Barraclough.
+
+        * WebView/WebScriptDebugDelegate.mm:
+        (-[WebScriptCallFrame scopeChain]):
+
 2012-08-28  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r126914.

Modified: trunk/Source/WebKit/mac/WebView/WebScriptDebugDelegate.mm (126961 => 126962)


--- trunk/Source/WebKit/mac/WebView/WebScriptDebugDelegate.mm	2012-08-29 06:29:34 UTC (rev 126961)
+++ trunk/Source/WebKit/mac/WebView/WebScriptDebugDelegate.mm	2012-08-29 06:40:09 UTC (rev 126962)
@@ -184,7 +184,7 @@
 
     ScopeChainIterator end = scopeChain->end();
     for (ScopeChainIterator it = scopeChain->begin(); it != end; ++it) {
-        JSObject* object = it->get();
+        JSObject* object = it.get();
         if (object->isActivationObject())
             object = DebuggerActivation::create(*scopeChain->globalData, object);
         [scopes addObject:[self _convertValueToObjcValue:object]];
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to