Commit 0210a252 authored by darin's avatar darin

- on the road to killing ActivationImp

        * kjs/function.h: Add get/put to FunctionImp. Remove argumentsObject() from
	ActivationImp. Add function() to ActivationImp.
        * kjs/function.cpp:
        (FunctionImp::FunctionImp): No arguments property.
        (FunctionImp::call): No need to set up the arguments property.
        (FunctionImp::parameterString): Remove ** strangeness.
        (FunctionImp::processParameters): Ditto.
        (FunctionImp::get): Added, handles arguments and length properties.
        (FunctionImp::put): Ditto.
        (FunctionImp::hasProperty): Ditto.
        (FunctionImp::deleteProperty): Ditto.
        (ActivationImp::ActivationImp): Store a function pointer so we can find it
	in the context.

        * kjs/function_object.cpp: (FunctionObjectImp::construct): No need to set up
	arguments property.
        * kjs/nodes.cpp: (FuncExprNode::evaluate): No need to set up length property.

        * kjs/internal.h: Return ObjectImp * for activation object.

        * kjs/interpreter.h: Remove stray declaration of ExecStateImp.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7fc08d7
2002-11-20 Darin Adler <darin@apple.com>
- on the road to killing ActivationImp
* kjs/function.h: Add get/put to FunctionImp. Remove argumentsObject() from
ActivationImp. Add function() to ActivationImp.
* kjs/function.cpp:
(FunctionImp::FunctionImp): No arguments property.
(FunctionImp::call): No need to set up the arguments property.
(FunctionImp::parameterString): Remove ** strangeness.
(FunctionImp::processParameters): Ditto.
(FunctionImp::get): Added, handles arguments and length properties.
(FunctionImp::put): Ditto.
(FunctionImp::hasProperty): Ditto.
(FunctionImp::deleteProperty): Ditto.
(ActivationImp::ActivationImp): Store a function pointer so we can find it
in the context.
* kjs/function_object.cpp: (FunctionObjectImp::construct): No need to set up
arguments property.
* kjs/nodes.cpp: (FuncExprNode::evaluate): No need to set up length property.
* kjs/internal.h: Return ObjectImp * for activation object.
* kjs/interpreter.h: Remove stray declaration of ExecStateImp.
2002-11-20 Darin Adler <darin@apple.com>
- add a couple of list operations to avoid clearing lists so much during sorting; gives 1.5% iBench
......
2002-11-20 Darin Adler <darin@apple.com>
- on the road to killing ActivationImp
* kjs/function.h: Add get/put to FunctionImp. Remove argumentsObject() from
ActivationImp. Add function() to ActivationImp.
* kjs/function.cpp:
(FunctionImp::FunctionImp): No arguments property.
(FunctionImp::call): No need to set up the arguments property.
(FunctionImp::parameterString): Remove ** strangeness.
(FunctionImp::processParameters): Ditto.
(FunctionImp::get): Added, handles arguments and length properties.
(FunctionImp::put): Ditto.
(FunctionImp::hasProperty): Ditto.
(FunctionImp::deleteProperty): Ditto.
(ActivationImp::ActivationImp): Store a function pointer so we can find it
in the context.
* kjs/function_object.cpp: (FunctionObjectImp::construct): No need to set up
arguments property.
* kjs/nodes.cpp: (FuncExprNode::evaluate): No need to set up length property.
* kjs/internal.h: Return ObjectImp * for activation object.
* kjs/interpreter.h: Remove stray declaration of ExecStateImp.
2002-11-20 Darin Adler <darin@apple.com>
- add a couple of list operations to avoid clearing lists so much during sorting; gives 1.5% iBench
......
2002-11-20 Darin Adler <darin@apple.com>
- on the road to killing ActivationImp
* kjs/function.h: Add get/put to FunctionImp. Remove argumentsObject() from
ActivationImp. Add function() to ActivationImp.
* kjs/function.cpp:
(FunctionImp::FunctionImp): No arguments property.
(FunctionImp::call): No need to set up the arguments property.
(FunctionImp::parameterString): Remove ** strangeness.
(FunctionImp::processParameters): Ditto.
(FunctionImp::get): Added, handles arguments and length properties.
(FunctionImp::put): Ditto.
(FunctionImp::hasProperty): Ditto.
(FunctionImp::deleteProperty): Ditto.
(ActivationImp::ActivationImp): Store a function pointer so we can find it
in the context.
* kjs/function_object.cpp: (FunctionObjectImp::construct): No need to set up
arguments property.
* kjs/nodes.cpp: (FuncExprNode::evaluate): No need to set up length property.
* kjs/internal.h: Return ObjectImp * for activation object.
* kjs/interpreter.h: Remove stray declaration of ExecStateImp.
2002-11-20 Darin Adler <darin@apple.com>
- add a couple of list operations to avoid clearing lists so much during sorting; gives 1.5% iBench
......
......@@ -57,9 +57,7 @@ FunctionImp::FunctionImp(ExecState *exec, const Identifier &n)
static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
), param(0L), ident(n)
{
Value protect(this);
//fprintf(stderr,"FunctionImp::FunctionImp this=%p\n");
put(exec,argumentsPropertyName,Null(),ReadOnly|DontDelete|DontEnum);
}
FunctionImp::~FunctionImp()
......@@ -104,18 +102,6 @@ Value FunctionImp::call(ExecState *exec, Object &thisObj, const List &args)
ExecState newExec(exec->interpreter(), &ctx);
newExec.setException(exec->exception()); // could be null
// In order to maintain our "arguments" property, we save the old
// value from a possible earlier call. Upon return, we restore the
// previous arguments object.
// Note: this does not appear to be part of the spec
Value oldArgs = get(&newExec, argumentsPropertyName);
if (codeType() == FunctionCode) {
assert(ctx.activationObject().inherits(&ActivationImp::info));
Object argsObj = static_cast<ActivationImp*>(ctx.activationObject().imp())->argumentsObject();
put(&newExec, argumentsPropertyName, argsObj, DontDelete|DontEnum|ReadOnly);
}
// assign user supplied arguments to parameters
processParameters(&newExec, args);
// add variable declarations (initialized to undefined)
......@@ -126,8 +112,6 @@ Value FunctionImp::call(ExecState *exec, Object &thisObj, const List &args)
// if an exception occured, propogate it back to the previous execution object
if (newExec.hadException())
exec->setException(newExec.exception());
if (codeType() == FunctionCode)
put(&newExec, argumentsPropertyName, oldArgs, DontDelete|DontEnum|ReadOnly);
#ifdef KJS_VERBOSE
if (comp.complType() == Throw)
......@@ -169,12 +153,12 @@ void FunctionImp::addParameter(const Identifier &n)
UString FunctionImp::parameterString() const
{
UString s;
const Parameter * const *p = &param;
while (*p) {
const Parameter *p = param;
while (p) {
if (!s.isEmpty())
s += ", ";
s += (*p)->name.ustring();
p = &(*p)->next;
s += p->name.ustring();
p = p->next;
}
return s;
......@@ -194,18 +178,18 @@ void FunctionImp::processParameters(ExecState *exec, const List &args)
if (param) {
ListIterator it = args.begin();
Parameter **p = &param;
while (*p) {
Parameter *p = param;
while (p) {
if (it != args.end()) {
#ifdef KJS_VERBOSE
fprintf(stderr, "setting parameter %s ", (*p)->name.ascii());
fprintf(stderr, "setting parameter %s ", p->name.ascii());
printInfo(exec,"to", *it);
#endif
variable.put(exec,(*p)->name, *it);
variable.put(exec, p->name, *it);
it++;
} else
variable.put(exec,(*p)->name, Undefined());
p = &(*p)->next;
variable.put(exec, p->name, Undefined());
p = p->next;
}
}
#ifdef KJS_VERBOSE
......@@ -220,6 +204,55 @@ void FunctionImp::processVarDecls(ExecState */*exec*/)
{
}
Value FunctionImp::get(ExecState *exec, const Identifier &propertyName) const
{
// Find the arguments from the closest context.
if (propertyName == argumentsPropertyName) {
ContextImp *context = exec->_context;
while (context) {
ActivationImp *activation = static_cast<ActivationImp *>(context->activationObject());
if (activation->function() == this)
return activation->get(exec, propertyName);
context = context->callingContext();
}
return Undefined();
}
// Compute length of parameters.
if (propertyName == lengthPropertyName) {
const Parameter * p = param;
int count = 0;
while (p) {
++count;
p = p->next;
}
return Number(count);
}
return InternalFunctionImp::get(exec, propertyName);
}
void FunctionImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
{
if (propertyName == argumentsPropertyName || propertyName == lengthPropertyName)
return;
InternalFunctionImp::put(exec, propertyName, value, attr);
}
bool FunctionImp::hasProperty(ExecState *exec, const Identifier &propertyName) const
{
if (propertyName == argumentsPropertyName || propertyName == lengthPropertyName)
return true;
return InternalFunctionImp::hasProperty(exec, propertyName);
}
bool FunctionImp::deleteProperty(ExecState *exec, const Identifier &propertyName)
{
if (propertyName == argumentsPropertyName || propertyName == lengthPropertyName)
return false;
return InternalFunctionImp::deleteProperty(exec, propertyName);
}
// ------------------------------ DeclaredFunctionImp --------------------------
// ### is "Function" correct here?
......@@ -304,7 +337,7 @@ const ClassInfo ActivationImp::info = {"Activation", 0, 0, 0};
// ECMA 10.1.6
ActivationImp::ActivationImp(ExecState *exec, FunctionImp *f, const List &args)
: ObjectImp()
: _function(f)
{
Value protect(this);
arguments = new ArgumentsImp(exec,f, args);
......
......@@ -39,6 +39,11 @@ namespace KJS {
FunctionImp(ExecState *exec, const Identifier &n = Identifier::null);
virtual ~FunctionImp();
virtual Value get(ExecState *exec, const Identifier &propertyName) const;
virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
virtual void mark();
virtual bool implementsCall() const;
......@@ -98,11 +103,13 @@ namespace KJS {
ActivationImp(ExecState *exec, FunctionImp *f, const List &args);
~ActivationImp();
Object argumentsObject() { return Object(arguments); }
virtual const ClassInfo *classInfo() const { return &info; }
static const ClassInfo info;
FunctionImp *function() const { return _function; }
private:
FunctionImp *_function;
ObjectImp* arguments;
};
......
......@@ -283,7 +283,6 @@ Object FunctionObjectImp::construct(ExecState *exec, const List &args)
prototype.put(exec, constructorPropertyName,
Object(fimp), DontEnum|DontDelete|ReadOnly);
fimp->put(exec,prototypePropertyName,prototype,DontEnum|DontDelete|ReadOnly);
fimp->put(exec,argumentsPropertyName,Null(),DontEnum|DontDelete|ReadOnly);
return ret;
}
......
......@@ -196,7 +196,7 @@ namespace KJS {
void setVariableObject(const Object &v) { variable = v; }
Object thisValue() const { return thisVal; }
ContextImp *callingContext() { return callingCon; }
Object activationObject() { return activation; }
ObjectImp *activationObject() { return activation.imp(); }
void pushScope(const Object &s);
void popScope();
......
......@@ -31,7 +31,6 @@
namespace KJS {
class ContextImp;
class ExecStateImp;
class InterpreterImp;
/**
......
......@@ -2830,7 +2830,6 @@ Value FuncExprNode::evaluate(ExecState *exec)
int plen = 0;
for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)
fimp->addParameter(p->ident());
fimp->put(exec,lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum);
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment