Commit 3e13aa6b authored by mjs's avatar mjs
Browse files

Reviewed by Geoff and Darin.

        
        Patch from Maks Orlovich, based on work by David Faure, hand-applied and 
        significantly reworked by me.
        
        - Patch: give internal function names (KJS merge)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=6279

        * tests/mozilla/expected.html: Updated for newly fixed test.

        * kjs/array_object.cpp:
        (ArrayProtoFunc::ArrayProtoFunc):
        * kjs/array_object.h:
        * kjs/bool_object.cpp:
        (BooleanPrototype::BooleanPrototype):
        (BooleanProtoFunc::BooleanProtoFunc):
        * kjs/bool_object.h:
        * kjs/date_object.cpp:
        (KJS::DateProtoFunc::DateProtoFunc):
        (KJS::DateObjectImp::DateObjectImp):
        (KJS::DateObjectFuncImp::DateObjectFuncImp):
        * kjs/error_object.cpp:
        (ErrorPrototype::ErrorPrototype):
        (ErrorProtoFunc::ErrorProtoFunc):
        * kjs/error_object.h:
        * kjs/function.cpp:
        (KJS::FunctionImp::FunctionImp):
        (KJS::GlobalFuncImp::GlobalFuncImp):
        * kjs/function.h:
        * kjs/function_object.cpp:
        (FunctionPrototype::FunctionPrototype):
        (FunctionProtoFunc::FunctionProtoFunc):
        (FunctionProtoFunc::callAsFunction):
        * kjs/function_object.h:
        * kjs/internal.cpp:
        (KJS::InterpreterImp::initGlobalObject):
        (KJS::InternalFunctionImp::InternalFunctionImp):
        * kjs/internal.h:
        (KJS::InternalFunctionImp::functionName):
        * kjs/lookup.h:
        (KJS::staticFunctionGetter):
        (KJS::HashEntryFunction::HashEntryFunction):
        (KJS::HashEntryFunction::implementsCall):
        (KJS::HashEntryFunction::toBoolean):
        (KJS::HashEntryFunction::implementsHasInstance):
        (KJS::HashEntryFunction::hasInstance):
        * kjs/math_object.cpp:
        (MathFuncImp::MathFuncImp):
        * kjs/math_object.h:
        * kjs/number_object.cpp:
        (NumberPrototype::NumberPrototype):
        (NumberProtoFunc::NumberProtoFunc):
        * kjs/number_object.h:
        * kjs/object.cpp:
        (KJS::JSObject::putDirectFunction):
        (KJS::Error::create):
        * kjs/object.h:
        * kjs/object_object.cpp:
        (ObjectPrototype::ObjectPrototype):
        (ObjectProtoFunc::ObjectProtoFunc):
        * kjs/object_object.h:
        * kjs/regexp_object.cpp:
        (RegExpPrototype::RegExpPrototype):
        (RegExpProtoFunc::RegExpProtoFunc):
        * kjs/regexp_object.h:
        * kjs/string_object.cpp:
        (StringProtoFunc::StringProtoFunc):
        (StringObjectImp::StringObjectImp):
        (StringObjectFuncImp::StringObjectFuncImp):
        * kjs/string_object.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@12911 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2e6c8fd0
