JavaScriptCore/runtime/JSActivation.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     8  * 1.  Redistributions of source code must retain the above copyright
       
     9  *     notice, this list of conditions and the following disclaimer.
       
    10  * 2.  Redistributions in binary form must reproduce the above copyright
       
    11  *     notice, this list of conditions and the following disclaimer in the
       
    12  *     documentation and/or other materials provided with the distribution.
       
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission.
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28  
       
    29 #include "config.h"
       
    30 #include "JSActivation.h"
       
    31 
       
    32 #include "Arguments.h"
       
    33 #include "Interpreter.h"
       
    34 #include "JSFunction.h"
       
    35 
       
    36 namespace JSC {
       
    37 
       
    38 ASSERT_CLASS_FITS_IN_CELL(JSActivation);
       
    39 
       
    40 const ClassInfo JSActivation::info = { "JSActivation", 0, 0, 0 };
       
    41 
       
    42 JSActivation::JSActivation(CallFrame* callFrame, NonNullPassRefPtr<FunctionExecutable> functionExecutable)
       
    43     : Base(callFrame->globalData().activationStructure, new JSActivationData(functionExecutable, callFrame->registers()))
       
    44 {
       
    45 }
       
    46 
       
    47 JSActivation::~JSActivation()
       
    48 {
       
    49     delete d();
       
    50 }
       
    51 
       
    52 void JSActivation::markChildren(MarkStack& markStack)
       
    53 {
       
    54     Base::markChildren(markStack);
       
    55 
       
    56     Register* registerArray = d()->registerArray.get();
       
    57     if (!registerArray)
       
    58         return;
       
    59 
       
    60     size_t numParametersMinusThis = d()->functionExecutable->parameterCount();
       
    61 
       
    62     size_t count = numParametersMinusThis;
       
    63     markStack.appendValues(registerArray, count);
       
    64 
       
    65     size_t numVars = d()->functionExecutable->variableCount();
       
    66 
       
    67     // Skip the call frame, which sits between the parameters and vars.
       
    68     markStack.appendValues(registerArray + count + RegisterFile::CallFrameHeaderSize, numVars, MayContainNullValues);
       
    69 }
       
    70 
       
    71 bool JSActivation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
    72 {
       
    73     if (propertyName == exec->propertyNames().arguments) {
       
    74         slot.setCustom(this, getArgumentsGetter());
       
    75         return true;
       
    76     }
       
    77 
       
    78     if (symbolTableGet(propertyName, slot))
       
    79         return true;
       
    80 
       
    81     if (JSValue* location = getDirectLocation(propertyName)) {
       
    82         slot.setValueSlot(location);
       
    83         return true;
       
    84     }
       
    85 
       
    86     // We don't call through to JSObject because there's no way to give an 
       
    87     // activation object getter properties or a prototype.
       
    88     ASSERT(!hasGetterSetterProperties());
       
    89     ASSERT(prototype().isNull());
       
    90     return false;
       
    91 }
       
    92 
       
    93 void JSActivation::put(ExecState*, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
       
    94 {
       
    95     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
       
    96 
       
    97     if (symbolTablePut(propertyName, value))
       
    98         return;
       
    99 
       
   100     // We don't call through to JSObject because __proto__ and getter/setter 
       
   101     // properties are non-standard extensions that other implementations do not
       
   102     // expose in the activation object.
       
   103     ASSERT(!hasGetterSetterProperties());
       
   104     putDirect(propertyName, value, 0, true, slot);
       
   105 }
       
   106 
       
   107 // FIXME: Make this function honor ReadOnly (const) and DontEnum
       
   108 void JSActivation::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
       
   109 {
       
   110     ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
       
   111 
       
   112     if (symbolTablePutWithAttributes(propertyName, value, attributes))
       
   113         return;
       
   114 
       
   115     // We don't call through to JSObject because __proto__ and getter/setter 
       
   116     // properties are non-standard extensions that other implementations do not
       
   117     // expose in the activation object.
       
   118     ASSERT(!hasGetterSetterProperties());
       
   119     PutPropertySlot slot;
       
   120     JSObject::putWithAttributes(exec, propertyName, value, attributes, true, slot);
       
   121 }
       
   122 
       
   123 bool JSActivation::deleteProperty(ExecState* exec, const Identifier& propertyName)
       
   124 {
       
   125     if (propertyName == exec->propertyNames().arguments)
       
   126         return false;
       
   127 
       
   128     return Base::deleteProperty(exec, propertyName);
       
   129 }
       
   130 
       
   131 JSObject* JSActivation::toThisObject(ExecState* exec) const
       
   132 {
       
   133     return exec->globalThisValue();
       
   134 }
       
   135 
       
   136 bool JSActivation::isDynamicScope(bool& requiresDynamicChecks) const
       
   137 {
       
   138     requiresDynamicChecks = d()->functionExecutable->usesEval();
       
   139     return false;
       
   140 }
       
   141 
       
   142 JSValue JSActivation::argumentsGetter(ExecState*, JSValue slotBase, const Identifier&)
       
   143 {
       
   144     JSActivation* activation = asActivation(slotBase);
       
   145     CallFrame* callFrame = CallFrame::create(activation->d()->registers);
       
   146     int argumentsRegister = activation->d()->functionExecutable->generatedBytecode().argumentsRegister();
       
   147     if (!callFrame->r(argumentsRegister).jsValue()) {
       
   148         JSValue arguments = JSValue(new (callFrame) Arguments(callFrame));
       
   149         callFrame->r(argumentsRegister) = arguments;
       
   150         callFrame->r(unmodifiedArgumentsRegister(argumentsRegister)) = arguments;
       
   151     }
       
   152 
       
   153     ASSERT(callFrame->r(argumentsRegister).jsValue().inherits(&Arguments::info));
       
   154     return callFrame->r(argumentsRegister).jsValue();
       
   155 }
       
   156 
       
   157 // These two functions serve the purpose of isolating the common case from a
       
   158 // PIC branch.
       
   159 
       
   160 PropertySlot::GetValueFunc JSActivation::getArgumentsGetter()
       
   161 {
       
   162     return argumentsGetter;
       
   163 }
       
   164 
       
   165 } // namespace JSC