X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/runtime/JSNameScope.h?ds=inline diff --git a/runtime/JSNameScope.h b/runtime/JSNameScope.h index 4376329..db8d008 100644 --- a/runtime/JSNameScope.h +++ b/runtime/JSNameScope.h @@ -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 @@ -26,69 +26,56 @@ #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(*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 + static T* create(VM& vm, JSGlobalObject* globalObject, JSScope* currentScope, SymbolTable* symbolTable, JSValue value) { - JSNameScope* scopeObject = new (NotNull, allocateCell(*exec->heap())) JSNameScope(exec, next); - scopeObject->finishCreation(exec, identifier, value, attributes); + T* scopeObject = new ( + NotNull, allocateCell(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(&m_registerStore + 1), - next - ) + JSNameScope(VM& vm, Structure* structure, JSScope* next, SymbolTable* symbolTable) + : Base(vm, structure, next, symbolTable) { + ASSERT(symbolTable->scopeSize() == 1); } - - WriteBarrier m_registerStore; }; -inline bool JSNameScope::isDynamicScope(bool&) const -{ - return false; -} - } #endif // JSNameScope_h