Ignore:
Timestamp:
Aug 21, 2013, 6:04:37 PM (12 years ago)
Author:
[email protected]
Message:

Clarify var/const/function declaration
https://bugs.webkit.org/show_bug.cgi?id=120144

Reviewed by Sam Weinig.

Add methods to JSGlobalObject to declare vars, consts, and functions.

  • runtime/Executable.cpp:

(JSC::ProgramExecutable::initializeGlobalProperties):

  • runtime/Executable.h:
    • Moved declaration code to JSGlobalObject
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::addGlobalVar):

  • internal implementation of addVar, addConst, addFunction
  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::addVar):
(JSC::JSGlobalObject::addConst):
(JSC::JSGlobalObject::addFunction):

  • Added methods to declare vars, consts, and functions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r154422 r154434  
    240240    }
    241241
     242    enum ConstantMode { IsConstant, IsVariable };
     243    enum FunctionMode { IsFunctionToSpecialize, NotFunctionOrNotSpecializable };
     244    int addGlobalVar(const Identifier&, ConstantMode, FunctionMode);
     245
    242246public:
    243247    JS_EXPORT_PRIVATE ~JSGlobalObject();
     
    261265    // lookups prior to initializing the properties
    262266    bool symbolTableHasProperty(PropertyName);
     267
     268    void addVar(ExecState* exec, const Identifier& propertyName)
     269    {
     270        if (!hasProperty(exec, propertyName))
     271            addGlobalVar(propertyName, IsVariable, NotFunctionOrNotSpecializable);
     272    }
     273    void addConst(ExecState* exec, const Identifier& propertyName)
     274    {
     275        if (!hasProperty(exec, propertyName))
     276            addGlobalVar(propertyName, IsConstant, NotFunctionOrNotSpecializable);
     277    }
     278    void addFunction(ExecState* exec, const Identifier& propertyName, JSValue value)
     279    {
     280        bool propertyDidExist = removeDirect(exec->vm(), propertyName); // Newly declared functions overwrite existing properties.
     281        int index = addGlobalVar(propertyName, IsVariable, !propertyDidExist ? IsFunctionToSpecialize : NotFunctionOrNotSpecializable);
     282        registerAt(index).set(exec->vm(), this, value);
     283    }
    263284
    264285    // The following accessors return pristine values, even if a script
Note: See TracChangeset for help on using the changeset viewer.