JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / JSNameScope.h
index 43763296c60b10239bbc3c076619109bf8ec9761..db8d0085d86bdc12ec087c6ee25079074c9a730b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2009, 2015 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef JSNameScope_h
 #define JSNameScope_h
 
+#include "JSEnvironmentRecord.h"
 #include "JSGlobalObject.h"
-#include "JSVariableObject.h"
 
 namespace JSC {
 
 // Used for scopes with a single named variable: catch and named function expression.
-class JSNameScope : public JSVariableObject {
+class JSNameScope : public JSEnvironmentRecord {
 public:
-    typedef JSVariableObject Base;
+    typedef JSEnvironmentRecord Base;
+    static const unsigned StructureFlags = Base::StructureFlags| OverridesGetOwnPropertySlot;
 
-    static JSNameScope* create(ExecState* exec, const Identifier& identifier, JSValue value, unsigned attributes)
-    {
-        JSNameScope* scopeObject = new (NotNull, allocateCell<JSNameScope>(*exec->heap())) JSNameScope(exec, exec->scope());
-        scopeObject->finishCreation(exec, identifier, value, attributes);
-        return scopeObject;
-    }
+    enum Type {
+        CatchScope,
+        FunctionNameScope
+    };
 
-    static JSNameScope* create(ExecState* exec, const Identifier& identifier, JSValue value, unsigned attributes, JSScope* next)
+    template<typename T>
+    static T* create(VM& vm, JSGlobalObject* globalObject, JSScope* currentScope, SymbolTable* symbolTable, JSValue value)
     {
-        JSNameScope* scopeObject = new (NotNull, allocateCell<JSNameScope>(*exec->heap())) JSNameScope(exec, next);
-        scopeObject->finishCreation(exec, identifier, value, attributes);
+        T* scopeObject = new (
+            NotNull, allocateCell<T>(vm.heap, allocationSizeForScopeSize(1)))
+            T(vm, globalObject, currentScope, symbolTable);
+        scopeObject->finishCreation(vm, value);
         return scopeObject;
     }
+    
+    static JSNameScope* create(VM&, JSGlobalObject*, JSScope* currentScope, SymbolTable*, JSValue, Type);
 
-    static void visitChildren(JSCell*, SlotVisitor&);
-    bool isDynamicScope(bool& requiresDynamicChecks) const;
-    static JSObject* toThisObject(JSCell*, ExecState*);
-    static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
+    static JSValue toThis(JSCell*, ExecState*, ECMAMode);
+    static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
 
-    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(vm, globalObject, proto, TypeInfo(NameScopeObjectType, StructureFlags), &s_info); }
+    DECLARE_INFO;
 
-    static const ClassInfo s_info;
+    JSValue value() { return variableAt(ScopeOffset(0)).get(); }
 
 protected:
-    void finishCreation(ExecState* exec, const Identifier& identifier, JSValue value, unsigned attributes)
+    void finishCreation(VM& vm, JSValue value)
     {
-        Base::finishCreation(exec->vm());
-        m_registerStore.set(exec->vm(), this, value);
-        symbolTable()->add(identifier.impl(), SymbolTableEntry(-1, attributes));
+        Base::finishCreationUninitialized(vm);
+        variableAt(ScopeOffset(0)).set(vm, this, value);
     }
 
-    static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | Base::StructureFlags;
-
-private:
-    JSNameScope(ExecState* exec, JSScope* next)
-        : Base(
-            exec->vm(),
-            exec->lexicalGlobalObject()->nameScopeStructure(),
-            reinterpret_cast<Register*>(&m_registerStore + 1),
-            next
-        )
+    JSNameScope(VM& vm, Structure* structure, JSScope* next, SymbolTable* symbolTable)
+        : Base(vm, structure, next, symbolTable)
     {
+        ASSERT(symbolTable->scopeSize() == 1);
     }
-
-    WriteBarrier<Unknown> m_registerStore;
 };
 
-inline bool JSNameScope::isDynamicScope(bool&) const
-{
-    return false;
-}
-
 }
 
 #endif // JSNameScope_h