2006-02-20 Maciej Stachowiak <mjs@apple.com>
Reviewed by Geoff and Darin.
Patch from Maks Orlovich, based on work by David Faure, hand-applied and
significantly reworked by me.
- Patch: give internal function names (KJS merge)
http://bugzilla.opendarwin.org/show_bug.cgi?id=6279
* tests/mozilla/expected.html: Updated for newly fixed test.
* kjs/array_object.cpp:
(ArrayProtoFunc::ArrayProtoFunc):
* kjs/array_object.h:
* kjs/bool_object.cpp:
(BooleanPrototype::BooleanPrototype):
(BooleanProtoFunc::BooleanProtoFunc):
* kjs/bool_object.h:
* kjs/date_object.cpp:
(KJS::DateProtoFunc::DateProtoFunc):
(KJS::DateObjectImp::DateObjectImp):
(KJS::DateObjectFuncImp::DateObjectFuncImp):
* kjs/error_object.cpp:
(ErrorPrototype::ErrorPrototype):
(ErrorProtoFunc::ErrorProtoFunc):
* kjs/error_object.h:
* kjs/function.cpp:
(KJS::FunctionImp::FunctionImp):
(KJS::GlobalFuncImp::GlobalFuncImp):
* kjs/function.h:
* kjs/function_object.cpp:
(FunctionPrototype::FunctionPrototype):
(FunctionProtoFunc::FunctionProtoFunc):
(FunctionProtoFunc::callAsFunction):
* kjs/function_object.h:
* kjs/internal.cpp:
(KJS::InterpreterImp::initGlobalObject):
(KJS::InternalFunctionImp::InternalFunctionImp):
* kjs/internal.h:
(KJS::InternalFunctionImp::functionName):
* kjs/lookup.h:
(KJS::staticFunctionGetter):
(KJS::HashEntryFunction::HashEntryFunction):
(KJS::HashEntryFunction::implementsCall):
(KJS::HashEntryFunction::toBoolean):
(KJS::HashEntryFunction::implementsHasInstance):
(KJS::HashEntryFunction::hasInstance):
* kjs/math_object.cpp:
(MathFuncImp::MathFuncImp):
* kjs/math_object.h:
* kjs/number_object.cpp:
(NumberPrototype::NumberPrototype):
(NumberProtoFunc::NumberProtoFunc):
* kjs/number_object.h:
* kjs/object.cpp:
(KJS::JSObject::putDirectFunction):
(KJS::Error::create):
* kjs/object.h:
* kjs/object_object.cpp:
(ObjectPrototype::ObjectPrototype):
(ObjectProtoFunc::ObjectProtoFunc):
* kjs/object_object.h:
* kjs/regexp_object.cpp:
(RegExpPrototype::RegExpPrototype):
(RegExpProtoFunc::RegExpProtoFunc):
* kjs/regexp_object.h:
* kjs/string_object.cpp:
(StringProtoFunc::StringProtoFunc):
(StringObjectImp::StringObjectImp):
(StringObjectFuncImp::StringObjectFuncImp):
* kjs/string_object.h:
2006-02-20 Geoffrey Garen <ggaren@apple.com>
Reviewed by Darin, with help from Eric, Maciej.
......
......@@ -433,10 +433,10 @@ bool ArrayPrototype::getOwnPropertySlot(ExecState *exec, const Identifier& prope
// ------------------------------ ArrayProtoFunc ----------------------------
ArrayProtoFunc::ArrayProtoFunc(ExecState *exec, int i, int len)
: InternalFunctionImp(
static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())
), id(i)
ArrayProtoFunc::ArrayProtoFunc(ExecState *exec, int i, int len, const Identifier& name)
: InternalFunctionImp(static_cast<FunctionPrototype*>
(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
, id(i)
{
put(exec,lengthPropertyName,jsNumber(len),DontDelete|ReadOnly|DontEnum);
}
......
......@@ -22,6 +22,7 @@
#ifndef _ARRAY_OBJECT_H_
#define _ARRAY_OBJECT_H_
#include "array_instance.h"
#include "internal.h"
#include "function_object.h"
......@@ -38,7 +39,7 @@ namespace KJS {
class ArrayProtoFunc : public InternalFunctionImp {
public:
ArrayProtoFunc(ExecState *exec, int i, int len);
ArrayProtoFunc(ExecState *exec, int i, int len, const Identifier& name);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
......
......@@ -46,24 +46,22 @@ BooleanInstance::BooleanInstance(JSObject *proto)
// ECMA 15.6.4
BooleanPrototype::BooleanPrototype(ExecState *exec,
ObjectPrototype *objectProto,
FunctionPrototype *funcProto)
BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectProto, FunctionPrototype* funcProto)
: BooleanInstance(objectProto)
{
// The constructor will be added later by InterpreterImp::InterpreterImp()
putDirect(toStringPropertyName, new BooleanProtoFunc(exec,funcProto,BooleanProtoFunc::ToString,0), DontEnum);
putDirect(valueOfPropertyName, new BooleanProtoFunc(exec,funcProto,BooleanProtoFunc::ValueOf,0), DontEnum);
putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, toStringPropertyName), DontEnum);
putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, valueOfPropertyName), DontEnum);
setInternalValue(jsBoolean(false));
}
// ------------------------------ BooleanProtoFunc --------------------------
BooleanProtoFunc::BooleanProtoFunc(ExecState *exec,
FunctionPrototype *funcProto, int i, int len)
: InternalFunctionImp(funcProto), id(i)
BooleanProtoFunc::BooleanProtoFunc(ExecState*, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
: InternalFunctionImp(funcProto, name)
, id(i)
{
putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
}
......
......@@ -56,8 +56,7 @@ namespace KJS {
*/
class BooleanProtoFunc : public InternalFunctionImp {
public:
BooleanProtoFunc(ExecState *exec,
FunctionPrototype *funcProto, int i, int len);
BooleanProtoFunc(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
......
......@@ -83,7 +83,7 @@ namespace KJS {
*/
class DateProtoFunc : public InternalFunctionImp {
public:
DateProtoFunc(ExecState *, int i, int len);
DateProtoFunc(ExecState *, int i, int len, const Identifier& date);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *, JSObject *thisObj, const List &args);
......@@ -110,7 +110,7 @@ private:
*/
class DateObjectFuncImp : public InternalFunctionImp {
public:
DateObjectFuncImp(ExecState *, FunctionPrototype *, int i, int len);
DateObjectFuncImp(ExecState *, FunctionPrototype *, int i, int len, const Identifier& );
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *, JSObject *thisObj, const List &args);
......@@ -539,9 +539,10 @@ bool DatePrototype::getOwnPropertySlot(ExecState *exec, const Identifier& proper
// ------------------------------ DateProtoFunc -----------------------------
DateProtoFunc::DateProtoFunc(ExecState *exec, int i, int len)
: InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())),
id(abs(i)), utc(i<0)
DateProtoFunc::DateProtoFunc(ExecState *exec, int i, int len, const Identifier& name)
: InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
, id(abs(i))
, utc(i < 0)
// We use a negative ID to denote the "UTC" variant.
{
putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
......@@ -719,9 +720,9 @@ DateObjectImp::DateObjectImp(ExecState *exec,
putDirect(prototypePropertyName, dateProto, DontEnum|DontDelete|ReadOnly);
static const Identifier parsePropertyName("parse");
putDirect(parsePropertyName, new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::Parse, 1), DontEnum);
putDirectFunction(new DateObjectFuncImp(exec, funcProto, DateObjectFuncImp::Parse, 1, parsePropertyName), DontEnum);
static const Identifier UTCPropertyName("UTC");
putDirect(UTCPropertyName, new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::UTC, 7), DontEnum);
putDirectFunction(new DateObjectFuncImp(exec, funcProto, DateObjectFuncImp::UTC, 7, UTCPropertyName), DontEnum);
// no. of arguments for constructor
putDirect(lengthPropertyName, 7, ReadOnly|DontDelete|DontEnum);
......@@ -810,8 +811,8 @@ JSValue *DateObjectImp::callAsFunction(ExecState * /*exec*/, JSObject * /*thisOb
// ------------------------------ DateObjectFuncImp ----------------------------
DateObjectFuncImp::DateObjectFuncImp(ExecState *exec, FunctionPrototype *funcProto, int i, int len)
: InternalFunctionImp(funcProto), id(i)
DateObjectFuncImp::DateObjectFuncImp(ExecState *exec, FunctionPrototype *funcProto, int i, int len, const Identifier& name)
: InternalFunctionImp(funcProto, name), id(i)
{
putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
}
......
......@@ -53,13 +53,13 @@ ErrorPrototype::ErrorPrototype(ExecState *exec,
put(exec, namePropertyName, jsString("Error"), DontEnum);
put(exec, messagePropertyName, jsString("Unknown error"), DontEnum);
putDirect(toStringPropertyName, new ErrorProtoFunc(exec,funcProto), DontEnum);
putDirectFunction(new ErrorProtoFunc(exec, funcProto, toStringPropertyName), DontEnum);
}
// ------------------------------ ErrorProtoFunc ----------------------------
ErrorProtoFunc::ErrorProtoFunc(ExecState *exec, FunctionPrototype *funcProto)
: InternalFunctionImp(funcProto)
ErrorProtoFunc::ErrorProtoFunc(ExecState*, FunctionPrototype* funcProto, const Identifier& name)
: InternalFunctionImp(funcProto, name)
{
putDirect(lengthPropertyName, jsNumber(0), DontDelete|ReadOnly|DontEnum);
}
......
......@@ -44,7 +44,7 @@ namespace KJS {
class ErrorProtoFunc : public InternalFunctionImp {
public:
ErrorProtoFunc(ExecState *exec, FunctionPrototype *funcProto);
ErrorProtoFunc(ExecState*, FunctionPrototype*, const Identifier&);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
};
......
......@@ -56,9 +56,9 @@ const ClassInfo FunctionImp::info = {"Function", &InternalFunctionImp::info, 0,
};
FunctionImp::FunctionImp(ExecState *exec, const Identifier &n)
: InternalFunctionImp(
static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())
), param(0L), ident(n)
: InternalFunctionImp(static_cast<FunctionPrototype*>
(exec->lexicalInterpreter()->builtinFunctionPrototype()), n)
, param(0L)
{
}
......@@ -557,8 +557,9 @@ void ActivationImp::createArgumentsObject(ExecState *exec) const
// ------------------------------ GlobalFunc -----------------------------------
GlobalFuncImp::GlobalFuncImp(ExecState *exec, FunctionPrototype *funcProto, int i, int len)
: InternalFunctionImp(funcProto), id(i)
GlobalFuncImp::GlobalFuncImp(ExecState*, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
: InternalFunctionImp(funcProto, name)
, id(i)
{
putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
}
......
......@@ -24,7 +24,6 @@
#ifndef KJS_FUNCTION_H
#define KJS_FUNCTION_H
#include "array_instance.h"
#include "internal.h"
#include <kxmlcore/OwnPtr.h>
......@@ -56,13 +55,11 @@ namespace KJS {
virtual CodeType codeType() const = 0;
virtual Completion execute(ExecState *exec) = 0;
Identifier name() const { return ident; }
virtual const ClassInfo *classInfo() const { return &info; }
static const ClassInfo info;
protected:
OwnPtr<Parameter> param;
Identifier ident;
private:
static JSValue *argumentsGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot&);
......@@ -98,7 +95,7 @@ namespace KJS {
Identifier& operator[](int index);
Identifier& operator[](const Identifier &indexIdentifier);
bool isMapped(const Identifier &index) const;
void IndexToNameMap::unMap(const Identifier &index);
void unMap(const Identifier &index);
private:
IndexToNameMap(); // prevent construction w/o parameters
......@@ -148,7 +145,7 @@ namespace KJS {
class GlobalFuncImp : public InternalFunctionImp {
public:
GlobalFuncImp(ExecState *exec, FunctionPrototype *funcProto, int i, int len);
GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
virtual CodeType codeType() const;
......
......@@ -40,12 +40,12 @@ using namespace KJS;
FunctionPrototype::FunctionPrototype(ExecState *exec)
{
putDirect(lengthPropertyName, jsNumber(0), DontDelete|ReadOnly|DontEnum);
putDirect(toStringPropertyName, new FunctionProtoFunc(exec, this, FunctionProtoFunc::ToString, 0), DontEnum);
putDirect(lengthPropertyName, jsNumber(0), DontDelete|ReadOnly|DontEnum);
putDirectFunction(new FunctionProtoFunc(exec, this, FunctionProtoFunc::ToString, 0, toStringPropertyName), DontEnum);
static const Identifier applyPropertyName("apply");
putDirect(applyPropertyName, new FunctionProtoFunc(exec, this, FunctionProtoFunc::Apply, 2), DontEnum);
putDirectFunction(new FunctionProtoFunc(exec, this, FunctionProtoFunc::Apply, 2, applyPropertyName), DontEnum);
static const Identifier callPropertyName("call");
putDirect(callPropertyName, new FunctionProtoFunc(exec, this, FunctionProtoFunc::Call, 1), DontEnum);
putDirectFunction(new FunctionProtoFunc(exec, this, FunctionProtoFunc::Call, 1, callPropertyName), DontEnum);
}
FunctionPrototype::~FunctionPrototype()
......@@ -65,9 +65,9 @@ JSValue *FunctionPrototype::callAsFunction(ExecState */*exec*/, JSObject */*this
// ------------------------------ FunctionProtoFunc -------------------------
FunctionProtoFunc::FunctionProtoFunc(ExecState *exec,
FunctionPrototype *funcProto, int i, int len)
: InternalFunctionImp(funcProto), id(i)
FunctionProtoFunc::FunctionProtoFunc(ExecState*, FunctionPrototype* funcProto, int i, int len, const Identifier& name)
: InternalFunctionImp(funcProto, name)
, id(i)
{
putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
}
......@@ -83,8 +83,7 @@ JSValue *FunctionProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, c
JSValue *result = NULL;
switch (id) {
case ToString: {
// ### also make this work for internal functions
case ToString:
if (!thisObj || !thisObj->inherits(&InternalFunctionImp::info)) {
#ifndef NDEBUG
fprintf(stderr,"attempted toString() call on null or non-function object\n");
......@@ -92,17 +91,15 @@ JSValue *FunctionProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, c
return throwError(exec, TypeError);
}
if (thisObj->inherits(&DeclaredFunctionImp::info)) {
DeclaredFunctionImp *fi = static_cast<DeclaredFunctionImp*>
(thisObj);
return jsString("function " + fi->name().ustring() + "(" +
fi->parameterString() + ") " + fi->body->toString());
} else if (thisObj->inherits(&FunctionImp::info) &&
!static_cast<FunctionImp*>(thisObj)->name().isNull()) {
result = jsString("function " + static_cast<FunctionImp*>(thisObj)->name().ustring() + "()");
}
else {
result = jsString("(Internal Function)");
}
DeclaredFunctionImp *fi = static_cast<DeclaredFunctionImp*>(thisObj);
return jsString("function " + fi->functionName().ustring() + "(" +
fi->parameterString() + ") " + fi->body->toString());
} else if (thisObj->inherits(&InternalFunctionImp::info) &&
!static_cast<InternalFunctionImp*>(thisObj)->functionName().isNull()) {
result = jsString("\nfunction " + static_cast<InternalFunctionImp*>(thisObj)->functionName().ustring() + "() {\n"
" [native code]\n}\n");
} else {
result = jsString("[function]");
}
break;
case Apply: {
......
......@@ -51,8 +51,7 @@ namespace KJS {
*/
class FunctionProtoFunc : public InternalFunctionImp {
public:
FunctionProtoFunc(ExecState *exec,
FunctionPrototype *funcProto, int i, int len);
FunctionProtoFunc(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
......
......@@ -454,7 +454,7 @@ void InterpreterImp::initGlobalObject()
b_uriError = new NativeErrorImp(&globExec, funcProto, b_uriErrorPrototype);
// ECMA 15.3.4.1
funcProto->put(&globExec, "constructor", b_Function, DontEnum);
funcProto->put(&globExec, constructorPropertyName, b_Function, DontEnum);
global->put(&globExec, "Object", b_Object, DontEnum);
global->put(&globExec, "Function", b_Function, DontEnum);
......@@ -474,22 +474,22 @@ void InterpreterImp::initGlobalObject()
global->put(&globExec, "TypeError",b_typeError, Internal);
global->put(&globExec, "URIError",b_uriError, Internal);
// Set the "constructor" property of all builtin constructors
objProto->put(&globExec, "constructor", b_Object, DontEnum | DontDelete | ReadOnly);
funcProto->put(&globExec, "constructor", b_Function, DontEnum | DontDelete | ReadOnly);
arrayProto->put(&globExec, "constructor", b_Array, DontEnum | DontDelete | ReadOnly);
booleanProto->put(&globExec, "constructor", b_Boolean, DontEnum | DontDelete | ReadOnly);
stringProto->put(&globExec, "constructor", b_String, DontEnum | DontDelete | ReadOnly);
numberProto->put(&globExec, "constructor", b_Number, DontEnum | DontDelete | ReadOnly);
dateProto->put(&globExec, "constructor", b_Date, DontEnum | DontDelete | ReadOnly);
regexpProto->put(&globExec, "constructor", b_RegExp, DontEnum | DontDelete | ReadOnly);
errorProto->put(&globExec, "constructor", b_Error, DontEnum | DontDelete | ReadOnly);
b_evalErrorPrototype->put(&globExec, "constructor", b_evalError, DontEnum | DontDelete | ReadOnly);
b_rangeErrorPrototype->put(&globExec, "constructor", b_rangeError, DontEnum | DontDelete | ReadOnly);
b_referenceErrorPrototype->put(&globExec, "constructor", b_referenceError, DontEnum | DontDelete | ReadOnly);
b_syntaxErrorPrototype->put(&globExec, "constructor", b_syntaxError, DontEnum | DontDelete | ReadOnly);
b_typeErrorPrototype->put(&globExec, "constructor", b_typeError, DontEnum | DontDelete | ReadOnly);
b_uriErrorPrototype->put(&globExec, "constructor", b_uriError, DontEnum | DontDelete | ReadOnly);
// Set the constructorPropertyName property of all builtin constructors
objProto->put(&globExec, constructorPropertyName, b_Object, DontEnum | DontDelete | ReadOnly);
funcProto->put(&globExec, constructorPropertyName, b_Function, DontEnum | DontDelete | ReadOnly);
arrayProto->put(&globExec, constructorPropertyName, b_Array, DontEnum | DontDelete | ReadOnly);
booleanProto->put(&globExec, constructorPropertyName, b_Boolean, DontEnum | DontDelete | ReadOnly);
stringProto->put(&globExec, constructorPropertyName, b_String, DontEnum | DontDelete | ReadOnly);
numberProto->put(&globExec, constructorPropertyName, b_Number, DontEnum | DontDelete | ReadOnly);
dateProto->put(&globExec, constructorPropertyName, b_Date, DontEnum | DontDelete | ReadOnly);
regexpProto->put(&globExec, constructorPropertyName, b_RegExp, DontEnum | DontDelete | ReadOnly);
errorProto->put(&globExec, constructorPropertyName, b_Error, DontEnum | DontDelete | ReadOnly);
b_evalErrorPrototype->put(&globExec, constructorPropertyName, b_evalError, DontEnum | DontDelete | ReadOnly);
b_rangeErrorPrototype->put(&globExec, constructorPropertyName, b_rangeError, DontEnum | DontDelete | ReadOnly);
b_referenceErrorPrototype->put(&globExec, constructorPropertyName, b_referenceError, DontEnum | DontDelete | ReadOnly);
b_syntaxErrorPrototype->put(&globExec, constructorPropertyName, b_syntaxError, DontEnum | DontDelete | ReadOnly);
b_typeErrorPrototype->put(&globExec, constructorPropertyName, b_typeError, DontEnum | DontDelete | ReadOnly);
b_uriErrorPrototype->put(&globExec, constructorPropertyName, b_uriError, DontEnum | DontDelete | ReadOnly);
// built-in values
global->put(&globExec, "NaN", jsNaN(), DontEnum|DontDelete);
......@@ -497,19 +497,19 @@ void InterpreterImp::initGlobalObject()
global->put(&globExec, "undefined", jsUndefined(), DontEnum|DontDelete);
// built-in functions
global->put(&globExec, "eval", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Eval, 1), DontEnum);
global->put(&globExec, "parseInt", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseInt, 2), DontEnum);
global->put(&globExec, "parseFloat", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseFloat, 1), DontEnum);
global->put(&globExec, "isNaN", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsNaN, 1), DontEnum);
global->put(&globExec, "isFinite", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsFinite, 1), DontEnum);
global->put(&globExec, "escape", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Escape, 1), DontEnum);
global->put(&globExec, "unescape", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::UnEscape, 1), DontEnum);
global->put(&globExec, "decodeURI", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURI, 1), DontEnum);
global->put(&globExec, "decodeURIComponent", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1), DontEnum);
global->put(&globExec, "encodeURI", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURI, 1), DontEnum);
global->put(&globExec, "encodeURIComponent", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
#ifndef NDEBUG
global->put(&globExec, "kjsprint", new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::KJSPrint, 1), DontEnum);
global->putDirectFunction(new GlobalFuncImp(&globExec, funcProto, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
#endif
// built-in objects
......@@ -710,11 +710,17 @@ InternalFunctionImp::InternalFunctionImp()
{
}
InternalFunctionImp::InternalFunctionImp(FunctionPrototype *funcProto)
InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto)
: JSObject(funcProto)
{
}
InternalFunctionImp::InternalFunctionImp(FunctionPrototype* funcProto, const Identifier& name)
: JSObject(funcProto)
, m_name(name)
{
}
bool InternalFunctionImp::implementsHasInstance() const
{
return true;
......
......@@ -348,12 +348,16 @@ namespace KJS {
class InternalFunctionImp : public JSObject {
public:
InternalFunctionImp();
InternalFunctionImp(FunctionPrototype *funcProto);
InternalFunctionImp(FunctionPrototype*);
InternalFunctionImp(FunctionPrototype*, const Identifier&);
bool implementsHasInstance() const;
bool hasInstance(ExecState *exec, JSValue *value);
virtual const ClassInfo *classInfo() const { return &info; }
static const ClassInfo info;
const Identifier& functionName() const { return m_name; }
private:
Identifier m_name;
};
// helper function for toInteger, toInt32, toUInt32 and toUInt16
......
......@@ -30,6 +30,8 @@
namespace KJS {
class FunctionPrototype;
/**
* An entry in a hash table.
*/
......@@ -130,7 +132,7 @@ namespace KJS {
return cachedVal;
const HashEntry *entry = slot.staticEntry();
JSValue *val = new FuncImp(exec, entry->value, entry->params);
JSValue *val = new FuncImp(exec, entry->value, entry->params, propertyName);
thisObj->putDirect(propertyName, val, entry->attr);
return val;
}
......@@ -247,7 +249,7 @@ namespace KJS {
else
thisObj->putValueProperty(exec, entry->value, value, attr);
}
} // namespace
/*
......@@ -340,9 +342,11 @@ inline KJS::JSObject *cacheGlobalObject(KJS::ExecState *exec, const KJS::Identif
}
#define KJS_IMPLEMENT_PROTOFUNC(ClassFunc) \
class ClassFunc : public DOMFunction { \
class ClassFunc : public InternalFunctionImp { \
public: \
ClassFunc(ExecState *exec, int i, int len) : id(i) \
ClassFunc(ExecState* exec, int i, int len, const Identifier& name) \
: InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name) \
, id(i) \
{ \
put(exec, lengthPropertyName, jsNumber(len), DontDelete|ReadOnly|DontEnum); \
} \
......
......@@ -153,10 +153,9 @@ JSValue *MathObjectImp::getValueProperty(ExecState *, int token) const
static bool randomSeeded = false;
MathFuncImp::MathFuncImp(ExecState *exec, int i, int l)
: InternalFunctionImp(
static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())
), id(i)
MathFuncImp::MathFuncImp(ExecState* exec, int i, int l, const Identifier& name)
: InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
, id(i)
{
putDirect(lengthPropertyName, l, DontDelete|ReadOnly|DontEnum);
}
......
......@@ -42,7 +42,7 @@ namespace KJS {
class MathFuncImp : public InternalFunctionImp {
public:
MathFuncImp(ExecState *exec, int i, int l);
MathFuncImp(ExecState *exec, int i, int l, const Identifier&);
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
private:
......
......@@ -60,20 +60,20 @@ NumberPrototype::NumberPrototype(ExecState *exec,
// The constructor will be added later, after NumberObjectImp has been constructed
putDirect(toStringPropertyName, new NumberProtoFunc(exec,funcProto,NumberProtoFunc::ToString, 1), DontEnum);
putDirect(toLocaleStringPropertyName, new NumberProtoFunc(exec,funcProto,NumberProtoFunc::ToLocaleString, 0), DontEnum);
putDirect(valueOfPropertyName, new NumberProtoFunc(exec,funcProto,NumberProtoFunc::ValueOf, 0), DontEnum);
putDirect(toFixedPropertyName, new NumberProtoFunc(exec,funcProto,NumberProtoFunc::ToFixed, 1), DontEnum);
putDirect(toExponentialPropertyName, new NumberProtoFunc(exec,funcProto,NumberProtoFunc::ToExponential, 1), DontEnum);