From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kjs/DESIGN.ideas | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 kjs/DESIGN.ideas (limited to 'kjs/DESIGN.ideas') diff --git a/kjs/DESIGN.ideas b/kjs/DESIGN.ideas new file mode 100644 index 000000000..d7684b45b --- /dev/null +++ b/kjs/DESIGN.ideas @@ -0,0 +1,110 @@ +Get rid of SourceElementsNode by integrating its functionality into +StatementNode. + +========================================================================== + +The hash value of a string could be calculated at creation time and be +stored in the UString instance for later use by the lookup functions. + +========================================================================== + +Proposal for a new object model. Far from being complete. + + Object Type ++---------+ +-------------+ +| type | ----------------> | toString() | +| | | toNumber() | +| data | | .... | ++---------+ | construct() | + | +-------------+ + | | /|\ + \|/ | | ++---------+ | | +| type | | | +| | Shared (optional) \|/ | +| data | +-------------+ ++---------+ +---------+ | types | + /|\ | |<------| gc | Interpreter/Environment + +-------| | | .... | + | | | excp state | + +---------+ +-------------+ + Garbage Collector + +Features: + - offers class static data (nice replacement for pointers to member + function objects in the prototype object) + - no more need to pass around ExecState pointers for the C++ user + (substituted with the need for Object* in the type implementation) + - simple types are stored simple (no new'ed Imp objects) + +Alternative A: pass around Object by pointer rather than value + rather than new'ing they should come out of a pool + +Alternative B: instead of virtual functions like toBoolean(), Type could + have an array of function pointers which can be modified + on the fly and checked for != 0. + +Limitations: Konqueror's requirement to allow access to other frame's + interpreter data but flagging errors on the caller's side + is not satisfied. + +class Interpreter; + +class Type { +public: + Type(Interpreter* i, Type *b) : ip(i), bs(b) { } + virtual UString name() const = 0; + Type* base() const { return bs; } + Interpreter* interpreter() const { return ip; } + + virtual bool toBoolean(Object *o); + // .... + virtual Object construct(const List &args); + + // factory + Boolean newBoolean(bool b) { return Boolean(interpreter(), b); } + +private: + Interpreter* ip; + Type* bs; +}; + +union Data { + bool b; + double d; + // UString ??? + Shared* sh; +}; + +class Object { +public: + // creation + Boolean newBoolean(bool b) { return Boolean(typ->interpreter(), b); } + + // conversion + bool to Boolean() const { return typ->toBoolean(this); } + + // this object's "parent" + Interpreter* interpreter() const { return typ->ip; } +private: + Type* typ; + Data dat; +}; + +class Boolean : public Object { +public: + // used by convenience function newBoolean() + Boolean(Interpreter *i, bool b) { + typ = i->booleanType(); + dat.b = b; + } + Boolean(const Boolean &b) { + typ = b.typ; + dat.b = b.b; + } + Boolean& operator=(const Boolean &b) { + type = b.typ; + dat.b = b.b; + return *this; + } +}; -- cgit v1.2.1