Commit 6f821c8d authored by mjs's avatar mjs

Merged changes from LABYRINTH_KDE_3_MERGE branch.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@798 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f54a76f3
......@@ -4,6 +4,8 @@ noinst_LIBRARIES = libkjs.o
libkjs_o_LDFLAGS = -Wl,-r -nostdlib
libkjs_o_AR = $(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) $(libkjs_o_LDFLAGS) -o
INCLUDES = $(KWQ_INCLUDES)
libkjs_o_SOURCES = \
array_object.cpp \
array_object.h \
......@@ -21,13 +23,12 @@ libkjs_o_SOURCES = \
function.h \
function_object.cpp \
function_object.h \
global_object.cpp \
grammar.cpp \
grammar.h \
internal.cpp \
internal.h \
kjs.cpp \
kjs.h \
interpreter.cpp \
interpreter.h \
lexer.cpp \
lexer.h \
lexer.lut.h \
......@@ -46,6 +47,8 @@ libkjs_o_SOURCES = \
object_object.h \
operations.cpp \
operations.h \
property_map.cpp \
property_map.h \
regexp.cpp \
regexp.h \
regexp_object.cpp \
......@@ -56,6 +59,8 @@ libkjs_o_SOURCES = \
types.h \
ustring.cpp \
ustring.h \
value.cpp \
value.h \
$(NULL)
noinst_PROGRAMS = testkjs
......@@ -75,7 +80,29 @@ grammar-stamp: grammar.y
ln -sf grammar.cpp.h grammar.h
touch ./grammar-stamp
BUILT_SOURCES = $(GRAMMAR_FILES) grammar-stamp
LUT_FILES = math_object.lut.h lexer.lut.h array_object.lut.h date_object.lut.h string_object.lut.h number_object.lut.h
lexer.lut.h: keywords.table
./create_hash_table keywords.table -i > lexer.lut.h;
array_object.lut.h: array_object.cpp
./create_hash_table array_object.cpp -i > array_object.lut.h
math_object.lut.h: math_object.cpp
./create_hash_table math_object.cpp -i > math_object.lut.h
date_object.lut.h: date_object.cpp
./create_hash_table date_object.cpp -i > date_object.lut.h
number_object.lut.h: number_object.cpp
./create_hash_table number_object.cpp -i > number_object.lut.h
string_object.lut.h: string_object.cpp
./create_hash_table string_object.cpp -i > string_object.lut.h
BUILT_SOURCES = $(GRAMMAR_FILES) $(LUT_FILES) grammar-stamp
CLEANFILES = $(BUILT_SOURCES)
This diff is collapsed.
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
......@@ -15,39 +16,64 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
#ifndef _ARRAY_OBJECT_H_
#define _ARRAY_OBJECT_H_
#include "object.h"
#include "function.h"
#include "internal.h"
#include "function_object.h"
namespace KJS {
class ArrayObject : public ConstructorImp {
class ArrayInstanceImp : public ObjectImp {
public:
ArrayObject(const Object &funcProto, const Object &arrayProto);
Completion execute(const List &);
Object construct(const List &);
ArrayInstanceImp(const Object &proto);
virtual void put(ExecState *exec, const UString &propertyName, const Value &value, int attr = None);
virtual void putDirect(ExecState *exec, const UString &propertyName, const Value &value, int attr = None);
virtual const ClassInfo *classInfo() const { return &info; }
static const ClassInfo info;
};
class ArrayPrototype : public ObjectImp {
class ArrayPrototypeImp : public ArrayInstanceImp {
public:
ArrayPrototype(const Object& proto);
virtual KJSO get(const UString &p) const;
ArrayPrototypeImp(ExecState *exec,
ObjectPrototypeImp *objProto);
Value get(ExecState *exec, const UString &p) const;
virtual const ClassInfo *classInfo() const { return &info; }
static const ClassInfo info;
};
class ArrayProtoFunc : public InternalFunctionImp {
class ArrayProtoFuncImp : public InternalFunctionImp {
public:
ArrayProtoFunc(int i) : id(i) { }
Completion execute(const List &);
ArrayProtoFuncImp(ExecState *exec, int i, int len);
virtual bool implementsCall() const;
virtual Value call(ExecState *exec, Object &thisObj, const List &args);
enum { ToString, ToLocaleString, Concat, Join, Pop, Push,
Reverse, Shift, Slice, Sort, Splice, UnShift };
private:
int id;
};
class ArrayObjectImp : public InternalFunctionImp {
public:
ArrayObjectImp(ExecState *exec,
FunctionPrototypeImp *funcProto,
ArrayPrototypeImp *arrayProto);
virtual bool implementsConstruct() const;
virtual Object construct(ExecState *exec, const List &args);
virtual bool implementsCall() const;
virtual Value call(ExecState *exec, Object &thisObj, const List &args);
};
}; // namespace
#endif
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
......@@ -15,89 +16,134 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "kjs.h"
#include "operations.h"
#include "value.h"
#include "object.h"
#include "types.h"
#include "interpreter.h"
#include "operations.h"
#include "bool_object.h"
#include "error_object.h"
#include <assert.h>
using namespace KJS;
BooleanObject::BooleanObject(const KJSO& funcProto, const KJSO &booleanProto)
: ConstructorImp(funcProto, 1)
// ------------------------------ BooleanInstanceImp ---------------------------
const ClassInfo BooleanInstanceImp::info = {"Boolean", 0, 0, 0};
BooleanInstanceImp::BooleanInstanceImp(const Object &proto)
: ObjectImp(proto)
{
// Boolean.prototype
setPrototypeProperty(booleanProto);
}
// ECMA 15.6.1
Completion BooleanObject::execute(const List &args)
{
Boolean b;
// ------------------------------ BooleanPrototypeImp --------------------------
if (args.isEmpty())
b = Boolean(false);
else
b = args[0].toBoolean();
// ECMA 15.6.4
BooleanPrototypeImp::BooleanPrototypeImp(ExecState *exec,
ObjectPrototypeImp *objectProto,
FunctionPrototypeImp *funcProto)
: BooleanInstanceImp(Object(objectProto))
{
Value protect(this);
// The constructor will be added later by InterpreterImp::InterpreterImp()
return Completion(ReturnValue, b);
put(exec,"toString", Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0)), DontEnum);
put(exec,"valueOf", Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0)), DontEnum);
setInternalValue(Boolean(false));
}
// ECMA 15.6.2
Object BooleanObject::construct(const List &args)
{
Boolean b;
if (args.size() > 0)
b = args.begin()->toBoolean();
else
b = Boolean(false);
return Object::create(BooleanClass, b);
// ------------------------------ BooleanProtoFuncImp --------------------------
BooleanProtoFuncImp::BooleanProtoFuncImp(ExecState *exec,
FunctionPrototypeImp *funcProto, int i, int len)
: InternalFunctionImp(funcProto), id(i)
{
Value protect(this);
put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
}
// ECMA 15.6.4
BooleanPrototype::BooleanPrototype(const Object& proto)
: ObjectImp(BooleanClass, Boolean(false), proto)
bool BooleanProtoFuncImp::implementsCall() const
{
// The constructor will be added later in BooleanObject's constructor
return true;
}
KJSO BooleanPrototype::get(const UString &p) const
// ECMA 15.6.4.2 + 15.6.4.3
Value BooleanProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)
{
if (p == "toString")
return Function(new BooleanProtoFunc(ToString));
else if (p == "valueOf")
return Function(new BooleanProtoFunc(ValueOf));
// no generic function. "this" has to be a Boolean object
if (!thisObj.inherits(&BooleanInstanceImp::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
// execute "toString()" or "valueOf()", respectively
Value v = thisObj.internalValue();
assert(!v.isNull());
if (id == ToString)
return String(v.toString(exec));
else
return Imp::get(p);
return Boolean(v.toBoolean(exec)); /* TODO: optimize for bool case */
}
BooleanProtoFunc::BooleanProtoFunc(int i)
: id(i)
// ------------------------------ BooleanObjectImp -----------------------------
BooleanObjectImp::BooleanObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
BooleanPrototypeImp *booleanProto)
: InternalFunctionImp(funcProto)
{