[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
mjs
mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:59:06 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 8d0834264b42b6cd35cdfcff3f5fd94ccd3d46f4
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Mar 27 04:19:29 2002 +0000
top level:
* configure.in: Remove WebCore/src/kjs and add JavaScriptCore to
build.
JavaScriptCore:
Set up kjs to build by itself into libJavaScriptCore.dylib.
* .cvsignore: Added.
* Makefile.am: Added.
* dummy.cpp: Added.
* kjs/.cvsignore: Added.
WebCore:
Removed kjs from here - it's now been moved to JavaScriptCore at
the top level.
* src/Makefile.am: Don't link libkjs.o.
* src/kdelibs/Makefile.am: Remove kjs from subdirs.
* src/kdelibs/kjs/.cvsignore: Removed.
* src/kdelibs/kjs/Makefile.am: Removed.
* src/kdelibs/kjs/array_object.cpp: Removed.
* src/kdelibs/kjs/array_object.h: Removed.
* src/kdelibs/kjs/bool_object.cpp: Removed.
* src/kdelibs/kjs/bool_object.h: Removed.
* src/kdelibs/kjs/collector.cpp: Removed.
* src/kdelibs/kjs/collector.h: Removed.
* src/kdelibs/kjs/create_hash_table: Removed.
* src/kdelibs/kjs/date_object.cpp: Removed.
* src/kdelibs/kjs/date_object.h: Removed.
* src/kdelibs/kjs/debugger.cpp: Removed.
* src/kdelibs/kjs/debugger.h: Removed.
* src/kdelibs/kjs/error_object.cpp: Removed.
* src/kdelibs/kjs/error_object.h: Removed.
* src/kdelibs/kjs/function.cpp: Removed.
* src/kdelibs/kjs/function.h: Removed.
* src/kdelibs/kjs/function_object.cpp: Removed.
* src/kdelibs/kjs/function_object.h: Removed.
* src/kdelibs/kjs/grammar.y: Removed.
* src/kdelibs/kjs/internal.cpp: Removed.
* src/kdelibs/kjs/internal.h: Removed.
* src/kdelibs/kjs/interpreter.cpp: Removed.
* src/kdelibs/kjs/interpreter.h: Removed.
* src/kdelibs/kjs/keywords.table: Removed.
* src/kdelibs/kjs/kjs-test: Removed.
* src/kdelibs/kjs/kjs-test.chk: Removed.
* src/kdelibs/kjs/lexer.cpp: Removed.
* src/kdelibs/kjs/lexer.h: Removed.
* src/kdelibs/kjs/lookup.cpp: Removed.
* src/kdelibs/kjs/lookup.h: Removed.
* src/kdelibs/kjs/math_object.cpp: Removed.
* src/kdelibs/kjs/math_object.h: Removed.
* src/kdelibs/kjs/nodes.cpp: Removed.
* src/kdelibs/kjs/nodes.h: Removed.
* src/kdelibs/kjs/nodes2string.cpp: Removed.
* src/kdelibs/kjs/number_object.cpp: Removed.
* src/kdelibs/kjs/number_object.h: Removed.
* src/kdelibs/kjs/object.cpp: Removed.
* src/kdelibs/kjs/object.h: Removed.
* src/kdelibs/kjs/object_object.cpp: Removed.
* src/kdelibs/kjs/object_object.h: Removed.
* src/kdelibs/kjs/operations.cpp: Removed.
* src/kdelibs/kjs/operations.h: Removed.
* src/kdelibs/kjs/property_map.cpp: Removed.
* src/kdelibs/kjs/property_map.h: Removed.
* src/kdelibs/kjs/regexp.cpp: Removed.
* src/kdelibs/kjs/regexp.h: Removed.
* src/kdelibs/kjs/regexp_object.cpp: Removed.
* src/kdelibs/kjs/regexp_object.h: Removed.
* src/kdelibs/kjs/string_object.cpp: Removed.
* src/kdelibs/kjs/string_object.h: Removed.
* src/kdelibs/kjs/test.js: Removed.
* src/kdelibs/kjs/testkjs.cpp: Removed.
* src/kdelibs/kjs/types.cpp: Removed.
* src/kdelibs/kjs/types.h: Removed.
* src/kdelibs/kjs/ustring.cpp: Removed.
* src/kdelibs/kjs/ustring.h: Removed.
* src/kdelibs/kjs/value.cpp: Removed.
* src/kdelibs/kjs/value.h: Removed.
WebKit:
* WebKit.pbproj/project.pbxproj: Fixed to build with standalone
libJavaScriptCore.dylib.
WebBrowser:
* WebBrowser.pbproj/project.pbxproj: Include libJavaScriptCore.dylib
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@866 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/.cvsignore b/JavaScriptCore/.cvsignore
new file mode 100644
index 0000000..5d40362
--- /dev/null
+++ b/JavaScriptCore/.cvsignore
@@ -0,0 +1,4 @@
+Makefile.in
+Makefile
+JavaScriptCore-install-stamp
+libJavaScriptCore.dylib
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
new file mode 100644
index 0000000..9eb45b4
--- /dev/null
+++ b/JavaScriptCore/ChangeLog
@@ -0,0 +1,8 @@
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
+ Set up kjs to build by itself into libJavaScriptCore.dylib.
+
+ * .cvsignore: Added.
+ * Makefile.am: Added.
+ * dummy.cpp: Added.
+ * kjs/.cvsignore: Added.
diff --git a/JavaScriptCore/ChangeLog-2002-12-03 b/JavaScriptCore/ChangeLog-2002-12-03
new file mode 100644
index 0000000..9eb45b4
--- /dev/null
+++ b/JavaScriptCore/ChangeLog-2002-12-03
@@ -0,0 +1,8 @@
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
+ Set up kjs to build by itself into libJavaScriptCore.dylib.
+
+ * .cvsignore: Added.
+ * Makefile.am: Added.
+ * dummy.cpp: Added.
+ * kjs/.cvsignore: Added.
diff --git a/JavaScriptCore/ChangeLog-2003-10-25 b/JavaScriptCore/ChangeLog-2003-10-25
new file mode 100644
index 0000000..9eb45b4
--- /dev/null
+++ b/JavaScriptCore/ChangeLog-2003-10-25
@@ -0,0 +1,8 @@
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
+ Set up kjs to build by itself into libJavaScriptCore.dylib.
+
+ * .cvsignore: Added.
+ * Makefile.am: Added.
+ * dummy.cpp: Added.
+ * kjs/.cvsignore: Added.
diff --git a/WebCore/src/Makefile.am b/JavaScriptCore/Makefile.am
similarity index 55%
copy from WebCore/src/Makefile.am
copy to JavaScriptCore/Makefile.am
index 35729be..ed972d5 100644
--- a/WebCore/src/Makefile.am
+++ b/JavaScriptCore/Makefile.am
@@ -1,30 +1,22 @@
NULL=
-SUBDIRS = \
- kdelibs \
- kwq \
- $(NULL)
-
+SUBDIRS = kjs
symrootsdir = $(SYMROOTS)
-symroots_LIBRARIES = libwebcore.dylib
+symroots_LIBRARIES = libJavaScriptCore.dylib
-libwebcore_dylib_SOURCES = \
- dummy.mm \
+libJavaScriptCore_dylib_SOURCES = \
+ dummy.cpp \
$(NULL)
-libwebcore_dylib_LIBADD = \
- ./kdelibs/kjs/libkjs.o \
- ./kdelibs/khtml/libkhtml.o \
- ./kwq/libkwq.o \
- -ljpeg \
+libJavaScriptCore_dylib_LIBADD = \
+ ./kjs/libkjs.o \
$(NULL)
+LIBJAVASCRIPTCORE_INSTALL_PATH = @executable_path/../Frameworks
-LIBWEBCORE_INSTALL_PATH = @executable_path/../Frameworks
-
-DYLIB_NAME = libwebcore.dylib
+DYLIB_NAME = libJavaScriptCore.dylib
EMBED_HOST = $(SYMROOTS)/Alexander.app
EMBED_DIR = $(EMBED_HOST)/Contents/Frameworks
@@ -49,23 +41,20 @@ embed:
fi
LDFLAGS = \
- -framework Cocoa \
- -framework CoreFoundation \
- -F$(symrootsdir) -framework WebFoundation \
-dynamiclib \
-twolevel_namespace \
-prebind \
-undefined error \
-all_load \
- -seg1addr 0x2200000 \
- -install_name $(LIBWEBCORE_INSTALL_PATH)/libwebcore.dylib \
+ -seg1addr 0x6000000 \
+ -install_name $(LIBJAVASCRIPTCORE_INSTALL_PATH)/libJavaScriptCore.dylib \
$(NULL)
-libwebcore_dylib_AR = $(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o
+libJavaScriptCore_dylib_AR = $(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o
-noinst_DATA = webcore-install-stamp
+noinst_DATA = JavaScriptCore-install-stamp
-webcore-install-stamp: libwebcore.dylib
+JavaScriptCore-install-stamp: libJavaScriptCore.dylib
$(MAKE) install-symrootsLIBRARIES
- touch ./webcore-install-stamp
+ touch ./JavaScriptCore-install-stamp
diff --git a/WebCore/kwq/KWQKSSLKeyGen.h b/JavaScriptCore/dummy.cpp
similarity index 100%
copy from WebCore/kwq/KWQKSSLKeyGen.h
copy to JavaScriptCore/dummy.cpp
diff --git a/WebCore/src/kdelibs/kjs/.cvsignore b/JavaScriptCore/kjs/.cvsignore
similarity index 100%
rename from WebCore/src/kdelibs/kjs/.cvsignore
rename to JavaScriptCore/kjs/.cvsignore
diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index d19853b..726c4af 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,5 +1,73 @@
2002-03-26 Maciej Stachowiak <mjs at apple.com>
+ Removed kjs from here - it's now been moved to JavaScriptCore at
+ the top level.
+
+ * src/Makefile.am: Don't link libkjs.o.
+ * src/kdelibs/Makefile.am: Remove kjs from subdirs.
+ * src/kdelibs/kjs/.cvsignore: Removed.
+ * src/kdelibs/kjs/Makefile.am: Removed.
+ * src/kdelibs/kjs/array_object.cpp: Removed.
+ * src/kdelibs/kjs/array_object.h: Removed.
+ * src/kdelibs/kjs/bool_object.cpp: Removed.
+ * src/kdelibs/kjs/bool_object.h: Removed.
+ * src/kdelibs/kjs/collector.cpp: Removed.
+ * src/kdelibs/kjs/collector.h: Removed.
+ * src/kdelibs/kjs/create_hash_table: Removed.
+ * src/kdelibs/kjs/date_object.cpp: Removed.
+ * src/kdelibs/kjs/date_object.h: Removed.
+ * src/kdelibs/kjs/debugger.cpp: Removed.
+ * src/kdelibs/kjs/debugger.h: Removed.
+ * src/kdelibs/kjs/error_object.cpp: Removed.
+ * src/kdelibs/kjs/error_object.h: Removed.
+ * src/kdelibs/kjs/function.cpp: Removed.
+ * src/kdelibs/kjs/function.h: Removed.
+ * src/kdelibs/kjs/function_object.cpp: Removed.
+ * src/kdelibs/kjs/function_object.h: Removed.
+ * src/kdelibs/kjs/grammar.y: Removed.
+ * src/kdelibs/kjs/internal.cpp: Removed.
+ * src/kdelibs/kjs/internal.h: Removed.
+ * src/kdelibs/kjs/interpreter.cpp: Removed.
+ * src/kdelibs/kjs/interpreter.h: Removed.
+ * src/kdelibs/kjs/keywords.table: Removed.
+ * src/kdelibs/kjs/kjs-test: Removed.
+ * src/kdelibs/kjs/kjs-test.chk: Removed.
+ * src/kdelibs/kjs/lexer.cpp: Removed.
+ * src/kdelibs/kjs/lexer.h: Removed.
+ * src/kdelibs/kjs/lookup.cpp: Removed.
+ * src/kdelibs/kjs/lookup.h: Removed.
+ * src/kdelibs/kjs/math_object.cpp: Removed.
+ * src/kdelibs/kjs/math_object.h: Removed.
+ * src/kdelibs/kjs/nodes.cpp: Removed.
+ * src/kdelibs/kjs/nodes.h: Removed.
+ * src/kdelibs/kjs/nodes2string.cpp: Removed.
+ * src/kdelibs/kjs/number_object.cpp: Removed.
+ * src/kdelibs/kjs/number_object.h: Removed.
+ * src/kdelibs/kjs/object.cpp: Removed.
+ * src/kdelibs/kjs/object.h: Removed.
+ * src/kdelibs/kjs/object_object.cpp: Removed.
+ * src/kdelibs/kjs/object_object.h: Removed.
+ * src/kdelibs/kjs/operations.cpp: Removed.
+ * src/kdelibs/kjs/operations.h: Removed.
+ * src/kdelibs/kjs/property_map.cpp: Removed.
+ * src/kdelibs/kjs/property_map.h: Removed.
+ * src/kdelibs/kjs/regexp.cpp: Removed.
+ * src/kdelibs/kjs/regexp.h: Removed.
+ * src/kdelibs/kjs/regexp_object.cpp: Removed.
+ * src/kdelibs/kjs/regexp_object.h: Removed.
+ * src/kdelibs/kjs/string_object.cpp: Removed.
+ * src/kdelibs/kjs/string_object.h: Removed.
+ * src/kdelibs/kjs/test.js: Removed.
+ * src/kdelibs/kjs/testkjs.cpp: Removed.
+ * src/kdelibs/kjs/types.cpp: Removed.
+ * src/kdelibs/kjs/types.h: Removed.
+ * src/kdelibs/kjs/ustring.cpp: Removed.
+ * src/kdelibs/kjs/ustring.h: Removed.
+ * src/kdelibs/kjs/value.cpp: Removed.
+ * src/kdelibs/kjs/value.h: Removed.
+
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
Removed all the borrowed Qt code.
* src/kwq/KWQGlobal.mm: Renamed from qt/_qglobal.cpp to avoid
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index d19853b..726c4af 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,5 +1,73 @@
2002-03-26 Maciej Stachowiak <mjs at apple.com>
+ Removed kjs from here - it's now been moved to JavaScriptCore at
+ the top level.
+
+ * src/Makefile.am: Don't link libkjs.o.
+ * src/kdelibs/Makefile.am: Remove kjs from subdirs.
+ * src/kdelibs/kjs/.cvsignore: Removed.
+ * src/kdelibs/kjs/Makefile.am: Removed.
+ * src/kdelibs/kjs/array_object.cpp: Removed.
+ * src/kdelibs/kjs/array_object.h: Removed.
+ * src/kdelibs/kjs/bool_object.cpp: Removed.
+ * src/kdelibs/kjs/bool_object.h: Removed.
+ * src/kdelibs/kjs/collector.cpp: Removed.
+ * src/kdelibs/kjs/collector.h: Removed.
+ * src/kdelibs/kjs/create_hash_table: Removed.
+ * src/kdelibs/kjs/date_object.cpp: Removed.
+ * src/kdelibs/kjs/date_object.h: Removed.
+ * src/kdelibs/kjs/debugger.cpp: Removed.
+ * src/kdelibs/kjs/debugger.h: Removed.
+ * src/kdelibs/kjs/error_object.cpp: Removed.
+ * src/kdelibs/kjs/error_object.h: Removed.
+ * src/kdelibs/kjs/function.cpp: Removed.
+ * src/kdelibs/kjs/function.h: Removed.
+ * src/kdelibs/kjs/function_object.cpp: Removed.
+ * src/kdelibs/kjs/function_object.h: Removed.
+ * src/kdelibs/kjs/grammar.y: Removed.
+ * src/kdelibs/kjs/internal.cpp: Removed.
+ * src/kdelibs/kjs/internal.h: Removed.
+ * src/kdelibs/kjs/interpreter.cpp: Removed.
+ * src/kdelibs/kjs/interpreter.h: Removed.
+ * src/kdelibs/kjs/keywords.table: Removed.
+ * src/kdelibs/kjs/kjs-test: Removed.
+ * src/kdelibs/kjs/kjs-test.chk: Removed.
+ * src/kdelibs/kjs/lexer.cpp: Removed.
+ * src/kdelibs/kjs/lexer.h: Removed.
+ * src/kdelibs/kjs/lookup.cpp: Removed.
+ * src/kdelibs/kjs/lookup.h: Removed.
+ * src/kdelibs/kjs/math_object.cpp: Removed.
+ * src/kdelibs/kjs/math_object.h: Removed.
+ * src/kdelibs/kjs/nodes.cpp: Removed.
+ * src/kdelibs/kjs/nodes.h: Removed.
+ * src/kdelibs/kjs/nodes2string.cpp: Removed.
+ * src/kdelibs/kjs/number_object.cpp: Removed.
+ * src/kdelibs/kjs/number_object.h: Removed.
+ * src/kdelibs/kjs/object.cpp: Removed.
+ * src/kdelibs/kjs/object.h: Removed.
+ * src/kdelibs/kjs/object_object.cpp: Removed.
+ * src/kdelibs/kjs/object_object.h: Removed.
+ * src/kdelibs/kjs/operations.cpp: Removed.
+ * src/kdelibs/kjs/operations.h: Removed.
+ * src/kdelibs/kjs/property_map.cpp: Removed.
+ * src/kdelibs/kjs/property_map.h: Removed.
+ * src/kdelibs/kjs/regexp.cpp: Removed.
+ * src/kdelibs/kjs/regexp.h: Removed.
+ * src/kdelibs/kjs/regexp_object.cpp: Removed.
+ * src/kdelibs/kjs/regexp_object.h: Removed.
+ * src/kdelibs/kjs/string_object.cpp: Removed.
+ * src/kdelibs/kjs/string_object.h: Removed.
+ * src/kdelibs/kjs/test.js: Removed.
+ * src/kdelibs/kjs/testkjs.cpp: Removed.
+ * src/kdelibs/kjs/types.cpp: Removed.
+ * src/kdelibs/kjs/types.h: Removed.
+ * src/kdelibs/kjs/ustring.cpp: Removed.
+ * src/kdelibs/kjs/ustring.h: Removed.
+ * src/kdelibs/kjs/value.cpp: Removed.
+ * src/kdelibs/kjs/value.h: Removed.
+
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
Removed all the borrowed Qt code.
* src/kwq/KWQGlobal.mm: Renamed from qt/_qglobal.cpp to avoid
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index d19853b..726c4af 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,5 +1,73 @@
2002-03-26 Maciej Stachowiak <mjs at apple.com>
+ Removed kjs from here - it's now been moved to JavaScriptCore at
+ the top level.
+
+ * src/Makefile.am: Don't link libkjs.o.
+ * src/kdelibs/Makefile.am: Remove kjs from subdirs.
+ * src/kdelibs/kjs/.cvsignore: Removed.
+ * src/kdelibs/kjs/Makefile.am: Removed.
+ * src/kdelibs/kjs/array_object.cpp: Removed.
+ * src/kdelibs/kjs/array_object.h: Removed.
+ * src/kdelibs/kjs/bool_object.cpp: Removed.
+ * src/kdelibs/kjs/bool_object.h: Removed.
+ * src/kdelibs/kjs/collector.cpp: Removed.
+ * src/kdelibs/kjs/collector.h: Removed.
+ * src/kdelibs/kjs/create_hash_table: Removed.
+ * src/kdelibs/kjs/date_object.cpp: Removed.
+ * src/kdelibs/kjs/date_object.h: Removed.
+ * src/kdelibs/kjs/debugger.cpp: Removed.
+ * src/kdelibs/kjs/debugger.h: Removed.
+ * src/kdelibs/kjs/error_object.cpp: Removed.
+ * src/kdelibs/kjs/error_object.h: Removed.
+ * src/kdelibs/kjs/function.cpp: Removed.
+ * src/kdelibs/kjs/function.h: Removed.
+ * src/kdelibs/kjs/function_object.cpp: Removed.
+ * src/kdelibs/kjs/function_object.h: Removed.
+ * src/kdelibs/kjs/grammar.y: Removed.
+ * src/kdelibs/kjs/internal.cpp: Removed.
+ * src/kdelibs/kjs/internal.h: Removed.
+ * src/kdelibs/kjs/interpreter.cpp: Removed.
+ * src/kdelibs/kjs/interpreter.h: Removed.
+ * src/kdelibs/kjs/keywords.table: Removed.
+ * src/kdelibs/kjs/kjs-test: Removed.
+ * src/kdelibs/kjs/kjs-test.chk: Removed.
+ * src/kdelibs/kjs/lexer.cpp: Removed.
+ * src/kdelibs/kjs/lexer.h: Removed.
+ * src/kdelibs/kjs/lookup.cpp: Removed.
+ * src/kdelibs/kjs/lookup.h: Removed.
+ * src/kdelibs/kjs/math_object.cpp: Removed.
+ * src/kdelibs/kjs/math_object.h: Removed.
+ * src/kdelibs/kjs/nodes.cpp: Removed.
+ * src/kdelibs/kjs/nodes.h: Removed.
+ * src/kdelibs/kjs/nodes2string.cpp: Removed.
+ * src/kdelibs/kjs/number_object.cpp: Removed.
+ * src/kdelibs/kjs/number_object.h: Removed.
+ * src/kdelibs/kjs/object.cpp: Removed.
+ * src/kdelibs/kjs/object.h: Removed.
+ * src/kdelibs/kjs/object_object.cpp: Removed.
+ * src/kdelibs/kjs/object_object.h: Removed.
+ * src/kdelibs/kjs/operations.cpp: Removed.
+ * src/kdelibs/kjs/operations.h: Removed.
+ * src/kdelibs/kjs/property_map.cpp: Removed.
+ * src/kdelibs/kjs/property_map.h: Removed.
+ * src/kdelibs/kjs/regexp.cpp: Removed.
+ * src/kdelibs/kjs/regexp.h: Removed.
+ * src/kdelibs/kjs/regexp_object.cpp: Removed.
+ * src/kdelibs/kjs/regexp_object.h: Removed.
+ * src/kdelibs/kjs/string_object.cpp: Removed.
+ * src/kdelibs/kjs/string_object.h: Removed.
+ * src/kdelibs/kjs/test.js: Removed.
+ * src/kdelibs/kjs/testkjs.cpp: Removed.
+ * src/kdelibs/kjs/types.cpp: Removed.
+ * src/kdelibs/kjs/types.h: Removed.
+ * src/kdelibs/kjs/ustring.cpp: Removed.
+ * src/kdelibs/kjs/ustring.h: Removed.
+ * src/kdelibs/kjs/value.cpp: Removed.
+ * src/kdelibs/kjs/value.h: Removed.
+
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
Removed all the borrowed Qt code.
* src/kwq/KWQGlobal.mm: Renamed from qt/_qglobal.cpp to avoid
diff --git a/WebCore/src/Makefile.am b/WebCore/src/Makefile.am
index 35729be..bbcac83 100644
--- a/WebCore/src/Makefile.am
+++ b/WebCore/src/Makefile.am
@@ -15,13 +15,12 @@ libwebcore_dylib_SOURCES = \
$(NULL)
libwebcore_dylib_LIBADD = \
- ./kdelibs/kjs/libkjs.o \
./kdelibs/khtml/libkhtml.o \
./kwq/libkwq.o \
-ljpeg \
+ -L$(symrootsdir) -lJavaScriptCore \
$(NULL)
-
LIBWEBCORE_INSTALL_PATH = @executable_path/../Frameworks
DYLIB_NAME = libwebcore.dylib
diff --git a/WebCore/src/kdelibs/Makefile.am b/WebCore/src/kdelibs/Makefile.am
index 17c0dfb..246964d 100644
--- a/WebCore/src/kdelibs/Makefile.am
+++ b/WebCore/src/kdelibs/Makefile.am
@@ -1,7 +1,6 @@
NULL=
SUBDIRS = \
- kjs \
kdecore \
khtml \
$(NULL)
diff --git a/WebCore/src/kdelibs/kjs/Makefile.am b/WebCore/src/kdelibs/kjs/Makefile.am
deleted file mode 100644
index 397059a..0000000
--- a/WebCore/src/kdelibs/kjs/Makefile.am
+++ /dev/null
@@ -1,106 +0,0 @@
-NULL =
-
-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 \
- bool_object.cpp \
- bool_object.h \
- collector.cpp \
- collector.h \
- date_object.cpp \
- date_object.h \
- debugger.cpp \
- debugger.h \
- error_object.cpp \
- error_object.h \
- function.cpp \
- function.h \
- function_object.cpp \
- function_object.h \
- grammar.cpp \
- grammar.h \
- internal.cpp \
- internal.h \
- interpreter.cpp \
- interpreter.h \
- lexer.cpp \
- lexer.h \
- lexer.lut.h \
- lookup.cpp \
- lookup.h \
- math_object.cpp \
- math_object.h \
- math_object.lut.h \
- nodes.cpp \
- nodes.h \
- number_object.cpp \
- number_object.h \
- object.cpp \
- object.h \
- object_object.cpp \
- object_object.h \
- operations.cpp \
- operations.h \
- property_map.cpp \
- property_map.h \
- regexp.cpp \
- regexp.h \
- regexp_object.cpp \
- regexp_object.h \
- string_object.cpp \
- string_object.h \
- types.cpp \
- types.h \
- ustring.cpp \
- ustring.h \
- value.cpp \
- value.h \
- $(NULL)
-
-noinst_PROGRAMS = testkjs
-
-testkjs_SOURCES = testkjs.cpp
-
-testkjs_LDADD = $(srcdir)/libkjs.o
-
-YACCFLAGS = -d --output-file=grammar.cpp --file-prefix=grammar --name-prefix=kjsyy
-
-GRAMMAR_FILES = grammar.h grammar.cpp.h grammar.cpp
-
-$(GRAMMAR_FILES): grammar-stamp
-
-grammar-stamp: grammar.y
- $(YACC) $(YACCFLAGS) $<
- ln -sf grammar.cpp.h grammar.h
- touch ./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)
-
diff --git a/WebCore/src/kdelibs/kjs/array_object.cpp b/WebCore/src/kdelibs/kjs/array_object.cpp
deleted file mode 100644
index a8aa622..0000000
--- a/WebCore/src/kdelibs/kjs/array_object.cpp
+++ /dev/null
@@ -1,527 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "array_object.h"
-#include "internal.h"
-#include "error_object.h"
-
-#include "array_object.lut.h"
-
-#include <stdio.h>
-#include <assert.h>
-
-using namespace KJS;
-
-// ------------------------------ ArrayInstanceImp -----------------------------
-
-const ClassInfo ArrayInstanceImp::info = {"Array", 0, 0, 0};
-
-ArrayInstanceImp::ArrayInstanceImp(const Object &proto)
- : ObjectImp(proto)
-{
-}
-
-// Special implementation of [[Put]] - see ECMA 15.4.5.1
-void ArrayInstanceImp::put(ExecState *exec, const UString &propertyName, const Value &value, int attr)
-{
- if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName))
- return;
-
- if (hasProperty(exec,propertyName)) {
- if (propertyName == "length") {
- Value len = get(exec,"length");
- unsigned int oldLen = len.toUInt32(exec);
- unsigned int newLen = value.toUInt32(exec);
- // shrink array
- for (unsigned int u = newLen; u < oldLen; u++) {
- UString p = UString::from(u);
- if (hasProperty(exec, p, false))
- deleteProperty(exec, p);
- }
- ObjectImp::put(exec, "length", Number(newLen), DontEnum | DontDelete);
- return;
- }
- // put(p, v);
- } // } else
- ObjectImp::put(exec, propertyName, value, attr);
-
- // array index ?
- unsigned int idx;
- if (!sscanf(propertyName.cstring().c_str(), "%u", &idx)) /* TODO */
- return;
-
- // do we need to update/create the length property ?
- if (hasProperty(exec, "length", false)) {
- Value len = get(exec, "length");
- if (idx < len.toUInt32(exec))
- return;
- }
-
- ObjectImp::put(exec, "length", Number(idx+1), DontDelete | DontEnum);
-}
-
-void ArrayInstanceImp::putDirect(ExecState *exec, const UString &propertyName, const Value &value, int attr)
-{
- ObjectImp::put(exec,propertyName,value,attr);
-}
-// ------------------------------ ArrayPrototypeImp ----------------------------
-
-const ClassInfo ArrayPrototypeImp::info = {"Array", &ArrayInstanceImp::info, &arrayTable, 0};
-
-/* Source for array_object.lut.h
- at begin arrayTable 13
- toString ArrayProtoFuncImp::ToString DontEnum|Function 0
- toLocaleString ArrayProtoFuncImp::ToLocaleString DontEnum|Function 0
- concat ArrayProtoFuncImp::Concat DontEnum|Function 1
- join ArrayProtoFuncImp::Join DontEnum|Function 1
- pop ArrayProtoFuncImp::Pop DontEnum|Function 0
- push ArrayProtoFuncImp::Push DontEnum|Function 1
- reverse ArrayProtoFuncImp::Reverse DontEnum|Function 0
- shift ArrayProtoFuncImp::Shift DontEnum|Function 0
- slice ArrayProtoFuncImp::Slice DontEnum|Function 2
- sort ArrayProtoFuncImp::Sort DontEnum|Function 1
- splice ArrayProtoFuncImp::Splice DontEnum|Function 2
- unshift ArrayProtoFuncImp::UnShift DontEnum|Function 1
- at end
-*/
-
-// ECMA 15.4.4
-ArrayPrototypeImp::ArrayPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto)
- : ArrayInstanceImp(Object(objProto))
-{
- Value protect(this);
- setInternalValue(Null());
-
- // The constructor will be added later, by InterpreterImp, once ArrayObjectImp has been constructed.
- put(exec,"length", Number(0), DontEnum | DontDelete);
-}
-
-Value ArrayPrototypeImp::get(ExecState *exec, const UString &propertyName) const
-{
- //fprintf( stderr, "ArrayPrototypeImp::get(%s)\n", propertyName.ascii() );
- return lookupGetFunction<ArrayProtoFuncImp, ArrayInstanceImp>( exec, propertyName, &arrayTable, this );
-}
-
-// ------------------------------ ArrayProtoFuncImp ----------------------------
-
-ArrayProtoFuncImp::ArrayProtoFuncImp(ExecState *exec, int i, int len)
- : InternalFunctionImp(
- static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
- ), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-bool ArrayProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.4.4
-Value ArrayProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)
-{
- unsigned int length = thisObj.get(exec,"length").toUInt32(exec);
-
- Value result;
- switch (id) {
- case ToLocaleString:
- // TODO - see 15.4.4.3
- // fall through
- case ToString:
-
- if (!thisObj.inherits(&ArrayInstanceImp::info)) {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
- // fall through
-
- case Join: {
- UString separator = ",";
- UString str = "";
-
- if (args.size() > 0)
- separator = args[0].toString(exec);
- for (unsigned int k = 0; k < length; k++) {
- if (k >= 1)
- str += separator;
- Value element = thisObj.get(exec,UString::from(k));
- if (element.type() != UndefinedType && element.type() != NullType)
- str += element.toString(exec);
- }
- result = String(str);
- break;
- }
- case Concat: {
- Object arr = Object::dynamicCast(exec->interpreter()->builtinArray().construct(exec,List::empty()));
- int n = 0;
- Value curArg = thisObj;
- Object curObj = Object::dynamicCast(thisObj);
- ListIterator it = args.begin();
- for (;;) {
- if (curArg.type() == ObjectType &&
- curObj.inherits(&ArrayInstanceImp::info)) {
- unsigned int k = 0;
- if (n > 0)
- length = curObj.get(exec,"length").toUInt32(exec);
- while (k < length) {
- UString p = UString::from(k);
- if (curObj.hasProperty(exec,p))
- arr.put(exec,UString::from(n), curObj.get(exec,p));
- n++;
- k++;
- }
- } else {
- arr.put(exec,UString::from(n), curArg);
- n++;
- }
- if (it == args.end())
- break;
- curArg = *it;
- curObj = Object::dynamicCast(it++); // may be 0
- }
- arr.put(exec,"length", Number(n), DontEnum | DontDelete);
-
- result = arr;
- break;
- }
- case Pop:{
-
- if (length == 0) {
- thisObj.put(exec, "length", Number(length), DontEnum | DontDelete);
- result = Undefined();
- } else {
- UString str = UString::from(length - 1);
- result = thisObj.get(exec,str);
- thisObj.deleteProperty(exec, str);
- thisObj.put(exec, "length", Number(length - 1), DontEnum | DontDelete);
- }
- break;
- }
- case Push: {
- for (int n = 0; n < args.size(); n++)
- thisObj.put(exec,UString::from(length + n), args[n]);
- length += args.size();
- thisObj.put(exec,"length", Number(length), DontEnum | DontDelete);
- result = Number(length);
- break;
- }
- case Reverse: {
-
- unsigned int middle = length / 2;
-
- for (unsigned int k = 0; k < middle; k++) {
- UString str = UString::from(k);
- UString str2 = UString::from(length - k - 1);
- Value obj = thisObj.get(exec,str);
- Value obj2 = thisObj.get(exec,str2);
- if (thisObj.hasProperty(exec,str2)) {
- if (thisObj.hasProperty(exec,str)) {
- thisObj.put(exec, str, obj2);
- thisObj.put(exec, str2, obj);
- } else {
- thisObj.put(exec, str, obj2);
- thisObj.deleteProperty(exec, str2);
- }
- } else {
- if (thisObj.hasProperty(exec, str)) {
- thisObj.deleteProperty(exec, str);
- thisObj.put(exec, str2, obj);
- } else {
- // why delete something that's not there ? Strange.
- thisObj.deleteProperty(exec, str);
- thisObj.deleteProperty(exec, str2);
- }
- }
- }
- result = thisObj;
- break;
- }
- case Shift: {
- if (length == 0) {
- thisObj.put(exec, "length", Number(length), DontEnum | DontDelete);
- result = Undefined();
- } else {
- result = thisObj.get(exec, "0");
- for(unsigned int k = 1; k < length; k++) {
- UString str = UString::from(k);
- UString str2 = UString::from(k-1);
- if (thisObj.hasProperty(exec, str)) {
- Value obj = thisObj.get(exec, str);
- thisObj.put(exec, str2, obj);
- } else
- thisObj.deleteProperty(exec, str2);
- }
- thisObj.deleteProperty(exec, UString::from(length - 1));
- thisObj.put(exec, "length", Number(length - 1), DontEnum | DontDelete);
- }
- break;
- }
- case Slice: {
- // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10
-
- // We return a new array
- Object resObj = Object::dynamicCast(exec->interpreter()->builtinArray().construct(exec,List::empty()));
- result = resObj;
- int begin = args[0].toUInt32(exec);
- if ( begin < 0 )
- begin = maxInt( begin + length, 0 );
- else
- begin = minInt( begin, length );
- int end = length;
- if (args[1].type() != UndefinedType)
- {
- end = args[1].toUInt32(exec);
- if ( end < 0 )
- end = maxInt( end + length, 0 );
- else
- end = minInt( end, length );
- }
-
- //printf( "Slicing from %d to %d \n", begin, end );
- for(unsigned int k = 0; k < (unsigned int) end-begin; k++) {
- UString str = UString::from(k+begin);
- if (thisObj.hasProperty(exec,str)) {
- UString str2 = UString::from(k);
- Value obj = thisObj.get(exec, str);
- resObj.put(exec, str2, obj);
- }
- }
- resObj.put(exec, "length", Number(end - begin), DontEnum | DontDelete);
- break;
- }
- case Sort:{
-#if 0
- printf("KJS Array::Sort length=%d\n", length);
- for ( unsigned int i = 0 ; i<length ; ++i )
- printf("KJS Array::Sort: %d: %s\n", i, thisObj.get(UString::from(i)).toString().value().ascii() );
-#endif
- Object sortFunction;
- bool useSortFunction = (args[0].type() != UndefinedType);
- if (useSortFunction)
- {
- sortFunction = args[0].toObject(exec);
- if (!sortFunction.implementsCall())
- useSortFunction = false;
- }
-
- if (length == 0) {
- thisObj.put(exec, "length", Number(0), DontEnum | DontDelete);
- result = Undefined();
- break;
- }
-
- // "Min" sort. Not the fastest, but definitely less code than heapsort
- // or quicksort, and much less swapping than bubblesort/insertionsort.
- for ( unsigned int i = 0 ; i<length-1 ; ++i )
- {
- Value iObj = thisObj.get(exec,UString::from(i));
- unsigned int themin = i;
- Value minObj = iObj;
- for ( unsigned int j = i+1 ; j<length ; ++j )
- {
- Value jObj = thisObj.get(exec,UString::from(j));
- int cmp;
- if ( useSortFunction )
- {
- List l;
- l.append(jObj);
- l.append(minObj);
- Object thisObj = exec->interpreter()->globalObject();
- cmp = sortFunction.call(exec,thisObj, l ).toInt32(exec);
- }
- else
- cmp = (jObj.toString(exec) < minObj.toString(exec)) ? -1 : 1;
- if ( cmp < 0 )
- {
- themin = j;
- minObj = jObj;
- }
- }
- // Swap themin and i
- if ( themin > i )
- {
- //printf("KJS Array::Sort: swapping %d and %d\n", i, themin );
- thisObj.put( exec, UString::from(i), minObj );
- thisObj.put( exec, UString::from(themin), iObj );
- }
- }
-#if 0
- printf("KJS Array::Sort -- Resulting array:\n");
- for ( unsigned int i = 0 ; i<length ; ++i )
- printf("KJS Array::Sort: %d: %s\n", i, thisObj.get(UString::from(i)).toString().value().ascii() );
-#endif
- result = thisObj;
- break;
- }
- case Splice: {
- // 15.4.4.12 - oh boy this is huge
- Object resObj = Object::dynamicCast(exec->interpreter()->builtinArray().construct(exec,List::empty()));
- result = resObj;
- int begin = args[0].toUInt32(exec);
- if ( begin < 0 )
- begin = maxInt( begin + length, 0 );
- else
- begin = minInt( begin, length );
- unsigned int deleteCount = minInt( maxInt( args[1].toUInt32(exec), 0 ), length - begin );
-
- //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount );
- for(unsigned int k = 0; k < deleteCount; k++) {
- UString str = UString::from(k+begin);
- if (thisObj.hasProperty(exec,str)) {
- UString str2 = UString::from(k);
- Value obj = thisObj.get(exec, str);
- resObj.put(exec, str2, obj);
- }
- }
- resObj.put(exec, "length", Number(deleteCount), DontEnum | DontDelete);
-
- unsigned int additionalArgs = maxInt( args.size() - 2, 0 );
- if ( additionalArgs != deleteCount )
- {
- if ( additionalArgs < deleteCount )
- {
- for ( unsigned int k = begin; k < length - deleteCount; ++k )
- {
- UString str = UString::from(k+deleteCount);
- UString str2 = UString::from(k+additionalArgs);
- if (thisObj.hasProperty(exec,str)) {
- Value obj = thisObj.get(exec, str);
- thisObj.put(exec, str2, obj);
- }
- else
- thisObj.deleteProperty(exec, str2);
- }
- for ( unsigned int k = length ; k > length - deleteCount + additionalArgs; --k )
- thisObj.deleteProperty(exec, UString::from(k-1));
- }
- else
- {
- for ( unsigned int k = length - deleteCount; (int)k > begin; --k )
- {
- UString str = UString::from(k+deleteCount-1);
- UString str2 = UString::from(k+additionalArgs-1);
- if (thisObj.hasProperty(exec,str)) {
- Value obj = thisObj.get(exec, str);
- thisObj.put(exec, str2, obj);
- }
- else
- thisObj.deleteProperty(exec, str2);
- }
- }
- }
- for ( unsigned int k = 0; k < additionalArgs; ++k )
- {
- thisObj.put(exec, UString::from(k+begin), args[k+2]);
- }
- thisObj.put(exec, "length", Number(length - deleteCount + additionalArgs), DontEnum | DontDelete);
- break;
- }
- case UnShift: { // 15.4.4.13
- unsigned int nrArgs = args.size();
- for ( unsigned int k = length; k > 0; --k )
- {
- UString str = UString::from(k-1);
- UString str2 = UString::from(k+nrArgs-1);
- if (thisObj.hasProperty(exec,str)) {
- Value obj = thisObj.get(exec, str);
- thisObj.put(exec, str2, obj);
- } else {
- thisObj.deleteProperty(exec, str2);
- }
- }
- for ( unsigned int k = 0; k < nrArgs; ++k )
- thisObj.put(exec, UString::from(k), args[k]);
- result = Number(length + nrArgs);
- thisObj.put(exec, "length", result, DontEnum | DontDelete);
- break;
- }
- default:
- assert(0);
- break;
- }
- return result;
-}
-
-// ------------------------------ ArrayObjectImp -------------------------------
-
-ArrayObjectImp::ArrayObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- ArrayPrototypeImp *arrayProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- // ECMA 15.4.3.1 Array.prototype
- put(exec,"prototype", Object(arrayProto), DontEnum|DontDelete|ReadOnly);
-
- // no. of arguments for constructor
- put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
-}
-
-bool ArrayObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.4.2
-Object ArrayObjectImp::construct(ExecState *exec, const List &args)
-{
- Object result(new ArrayInstanceImp(exec->interpreter()->builtinArrayPrototype()));
-
- unsigned int len;
- ListIterator it = args.begin();
- // a single argument might denote the array size
- if (args.size() == 1 && it->type() == NumberType)
- len = it->toUInt32(exec);
- else {
- // initialize array
- len = args.size();
- for (unsigned int u = 0; it != args.end(); it++, u++)
- result.put(exec, UString::from(u), *it);
- }
-
- // array size
- result.put(exec, "length", Number(len), DontEnum | DontDelete);
- static_cast<ArrayInstanceImp*>(result.imp())->putDirect(exec, "length", Number(len), DontEnum | DontDelete);
-
- return result;
-}
-
-bool ArrayObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.6.1
-Value ArrayObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- // equivalent to 'new Array(....)'
- return construct(exec,args);
-}
-
diff --git a/WebCore/src/kdelibs/kjs/array_object.h b/WebCore/src/kdelibs/kjs/array_object.h
deleted file mode 100644
index 17641d1..0000000
--- a/WebCore/src/kdelibs/kjs/array_object.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class ArrayInstanceImp : public ObjectImp {
- public:
- 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 ArrayPrototypeImp : public ArrayInstanceImp {
- public:
- 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 ArrayProtoFuncImp : public InternalFunctionImp {
- public:
- 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
diff --git a/WebCore/src/kdelibs/kjs/bool_object.cpp b/WebCore/src/kdelibs/kjs/bool_object.cpp
deleted file mode 100644
index 7e10643..0000000
--- a/WebCore/src/kdelibs/kjs/bool_object.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 "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;
-
-// ------------------------------ BooleanInstanceImp ---------------------------
-
-const ClassInfo BooleanInstanceImp::info = {"Boolean", 0, 0, 0};
-
-BooleanInstanceImp::BooleanInstanceImp(const Object &proto)
- : ObjectImp(proto)
-{
-}
-
-// ------------------------------ BooleanPrototypeImp --------------------------
-
-// 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()
-
- 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));
-}
-
-
-// ------------------------------ 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);
-}
-
-
-bool BooleanProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-
-// ECMA 15.6.4.2 + 15.6.4.3
-Value BooleanProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)
-{
- // 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 Boolean(v.toBoolean(exec)); /* TODO: optimize for bool case */
-}
-
-// ------------------------------ BooleanObjectImp -----------------------------
-
-
-BooleanObjectImp::BooleanObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- BooleanPrototypeImp *booleanProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- put(exec,"prototype", Object(booleanProto),DontEnum|DontDelete|ReadOnly);
-
- // no. of arguments for constructor
- put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
-}
-
-
-bool BooleanObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.6.2
-Object BooleanObjectImp::construct(ExecState *exec, const List &args)
-{
- Object proto = exec->interpreter()->builtinBooleanPrototype();
- Object obj(new BooleanInstanceImp(proto));
-
- Boolean b;
- if (args.size() > 0)
- b = args.begin()->toBoolean(exec);
- else
- b = Boolean(false);
-
- obj.setInternalValue(b);
-
- return obj;
-}
-
-bool BooleanObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.6.1
-Value BooleanObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- if (args.isEmpty())
- return Boolean(false);
- else
- return Boolean(args[0].toBoolean(exec)); /* TODO: optimize for bool case */
-}
-
diff --git a/WebCore/src/kdelibs/kjs/bool_object.h b/WebCore/src/kdelibs/kjs/bool_object.h
deleted file mode 100644
index c395179..0000000
--- a/WebCore/src/kdelibs/kjs/bool_object.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _BOOL_OBJECT_H_
-#define _BOOL_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class BooleanInstanceImp : public ObjectImp {
- public:
- BooleanInstanceImp(const Object &proto);
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- /**
- * @internal
- *
- * The initial value of Boolean.prototype (and thus all objects created
- * with the Boolean constructor
- */
- class BooleanPrototypeImp : public BooleanInstanceImp {
- public:
- BooleanPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objectProto,
- FunctionPrototypeImp *funcProto);
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * Boolean.prototype object
- */
- class BooleanProtoFuncImp : public InternalFunctionImp {
- public:
- BooleanProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto, int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { ToString, ValueOf };
- private:
- int id;
- };
-
- /**
- * @internal
- *
- * The initial value of the the global variable's "Boolean" property
- */
- class BooleanObjectImp : public InternalFunctionImp {
- friend class BooleanProtoFuncImp;
- public:
- BooleanObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- BooleanPrototypeImp *booleanProto);
-
- 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
diff --git a/WebCore/src/kdelibs/kjs/collector.cpp b/WebCore/src/kdelibs/kjs/collector.cpp
deleted file mode 100644
index 2bed7e1..0000000
--- a/WebCore/src/kdelibs/kjs/collector.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include "collector.h"
-#include "internal.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#ifdef KJS_DEBUG_MEM
-#include <typeinfo>
-#endif
-
-namespace KJS {
-
- class CollectorBlock {
- public:
- CollectorBlock(int s);
- ~CollectorBlock();
- int size;
- int filled;
- void** mem;
- CollectorBlock *prev, *next;
- };
-
-}; // namespace
-
-using namespace KJS;
-
-CollectorBlock::CollectorBlock(int s)
- : size(s),
- filled(0),
- prev(0L),
- next(0L)
-{
- mem = new void*[size];
- memset(mem, 0, size * sizeof(void*));
-}
-
-CollectorBlock::~CollectorBlock()
-{
- delete [] mem;
- mem = 0L;
-}
-
-CollectorBlock* Collector::root = 0L;
-CollectorBlock* Collector::currentBlock = 0L;
-unsigned long Collector::filled = 0;
-unsigned long Collector::softLimit = KJS_MEM_INCREMENT;
-
-unsigned long Collector::timesFilled = 0;
-unsigned long Collector::increaseLimitAt = 1;
-
-bool Collector::memLimitReached = false;
-
-#ifdef KJS_DEBUG_MEM
-bool Collector::collecting = false;
-#endif
-
-void* Collector::allocate(size_t s)
-{
- if (s == 0)
- return 0L;
-
- // Try and deal with memory requirements in a scalable way. Simple scripts
- // should only require small amounts of memory, but for complex scripts we don't
- // want to end up running the garbage collector hundreds of times a second.
- if (filled >= softLimit) {
- timesFilled++;
- collect();
-
- if (filled >= softLimit && softLimit < KJS_MEM_LIMIT) {
- // Even after collection we are still using more than the limit, so increase
- // the limit
- softLimit *= 2;
- }
- else if (timesFilled == increaseLimitAt && increaseLimitAt < 128) {
- // The allowed memory limit keeps getting reached (lots of objects created
- // and deleted). Increase it a bit so GC gets run less often.
- timesFilled = 0;
- softLimit *= 2;
- increaseLimitAt *= 2;
- }
- }
-
- void *m = malloc(s);
-#ifdef KJS_DEBUG_MEM
- //fprintf( stderr, "allocate: size=%d valueimp=%p\n",s,m);
-#endif
-
- // VI_CREATED and VI_GCALLOWED being unset ensure that value
- // is protected from GC before any constructors are run
- static_cast<ValueImp*>(m)->_flags = 0;
-
- if (!root) {
- root = new CollectorBlock(BlockSize);
- currentBlock = root;
- }
-
- CollectorBlock *block = currentBlock;
- if (!block)
- block = root;
-
- // search for a block with space left
- while (block->next && block->filled == block->size)
- block = block->next;
-
- if (block->filled >= block->size) {
-#ifdef KJS_DEBUG_MEM
- //fprintf( stderr, "allocating new block of size %d\n", block->size);
-#endif
- CollectorBlock *tmp = new CollectorBlock(BlockSize);
- block->next = tmp;
- tmp->prev = block;
- block = tmp;
- }
- currentBlock = block;
- // look for a free spot in the block
- void **r = block->mem;
- while (*r)
- r++;
- *r = m;
- filled++;
- block->filled++;
-
- if (softLimit >= KJS_MEM_LIMIT) {
- memLimitReached = true;
- fprintf(stderr,"Out of memory");
- }
-
- return m;
-}
-
-/**
- * Mark-sweep garbage collection.
- */
-bool Collector::collect()
-{
-#ifdef KJS_DEBUG_MEM
- fprintf(stderr,"Collector::collect()\n");
-#endif
- bool deleted = false;
- // MARK: first unmark everything
- CollectorBlock *block = root;
- while (block) {
- ValueImp **r = (ValueImp**)block->mem;
- assert(r);
- for (int i = 0; i < block->size; i++, r++)
- if (*r) {
- (*r)->_flags &= ~ValueImp::VI_MARKED;
- }
- block = block->next;
- }
-
- // mark all referenced objects recursively
- // starting out from the set of root objects
- if (InterpreterImp::s_hook) {
- InterpreterImp *scr = InterpreterImp::s_hook;
- do {
- //fprintf( stderr, "Collector marking interpreter %p\n",(void*)scr);
- scr->mark();
- scr = scr->next;
- } while (scr != InterpreterImp::s_hook);
- }
-
- // mark any other objects that we wouldn't delete anyway
- block = root;
- while (block) {
- ValueImp **r = (ValueImp**)block->mem;
- assert(r);
- for (int i = 0; i < block->size; i++, r++)
- {
- ValueImp *imp = (*r);
- // Check for created=true, marked=false and (gcallowed=false or refcount>0)
- if (imp &&
- (imp->_flags & (ValueImp::VI_CREATED|ValueImp::VI_MARKED)) == ValueImp::VI_CREATED &&
- ( (imp->_flags & ValueImp::VI_GCALLOWED) == 0 || imp->refcount ) ) {
- //fprintf( stderr, "Collector marking imp=%p\n",(void*)imp);
- imp->mark();
- }
- }
- block = block->next;
- }
-
- // SWEEP: delete everything with a zero refcount (garbage)
- block = root;
- while (block) {
- ValueImp **r = (ValueImp**)block->mem;
- int del = 0;
- for (int i = 0; i < block->size; i++, r++) {
- ValueImp *imp = (*r);
- // Can delete if refcount==0, created==true, gcAllowed==true, and marked==false
- // Make sure to update the test if you add more bits to _flags.
- if (imp &&
- !imp->refcount && imp->_flags == (ValueImp::VI_GCALLOWED | ValueImp::VI_CREATED)) {
- // emulate destructing part of 'operator delete()'
- //fprintf( stderr, "Collector::deleting ValueImp %p (%s)\n", (void*)imp, typeid(*imp).name());
- imp->~ValueImp();
- free(imp);
- *r = 0L;
- del++;
- }
- }
- filled -= del;
- block->filled -= del;
- block = block->next;
- if (del)
- deleted = true;
- }
-
- // delete the empty containers
- block = root;
- while (block) {
- CollectorBlock *next = block->next;
- if (block->filled == 0) {
- if (block->prev)
- block->prev->next = next;
- if (block == root)
- root = next;
- if (next)
- next->prev = block->prev;
- if (block == currentBlock) // we don't want a dangling pointer
- currentBlock = 0L;
- assert(block != root);
- delete block;
- }
- block = next;
- }
-#if 0
- // This is useful to track down memory leaks
- static int s_count = 0;
- fprintf(stderr, "Collector done (was run %d)\n",s_count);
- if (s_count++ % 50 == 2)
- finalCheck();
-#endif
- return deleted;
-}
-
-#ifdef KJS_DEBUG_MEM
-void Collector::finalCheck()
-{
- CollectorBlock *block = root;
- while (block) {
- ValueImp **r = (ValueImp**)block->mem;
- for (int i = 0; i < block->size; i++, r++) {
- if (*r ) {
- fprintf( stderr, "Collector::finalCheck() still having ValueImp %p (%s) [marked:%d gcAllowed:%d created:%d refcount:%d]\n",
- (void*)(*r), typeid( **r ).name(),
- (bool)((*r)->_flags & ValueImp::VI_MARKED),
- (bool)((*r)->_flags & ValueImp::VI_GCALLOWED),
- (bool)((*r)->_flags & ValueImp::VI_CREATED),
- (*r)->refcount);
- }
- }
- block = block->next;
- }
-}
-#endif
diff --git a/WebCore/src/kdelibs/kjs/collector.h b/WebCore/src/kdelibs/kjs/collector.h
deleted file mode 100644
index 86cc210..0000000
--- a/WebCore/src/kdelibs/kjs/collector.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _KJSCOLLECTOR_H_
-#define _KJSCOLLECTOR_H_
-
-// KJS_MEM_LIMIT and KJS_MEM_INCREMENT can be tweaked to adjust how the
-// garbage collector allocates memory. KJS_MEM_LIMIT is the largest # of objects
-// the collector will allow to be present in memory. Once this limit is reached,
-// a running script will get an "out of memory" exception.
-//
-// KJS_MEM_INCREMENT specifies the amount by which the "soft limit" on memory is
-// increased when the memory gets filled up. The soft limit is the amount after
-// which the GC will run and delete unused objects.
-//
-// If you are debugging seemingly random crashes where an object has been deleted,
-// try setting KJS_MEM_INCREMENT to something small, e.g. 300, to force garbage
-// collection to happen more often, and disable the softLimit increase &
-// out-of-memory testing code in Collector::allocate()
-
-#define KJS_MEM_LIMIT 500000
-#define KJS_MEM_INCREMENT 1000
-
-#include <stdlib.h>
-
-// for DEBUG_*
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-
-namespace KJS {
-
- class CollectorBlock;
-
- /**
- * @short Garbage collector.
- */
- class Collector {
- // disallow direct construction/destruction
- Collector();
- public:
- /**
- * Register an object with the collector. The following assumptions are
- * made:
- * @li the operator new() of the object class is overloaded.
- * @li operator delete() has been overloaded as well and does not free
- * the memory on its own.
- *
- * @param s Size of the memory to be registered.
- * @return A pointer to the allocated memory.
- */
- static void* allocate(size_t s);
- /**
- * Run the garbage collection. This involves calling the delete operator
- * on each object and freeing the used memory.
- */
- static bool collect();
- static int size() { return filled; }
- static bool outOfMemory() { return memLimitReached; }
-
-#ifdef KJS_DEBUG_MEM
- /** Check that nothing is left when the last interpreter gets deleted */
- static void finalCheck();
- /**
- * @internal
- */
- static bool collecting;
-#endif
- private:
- static CollectorBlock* root;
- static CollectorBlock* currentBlock;
- static unsigned long filled;
- static unsigned long softLimit;
- static unsigned long timesFilled;
- static unsigned long increaseLimitAt;
- static bool memLimitReached;
- enum { BlockSize = 100 };
- };
-
-};
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/create_hash_table b/WebCore/src/kdelibs/kjs/create_hash_table
deleted file mode 100755
index 689e777..0000000
--- a/WebCore/src/kdelibs/kjs/create_hash_table
+++ /dev/null
@@ -1,161 +0,0 @@
-#! /usr/bin/perl -w
-#
-# Static Hashtable Generator
-#
-# (c) 2000-2002 by Harri Porten <porten at kde.org> and
-# David Faure <faure at kde.org>
-
-$file = $ARGV[0];
-shift;
-my $findSize = 0;
-my $includelookup = 0;
-# Use -s as second argument to make it try many hash sizes
-$findSize = 1 if (defined($ARGV[0]) && $ARGV[0] eq "-s");
-# Use -i as second argument to make it include "lookup.h"
-$includelookup = 1 if (defined($ARGV[0]) && $ARGV[0] eq "-i");
-print STDERR "Creating hashtable for $file\n";
-open(IN, $file) or die "No such file $file";
-
- at keys = ();
- at values = ();
- at attrs = ();
- at params = ();
-
-my $inside = 0;
-my $name;
-my $size;
-my $hashsize;
-my $banner = 0;
-sub calcTable();
-sub output();
-sub hashValue($);
-
-while (<IN>) {
- chop;
- s/^\s*//g;
- if (/^\#|^$/) {
- # comment. do nothing
- } elsif (/^\@begin\s*(\w+)\s*(\d+)\s*$/ && !$inside) {
- $inside = 1;
- $name = $1;
- $hashsize = $2;
- } elsif (/^\@end\s*$/ && $inside) {
-
- if($findSize) {
- my $entriesnum=@keys;
- print STDERR "Table: $name $entriesnum entries\n";
- for( $i=3 ; $i<79 ; ++$i) { $hashsize=$i ; calcTable(); }
- } else {
- calcTable();
- }
-
- output();
- @keys = ();
- @values = ();
- @attrs = ();
- @params = ();
- $inside = 0;
- } elsif (/^([\w\[\=\]]+)\s*([\w\:-]+)\s*([\w\|]*)\s*(\w*)\s*$/ && $inside) {
- my $key = $1;
- my $val = $2;
- my $att = $3;
- my $param = $4;
- push(@keys, $key);
- push(@values, $val);
- printf STDERR "WARNING: Number of arguments missing for $key/$val\n"
- if ( $att =~ m/Function/ && length($param) == 0);
- push(@attrs, length($att) > 0 ? $att : "0");
- push(@params, length($param) > 0 ? $param : "0");
- } elsif ($inside) {
- die "invalid data";
- }
-}
-
-die "missing closing \@end" if ($inside);
-
-sub calcTable() {
- @table = ();
- @links = ();
- $size = $hashsize;
- my $collisions = 0;
- my $maxdepth = 0;
- my $i = 0;
- foreach $key (@keys) {
- my $depth = 0;
- my $h = hashValue($key) % $hashsize;
- while (defined($table[$h])) {
- if (defined($links[$h])) {
- $h = $links[$h];
- $depth++;
- } else {
- $collisions++;
- $links[$h] = $size;
- $h = $size;
- $size++;
- }
- }
- $table[$h] = $i;
- $i++;
- $maxdepth = $depth if ( $depth > $maxdepth);
- }
-
- if ($findSize) {
- my $emptycount = 0;
- foreach $entry (@table) {
- $emptycount++ if (!defined($entry));
- }
- print STDERR "Hashsize: $hashsize Total Size: $size Empty: $emptycount MaxDepth: $maxdepth Collisions: $collisions\n";
- }
-# my $i = 0;
-# foreach $entry (@table) {
-# print "$i " . $entry;
-# print " -> " . $links[$i] if (defined($links[$i]));
-# print "\n";
-# $i++;
-# }
-}
-
-sub hashValue($) {
- @chars = split(/ */, $_[0]);
- my $val = 0;
- foreach $c (@chars) {
- $val += ord($c);
- }
- return $val;
-}
-
-sub output() {
- if (!$banner) {
- $banner = 1;
- print "/* Automatically generated from $file using $0. DO NOT EDIT ! */\n";
- }
-
- print "\n#include \"lookup.h\"\n" if ($includelookup);
- print "\nnamespace KJS {\n";
- print "\nconst struct HashEntry ${name}Entries[] = {\n";
- my $i = 0;
- foreach $entry (@table) {
- if (defined($entry)) {
- my $key = $keys[$entry];
- print " \{ \"" . $key . "\"";
- print ", " . $values[$entry];
- print ", " . $attrs[$entry];
- print ", " . $params[$entry];
- print ", ";
- if (defined($links[$i])) {
- print "&${name}Entries[$links[$i]]" . " \}";
- } else {
- print "0 \}"
- }
- } else {
- print " \{ 0, 0, 0, 0, 0 \}";
- }
- print "," unless ($i == $size - 1);
- print "\n";
- $i++;
- }
- print "};\n";
- print "\nconst struct HashTable $name = ";
- print "\{ 2, $size, ${name}Entries, $hashsize \};\n\n";
- print "}; // namespace\n";
-}
diff --git a/WebCore/src/kdelibs/kjs/date_object.cpp b/WebCore/src/kdelibs/kjs/date_object.cpp
deleted file mode 100644
index c3f7578..0000000
--- a/WebCore/src/kdelibs/kjs/date_object.cpp
+++ /dev/null
@@ -1,788 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifndef HAVE_SYS_TIMEB_H
-#define HAVE_SYS_TIMEB_H 0
-#endif
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#else
-# include <time.h>
-# endif
-#endif
-#if HAVE_SYS_TIMEB_H
-#include <sys/timeb.h>
-#endif
-
-#ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif // HAVE_SYS_PARAM_H
-
-#include <math.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <locale.h>
-#include <ctype.h>
-
-#include "date_object.h"
-#include "error_object.h"
-#include "operations.h"
-
-#include "date_object.lut.h"
-
-using namespace KJS;
-
-// ------------------------------ DateInstanceImp ------------------------------
-
-const ClassInfo DateInstanceImp::info = {"Date", 0, 0, 0};
-
-DateInstanceImp::DateInstanceImp(const Object &proto)
- : ObjectImp(proto)
-{
-}
-
-// ------------------------------ DatePrototypeImp -----------------------------
-
-const ClassInfo DatePrototypeImp::info = {"Date", 0, &dateTable, 0};
-
-/* Source for date_object.lut.h
- We use a negative ID to denote the "UTC" variant.
- at begin dateTable 61
- toString DateProtoFuncImp::ToString DontEnum|Function 0
- toUTCString -DateProtoFuncImp::ToString DontEnum|Function 0
- toDateString DateProtoFuncImp::ToDateString DontEnum|Function 0
- toTimeString DateProtoFuncImp::ToTimeString DontEnum|Function 0
- toLocaleString DateProtoFuncImp::ToLocaleString DontEnum|Function 0
- toLocaleDateString DateProtoFuncImp::ToLocaleDateString DontEnum|Function 0
- toLocaleTimeString DateProtoFuncImp::ToLocaleTimeString DontEnum|Function 0
- valueOf DateProtoFuncImp::ValueOf DontEnum|Function 0
- getTime DateProtoFuncImp::GetTime DontEnum|Function 0
- getFullYear DateProtoFuncImp::GetFullYear DontEnum|Function 0
- getUTCFullYear -DateProtoFuncImp::GetFullYear DontEnum|Function 0
- toGMTString DateProtoFuncImp::ToGMTString DontEnum|Function 0
- getMonth DateProtoFuncImp::GetMonth DontEnum|Function 0
- getUTCMonth -DateProtoFuncImp::GetMonth DontEnum|Function 0
- getDate DateProtoFuncImp::GetDate DontEnum|Function 0
- getUTCDate -DateProtoFuncImp::GetDate DontEnum|Function 0
- getDay DateProtoFuncImp::GetDay DontEnum|Function 0
- getUTCDay -DateProtoFuncImp::GetDay DontEnum|Function 0
- getHours DateProtoFuncImp::GetHours DontEnum|Function 0
- getUTCHours -DateProtoFuncImp::GetHours DontEnum|Function 0
- getMinutes DateProtoFuncImp::GetMinutes DontEnum|Function 0
- getUTCMinutes -DateProtoFuncImp::GetMinutes DontEnum|Function 0
- getSeconds DateProtoFuncImp::GetSeconds DontEnum|Function 0
- getUTCSeconds -DateProtoFuncImp::GetSeconds DontEnum|Function 0
- getMilliseconds DateProtoFuncImp::GetMilliSeconds DontEnum|Function 0
- getUTCMilliseconds -DateProtoFuncImp::GetMilliSeconds DontEnum|Function 0
- getTimezoneOffset DateProtoFuncImp::GetTimezoneOffset DontEnum|Function 0
- setTime DateProtoFuncImp::SetTime DontEnum|Function 1
- setMilliseconds DateProtoFuncImp::SetMilliSeconds DontEnum|Function 1
- setUTCMilliseconds -DateProtoFuncImp::SetMilliSeconds DontEnum|Function 1
- setSeconds DateProtoFuncImp::SetSeconds DontEnum|Function 2
- setUTCSeconds -DateProtoFuncImp::SetSeconds DontEnum|Function 2
- setMinutes DateProtoFuncImp::SetMinutes DontEnum|Function 3
- setUTCMinutes -DateProtoFuncImp::SetMinutes DontEnum|Function 3
- setHours DateProtoFuncImp::SetHours DontEnum|Function 4
- setUTCHours -DateProtoFuncImp::SetHours DontEnum|Function 4
- setDate DateProtoFuncImp::SetDate DontEnum|Function 1
- setUTCDate -DateProtoFuncImp::SetDate DontEnum|Function 1
- setMonth DateProtoFuncImp::SetMonth DontEnum|Function 2
- setUTCMonth -DateProtoFuncImp::SetMonth DontEnum|Function 2
- setFullYear DateProtoFuncImp::SetFullYear DontEnum|Function 3
- setUTCFullYear -DateProtoFuncImp::SetFullYear DontEnum|Function 3
- setYear DateProtoFuncImp::SetYear DontEnum|Function 1
- getYear DateProtoFuncImp::GetYear DontEnum|Function 0
- toGMTString DateProtoFuncImp::ToGMTString DontEnum|Function 0
- at end
-*/
-// ECMA 15.9.4
-
-DatePrototypeImp::DatePrototypeImp(ExecState *,
- ObjectPrototypeImp *objectProto)
- : DateInstanceImp(Object(objectProto))
-{
- Value protect(this);
- setInternalValue(Number(NaN));
- // The constructor will be added later, after DateObjectImp has been built
-}
-
-Value DatePrototypeImp::get(ExecState *exec, const UString &propertyName) const
-{
- return lookupGetFunction<DateProtoFuncImp, ObjectImp>( exec, propertyName, &dateTable, this );
-}
-
-// ------------------------------ DateProtoFuncImp -----------------------------
-
-DateProtoFuncImp::DateProtoFuncImp(ExecState *exec, int i, int len)
- : InternalFunctionImp(
- static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
- ), id(abs(i)), utc(i<0)
- // We use a negative ID to denote the "UTC" variant.
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-bool DateProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value DateProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)
-{
- if ((id == ToString || id == ValueOf || id == GetTime || id == SetTime) &&
- !thisObj.inherits(&DateInstanceImp::info)) {
- // non-generic function called on non-date object
-
- // ToString and ValueOf are generic according to the spec, but the mozilla
- // tests suggest otherwise...
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
-
- Value result;
- UString s;
- const int bufsize=100;
- char timebuffer[bufsize];
- char *oldlocale = setlocale(LC_TIME,NULL);
- if (!oldlocale)
- oldlocale = setlocale(LC_ALL, NULL);
- Value v = thisObj.internalValue();
- double milli = v.toNumber(exec);
- time_t tv = (time_t) floor(milli / 1000.0);
- int ms = int(milli - tv * 1000.0);
-
- struct tm *t;
- if (utc)
- t = gmtime(&tv);
- else
- t = localtime(&tv);
-
- switch (id) {
- case ToString:
- s = ctime(&tv);
- result = String(s.substr(0, s.size() - 1));
- break;
- case ToDateString:
- case ToTimeString:
- case ToGMTString:
- setlocale(LC_TIME,"C");
- if (id == DateProtoFuncImp::ToDateString) {
- strftime(timebuffer, bufsize, "%x",t);
- } else if (id == DateProtoFuncImp::ToTimeString) {
- strftime(timebuffer, bufsize, "%X",t);
- } else {
- t = gmtime(&tv);
- strftime(timebuffer, bufsize, "%a, %d-%b-%y %H:%M:%S %Z", t);
- }
- setlocale(LC_TIME,oldlocale);
- result = String(timebuffer);
- break;
- case ToLocaleString:
- strftime(timebuffer, bufsize, "%c", t);
- result = String(timebuffer);
- break;
- case ToLocaleDateString:
- strftime(timebuffer, bufsize, "%x", t);
- result = String(timebuffer);
- break;
- case ToLocaleTimeString:
- strftime(timebuffer, bufsize, "%X", t);
- result = String(timebuffer);
- break;
- case ValueOf:
- result = Number(milli);
- break;
- case GetTime:
- result = Number(milli);
- break;
- case GetYear:
- // IE returns the full year even in getYear.
- if ( exec->interpreter()->compatMode() == Interpreter::IECompat )
- result = Number(1900 + t->tm_year);
- else
- result = Number(t->tm_year);
- break;
- case GetFullYear:
- result = Number(1900 + t->tm_year);
- break;
- case GetMonth:
- result = Number(t->tm_mon);
- break;
- case GetDate:
- result = Number(t->tm_mday);
- break;
- case GetDay:
- result = Number(t->tm_wday);
- break;
- case GetHours:
- result = Number(t->tm_hour);
- break;
- case GetMinutes:
- result = Number(t->tm_min);
- break;
- case GetSeconds:
- result = Number(t->tm_sec);
- break;
- case GetMilliSeconds:
- result = Number(ms);
- break;
- case GetTimezoneOffset:
-#if defined BSD || defined(__APPLE__)
- result = Number(-( t->tm_gmtoff / 60 ) + ( t->tm_isdst ? 60 : 0 ));
-#else
-# if defined(__BORLANDC__)
-#error please add daylight savings offset here!
- result = Number(_timezone / 60 - (_daylight ? 60 : 0));
-# else
- result = Number(( timezone / 60 - ( daylight ? 60 : 0 )));
-# endif
-#endif
- break;
- case SetTime:
- milli = roundValue(exec,args[0]);
- result = Number(milli);
- thisObj.setInternalValue(result);
- break;
- case SetMilliSeconds:
- ms = args[0].toInt32(exec);
- break;
- case SetSeconds:
- t->tm_sec = args[0].toInt32(exec);
- break;
- case SetMinutes:
- t->tm_min = args[0].toInt32(exec);
- break;
- case SetHours:
- t->tm_hour = args[0].toInt32(exec);
- break;
- case SetDate:
- t->tm_mday = args[0].toInt32(exec);
- break;
- case SetMonth:
- t->tm_mon = args[0].toInt32(exec);
- break;
- case SetFullYear:
- t->tm_year = args[0].toInt32(exec) - 1900;
- break;
- case SetYear:
- t->tm_year = args[0].toInt32(exec) >= 1900 ? args[0].toInt32(exec) - 1900 : args[0].toInt32(exec);
- break;
- }
-
- if (id == SetYear || id == SetMilliSeconds || id == SetSeconds ||
- id == SetMinutes || id == SetHours || id == SetDate ||
- id == SetMonth || id == SetFullYear ) {
- result = Number(mktime(t) * 1000.0 + ms);
- thisObj.setInternalValue(result);
- }
-
- return result;
-}
-
-// ------------------------------ DateObjectImp --------------------------------
-
-// TODO: MakeTime (15.9.11.1) etc. ?
-
-DateObjectImp::DateObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- DatePrototypeImp *dateProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- // ECMA 15.9.4.1 Date.prototype
- put(exec,"prototype", Object(dateProto), DontEnum|DontDelete|ReadOnly);
-
- put(exec,"parse", Object(new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::Parse, 1)), DontEnum);
- put(exec,"UTC", Object(new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::UTC, 7)), DontEnum);
-
- // no. of arguments for constructor
- put(exec,"length", Number(7), ReadOnly|DontDelete|DontEnum);
-}
-
-bool DateObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.9.3
-Object DateObjectImp::construct(ExecState *exec, const List &args)
-{
- int numArgs = args.size();
-
-#ifdef KJS_VERBOSE
- fprintf(stderr,"DateObjectImp::construct - %d args\n", numArgs);
-#endif
- Value value;
-
- if (numArgs == 0) { // new Date() ECMA 15.9.3.3
-#if HAVE_SYS_TIMEB_H
-# if defined(__BORLANDC__)
- struct timeb timebuffer;
- ftime(&timebuffer);
-# else
- struct _timeb timebuffer;
- _ftime(&timebuffer);
-# endif
- double utc = floor((double)timebuffer.time * 1000.0 + (double)timebuffer.millitm);
-#else
- struct timeval tv;
- gettimeofday(&tv, 0L);
- double utc = floor((double)tv.tv_sec * 1000.0 + (double)tv.tv_usec / 1000.0);
-#endif
- value = Number(utc);
- } else if (numArgs == 1) {
- UString s = args[0].toString(exec);
- double d = s.toDouble();
- if (isNaN(d))
- value = parseDate(s);
- else
- value = Number(d);
- } else {
- struct tm t;
- memset(&t, 0, sizeof(t));
- Number y = args[0].toNumber(exec);
- // TODO: check for NaN
- int year = y.toInt32(exec);
- t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900;
- t.tm_mon = args[1].toInt32(exec);
- t.tm_mday = (numArgs >= 3) ? args[2].toInt32(exec) : 1;
- t.tm_hour = (numArgs >= 4) ? args[3].toInt32(exec) : 0;
- t.tm_min = (numArgs >= 5) ? args[4].toInt32(exec) : 0;
- t.tm_sec = (numArgs >= 6) ? args[5].toInt32(exec) : 0;
- t.tm_isdst = -1;
- int ms = (numArgs >= 7) ? args[6].toInt32(exec) : 0;
- value = Number(mktime(&t) * 1000.0 + ms);
- }
-
- Object proto = exec->interpreter()->builtinDatePrototype();
- Object ret(new DateInstanceImp(proto));
- ret.setInternalValue(timeClip(value));
- return ret;
-}
-
-bool DateObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.9.2
-Value DateObjectImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)
-{
-#ifdef KJS_VERBOSE
- fprintf(stderr,"DateObjectImp::call - current time\n");
-#endif
- time_t t = time(0L);
- UString s(ctime(&t));
-
- // return formatted string minus trailing \n
- return String(s.substr(0, s.size() - 1));
-}
-
-// ------------------------------ DateObjectFuncImp ----------------------------
-
-DateObjectFuncImp::DateObjectFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- int i, int len)
- : InternalFunctionImp(funcProto), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-bool DateObjectFuncImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.9.4.2 - 3
-Value DateObjectFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- if (id == Parse) {
- if (args[0].type() == StringType)
- return parseDate(args[0].toString(exec));
- else
- return Undefined();
- }
- else { // UTC
- struct tm t;
- memset(&t, 0, sizeof(t));
- int n = args.size();
- Number y = args[0].toNumber(exec);
- // TODO: check for NaN
- int year = y.toInt32(exec);
- t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900;
- t.tm_mon = args[1].toInt32(exec);
- t.tm_mday = (n >= 3) ? args[2].toInt32(exec) : 1;
- t.tm_hour = (n >= 4) ? args[3].toInt32(exec) : 0;
- t.tm_min = (n >= 5) ? args[4].toInt32(exec) : 0;
- t.tm_sec = (n >= 6) ? args[5].toInt32(exec) : 0;
- int ms = (n >= 7) ? args[6].toInt32(exec) : 0;
- return Number(mktime(&t) * 1000.0 + ms);
- }
-}
-
-// -----------------------------------------------------------------------------
-
-
-Value KJS::parseDate(const String &s)
-{
- UString u = s.value();
-#ifdef KJS_VERBOSE
- fprintf(stderr,"KJS::parseDate %s\n",u.ascii());
-#endif
- int firstSlash = u.find('/');
- if ( firstSlash == -1 )
- {
- time_t seconds = KRFCDate_parseDate( u );
-#ifdef KJS_VERBOSE
- fprintf(stderr,"KRFCDate_parseDate returned seconds=%d\n",seconds);
-#endif
- if ( seconds == -1 )
- return Undefined();
- else
- return Number(seconds * 1000.0);
- }
- else
- {
- // Found 12/31/2099 on some website -> obviously MM/DD/YYYY
- int month = u.substr(0,firstSlash).toULong();
- int secondSlash = u.find('/',firstSlash+1);
- //fprintf(stdout,"KJS::parseDate firstSlash=%d, secondSlash=%d\n", firstSlash, secondSlash);
- if ( secondSlash == -1 )
- {
- fprintf(stderr,"KJS::parseDate parsing for this format isn't implemented\n%s", u.ascii());
- return Number(0);
- }
- int day = u.substr(firstSlash+1,secondSlash-firstSlash-1).toULong();
- int year = u.substr(secondSlash+1).toULong();
- //fprintf(stdout,"KJS::parseDate day=%d, month=%d, year=%d\n", day, month, year);
- struct tm t;
- memset( &t, 0, sizeof(t) );
- year = (year > 2037) ? 2037 : year; // mktime is limited to 2037 !!!
- t.tm_year = (year >= 0 && year <= 99) ? year : year - 1900;
- t.tm_mon = month-1; // mktime wants 0-11 for some reason
- t.tm_mday = day;
- time_t seconds = mktime(&t);
- if ( seconds == -1 )
- {
- fprintf(stderr,"KJS::parseDate mktime returned -1.\n%s", u.ascii());
- return Undefined();
- }
- else
- return Number(seconds * 1000.0);
- }
-}
-
-///// Awful duplication from krfcdate.cpp - we don't link to kdecore
-
-static unsigned int ymdhms_to_seconds(int year, int mon, int day, int hour, int minute, int second)
-{
- unsigned int ret = (day - 32075) /* days */
- + 1461L * (year + 4800L + (mon - 14) / 12) / 4
- + 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12
- - 3 * ((year + 4900L + (mon - 14) / 12) / 100) / 4
- - 2440588;
- ret = 24*ret + hour; /* hours */
- ret = 60*ret + minute; /* minutes */
- ret = 60*ret + second; /* seconds */
-
- return ret;
-}
-
-static const char haystack[37]="janfebmaraprmayjunjulaugsepoctnovdec";
-
-// we follow the recommendation of rfc2822 to consider all
-// obsolete time zones not listed here equivalent to "-0000"
-static const struct {
- const char *tzName;
- int tzOffset;
-} known_zones[] = {
- { "UT", 0 },
- { "GMT", 0 },
- { "EST", -300 },
- { "EDT", -240 },
- { "CST", -360 },
- { "CDT", -300 },
- { "MST", -420 },
- { "MDT", -360 },
- { "PST", -480 },
- { "PDT", -420 },
- { 0, 0 }
-};
-
-time_t KJS::KRFCDate_parseDate(const UString &_date)
-{
- // This parse a date in the form:
- // Wednesday, 09-Nov-99 23:12:40 GMT
- // or
- // Sat, 01-Jan-2000 08:00:00 GMT
- // or
- // Sat, 01 Jan 2000 08:00:00 GMT
- // or
- // 01 Jan 99 22:00 +0100 (exceptions in rfc822/rfc2822)
- // ### non RFC format, added for Javascript:
- // [Wednesday] January 09 1999 23:12:40 GMT
- //
- // We ignore the weekday
- //
- time_t result = 0;
- int offset = 0;
- char *newPosStr;
- const char *dateString = _date.ascii();
- int day = 0;
- char monthStr[4];
- int month = -1; // not set yet
- int year = 0;
- int hour = 0;
- int minute = 0;
- int second = 0;
-
- // Skip leading space
- while(*dateString && isspace(*dateString))
- dateString++;
-
- const char *wordStart = dateString;
- // Check contents of first words if not number
- while(*dateString && !isdigit(*dateString))
- {
- if ( isspace(*dateString) && dateString - wordStart >= 3 )
- {
- monthStr[0] = tolower(*wordStart++);
- monthStr[1] = tolower(*wordStart++);
- monthStr[2] = tolower(*wordStart++);
- monthStr[3] = '\0';
- //fprintf(stderr,"KJS::parseDate found word starting with '%s'\n", monthStr);
- const char *str = strstr(haystack, monthStr);
- if (str)
- month = (str-haystack)/3; // Jan=00, Feb=01, Mar=02, ..
- while(*dateString && isspace(*dateString))
- dateString++;
- wordStart = dateString;
- }
- else
- dateString++;
- }
-
- while(*dateString && isspace(*dateString))
- dateString++;
-
- if (!*dateString)
- return result; // Invalid date
-
- // ' 09-Nov-99 23:12:40 GMT'
- day = strtol(dateString, &newPosStr, 10);
- dateString = newPosStr;
-
- if ((day < 1) || (day > 31))
- return result; // Invalid date;
- if (!*dateString)
- return result; // Invalid date
-
- if (*dateString == '-')
- dateString++;
-
- while(*dateString && isspace(*dateString))
- dateString++;
-
- if ( month == -1 ) // not found yet
- {
- for(int i=0; i < 3;i++)
- {
- if (!*dateString || (*dateString == '-') || isspace(*dateString))
- return result; // Invalid date
- monthStr[i] = tolower(*dateString++);
- }
- monthStr[3] = '\0';
-
- newPosStr = (char*)strstr(haystack, monthStr);
-
- if (!newPosStr)
- return result; // Invalid date
-
- month = (newPosStr-haystack)/3; // Jan=00, Feb=01, Mar=02, ..
-
- if ((month < 0) || (month > 11))
- return result; // Invalid date
-
- while(*dateString && (*dateString != '-') && !isspace(*dateString))
- dateString++;
-
- if (!*dateString)
- return result; // Invalid date
-
- // '-99 23:12:40 GMT'
- if ((*dateString != '-') && !isspace(*dateString))
- return result; // Invalid date
- dateString++;
- }
-
- if ((month < 0) || (month > 11))
- return result; // Invalid date
-
- // '99 23:12:40 GMT'
- year = strtol(dateString, &newPosStr, 10);
- dateString = newPosStr;
-
- // Y2K: Solve 2 digit years
- if ((year >= 0) && (year < 50))
- year += 2000;
-
- if ((year >= 50) && (year < 100))
- year += 1900; // Y2K
-
- if ((year < 1900) || (year > 2500))
- return result; // Invalid date
-
- // Don't fail if the time is missing.
- if (*dateString)
- {
- // ' 23:12:40 GMT'
- if (!isspace(*dateString++))
- return result; // Invalid date
-
- hour = strtol(dateString, &newPosStr, 10);
- dateString = newPosStr;
-
- if ((hour < 0) || (hour > 23))
- return result; // Invalid date
-
- if (!*dateString)
- return result; // Invalid date
-
- // ':12:40 GMT'
- if (*dateString++ != ':')
- return result; // Invalid date
-
- minute = strtol(dateString, &newPosStr, 10);
- dateString = newPosStr;
-
- if ((minute < 0) || (minute > 59))
- return result; // Invalid date
-
- if (!*dateString)
- return result; // Invalid date
-
- // ':40 GMT'
- if (*dateString != ':' && !isspace(*dateString))
- return result; // Invalid date
-
- // seconds are optional in rfc822 + rfc2822
- if (*dateString ==':') {
- dateString++;
-
- second = strtol(dateString, &newPosStr, 10);
- dateString = newPosStr;
-
- if ((second < 0) || (second > 59))
- return result; // Invalid date
- } else {
- dateString++;
- }
-
- while(*dateString && isspace(*dateString))
- dateString++;
- }
-
- // don't fail if the time zone is missing, some
- // broken mail-/news-clients omit the time zone
- if (*dateString) {
-
- if ((*dateString == '+') || (*dateString == '-')) {
- offset = strtol(dateString, &newPosStr, 10);
-
- if ((offset < -9959) || (offset > 9959))
- return result; // Invalid date
-
- int sgn = (offset < 0)? -1:1;
- offset = abs(offset);
- offset = ((offset / 100)*60 + (offset % 100))*sgn;
- } else {
- for (int i=0; known_zones[i].tzName != 0; i++) {
- if (0 == strncasecmp(dateString, known_zones[i].tzName, strlen(known_zones[i].tzName))) {
- offset = known_zones[i].tzOffset;
- break;
- }
- }
- }
- }
- if (sizeof(time_t) == 4)
- {
- if ((time_t)-1 < 0)
- {
- if (year >= 2038)
- {
- year = 2038;
- month = 0;
- day = 1;
- hour = 0;
- minute = 0;
- second = 0;
- }
- }
- else
- {
- if (year >= 2115)
- {
- year = 2115;
- month = 0;
- day = 1;
- hour = 0;
- minute = 0;
- second = 0;
- }
- }
- }
-
- result = ymdhms_to_seconds(year, month+1, day, hour, minute, second);
-
- // avoid negative time values
- if ((offset > 0) && (offset > result))
- offset = 0;
-
- result -= offset*60;
-
- // If epoch 0 return epoch +1 which is Thu, 01-Jan-70 00:00:01 GMT
- // This is so that parse error and valid epoch 0 return values won't
- // be the same for sensitive applications...
- if (result < 1) result = 1;
-
- return result;
-}
-
-
-Value KJS::timeClip(const Value &t)
-{
- /* TODO */
- return t;
-}
-
diff --git a/WebCore/src/kdelibs/kjs/date_object.h b/WebCore/src/kdelibs/kjs/date_object.h
deleted file mode 100644
index e20a421..0000000
--- a/WebCore/src/kdelibs/kjs/date_object.h
+++ /dev/null
@@ -1,127 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _DATE_OBJECT_H_
-#define _DATE_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class DateInstanceImp : public ObjectImp {
- public:
- DateInstanceImp(const Object &proto);
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- /**
- * @internal
- *
- * The initial value of Date.prototype (and thus all objects created
- * with the Date constructor
- */
- class DatePrototypeImp : public DateInstanceImp {
- public:
- DatePrototypeImp(ExecState *exec, ObjectPrototypeImp *objectProto);
- Value get(ExecState *exec, const UString &p) const;
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * Date.prototype object
- */
- class DateProtoFuncImp : public InternalFunctionImp {
- public:
- DateProtoFuncImp(ExecState *exec, int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
-
- Completion execute(const List &);
- enum { ToString, ToDateString, ToTimeString, ToLocaleString,
- ToLocaleDateString, ToLocaleTimeString, ValueOf, GetTime,
- GetFullYear, GetMonth, GetDate, GetDay, GetHours, GetMinutes,
- GetSeconds, GetMilliSeconds, GetTimezoneOffset, SetTime,
- SetMilliSeconds, SetSeconds, SetMinutes, SetHours, SetDate,
- SetMonth, SetFullYear, ToUTCString,
- // non-normative properties (Appendix B)
- GetYear, SetYear, ToGMTString };
- private:
- int id;
- bool utc;
- };
-
- /**
- * @internal
- *
- * The initial value of the the global variable's "Date" property
- */
- class DateObjectImp : public InternalFunctionImp {
- public:
- DateObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- DatePrototypeImp *dateProto);
-
- 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);
-
- Completion execute(const List &);
- Object construct(const List &);
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * Date object
- */
- class DateObjectFuncImp : public InternalFunctionImp {
- public:
- DateObjectFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { Parse, UTC };
- private:
- int id;
- };
-
- // helper functions
- Value parseDate(const String &s);
- time_t KRFCDate_parseDate(const UString &_date);
- Value timeClip(const Value &t);
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/debugger.cpp b/WebCore/src/kdelibs/kjs/debugger.cpp
deleted file mode 100644
index 8ce7d81..0000000
--- a/WebCore/src/kdelibs/kjs/debugger.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include "debugger.h"
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "internal.h"
-#include "ustring.h"
-
-using namespace KJS;
-
-// ------------------------------ Debugger -------------------------------------
-
-namespace KJS {
- struct AttachedInterpreter
- {
- public:
- AttachedInterpreter(Interpreter *i) : interp(i) {}
- Interpreter *interp;
- AttachedInterpreter *next;
- };
-
-}
-
-Debugger::Debugger()
-{
- rep = new DebuggerImp();
-}
-
-Debugger::~Debugger()
-{
- // detach from all interpreters
- while (rep->interps)
- detach(rep->interps->interp);
-
- delete rep;
-}
-
-void Debugger::attach(Interpreter *interp)
-{
- if (interp->imp()->debugger() != this)
- interp->imp()->setDebugger(this);
-
- // add to the list of attached interpreters
- if (!rep->interps)
- rep->interps = new AttachedInterpreter(interp);
- else {
- AttachedInterpreter *ai = rep->interps;
- while (ai->next)
- ai = ai->next;
- ai->next = new AttachedInterpreter(interp);;
- }
-}
-
-void Debugger::detach(Interpreter *interp)
-{
- if (interp->imp()->debugger() == this)
- interp->imp()->setDebugger(this);
-
- // remove from the list of attached interpreters
- if (rep->interps->interp == interp) {
- AttachedInterpreter *old = rep->interps;
- rep->interps = rep->interps->next;
- delete old;
- }
-
- AttachedInterpreter *ai = rep->interps;
- while (ai->next && ai->next->interp != interp)
- ai = ai->next;
- if (ai->next) {
- AttachedInterpreter *old = ai->next;
- ai->next = ai->next->next;
- delete old;
- }
-}
-
-bool Debugger::sourceParsed(ExecState */*exec*/, int /*sourceId*/,
- const UString &/*source*/, int /*errorLine*/)
-{
- return true;
-}
-
-bool Debugger::sourceUnused(ExecState */*exec*/, int /*sourceId*/)
-{
- return true;
-}
-
-bool Debugger::exception(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/,
- Object &/*exceptionObj*/)
-{
- return true;
-}
-
-bool Debugger::atStatement(ExecState */*exec*/, int /*sourceId*/, int /*firstLine*/,
- int /*lastLine*/)
-{
- return true;
-}
-
-bool Debugger::callEvent(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/,
- Object &/*function*/, const List &/*args*/)
-{
- return true;
-}
-
-bool Debugger::returnEvent(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/,
- Object &/*function*/)
-{
- return true;
-}
-
diff --git a/WebCore/src/kdelibs/kjs/debugger.h b/WebCore/src/kdelibs/kjs/debugger.h
deleted file mode 100644
index 92bc870..0000000
--- a/WebCore/src/kdelibs/kjs/debugger.h
+++ /dev/null
@@ -1,213 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _KJSDEBUGGER_H_
-#define _KJSDEBUGGER_H_
-
-namespace KJS {
-
- class DebuggerImp;
- class Interpreter;
- class ExecState;
- class Object;
- class UString;
- class List;
-
- /**
- * @internal
- *
- * Provides an interface which receives notification about various
- * script-execution related events such as statement execution and function
- * calls.
- *
- * WARNING: This interface is still a work in progress and is not yet
- * offically publicly available. It is likely to change in binary incompatible
- * (and possibly source incompatible) ways in future versions. It is
- * anticipated that at some stage the interface will be frozen and made
- * available for general use.
- */
- class Debugger {
- public:
-
- /**
- * Creates a new debugger
- */
- Debugger();
-
- /**
- * Destroys the debugger. If the debugger is attached to any interpreters,
- * it is automatically detached.
- */
- virtual ~Debugger();
-
- DebuggerImp *imp() const { return rep; }
-
- /**
- * Attaches the debugger to specified interpreter. This will cause this
- * object to receive notification of events from the interpreter.
- *
- * If the interpreter is deleted, the debugger will automatically be
- * detached.
- *
- * Note: only one debugger can be attached to an interpreter at a time.
- * Attaching another debugger to the same interpreter will cause the
- * original debugger to be detached from that interpreter.
- *
- * @param interp The interpreter to attach to
- *
- * @see detach()
- */
- void attach(Interpreter *interp);
-
- /**
- * Detach the debugger from an interpreter
- *
- * @param interp The interpreter to detach from. If 0, the debugger will be
- * detached from all interpreters to which it is attached.
- *
- * @see attach()
- */
- void detach(Interpreter *interp);
-
- /**
- * Called to notify the debugger that some javascript source code has
- * been parsed. For calls to Interpreter::evaluate(), this will be called
- * with the supplied source code before any other code is parsed.
- * Other situations in which this may be called include creation of a
- * function using the Function() constructor, or the eval() function.
- *
- * The default implementation does nothing. Override this method if
- * you want to process this event.
- *
- * @param exec The current execution state
- * @param sourceId The ID of the source code (corresponds to the
- * sourceId supplied in other functions such as @ref atStatement()
- * @param source The source code that was parsed
- * @param errorLine The line number at which parsing encountered an
- * error, or -1 if the source code was valid and parsed succesfully
- * @return true if execution should be continue, false if it should
- * be aborted
- */
- virtual bool sourceParsed(ExecState *exec, int sourceId,
- const UString &source, int errorLine);
-
- /**
- * Called when all functions/programs associated with a particular
- * sourceId have been deleted. After this function has been called for
- * a particular sourceId, that sourceId will not be used again.
- *
- * The default implementation does nothing. Override this method if
- * you want to process this event.
- *
- * @param exec The current execution state
- * @param sourceId The ID of the source code (corresponds to the
- * sourceId supplied in other functions such as atLine()
- * @return true if execution should be continue, false if it should
- * be aborted
- */
- virtual bool sourceUnused(ExecState *exec, int sourceId);
-
- /**
- * Called when an exception is thrown during script execution.
- *
- * The default implementation does nothing. Override this method if
- * you want to process this event.
- *
- * @param exec The current execution state
- * @param sourceId The ID of the source code being executed
- * @param lineno The line at which the error occurred
- * @param exceptionObj The exception object
- * @return true if execution should be continue, false if it should
- * be aborted
- */
- virtual bool exception(ExecState *exec, int sourceId, int lineno,
- Object &exceptionObj);
-
- /**
- * Called when a line of the script is reached (before it is executed)
- *
- * The default implementation does nothing. Override this method if
- * you want to process this event.
- *
- * @param exec The current execution state
- * @param sourceId The ID of the source code being executed
- * @param firstLine The starting line of the statement that is about to be
- * executed
- * @param firstLine The ending line of the statement that is about to be
- * executed (usually the same as firstLine)
- * @return true if execution should be continue, false if it should
- * be aborted
- */
- virtual bool atStatement(ExecState *exec, int sourceId, int firstLine,
- int lastLine);
- /**
- * Called on each function call. Use together with @ref #returnEvent
- * if you want to keep track of the call stack.
- *
- * Note: This only gets called for functions that are declared in ECMAScript
- * source code or passed to eval(), not for internal KJS or
- * application-supplied functions.
- *
- * The default implementation does nothing. Override this method if
- * you want to process this event.
- *
- * @param exec The current execution state
- * @param sourceId The ID of the source code being executed
- * @param lineno The line that is about to be executed
- * @param function The function being called
- * @param args The arguments that were passed to the function
- * line is being executed
- * @return true if execution should be continue, false if it should
- * be aborted
- */
- virtual bool callEvent(ExecState *exec, int sourceId, int lineno,
- Object &function, const List &args);
-
- /**
- * Called on each function exit. The function being returned from is that
- * which was supplied in the last callEvent().
- *
- * Note: This only gets called for functions that are declared in ECMAScript
- * source code or passed to eval(), not for internal KJS or
- * application-supplied functions.
- *
- * The default implementation does nothing. Override this method if
- * you want to process this event.
- *
- * @param exec The current execution state
- * @param sourceId The ID of the source code being executed
- * @param lineno The line that is about to be executed
- * @param function The function being called
- * @return true if execution should be continue, false if it should
- * be aborted
- */
- virtual bool returnEvent(ExecState *exec, int sourceId, int lineno,
- Object &function);
-
- private:
- DebuggerImp *rep;
- };
-
-};
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/error_object.cpp b/WebCore/src/kdelibs/kjs/error_object.cpp
deleted file mode 100644
index 3bf338b..0000000
--- a/WebCore/src/kdelibs/kjs/error_object.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "error_object.h"
-//#include "debugger.h"
-
-using namespace KJS;
-
-// ------------------------------ ErrorPrototypeImp ----------------------------
-
-// ECMA 15.9.4
-ErrorPrototypeImp::ErrorPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objectProto,
- FunctionPrototypeImp *funcProto)
- : ObjectImp(Object(objectProto))
-{
- Value protect(this);
- setInternalValue(Undefined());
- // The constructor will be added later in ErrorObjectImp's constructor
-
- put(exec, "name", String("Error"), DontEnum);
- put(exec, "message", String("Unknown error"), DontEnum);
- put(exec, "toString", Object(new ErrorProtoFuncImp(exec,funcProto)), DontEnum);
-}
-
-// ------------------------------ ErrorProtoFuncImp ----------------------------
-
-ErrorProtoFuncImp::ErrorProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- put(exec,"length",Number(0),DontDelete|ReadOnly|DontEnum);
-}
-
-bool ErrorProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value ErrorProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)
-{
- // toString()
- UString s = "Error";
-
- Value v = thisObj.get(exec,"name");
- if (v.type() != UndefinedType) {
- s = v.toString(exec);
- }
-
- v = thisObj.get(exec,"message");
- if (v.type() != UndefinedType) {
- s += ": "+v.toString(exec);
- }
-
- return String(s);
-}
-
-// ------------------------------ ErrorObjectImp -------------------------------
-
-ErrorObjectImp::ErrorObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- ErrorPrototypeImp *errorProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- // ECMA 15.11.3.1 Error.prototype
- put(exec, "prototype", Object(errorProto), DontEnum|DontDelete|ReadOnly);
- //put(exec, "name", String(n));
-}
-
-bool ErrorObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.9.3
-Object ErrorObjectImp::construct(ExecState *exec, const List &args)
-{
- Object proto = Object::dynamicCast(exec->interpreter()->builtinErrorPrototype());
- Object obj(new ObjectImp(proto));
-
- if (!args.isEmpty() && args[0].type() != UndefinedType) {
- obj.put(exec,"message", String(args[0].toString(exec)));
- }
-
- return obj;
-}
-
-bool ErrorObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.9.2
-Value ErrorObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- // "Error()" gives the sames result as "new Error()"
- return construct(exec,args);
-}
-
-// ------------------------------ NativeErrorPrototypeImp ----------------------
-
-NativeErrorPrototypeImp::NativeErrorPrototypeImp(ExecState *exec, ErrorPrototypeImp *errorProto,
- ErrorType et, UString name, UString message)
- : ObjectImp(Object(errorProto))
-{
- Value protect(this);
- errType = et;
- put(exec,"name",String(name));
- put(exec,"message",String(message));
-}
-
-// ------------------------------ NativeErrorImp -------------------------------
-
-const ClassInfo NativeErrorImp::info = {"Error", &InternalFunctionImp::info, 0, 0};
-
-NativeErrorImp::NativeErrorImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- const Object &prot)
- : InternalFunctionImp(funcProto), proto(0)
-{
- Value protect(this);
- proto = static_cast<ObjectImp*>(prot.imp());
-
- put(exec,"length",Number(1),DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5
- put(exec,"prototype",prot);
-}
-
-bool NativeErrorImp::implementsConstruct() const
-{
- return true;
-}
-
-Object NativeErrorImp::construct(ExecState *exec, const List &args)
-{
- Object obj(new ObjectImp(Object(proto)));
- if (args[0].type() != UndefinedType)
- obj.put(exec, "message", String(args[0].toString(exec)));
- return obj;
-}
-
-bool NativeErrorImp::implementsCall() const
-{
- return true;
-}
-
-Value NativeErrorImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- return construct(exec,args);
-}
-
-void NativeErrorImp::mark()
-{
- ObjectImp::mark();
- if (proto && !proto->marked())
- proto->mark();
-}
-
diff --git a/WebCore/src/kdelibs/kjs/error_object.h b/WebCore/src/kdelibs/kjs/error_object.h
deleted file mode 100644
index 0bfba1d..0000000
--- a/WebCore/src/kdelibs/kjs/error_object.h
+++ /dev/null
@@ -1,89 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _ERROR_OBJECT_H_
-#define _ERROR_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class ErrorPrototypeImp : public ObjectImp {
- public:
- ErrorPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objectProto,
- FunctionPrototypeImp *funcProto);
- };
-
- class ErrorProtoFuncImp : public InternalFunctionImp {
- public:
- ErrorProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto);
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
- };
-
- class ErrorObjectImp : public InternalFunctionImp {
- public:
- ErrorObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- ErrorPrototypeImp *errorProto);
-
- 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);
- };
-
-
-
-
-
- class NativeErrorPrototypeImp : public ObjectImp {
- public:
- NativeErrorPrototypeImp(ExecState *exec, ErrorPrototypeImp *errorProto,
- ErrorType et, UString name, UString message);
- private:
- ErrorType errType;
- };
-
- class NativeErrorImp : public InternalFunctionImp {
- public:
- NativeErrorImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- const Object &prot);
-
- 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);
-
- virtual void mark();
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- private:
- ObjectImp *proto;
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/function.cpp b/WebCore/src/kdelibs/kjs/function.cpp
deleted file mode 100644
index 51382f8..0000000
--- a/WebCore/src/kdelibs/kjs/function.cpp
+++ /dev/null
@@ -1,476 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#include "function.h"
-
-#include "internal.h"
-#include "function_object.h"
-#include "lexer.h"
-#include "nodes.h"
-#include "operations.h"
-#include "debugger.h"
-
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-
-using namespace KJS;
-
-// ------------------------------ FunctionImp ----------------------------------
-
-const ClassInfo FunctionImp::info = {"Function", &InternalFunctionImp::info, 0, 0};
-
-namespace KJS {
- class Parameter {
- public:
- Parameter(const UString &n) : name(n), next(0L) { }
- ~Parameter() { delete next; }
- UString name;
- Parameter *next;
- };
-};
-
-FunctionImp::FunctionImp(ExecState *exec, const UString &n)
- : InternalFunctionImp(
- static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
- ), param(0L), ident(n), argStack(0)
-{
- Value protect(this);
- argStack = new ListImp();
- put(exec,"arguments",Null(),ReadOnly|DontDelete|DontEnum);
-}
-
-FunctionImp::~FunctionImp()
-{
- argStack->setGcAllowed();
- // The function shouldn't be deleted while it is still executed; argStack
- // should be set to 0 by the last call to popArgs()
- assert(argStack->isEmpty());
- delete param;
-}
-
-void FunctionImp::mark()
-{
- InternalFunctionImp::mark();
- if (argStack && !argStack->marked())
- argStack->mark();
-}
-
-bool FunctionImp::implementsCall() const
-{
- return true;
-}
-
-Value FunctionImp::call(ExecState *exec, Object &thisObj, const List &args)
-{
- Object globalObj = exec->interpreter()->globalObject();
-
- Debugger *dbg = exec->interpreter()->imp()->debugger();
- int sid = -1;
- int lineno = -1;
- if (dbg) {
- if (inherits(&DeclaredFunctionImp::info)) {
- sid = static_cast<DeclaredFunctionImp*>(this)->body->sourceId();
- lineno = static_cast<DeclaredFunctionImp*>(this)->body->firstLine();
- }
-
- Object func(this);
- int cont = dbg->callEvent(exec,sid,lineno,func,args);
- if (!cont) {
- dbg->imp()->abort();
- return Undefined();
- }
- }
-
- // enter a new execution context
- ContextImp *ctx = new ContextImp(globalObj, exec, thisObj,
- codeType(), exec->context().imp(), this, args);
- ExecState *newExec = new ExecState(exec->interpreter(),ctx);
- newExec->setException(exec->exception()); // could be null
-
- // In order to maintain our "arguments" property, we maintain a list of arguments
- // properties from earlier in the execution stack. Upon return, we restore the
- // previous arguments object using popArgs().
- // Note: this does not appear to be part of the spec
- if (codeType() == FunctionCode) {
- assert(ctx->activationObject().inherits(&ActivationImp::info));
- Object argsObj = static_cast<ActivationImp*>(ctx->activationObject().imp())->argumentsObject();
- put(newExec,"arguments", argsObj, DontDelete|DontEnum|ReadOnly);
- pushArgs(newExec,argsObj);
- }
-
- // assign user supplied arguments to parameters
- processParameters(newExec,args);
- // add variable declarations (initialized to undefined)
- processVarDecls(newExec);
-
- Completion comp = execute(newExec);
-
- // if an exception occured, propogate it back to the previous execution object
- if (newExec->hadException())
- exec->setException(newExec->exception());
- if (codeType() == FunctionCode)
- popArgs(newExec);
- delete newExec;
- delete ctx;
-
-#ifdef KJS_VERBOSE
- if (comp.complType() == Throw)
- printInfo(exec,"throwing", comp.value());
- else if (comp.complType() == ReturnValue)
- printInfo(exec,"returning", comp.value());
- else
- fprintf(stderr, "returning: undefined\n");
-#endif
-
- if (dbg) {
- Object func(this);
- int cont = dbg->returnEvent(exec,sid,lineno,func);
- if (!cont) {
- dbg->imp()->abort();
- return Undefined();
- }
- }
-
- if (comp.complType() == Throw) {
- exec->setException(comp.value());
- return comp.value();
- }
- else if (comp.complType() == ReturnValue)
- return comp.value();
- else
- return Undefined();
-}
-
-void FunctionImp::addParameter(const UString &n)
-{
- Parameter **p = ¶m;
- while (*p)
- p = &(*p)->next;
-
- *p = new Parameter(n);
-}
-
-
-// ECMA 10.1.3q
-void FunctionImp::processParameters(ExecState *exec, const List &args)
-{
- Object variable = exec->context().imp()->variableObject();
-
-#ifdef KJS_VERBOSE
- fprintf(stderr, "---------------------------------------------------\n"
- "processing parameters for %s call\n",
- name().isEmpty() ? "(internal)" : name().ascii());
-#endif
-
- if (param) {
- ListIterator it = args.begin();
- Parameter **p = ¶m;
- while (*p) {
- if (it != args.end()) {
-#ifdef KJS_VERBOSE
- fprintf(stderr, "setting parameter %s ", (*p)->name.ascii());
- printInfo(exec,"to", *it);
-#endif
- variable.put(exec,(*p)->name, *it);
- it++;
- } else
- variable.put(exec,(*p)->name, Undefined());
- p = &(*p)->next;
- }
- }
-#ifdef KJS_VERBOSE
- else {
- for (int i = 0; i < args.size(); i++)
- printInfo(exec,"setting argument", args[i]);
- }
-#endif
-}
-
-void FunctionImp::processVarDecls(ExecState */*exec*/)
-{
-}
-
-void FunctionImp::pushArgs(ExecState *exec, const Object &args)
-{
- argStack->append(args);
- put(exec,"arguments",args,ReadOnly|DontDelete|DontEnum);
-}
-
-void FunctionImp::popArgs(ExecState *exec)
-{
- argStack->removeLast();
- if (argStack->isEmpty()) {
- put(exec,"arguments",Null(),ReadOnly|DontDelete|DontEnum);
- }
- else
- put(exec,"arguments",argStack->at(argStack->size()-1),ReadOnly|DontDelete|DontEnum);
-}
-
-// ------------------------------ DeclaredFunctionImp --------------------------
-
-// ### is "Function" correct here?
-const ClassInfo DeclaredFunctionImp::info = {"Function", &FunctionImp::info, 0, 0};
-
-DeclaredFunctionImp::DeclaredFunctionImp(ExecState *exec, const UString &n,
- FunctionBodyNode *b, const List &sc)
- : FunctionImp(exec,n), body(b)
-{
- Value protect(this);
- body->ref();
- setScope(sc.copy());
-}
-
-DeclaredFunctionImp::~DeclaredFunctionImp()
-{
- if ( body->deref() )
- delete body;
-}
-
-bool DeclaredFunctionImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 13.2.2 [[Construct]]
-Object DeclaredFunctionImp::construct(ExecState *exec, const List &args)
-{
- Object proto;
- Value p = get(exec,"prototype");
- if (p.type() == ObjectType)
- proto = Object(static_cast<ObjectImp*>(p.imp()));
- else
- proto = exec->interpreter()->builtinObjectPrototype();
-
- Object obj(new ObjectImp(proto));
-
- Value res = call(exec,obj,args);
-
- if (res.type() == ObjectType)
- return Object::dynamicCast(res);
- else
- return obj;
-}
-
-Completion DeclaredFunctionImp::execute(ExecState *exec)
-{
- Completion result = body->execute(exec);
-
- if (result.complType() == Throw || result.complType() == ReturnValue)
- return result;
- return Completion(Normal, Undefined()); // TODO: or ReturnValue ?
-}
-
-void DeclaredFunctionImp::processVarDecls(ExecState *exec)
-{
- body->processVarDecls(exec);
-}
-
-// ------------------------------ ArgumentsImp ---------------------------------
-
-const ClassInfo ArgumentsImp::info = {"Arguments", 0, 0, 0};
-
-// ECMA 10.1.8
-ArgumentsImp::ArgumentsImp(ExecState *exec, FunctionImp *func, const List &args)
- : ObjectImp(exec->interpreter()->builtinObjectPrototype())
-{
- Value protect(this);
- put(exec,"callee", Object(func), DontEnum);
- put(exec,"length", Number(args.size()), DontEnum);
- if (!args.isEmpty()) {
- ListIterator arg = args.begin();
- for (int i = 0; arg != args.end(); arg++, i++) {
- put(exec,UString::from(i), *arg, DontEnum);
- }
- }
-}
-
-// ------------------------------ ActivationImp --------------------------------
-
-const ClassInfo ActivationImp::info = {"Activation", 0, 0, 0};
-
-// ECMA 10.1.6
-ActivationImp::ActivationImp(ExecState *exec, FunctionImp *f, const List &args)
- : ObjectImp()
-{
- Value protect(this);
- arguments = new ArgumentsImp(exec,f, args);
- put(exec, "arguments", Object(arguments), Internal|DontDelete);
-}
-
-ActivationImp::~ActivationImp()
-{
- arguments->setGcAllowed();
-}
-
-// ------------------------------ GlobalFunc -----------------------------------
-
-
-GlobalFuncImp::GlobalFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len)
- : InternalFunctionImp(funcProto), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-CodeType GlobalFuncImp::codeType() const
-{
- return id == Eval ? EvalCode : codeType();
-}
-
-bool GlobalFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value GlobalFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- Value res;
-
- static const char non_escape[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789@*_+-./";
-
- if (id == Eval) { // eval()
- Value x = args[0];
- if (x.type() != StringType)
- return x;
- else {
- UString s = x.toString(exec);
-
- int sid;
- int errLine;
- UString errMsg;
- ProgramNode *progNode = Parser::parse(s.data(),s.size(),&sid,&errLine,&errMsg);
-
- // no program node means a syntax occurred
- if (!progNode) {
- Object err = Error::create(exec,SyntaxError,errMsg.ascii(),errLine);
- err.put(exec,"sid",Number(sid));
- exec->setException(err);
- return err;
- }
-
- progNode->ref();
-
- // enter a new execution context
- Object glob(exec->interpreter()->globalObject());
- Object thisVal(Object::dynamicCast(exec->context().thisValue()));
- ContextImp *ctx = new ContextImp(glob,
- exec,
- thisVal,
- EvalCode,
- exec->context().imp());
-
- ExecState *newExec = new ExecState(exec->interpreter(),ctx);
- newExec->setException(exec->exception()); // could be null
-
- // execute the code
- Completion c = progNode->execute(newExec);
-
- // if an exception occured, propogate it back to the previous execution object
- if (newExec->hadException())
- exec->setException(newExec->exception());
- delete newExec;
- delete ctx;
-
- if ( progNode->deref() )
- delete progNode;
- if (c.complType() == ReturnValue)
- return c;
- // ### setException() on throw?
- else if (c.complType() == Normal) {
- if (c.isValueCompletion())
- return c.value();
- else
- return Undefined();
- } else
- return c;
- }
- } else if (id == ParseInt) {
- String str = args[0].toString(exec);
- int radix = args[1].toInt32(exec);
- if (radix == 0)
- radix = 10;
- else if (radix < 2 || radix > 36) {
- res = Number(NaN);
- return res;
- }
- /* TODO: use radix */
- // Can't use toULong(), we want to accept floating point values too
- double value = str.value().toDouble( true /*tolerant*/ );
- if ( isNaN(value) )
- res = Number(NaN);
- else
- res = Number(static_cast<long>(value)); // remove floating-point part
- } else if (id == ParseFloat) {
- String str = args[0].toString(exec);
- res = Number(str.value().toDouble( true /*tolerant*/ ));
- } else if (id == IsNaN) {
- res = Boolean(isNaN(args[0].toNumber(exec)));
- } else if (id == IsFinite) {
- Number n = args[0].toNumber(exec);
- res = Boolean(!n.isNaN() && !n.isInf());
- } else if (id == Escape) {
- UString r = "", s, str = args[0].toString(exec);
- const UChar *c = str.data();
- for (int k = 0; k < str.size(); k++, c++) {
- int u = c->unicode();
- if (u > 255) {
- char tmp[7];
- sprintf(tmp, "%%u%04X", u);
- s = UString(tmp);
- } else if (strchr(non_escape, (char)u)) {
- s = UString(c, 1);
- } else {
- char tmp[4];
- sprintf(tmp, "%%%02X", u);
- s = UString(tmp);
- }
- r += s;
- }
- res = String(r);
- } else if (id == UnEscape) {
- UString s, str = args[0].toString(exec);
- int k = 0, len = str.size();
- while (k < len) {
- const UChar *c = str.data() + k;
- UChar u;
- if (*c == UChar('%') && k <= len - 6 && *(c+1) == UChar('u')) {
- u = Lexer::convertUnicode((c+2)->unicode(), (c+3)->unicode(),
- (c+4)->unicode(), (c+5)->unicode());
- c = &u;
- k += 5;
- } else if (*c == UChar('%') && k <= len - 3) {
- u = UChar(Lexer::convertHex((c+1)->unicode(), (c+2)->unicode()));
- c = &u;
- k += 2;
- }
- k++;
- s += UString(c, 1);
- }
- res = String(s);
- }
-
- return res;
-}
diff --git a/WebCore/src/kdelibs/kjs/function.h b/WebCore/src/kdelibs/kjs/function.h
deleted file mode 100644
index 56d3491..0000000
--- a/WebCore/src/kdelibs/kjs/function.h
+++ /dev/null
@@ -1,127 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _KJS_FUNCTION_H_
-#define _KJS_FUNCTION_H_
-
-#include "internal.h"
-
-namespace KJS {
-
- class Parameter;
-
- /**
- * @short Implementation class for internal Functions.
- */
- class FunctionImp : public InternalFunctionImp {
- friend class Function;
- friend class ActivationImp;
- public:
- FunctionImp(ExecState *exec, const UString &n = UString::null);
- virtual ~FunctionImp();
-
- virtual void mark();
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- void addParameter(const UString &n);
- virtual CodeType codeType() const = 0;
-
- virtual Completion execute(ExecState *exec) = 0;
- UString name() const { return ident; }
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- protected:
- Parameter *param;
- UString ident;
-
- private:
- void processParameters(ExecState *exec, const List &);
- virtual void processVarDecls(ExecState *exec);
-
- void pushArgs(ExecState *exec, const Object &args);
- void popArgs(ExecState *exec);
- ListImp *argStack;
- };
-
- class DeclaredFunctionImp : public FunctionImp {
- public:
- DeclaredFunctionImp(ExecState *exec, const UString &n,
- FunctionBodyNode *b, const List &sc);
- ~DeclaredFunctionImp();
-
- bool implementsConstruct() const;
- Object construct(ExecState *exec, const List &args);
-
- virtual Completion execute(ExecState *exec);
- CodeType codeType() const { return FunctionCode; }
- FunctionBodyNode *body;
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- private:
- virtual void processVarDecls(ExecState *exec);
- };
-
-
-
-
- class ArgumentsImp : public ObjectImp {
- public:
- ArgumentsImp(ExecState *exec, FunctionImp *func, const List &args);
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- class ActivationImp : public ObjectImp {
- public:
- 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;
- private:
- ObjectImp* arguments;
- };
-
- class GlobalFuncImp : public InternalFunctionImp {
- public:
- GlobalFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len);
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
- virtual CodeType codeType() const;
- enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape };
- private:
- int id;
- };
-
-
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/function_object.cpp b/WebCore/src/kdelibs/kjs/function_object.cpp
deleted file mode 100644
index d2e059f..0000000
--- a/WebCore/src/kdelibs/kjs/function_object.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 "function_object.h"
-#include "internal.h"
-#include "function.h"
-#include "array_object.h"
-#include "nodes.h"
-#include "lexer.h"
-#include "debugger.h"
-#include "object.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-using namespace KJS;
-
-// ------------------------------ FunctionPrototypeImp -------------------------
-
-FunctionPrototypeImp::FunctionPrototypeImp(ExecState *exec)
- : InternalFunctionImp(0)
-{
- Value protect(this);
- put(exec, "toString", Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::ToString, 0)), DontEnum);
- put(exec, "apply", Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::Apply, 2)), DontEnum);
- put(exec, "call", Object(new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::Call, 1)), DontEnum);
-}
-
-FunctionPrototypeImp::~FunctionPrototypeImp()
-{
-}
-
-bool FunctionPrototypeImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.3.4
-Value FunctionPrototypeImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)
-{
- return Undefined();
-}
-
-// ------------------------------ FunctionProtoFuncImp -------------------------
-
-FunctionProtoFuncImp::FunctionProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto, int i, int len)
- : InternalFunctionImp(funcProto), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-
-bool FunctionProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value FunctionProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)
-{
- Value result;
-
- switch (id) {
- case ToString: {
- // ### also make this work for internal functions
- // ### return the text of the function body (see 15.3.4.2)
- if (thisObj.isNull() || !thisObj.inherits(&InternalFunctionImp::info)) {
-#ifndef NDEBUG
- fprintf(stderr,"attempted toString() call on null or non-function object\n");
-#endif
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
- if (thisObj.inherits(&FunctionImp::info) &&
- !static_cast<FunctionImp*>(thisObj.imp())->name().isNull()) {
- result = String("function " + static_cast<FunctionImp*>(thisObj.imp())->name() + "()");
- }
- else {
- result = String("(Internal function)");
- }
- }
- break;
- case Apply: {
- Value thisArg = args[0];
- Value argArray = args[1];
- Object func = thisObj;
-
- if (!func.implementsCall()) {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
- Object applyThis;
- if (thisArg.isA(NullType) || thisArg.isA(UndefinedType))
- applyThis = exec->interpreter()->globalObject();
- else
- applyThis = thisArg.toObject(exec);
-
- List applyArgs;
- if (!argArray.isA(NullType) && !argArray.isA(UndefinedType)) {
- if ((argArray.isA(ObjectType) &&
- Object::dynamicCast(argArray).inherits(&ArrayInstanceImp::info)) ||
- Object::dynamicCast(argArray).inherits(&ArgumentsImp::info)) {
-
- Object argArrayObj = Object::dynamicCast(argArray);
- unsigned int length = argArrayObj.get(exec,"length").toUInt32(exec);
- for (uint i = 0; i < length; i++)
- applyArgs.append(argArrayObj.get(exec,UString::from(i)));
- }
- else {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
- }
- result = func.call(exec,applyThis,applyArgs);
- }
- break;
- case Call: {
- Value thisArg = args[0];
- Object func = thisObj;
-
- if (!func.implementsCall()) {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
- Object callThis;
- if (thisArg.isA(NullType) || thisArg.isA(UndefinedType))
- callThis = exec->interpreter()->globalObject();
- else
- callThis = thisArg.toObject(exec);
-
- List callArgs = args.copy();
- callArgs.removeFirst();
- result = func.call(exec,callThis,callArgs);
- }
- break;
- }
-
- return result;
-}
-
-// ------------------------------ FunctionObjectImp ----------------------------
-
-FunctionObjectImp::FunctionObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- put(exec,"prototype", Object(funcProto), DontEnum|DontDelete|ReadOnly);
-
- // no. of arguments for constructor
- put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
-}
-
-FunctionObjectImp::~FunctionObjectImp()
-{
-}
-
-bool FunctionObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.3.2 The Function Constructor
-Object FunctionObjectImp::construct(ExecState *exec, const List &args)
-{
- UString p("");
- UString body;
- int argsSize = args.size();
- if (argsSize == 0) {
- body = "";
- } else if (argsSize == 1) {
- body = args[0].toString(exec);
- } else {
- p = args[0].toString(exec);
- for (int k = 1; k < argsSize - 1; k++)
- p += "," + args[k].toString(exec);
- body = args[argsSize-1].toString(exec);
- }
-
- // parse the source code
- int sid;
- int errLine;
- UString errMsg;
- ProgramNode *progNode = Parser::parse(body.data(),body.size(),&sid,&errLine,&errMsg);
-
- // notify debugger that source has been parsed
- Debugger *dbg = exec->interpreter()->imp()->debugger();
- if (dbg) {
- bool cont = dbg->sourceParsed(exec,sid,body,errLine);
- if (!cont) {
- dbg->imp()->abort();
- return Object(new ObjectImp());
- }
- }
-
- // no program node == syntax error - throw a syntax error
- if (!progNode) {
- Object err = Error::create(exec,SyntaxError,errMsg.ascii(),errLine);
- // we can't return a Completion(Throw) here, so just set the exception
- // and return it
- exec->setException(err);
- return err;
- }
-
- List scopeChain;
- scopeChain.append(exec->interpreter()->globalObject());
- FunctionBodyNode *bodyNode = progNode;
-
- FunctionImp *fimp = new DeclaredFunctionImp(exec, UString::null, bodyNode,
- scopeChain);
- Object ret(fimp); // protect from GC
-
- // parse parameter list. throw syntax error on illegal identifiers
- int len = p.size();
- const UChar *c = p.data();
- int i = 0, params = 0;
- UString param;
- while (i < len) {
- while (*c == ' ' && i < len)
- c++, i++;
- if (Lexer::isIdentLetter(c->unicode())) { // else error
- param = UString(c, 1);
- c++, i++;
- while (i < len && (Lexer::isIdentLetter(c->unicode()) ||
- Lexer::isDecimalDigit(c->unicode()))) {
- param += UString(c, 1);
- c++, i++;
- }
- while (i < len && *c == ' ')
- c++, i++;
- if (i == len) {
- fimp->addParameter(param);
- params++;
- break;
- } else if (*c == ',') {
- fimp->addParameter(param);
- params++;
- c++, i++;
- continue;
- } // else error
- }
- Object err = Error::create(exec,SyntaxError,
- I18N_NOOP("Syntax error in parameter list"),
- -1);
- exec->setException(err);
- return err;
- }
-
- fimp->put(exec,"length", Number(params),ReadOnly|DontDelete|DontEnum);
- List consArgs;
-
- Object objCons = exec->interpreter()->builtinObject();
- Object prototype = objCons.construct(exec,List::empty());
- prototype.put(exec, "constructor",
- Object(fimp), DontEnum|DontDelete|ReadOnly);
- fimp->put(exec,"prototype",prototype,DontEnum|DontDelete|ReadOnly);
- fimp->put(exec,"arguments",Null(),DontEnum|DontDelete|ReadOnly);
- return ret;
-}
-
-bool FunctionObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.3.1 The Function Constructor Called as a Function
-Value FunctionObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- return construct(exec,args);
-}
-
diff --git a/WebCore/src/kdelibs/kjs/function_object.h b/WebCore/src/kdelibs/kjs/function_object.h
deleted file mode 100644
index 8e6156e..0000000
--- a/WebCore/src/kdelibs/kjs/function_object.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _FUNCTION_OBJECT_H_
-#define _FUNCTION_OBJECT_H_
-
-#include "internal.h"
-#include "object_object.h"
-#include "function.h"
-
-namespace KJS {
-
- /**
- * @internal
- *
- * The initial value of Function.prototype (and thus all objects created
- * with the Function constructor
- */
- class FunctionPrototypeImp : public InternalFunctionImp {
- public:
- FunctionPrototypeImp(ExecState *exec);
- virtual ~FunctionPrototypeImp();
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * Function.prototype object
- */
- class FunctionProtoFuncImp : public InternalFunctionImp {
- public:
- FunctionProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto, int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { ToString, Apply, Call };
- private:
- int id;
- };
-
- /**
- * @internal
- *
- * The initial value of the the global variable's "Function" property
- */
- class FunctionObjectImp : public InternalFunctionImp {
- public:
- FunctionObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto);
- virtual ~FunctionObjectImp();
-
- 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 // _FUNCTION_OBJECT_H_
diff --git a/WebCore/src/kdelibs/kjs/grammar.y b/WebCore/src/kdelibs/kjs/grammar.y
deleted file mode 100644
index 7819860..0000000
--- a/WebCore/src/kdelibs/kjs/grammar.y
+++ /dev/null
@@ -1,649 +0,0 @@
-%{
-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <string.h>
-#include <stdlib.h>
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "nodes.h"
-#include "lexer.h"
-#include "internal.h"
-
-/* default values for bison */
-#define YYDEBUG 0
-#define YYMAXDEPTH 0
-#ifdef APPLE_CHANGES
-#else
-#define YYERROR_VERBOSE
-#endif
-#define DBG(l, s, e) { l->setLoc(s.first_line, e.last_line, Parser::sid); } // location
-
-extern int yylex();
-int yyerror (const char *);
-bool automatic();
-
-using namespace KJS;
-
-%}
-
-%union {
- int ival;
- double dval;
- UString *ustr;
- Node *node;
- StatementNode *stat;
- ParameterNode *param;
- FunctionBodyNode *body;
- FuncDeclNode *func;
- ProgramNode *prog;
- AssignExprNode *init;
- SourceElementNode *src;
- SourceElementsNode *srcs;
- StatListNode *slist;
- ArgumentsNode *args;
- ArgumentListNode *alist;
- VarDeclNode *decl;
- VarDeclListNode *vlist;
- CaseBlockNode *cblk;
- ClauseListNode *clist;
- CaseClauseNode *ccl;
- ElementNode *elm;
- ElisionNode *eli;
- Operator op;
-}
-
-%start Program
-
-/* expect a shift/reduce conflict from the "dangling else" problem
- when using bison the warning can be supressed */
-// %expect 1
-
-/* literals */
-%token NULLTOKEN TRUETOKEN FALSETOKEN
-%token STRING NUMBER
-
-/* keywords */
-%token BREAK CASE DEFAULT FOR NEW VAR CONTINUE
-%token FUNCTION RETURN VOID DELETE
-%token IF THIS DO WHILE ELSE IN INSTANCEOF TYPEOF
-%token SWITCH WITH RESERVED
-%token THROW TRY CATCH FINALLY
-
-/* punctuators */
-%token EQEQ NE /* == and != */
-%token STREQ STRNEQ /* === and !== */
-%token LE GE /* < and > */
-%token OR AND /* || and && */
-%token PLUSPLUS MINUSMINUS /* ++ and -- */
-%token LSHIFT /* << */
-%token RSHIFT URSHIFT /* >> and >>> */
-%token PLUSEQUAL MINUSEQUAL /* += and -= */
-%token MULTEQUAL DIVEQUAL /* *= and /= */
-%token LSHIFTEQUAL /* <<= */
-%token RSHIFTEQUAL URSHIFTEQUAL /* >>= and >>>= */
-%token ANDEQUAL MODEQUAL /* &= and %= */
-%token XOREQUAL OREQUAL /* ^= and |= */
-
-/* terminal types */
-%token <dval> NUMBER
-%token <ustr> STRING
-%token <ustr> IDENT
-
-/* automatically inserted semicolon */
-%token AUTOPLUSPLUS AUTOMINUSMINUS
-
-/* non-terminal types */
-%type <node> Literal PrimaryExpr Expr MemberExpr FunctionExpr NewExpr CallExpr
-%type <node> ArrayLiteral PropertyName PropertyNameAndValueList
-%type <node> LeftHandSideExpr PostfixExpr UnaryExpr
-%type <node> MultiplicativeExpr AdditiveExpr
-%type <node> ShiftExpr RelationalExpr EqualityExpr
-%type <node> BitwiseANDExpr BitwiseXORExpr BitwiseORExpr
-%type <node> LogicalANDExpr LogicalORExpr
-%type <node> ConditionalExpr AssignmentExpr
-%type <node> ExprOpt
-%type <node> CallExpr
-%type <node> Catch Finally
-
-%type <stat> Statement Block
-%type <stat> VariableStatement EmptyStatement ExprStatement
-%type <stat> IfStatement IterationStatement ContinueStatement
-%type <stat> BreakStatement ReturnStatement WithStatement
-%type <stat> SwitchStatement LabelledStatement
-%type <stat> ThrowStatement TryStatement
-
-%type <slist> StatementList
-%type <init> Initializer
-%type <func> FunctionDeclaration
-%type <body> FunctionBody
-%type <src> SourceElement
-%type <srcs> SourceElements
-%type <param> FormalParameterList
-%type <op> AssignmentOperator
-%type <prog> Program
-%type <args> Arguments
-%type <alist> ArgumentList
-%type <vlist> VariableDeclarationList
-%type <decl> VariableDeclaration
-%type <cblk> CaseBlock
-%type <ccl> CaseClause DefaultClause
-%type <clist> CaseClauses CaseClausesOpt
-%type <eli> Elision ElisionOpt
-%type <elm> ElementList
-
-%%
-
-Literal:
- NULLTOKEN { $$ = new NullNode(); }
- | TRUETOKEN { $$ = new BooleanNode(true); }
- | FALSETOKEN { $$ = new BooleanNode(false); }
- | NUMBER { $$ = new NumberNode($1); }
- | STRING { $$ = new StringNode($1); delete $1; }
- | '/' /* a RegExp ? */ { Lexer *l = Lexer::curr();
- if (!l->scanRegExp()) YYABORT;
- $$ = new RegExpNode(l->pattern,l->flags);}
- | DIVEQUAL /* a RegExp starting with /= ! */
- { Lexer *l = Lexer::curr();
- if (!l->scanRegExp()) YYABORT;
- $$ = new RegExpNode(UString('=')+l->pattern,l->flags);}
-;
-
-PrimaryExpr:
- THIS { $$ = new ThisNode(); }
- | IDENT { $$ = new ResolveNode($1);
- delete $1; }
- | Literal
- | ArrayLiteral
- | '(' Expr ')' { $$ = new GroupNode($2); }
- | '{' '}' { $$ = new ObjectLiteralNode(0L); }
- | '{' PropertyNameAndValueList '}' { $$ = new ObjectLiteralNode($2); }
-;
-
-ArrayLiteral:
- '[' ElisionOpt ']' { $$ = new ArrayNode($2); }
- | '[' ElementList ']' { $$ = new ArrayNode($2); }
- | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2); }
-;
-
-ElementList:
- ElisionOpt AssignmentExpr { $$ = new ElementNode($1, $2); }
- | ElementList ',' ElisionOpt AssignmentExpr
- { $$ = new ElementNode($1, $3, $4); }
-;
-
-ElisionOpt:
- /* nothing */ { $$ = 0L; }
- | Elision
-;
-
-Elision:
- ',' { $$ = new ElisionNode(0L); }
- | Elision ',' { $$ = new ElisionNode($1); }
-;
-
-PropertyNameAndValueList:
- PropertyName ':' AssignmentExpr { $$ = new PropertyValueNode($1, $3); }
- | PropertyNameAndValueList ',' PropertyName ':' AssignmentExpr
- { $$ = new PropertyValueNode($3, $5, $1); }
-;
-
-PropertyName:
- IDENT { $$ = new PropertyNode($1);
- delete $1; }
- | STRING { $$ = new PropertyNode($1); delete $1; }
- | NUMBER { $$ = new PropertyNode($1); }
-;
-
-MemberExpr:
- PrimaryExpr
- | FunctionExpr
- | MemberExpr '[' Expr ']' { $$ = new AccessorNode1($1, $3); }
- | MemberExpr '.' IDENT { $$ = new AccessorNode2($1, $3);
- delete $3; }
- | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
-;
-
-NewExpr:
- MemberExpr
- | NEW NewExpr { $$ = new NewExprNode($2); }
-;
-
-CallExpr:
- MemberExpr Arguments { $$ = new FunctionCallNode($1, $2); }
- | CallExpr Arguments { $$ = new FunctionCallNode($1, $2); }
- | CallExpr '[' Expr ']' { $$ = new AccessorNode1($1, $3); }
- | CallExpr '.' IDENT { $$ = new AccessorNode2($1, $3); }
-;
-
-Arguments:
- '(' ')' { $$ = new ArgumentsNode(0L); }
- | '(' ArgumentList ')' { $$ = new ArgumentsNode($2); }
-;
-
-ArgumentList:
- AssignmentExpr { $$ = new ArgumentListNode($1); }
- | ArgumentList ',' AssignmentExpr { $$ = new ArgumentListNode($1, $3); }
-;
-
-LeftHandSideExpr:
- NewExpr
- | CallExpr
-;
-
-PostfixExpr: /* TODO: no line terminator here */
- LeftHandSideExpr
- | LeftHandSideExpr PLUSPLUS { $$ = new PostfixNode($1, OpPlusPlus); }
- | LeftHandSideExpr MINUSMINUS { $$ = new PostfixNode($1, OpMinusMinus); }
-;
-
-UnaryExpr:
- PostfixExpr
- | DELETE UnaryExpr { $$ = new DeleteNode($2); }
- | VOID UnaryExpr { $$ = new VoidNode($2); }
- | TYPEOF UnaryExpr { $$ = new TypeOfNode($2); }
- | PLUSPLUS UnaryExpr { $$ = new PrefixNode(OpPlusPlus, $2); }
- | AUTOPLUSPLUS UnaryExpr { $$ = new PrefixNode(OpPlusPlus, $2); }
- | MINUSMINUS UnaryExpr { $$ = new PrefixNode(OpMinusMinus, $2); }
- | AUTOMINUSMINUS UnaryExpr { $$ = new PrefixNode(OpMinusMinus, $2); }
- | '+' UnaryExpr { $$ = new UnaryPlusNode($2); }
- | '-' UnaryExpr { $$ = new NegateNode($2); }
- | '~' UnaryExpr { $$ = new BitwiseNotNode($2); }
- | '!' UnaryExpr { $$ = new LogicalNotNode($2); }
-;
-
-MultiplicativeExpr:
- UnaryExpr
- | MultiplicativeExpr '*' UnaryExpr { $$ = new MultNode($1, $3, '*'); }
- | MultiplicativeExpr '/' UnaryExpr { $$ = new MultNode($1, $3, '/'); }
- | MultiplicativeExpr '%' UnaryExpr { $$ = new MultNode($1,$3,'%'); }
-;
-
-AdditiveExpr:
- MultiplicativeExpr
- | AdditiveExpr '+' MultiplicativeExpr { $$ = new AddNode($1, $3, '+'); }
- | AdditiveExpr '-' MultiplicativeExpr { $$ = new AddNode($1, $3, '-'); }
-;
-
-ShiftExpr:
- AdditiveExpr
- | ShiftExpr LSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpLShift, $3); }
- | ShiftExpr RSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpRShift, $3); }
- | ShiftExpr URSHIFT AdditiveExpr { $$ = new ShiftNode($1, OpURShift, $3); }
-;
-
-RelationalExpr:
- ShiftExpr
- | RelationalExpr '<' ShiftExpr
- { $$ = new RelationalNode($1, OpLess, $3); }
- | RelationalExpr '>' ShiftExpr
- { $$ = new RelationalNode($1, OpGreater, $3); }
- | RelationalExpr LE ShiftExpr
- { $$ = new RelationalNode($1, OpLessEq, $3); }
- | RelationalExpr GE ShiftExpr
- { $$ = new RelationalNode($1, OpGreaterEq, $3); }
- | RelationalExpr INSTANCEOF ShiftExpr
- { $$ = new RelationalNode($1, OpInstanceOf, $3); }
- | RelationalExpr IN ShiftExpr
- { $$ = new RelationalNode($1, OpIn, $3); }
-;
-
-EqualityExpr:
- RelationalExpr
- | EqualityExpr EQEQ RelationalExpr { $$ = new EqualNode($1, OpEqEq, $3); }
- | EqualityExpr NE RelationalExpr { $$ = new EqualNode($1, OpNotEq, $3); }
- | EqualityExpr STREQ RelationalExpr { $$ = new EqualNode($1, OpStrEq, $3); }
- | EqualityExpr STRNEQ RelationalExpr { $$ = new EqualNode($1, OpStrNEq, $3);}
-;
-
-BitwiseANDExpr:
- EqualityExpr
- | BitwiseANDExpr '&' EqualityExpr { $$ = new BitOperNode($1, OpBitAnd, $3); }
-;
-
-BitwiseXORExpr:
- BitwiseANDExpr
- | BitwiseXORExpr '^' EqualityExpr { $$ = new BitOperNode($1, OpBitXOr, $3); }
-;
-
-BitwiseORExpr:
- BitwiseXORExpr
- | BitwiseORExpr '|' EqualityExpr { $$ = new BitOperNode($1, OpBitOr, $3); }
-;
-
-LogicalANDExpr:
- BitwiseORExpr
- | LogicalANDExpr AND BitwiseORExpr
- { $$ = new BinaryLogicalNode($1, OpAnd, $3); }
-;
-
-LogicalORExpr:
- LogicalANDExpr
- | LogicalORExpr OR LogicalANDExpr
- { $$ = new BinaryLogicalNode($1, OpOr, $3); }
-;
-
-ConditionalExpr:
- LogicalORExpr
- | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr
- { $$ = new ConditionalNode($1, $3, $5); }
-;
-
-AssignmentExpr:
- ConditionalExpr
- | LeftHandSideExpr AssignmentOperator AssignmentExpr
- { $$ = new AssignNode($1, $2, $3);}
-;
-
-AssignmentOperator:
- '=' { $$ = OpEqual; }
- | PLUSEQUAL { $$ = OpPlusEq; }
- | MINUSEQUAL { $$ = OpMinusEq; }
- | MULTEQUAL { $$ = OpMultEq; }
- | DIVEQUAL { $$ = OpDivEq; }
- | LSHIFTEQUAL { $$ = OpLShift; }
- | RSHIFTEQUAL { $$ = OpRShift; }
- | URSHIFTEQUAL { $$ = OpURShift; }
- | ANDEQUAL { $$ = OpAndEq; }
- | XOREQUAL { $$ = OpXOrEq; }
- | OREQUAL { $$ = OpOrEq; }
- | MODEQUAL { $$ = OpModEq; }
-;
-
-Expr:
- AssignmentExpr
- | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
-;
-
-Statement:
- Block
- | VariableStatement
- | EmptyStatement
- | ExprStatement
- | IfStatement
- | IterationStatement
- | ContinueStatement
- | BreakStatement
- | ReturnStatement
- | WithStatement
- | SwitchStatement
- | LabelledStatement
- | ThrowStatement
- | TryStatement
-;
-
-Block:
- '{' '}' { $$ = new BlockNode(0L); DBG($$, @2, @2); }
- | '{' SourceElements '}' { $$ = new BlockNode($2); DBG($$, @3, @3); }
-;
-
-StatementList:
- Statement { $$ = new StatListNode($1); }
- | StatementList Statement { $$ = new StatListNode($1, $2); }
-;
-
-VariableStatement:
- VAR VariableDeclarationList ';' { $$ = new VarStatementNode($2);
- DBG($$, @1, @3); }
- | VAR VariableDeclarationList error { if (automatic()) {
- $$ = new VarStatementNode($2);
- DBG($$, @1, @2);
- } else {
- YYABORT;
- }
- }
-;
-
-VariableDeclarationList:
- VariableDeclaration { $$ = new VarDeclListNode($1); }
- | VariableDeclarationList ',' VariableDeclaration
- { $$ = new VarDeclListNode($1, $3); }
-;
-
-VariableDeclaration:
- IDENT { $$ = new VarDeclNode($1, 0); delete $1; }
- | IDENT Initializer { $$ = new VarDeclNode($1, $2); delete $1; }
-;
-
-Initializer:
- '=' AssignmentExpr { $$ = new AssignExprNode($2); }
-;
-
-EmptyStatement:
- ';' { $$ = new EmptyStatementNode(); }
-;
-
-ExprStatement:
- Expr ';' { $$ = new ExprStatementNode($1);
- DBG($$, @1, @2); }
- | Expr error { if (automatic()) {
- $$ = new ExprStatementNode($1);
- DBG($$, @1, @1);
- } else
- YYABORT; }
-;
-
-IfStatement: /* shift/reduce conflict due to dangling else */
- IF '(' Expr ')' Statement { $$ = new IfNode($3,$5,0L);DBG($$, at 1, at 4); }
- | IF '(' Expr ')' Statement ELSE Statement
- { $$ = new IfNode($3,$5,$7);DBG($$, at 1, at 4); }
-;
-
-IterationStatement:
- DO Statement WHILE '(' Expr ')' { $$=new DoWhileNode($2,$5);DBG($$, at 1, at 3);}
- | WHILE '(' Expr ')' Statement { $$ = new WhileNode($3,$5);DBG($$, at 1, at 4); }
- | FOR '(' ExprOpt ';' ExprOpt ';' ExprOpt ')'
- Statement { $$ = new ForNode($3,$5,$7,$9);
- DBG($$, at 1, at 8); }
- | FOR '(' VAR VariableDeclarationList ';' ExprOpt ';' ExprOpt ')'
- Statement { $$ = new ForNode($4,$6,$8,$10);
- DBG($$, at 1, at 9); }
- | FOR '(' LeftHandSideExpr IN Expr ')'
- Statement { $$ = new ForInNode($3, $5, $7);
- DBG($$, at 1, at 6); }
- | FOR '(' VAR IDENT IN Expr ')'
- Statement { $$ = new ForInNode($4,0L,$6,$8);
- DBG($$, at 1, at 7);
- delete $4; }
- | FOR '(' VAR IDENT Initializer IN Expr ')'
- Statement { $$ = new ForInNode($4,$5,$7,$9);
- DBG($$, at 1, at 8);
- delete $4; }
-;
-
-ExprOpt:
- /* nothing */ { $$ = 0L; }
- | Expr
-;
-
-ContinueStatement:
- CONTINUE ';' { $$ = new ContinueNode(); DBG($$, at 1, at 2); }
- | CONTINUE error { if (automatic()) {
- $$ = new ContinueNode(); DBG($$, at 1, at 2);
- } else
- YYABORT; }
- | CONTINUE IDENT ';' { $$ = new ContinueNode($2); DBG($$, at 1, at 3);
- delete $2; }
- | CONTINUE IDENT error { if (automatic()) {
- $$ = new ContinueNode($2);DBG($$, at 1, at 2);
- delete $2;
- } else
- YYABORT; }
-;
-
-BreakStatement:
- BREAK ';' { $$ = new BreakNode();DBG($$, at 1, at 2); }
- | BREAK error { if (automatic()) {
- $$ = new BreakNode(); DBG($$, at 1, at 1);
- } else
- YYABORT; }
- | BREAK IDENT ';' { $$ = new BreakNode($2); DBG($$, at 1, at 3);
- delete $2; }
- | BREAK IDENT error { if (automatic()) {
- $$ = new BreakNode($2); DBG($$, at 1, at 2);
- delete $2;
- } else
- YYABORT;
- }
-;
-
-ReturnStatement:
- RETURN ';' { $$ = new ReturnNode(0L); DBG($$, at 1, at 2); }
- | RETURN error { if (automatic()) {
- $$ = new ReturnNode(0L); DBG($$, at 1, at 1);
- } else
- YYABORT; }
- | RETURN Expr ';' { $$ = new ReturnNode($2); }
- | RETURN Expr error { if (automatic())
- $$ = new ReturnNode($2);
- else
- YYABORT; }
-;
-
-WithStatement:
- WITH '(' Expr ')' Statement { $$ = new WithNode($3,$5);
- DBG($$, @1, @4); }
-;
-
-SwitchStatement:
- SWITCH '(' Expr ')' CaseBlock { $$ = new SwitchNode($3, $5);
- DBG($$, @1, @4); }
-;
-
-CaseBlock:
- '{' CaseClausesOpt '}' { $$ = new CaseBlockNode($2, 0L, 0L); }
- | '{' CaseClausesOpt DefaultClause CaseClausesOpt '}'
- { $$ = new CaseBlockNode($2, $3, $4); }
-;
-
-CaseClausesOpt:
- /* nothing */ { $$ = 0L; }
- | CaseClauses
-;
-
-CaseClauses:
- CaseClause { $$ = new ClauseListNode($1); }
- | CaseClauses CaseClause { $$ = $1->append($2); }
-;
-
-CaseClause:
- CASE Expr ':' { $$ = new CaseClauseNode($2, 0L); }
- | CASE Expr ':' StatementList { $$ = new CaseClauseNode($2, $4); }
-;
-
-DefaultClause:
- DEFAULT ':' { $$ = new CaseClauseNode(0L, 0L);; }
- | DEFAULT ':' StatementList { $$ = new CaseClauseNode(0L, $3); }
-;
-
-LabelledStatement:
- IDENT ':' Statement { $3->pushLabel($1);
- $$ = new LabelNode($1, $3);
- delete $1; }
-;
-
-ThrowStatement:
- THROW Expr ';' { $$ = new ThrowNode($2); }
-;
-
-TryStatement:
- TRY Block Catch { $$ = new TryNode($2, $3); }
- | TRY Block Finally { $$ = new TryNode($2, 0L, $3); }
- | TRY Block Catch Finally { $$ = new TryNode($2, $3, $4); }
-;
-
-Catch:
- CATCH '(' IDENT ')' Block { $$ = new CatchNode($3, $5); delete $3; }
-;
-
-Finally:
- FINALLY Block { $$ = new FinallyNode($2); }
-;
-
-FunctionDeclaration:
- FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncDeclNode($2, 0L, $5);
- delete $2; }
- | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody
- { $$ = new FuncDeclNode($2, $4, $6);
- delete $2; }
-
-FunctionExpr:
- FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode(0L, $4); }
- | FUNCTION '(' FormalParameterList ')' FunctionBody
- { $$ = new FuncExprNode($3, $5); }
-
-;
-
-FormalParameterList:
- IDENT { $$ = new ParameterNode($1); delete $1; }
- | FormalParameterList ',' IDENT { $$ = $1->append($3);
- delete $3; }
-;
-
-FunctionBody:
- '{' '}' /* TODO: spec ??? */ { $$ = new FunctionBodyNode(0L);
- DBG($$, @1, @2);}
- | '{' SourceElements '}' { $$ = new FunctionBodyNode($2);
- DBG($$, @1, @3);}
-;
-
-Program:
- /* nothing, empty script */ { $$ = new ProgramNode(0L);
- Parser::progNode = $$; }
- | SourceElements { $$ = new ProgramNode($1);
- Parser::progNode = $$; }
-;
-
-SourceElements:
- SourceElement { $$ = new SourceElementsNode($1); }
- | SourceElements SourceElement { $$ = new SourceElementsNode($1, $2); }
-;
-
-SourceElement:
- Statement { $$ = new SourceElementNode($1); }
- | FunctionDeclaration { $$ = new SourceElementNode($1); }
-;
-
-%%
-
-int yyerror (const char *) /* Called by yyparse on error */
-{
-// fprintf(stderr, "ERROR: %s at line %d\n",
-// s, KJScript::lexer()->lineNo());
- return 1;
-}
-
-/* may we automatically insert a semicolon ? */
-bool automatic()
-{
- if (yychar == '}' || yychar == 0)
- return true;
- else if (Lexer::curr()->prevTerminator())
- return true;
-
- return false;
-}
diff --git a/WebCore/src/kdelibs/kjs/internal.cpp b/WebCore/src/kdelibs/kjs/internal.cpp
deleted file mode 100644
index 9011ede..0000000
--- a/WebCore/src/kdelibs/kjs/internal.cpp
+++ /dev/null
@@ -1,1160 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#include <stdio.h>
-#include <math.h>
-#include <assert.h>
-#ifndef NDEBUG
-#include <strings.h> // for strdup
-#endif
-
-#include "array_object.h"
-#include "bool_object.h"
-#include "collector.h"
-#include "date_object.h"
-#include "debugger.h"
-#include "error_object.h"
-#include "function_object.h"
-#include "internal.h"
-#include "lexer.h"
-#include "math_object.h"
-#include "nodes.h"
-#include "number_object.h"
-#include "object.h"
-#include "object_object.h"
-#include "operations.h"
-#include "regexp_object.h"
-#include "string_object.h"
-
-#define I18N_NOOP(s) s
-
-extern int kjsyyparse();
-
-using namespace KJS;
-
-namespace KJS {
-#ifdef WORDS_BIGENDIAN
- unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
- unsigned char Inf_Bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
-#elif defined(arm)
- unsigned char NaN_Bytes[] = { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 };
- unsigned char Inf_Bytes[] = { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 };
-#else
- unsigned char NaN_Bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
- unsigned char Inf_Bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
-#endif
-
- const double NaN = *(const double*) NaN_Bytes;
- const double Inf = *(const double*) Inf_Bytes;
-};
-
-// ------------------------------ UndefinedImp ---------------------------------
-
-UndefinedImp *UndefinedImp::staticUndefined = 0;
-
-Value UndefinedImp::toPrimitive(ExecState */*exec*/, Type) const
-{
- return Value((ValueImp*)this);
-}
-
-bool UndefinedImp::toBoolean(ExecState */*exec*/) const
-{
- return false;
-}
-
-double UndefinedImp::toNumber(ExecState */*exec*/) const
-{
- return NaN;
-}
-
-UString UndefinedImp::toString(ExecState */*exec*/) const
-{
- return "undefined";
-}
-
-Object UndefinedImp::toObject(ExecState *exec) const
-{
- Object err = Error::create(exec, TypeError, I18N_NOOP("Undefined value"));
- exec->setException(err);
- return err;
-}
-
-// ------------------------------ NullImp --------------------------------------
-
-NullImp *NullImp::staticNull = 0;
-
-Value NullImp::toPrimitive(ExecState */*exec*/, Type) const
-{
- return Value((ValueImp*)this);
-}
-
-bool NullImp::toBoolean(ExecState */*exec*/) const
-{
- return false;
-}
-
-double NullImp::toNumber(ExecState */*exec*/) const
-{
- return 0.0;
-}
-
-UString NullImp::toString(ExecState */*exec*/) const
-{
- return "null";
-}
-
-Object NullImp::toObject(ExecState *exec) const
-{
- Object err = Error::create(exec, TypeError, I18N_NOOP("Null value"));
- exec->setException(err);
- return err;
-}
-
-// ------------------------------ BooleanImp -----------------------------------
-
-BooleanImp* BooleanImp::staticTrue = 0;
-BooleanImp* BooleanImp::staticFalse = 0;
-
-Value BooleanImp::toPrimitive(ExecState */*exec*/, Type) const
-{
- return Value((ValueImp*)this);
-}
-
-bool BooleanImp::toBoolean(ExecState */*exec*/) const
-{
- return val;
-}
-
-double BooleanImp::toNumber(ExecState */*exec*/) const
-{
- return val ? 1.0 : 0.0;
-}
-
-UString BooleanImp::toString(ExecState */*exec*/) const
-{
- return val ? "true" : "false";
-}
-
-Object BooleanImp::toObject(ExecState *exec) const
-{
- List args;
- args.append(Boolean(const_cast<BooleanImp*>(this)));
- return Object::dynamicCast(exec->interpreter()->builtinBoolean().construct(exec,args));
-}
-
-// ------------------------------ StringImp ------------------------------------
-
-StringImp::StringImp(const UString& v)
- : val(v)
-{
-}
-
-Value StringImp::toPrimitive(ExecState */*exec*/, Type) const
-{
- return Value((ValueImp*)this);
-}
-
-bool StringImp::toBoolean(ExecState */*exec*/) const
-{
- return (val.size() > 0);
-}
-
-double StringImp::toNumber(ExecState */*exec*/) const
-{
- return val.toDouble();
-}
-
-UString StringImp::toString(ExecState */*exec*/) const
-{
- return val;
-}
-
-Object StringImp::toObject(ExecState *exec) const
-{
- List args;
- args.append(String(const_cast<StringImp*>(this)));
- return Object::dynamicCast(exec->interpreter()->builtinString().construct(exec,args));
-}
-
-// ------------------------------ NumberImp ------------------------------------
-
-NumberImp::NumberImp(double v)
- : val(v)
-{
-}
-
-Value NumberImp::toPrimitive(ExecState *, Type) const
-{
- return Number((NumberImp*)this);
-}
-
-bool NumberImp::toBoolean(ExecState *) const
-{
- return !((val == 0) /* || (iVal() == N0) */ || isNaN(val));
-}
-
-double NumberImp::toNumber(ExecState *) const
-{
- return val;
-}
-
-UString NumberImp::toString(ExecState *) const
-{
- return UString::from(val);
-}
-
-Object NumberImp::toObject(ExecState *exec) const
-{
- List args;
- args.append(Number(const_cast<NumberImp*>(this)));
- return Object::dynamicCast(exec->interpreter()->builtinNumber().construct(exec,args));
-}
-
-// ------------------------------ ReferenceImp ---------------------------------
-
-ReferenceImp::ReferenceImp(const Value& v, const UString& p)
- : base(v.imp()), prop(p)
-{
-}
-
-void ReferenceImp::mark()
-{
- ValueImp::mark();
- if (base && !base->marked())
- base->mark();
-}
-
-Value ReferenceImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
-{
- // invalid for Reference
- assert(false);
- return Value();
-}
-
-bool ReferenceImp::toBoolean(ExecState */*exec*/) const
-{
- // invalid for Reference
- assert(false);
- return false;
-}
-
-double ReferenceImp::toNumber(ExecState */*exec*/) const
-{
- // invalid for Reference
- assert(false);
- return 0;
-}
-
-UString ReferenceImp::toString(ExecState */*exec*/) const
-{
- // invalid for Reference
- assert(false);
- return UString::null;
-}
-
-Object ReferenceImp::toObject(ExecState */*exec*/) const
-{
- // invalid for Reference
- assert(false);
- return Object();
-}
-
-// ------------------------------ LabelStack -----------------------------------
-
-LabelStack::LabelStack(const LabelStack &other)
-{
- tos = 0;
- *this = other;
-}
-
-LabelStack &LabelStack::operator=(const LabelStack &other)
-{
- clear();
- tos = 0;
- StackElem *cur = 0;
- StackElem *se = other.tos;
- while (se) {
- StackElem *newPrev = new StackElem;
- newPrev->prev = 0;
- newPrev->id = se->id;
- if (cur)
- cur->prev = newPrev;
- else
- tos = newPrev;
- cur = newPrev;
- se = se->prev;
- }
- return *this;
-}
-
-bool LabelStack::push(const UString &id)
-{
- if (id.isEmpty() || contains(id))
- return false;
-
- StackElem *newtos = new StackElem;
- newtos->id = id;
- newtos->prev = tos;
- tos = newtos;
- return true;
-}
-
-bool LabelStack::contains(const UString &id) const
-{
- if (id.isEmpty())
- return true;
-
- for (StackElem *curr = tos; curr; curr = curr->prev)
- if (curr->id == id)
- return true;
-
- return false;
-}
-
-void LabelStack::pop()
-{
- if (tos) {
- StackElem *prev = tos->prev;
- delete tos;
- tos = prev;
- }
-}
-
-LabelStack::~LabelStack()
-{
- clear();
-}
-
-void LabelStack::clear()
-{
- StackElem *prev;
-
- while (tos) {
- prev = tos->prev;
- delete tos;
- tos = prev;
- }
-}
-
-// ------------------------------ CompletionImp --------------------------------
-
-CompletionImp::CompletionImp(ComplType c, const Value& v, const UString& t)
- : comp(c), val(v.imp()), tar(t)
-{
-}
-
-CompletionImp::~CompletionImp()
-{
-}
-
-void CompletionImp::mark()
-{
- ValueImp::mark();
-
- if (val && !val->marked())
- val->mark();
-}
-
-Value CompletionImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
-{
- // invalid for Completion
- assert(false);
- return Value();
-}
-
-bool CompletionImp::toBoolean(ExecState */*exec*/) const
-{
- // invalid for Completion
- assert(false);
- return false;
-}
-
-double CompletionImp::toNumber(ExecState */*exec*/) const
-{
- // invalid for Completion
- assert(false);
- return 0;
-}
-
-UString CompletionImp::toString(ExecState */*exec*/) const
-{
- // invalid for Completion
- assert(false);
- return UString::null;
-}
-
-Object CompletionImp::toObject(ExecState */*exec*/) const
-{
- // invalid for Completion
- assert(false);
- return Object();
-}
-
-// ------------------------------ ListImp --------------------------------------
-
-#ifdef KJS_DEBUG_MEM
-int ListImp::count = 0;
-#endif
-
-Value ListImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
-{
- // invalid for List
- assert(false);
- return Value();
-}
-
-bool ListImp::toBoolean(ExecState */*exec*/) const
-{
- // invalid for List
- assert(false);
- return false;
-}
-
-double ListImp::toNumber(ExecState */*exec*/) const
-{
- // invalid for List
- assert(false);
- return 0;
-}
-
-UString ListImp::toString(ExecState */*exec*/) const
-{
- // invalid for List
- assert(false);
- return UString::null;
-}
-
-Object ListImp::toObject(ExecState */*exec*/) const
-{
- // invalid for List
- assert(false);
- return Object();
-}
-
-ListImp::ListImp()
-{
-#ifdef KJS_DEBUG_MEM
- count++;
-#endif
-
- hook = new ListNode(Null(), 0L, 0L);
- hook->next = hook;
- hook->prev = hook;
- //fprintf(stderr,"ListImp::ListImp %p hook=%p\n",this,hook);
-}
-
-ListImp::~ListImp()
-{
- //fprintf(stderr,"ListImp::~ListImp %p\n",this);
-#ifdef KJS_DEBUG_MEM
- count--;
-#endif
-
- clear();
- delete hook;
-}
-
-void ListImp::mark()
-{
- ListNode *n = hook->next;
- while (n != hook) {
- if (!n->member->marked())
- n->member->mark();
- n = n->next;
- }
- ValueImp::mark();
-}
-
-void ListImp::append(const Value& obj)
-{
- ListNode *n = new ListNode(obj, hook->prev, hook);
- hook->prev->next = n;
- hook->prev = n;
-}
-
-void ListImp::prepend(const Value& obj)
-{
- ListNode *n = new ListNode(obj, hook, hook->next);
- hook->next->prev = n;
- hook->next = n;
-}
-
-void ListImp::appendList(const List& lst)
-{
- ListIterator it = lst.begin();
- ListIterator e = lst.end();
- while(it != e) {
- append(*it);
- ++it;
- }
-}
-
-void ListImp::prependList(const List& lst)
-{
- ListIterator it = lst.end();
- ListIterator e = lst.begin();
- while(it != e) {
- --it;
- prepend(*it);
- }
-}
-
-void ListImp::removeFirst()
-{
- erase(hook->next);
-}
-
-void ListImp::removeLast()
-{
- erase(hook->prev);
-}
-
-void ListImp::remove(const Value &obj)
-{
- if (obj.isNull())
- return;
- ListNode *n = hook->next;
- while (n != hook) {
- if (n->member == obj.imp()) {
- erase(n);
- return;
- }
- n = n->next;
- }
-}
-
-void ListImp::clear()
-{
- ListNode *n = hook->next;
- while (n != hook) {
- n = n->next;
- delete n->prev;
- }
-
- hook->next = hook;
- hook->prev = hook;
-}
-
-ListImp *ListImp::copy() const
-{
- ListImp* newList = new ListImp;
-
- ListIterator e = end();
- ListIterator it = begin();
-
- while(it != e) {
- newList->append(*it);
- ++it;
- }
-
- //fprintf( stderr, "ListImp::copy returning newList=%p\n", newList );
- return newList;
-}
-
-void ListImp::erase(ListNode *n)
-{
- if (n != hook) {
- n->next->prev = n->prev;
- n->prev->next = n->next;
- delete n;
- }
-}
-
-bool ListImp::isEmpty() const
-{
- return (hook->prev == hook);
-}
-
-int ListImp::size() const
-{
- int s = 0;
- ListNode *node = hook;
- while ((node = node->next) != hook)
- s++;
-
- return s;
-}
-
-Value ListImp::at(int i) const
-{
- if (i < 0 || i >= size())
- return Undefined();
-
- ListIterator it = begin();
- int j = 0;
- while ((j++ < i))
- it++;
-
- return *it;
-}
-
-ListImp *ListImp::emptyList = 0L;
-
-ListImp *ListImp::empty()
-{
- if (!emptyList)
- emptyList = new ListImp();
- return emptyList;
-}
-
-// ------------------------------ ContextImp -----------------------------------
-
-
-// ECMA 10.2
-ContextImp::ContextImp(Object &glob, ExecState *exec, Object &thisV, CodeType type,
- ContextImp *_callingContext, FunctionImp *func, const List &args)
-{
- codeType = type;
- callingCon = _callingContext;
-
- // create and initialize activation object (ECMA 10.1.6)
- if (type == FunctionCode || type == AnonymousCode ) {
- activation = Object(new ActivationImp(exec,func,args));
- variable = activation;
- } else {
- activation = Object();
- variable = glob;
- }
-
- // ECMA 10.2
- switch(type) {
- case EvalCode:
- if (callingCon) {
- scope = callingCon->scopeChain().copy();
- variable = callingCon->variableObject();
- thisVal = callingCon->thisValue();
- break;
- } // else same as GlobalCode
- case GlobalCode:
- scope = List();
- scope.append(glob);
- thisVal = Object(static_cast<ObjectImp*>(glob.imp()));
- break;
- case FunctionCode:
- case AnonymousCode:
- if (type == FunctionCode) {
- scope = func->scope().copy();
- scope.prepend(activation);
- } else {
- scope = List();
- scope.append(activation);
- scope.append(glob);
- }
- variable = activation; // TODO: DontDelete ? (ECMA 10.2.3)
- thisVal = thisV;
- break;
- }
-
-}
-
-ContextImp::~ContextImp()
-{
-}
-
-void ContextImp::pushScope(const Object &s)
-{
- scope.prepend(s);
-}
-
-void ContextImp::popScope()
-{
- scope.removeFirst();
-}
-
-// ------------------------------ Parser ---------------------------------------
-
-ProgramNode *Parser::progNode = 0;
-int Parser::sid = 0;
-
-ProgramNode *Parser::parse(const UChar *code, unsigned int length, int *sourceId,
- int *errLine, UString *errMsg)
-{
- if (errLine)
- *errLine = -1;
- if (errMsg)
- *errMsg = 0;
-
- Lexer::curr()->setCode(code, length);
- progNode = 0;
- sid++;
- if (sourceId)
- *sourceId = sid;
- // Enable this (and the #define YYDEBUG in grammar.y) to debug a parse error
- //extern int kjsyydebug;
- //kjsyydebug=1;
- int parseError = kjsyyparse();
- ProgramNode *prog = progNode;
- progNode = 0;
- sid = -1;
-
- if (parseError) {
- int eline = Lexer::curr()->lineNo();
- if (errLine)
- *errLine = eline;
- if (errMsg)
- *errMsg = "Parse error at line " + UString::from(eline);
-#ifndef NDEBUG
- fprintf(stderr, "KJS: JavaScript parse error at line %d.\n", eline);
-#endif
- delete prog;
- return 0;
- }
-
- return prog;
-}
-
-// ------------------------------ InterpreterImp -------------------------------
-
-InterpreterImp* InterpreterImp::s_hook = 0L;
-
-void InterpreterImp::globalInit()
-{
- //fprintf( stderr, "InterpreterImp::globalInit()\n" );
- UndefinedImp::staticUndefined = new UndefinedImp();
- UndefinedImp::staticUndefined->ref();
- NullImp::staticNull = new NullImp();
- NullImp::staticNull->ref();
- BooleanImp::staticTrue = new BooleanImp(true);
- BooleanImp::staticTrue->ref();
- BooleanImp::staticFalse = new BooleanImp(false);
- BooleanImp::staticFalse->ref();
-}
-
-void InterpreterImp::globalClear()
-{
- //fprintf( stderr, "InterpreterImp::globalClear()\n" );
- UndefinedImp::staticUndefined->deref();
- UndefinedImp::staticUndefined->setGcAllowed();
- UndefinedImp::staticUndefined = 0L;
- NullImp::staticNull->deref();
- NullImp::staticNull->setGcAllowed();
- NullImp::staticNull = 0L;
- BooleanImp::staticTrue->deref();
- BooleanImp::staticTrue->setGcAllowed();
- BooleanImp::staticTrue = 0L;
- BooleanImp::staticFalse->deref();
- BooleanImp::staticFalse->setGcAllowed();
- BooleanImp::staticFalse = 0L;
-}
-
-InterpreterImp::InterpreterImp(Interpreter *interp, const Object &glob)
-{
- // add this interpreter to the global chain
- // as a root set for garbage collection
- if (s_hook) {
- prev = s_hook;
- next = s_hook->next;
- s_hook->next->prev = this;
- s_hook->next = this;
- } else {
- // This is the first interpreter
- s_hook = next = prev = this;
- globalInit();
- }
-
- m_interpreter = interp;
- global = glob;
- globExec = new ExecState(m_interpreter,0);
- dbg = 0;
- m_compatMode = Interpreter::NativeMode;
-
- // initialize properties of the global object
-
- // Contructor prototype objects (Object.prototype, Array.prototype etc)
-
- FunctionPrototypeImp *funcProto = new FunctionPrototypeImp(globExec);
- b_FunctionPrototype = Object(funcProto);
- ObjectPrototypeImp *objProto = new ObjectPrototypeImp(globExec,funcProto);
- b_ObjectPrototype = Object(objProto);
- funcProto->setPrototype(b_ObjectPrototype);
-
- ArrayPrototypeImp *arrayProto = new ArrayPrototypeImp(globExec,objProto);
- b_ArrayPrototype = Object(arrayProto);
- StringPrototypeImp *stringProto = new StringPrototypeImp(globExec,objProto);
- b_StringPrototype = Object(stringProto);
- BooleanPrototypeImp *booleanProto = new BooleanPrototypeImp(globExec,objProto,funcProto);
- b_BooleanPrototype = Object(booleanProto);
- NumberPrototypeImp *numberProto = new NumberPrototypeImp(globExec,objProto,funcProto);
- b_NumberPrototype = Object(numberProto);
- DatePrototypeImp *dateProto = new DatePrototypeImp(globExec,objProto);
- b_DatePrototype = Object(dateProto);
- RegExpPrototypeImp *regexpProto = new RegExpPrototypeImp(globExec,objProto,funcProto);
- b_RegExpPrototype = Object(regexpProto);
- ErrorPrototypeImp *errorProto = new ErrorPrototypeImp(globExec,objProto,funcProto);
- b_ErrorPrototype = Object(errorProto);
-
- static_cast<ObjectImp*>(global.imp())->setPrototype(b_ObjectPrototype);
-
- // Constructors (Object, Array, etc.)
-
- ObjectObjectImp *objectObj = new ObjectObjectImp(globExec,objProto,funcProto);
- b_Object = Object(objectObj);
- FunctionObjectImp *funcObj = new FunctionObjectImp(globExec,funcProto);
- b_Function = Object(funcObj);
- ArrayObjectImp *arrayObj = new ArrayObjectImp(globExec,funcProto,arrayProto);
- b_Array = Object(arrayObj);
- StringObjectImp *stringObj = new StringObjectImp(globExec,funcProto,stringProto);
- b_String = Object(stringObj);
- BooleanObjectImp *booleanObj = new BooleanObjectImp(globExec,funcProto,booleanProto);
- b_Boolean = Object(booleanObj);
- NumberObjectImp *numberObj = new NumberObjectImp(globExec,funcProto,numberProto);
- b_Number = Object(numberObj);
- DateObjectImp *dateObj = new DateObjectImp(globExec,funcProto,dateProto);
- b_Date = Object(dateObj);
- RegExpObjectImp *regexpObj = new RegExpObjectImp(globExec,regexpProto,funcProto);
- b_RegExp = Object(regexpObj);
- ErrorObjectImp *errorObj = new ErrorObjectImp(globExec,funcProto,errorProto);
- b_Error = Object(errorObj);
-
- // Error object prototypes
- b_evalErrorPrototype = Object(new NativeErrorPrototypeImp(globExec,errorProto,EvalError,
- "EvalError","EvalError"));
- b_rangeErrorPrototype = Object(new NativeErrorPrototypeImp(globExec,errorProto,RangeError,
- "RangeError","RangeError"));
- b_referenceErrorPrototype = Object(new NativeErrorPrototypeImp(globExec,errorProto,ReferenceError,
- "ReferenceError","ReferenceError"));
- b_syntaxErrorPrototype = Object(new NativeErrorPrototypeImp(globExec,errorProto,SyntaxError,
- "SyntaxError","SyntaxError"));
- b_typeErrorPrototype = Object(new NativeErrorPrototypeImp(globExec,errorProto,TypeError,
- "TypeError","TypeError"));
- b_uriErrorPrototype = Object(new NativeErrorPrototypeImp(globExec,errorProto,URIError,
- "URIError","URIError"));
-
- // Error objects
- b_evalError = Object(new NativeErrorImp(globExec,funcProto,b_evalErrorPrototype));
- b_rangeError = Object(new NativeErrorImp(globExec,funcProto,b_rangeErrorPrototype));
- b_referenceError = Object(new NativeErrorImp(globExec,funcProto,b_referenceErrorPrototype));
- b_syntaxError = Object(new NativeErrorImp(globExec,funcProto,b_syntaxErrorPrototype));
- b_typeError = Object(new NativeErrorImp(globExec,funcProto,b_typeErrorPrototype));
- b_uriError = Object(new NativeErrorImp(globExec,funcProto,b_uriErrorPrototype));
-
- // ECMA 15.3.4.1
- funcProto->put(globExec,"constructor", b_Function, DontEnum);
-
- global.put(globExec,"Object", b_Object, DontEnum);
- global.put(globExec,"Function", b_Function, DontEnum);
- global.put(globExec,"Array", b_Array, DontEnum);
- global.put(globExec,"Boolean", b_Boolean, DontEnum);
- global.put(globExec,"String", b_String, DontEnum);
- global.put(globExec,"Number", b_Number, DontEnum);
- global.put(globExec,"Date", b_Date, DontEnum);
- global.put(globExec,"RegExp", b_RegExp, DontEnum);
- global.put(globExec,"Error", b_Error, DontEnum);
- // Using Internal for those to have something != 0
- // (see kjs_window). Maybe DontEnum would be ok too ?
- global.put(globExec,"EvalError",b_evalError, Internal);
- global.put(globExec,"RangeError",b_rangeError, Internal);
- global.put(globExec,"ReferenceError",b_referenceError, Internal);
- global.put(globExec,"SyntaxError",b_syntaxError, Internal);
- 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);
-
- // built-in values
- global.put(globExec,"NaN", Number(NaN), DontEnum);
- global.put(globExec,"Infinity", Number(Inf), DontEnum);
- global.put(globExec,"undefined", Undefined(), DontEnum);
-
- // built-in functions
- global.put(globExec,"eval", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::Eval, 1)), DontEnum);
- global.put(globExec,"parseInt", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::ParseInt, 2)), DontEnum);
- global.put(globExec,"parseFloat", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::ParseFloat, 1)), DontEnum);
- global.put(globExec,"isNaN", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::IsNaN, 1)), DontEnum);
- global.put(globExec,"isFinite", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::IsFinite, 1)), DontEnum);
- global.put(globExec,"escape", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::Escape, 1)), DontEnum);
- global.put(globExec,"unescape", Object(new GlobalFuncImp(globExec,funcProto,GlobalFuncImp::UnEscape, 1)), DontEnum);
-
- // built-in objects
- global.put(globExec,"Math", Object(new MathObjectImp(globExec,objProto)), DontEnum);
-
- recursion = 0;
-}
-
-InterpreterImp::~InterpreterImp()
-{
- if (dbg)
- dbg->detach(m_interpreter);
- delete globExec;
- globExec = 0L;
- clear();
-}
-
-void InterpreterImp::clear()
-{
- //fprintf(stderr,"InterpreterImp::clear\n");
- // remove from global chain (see init())
- next->prev = prev;
- prev->next = next;
- s_hook = next;
- if (s_hook == this)
- {
- // This was the last interpreter
- s_hook = 0L;
- globalClear();
- }
-}
-
-void InterpreterImp::mark()
-{
- //if (exVal && !exVal->marked())
- // exVal->mark();
- //if (retVal && !retVal->marked())
- // retVal->mark();
- if (UndefinedImp::staticUndefined && !UndefinedImp::staticUndefined->marked())
- UndefinedImp::staticUndefined->mark();
- if (NullImp::staticNull && !NullImp::staticNull->marked())
- NullImp::staticNull->mark();
- if (BooleanImp::staticTrue && !BooleanImp::staticTrue->marked())
- BooleanImp::staticTrue->mark();
- if (BooleanImp::staticFalse && !BooleanImp::staticFalse->marked())
- BooleanImp::staticFalse->mark();
- if (ListImp::emptyList && !ListImp::emptyList->marked())
- ListImp::emptyList->mark();
- //fprintf( stderr, "InterpreterImp::mark this=%p global.imp()=%p\n", this, global.imp() );
- if (global.imp())
- global.imp()->mark();
- if (m_interpreter)
- m_interpreter->mark();
-}
-
-bool InterpreterImp::checkSyntax(const UString &code)
-{
- // Parser::parse() returns 0 in a syntax error occurs, so we just check for that
- ProgramNode *progNode = Parser::parse(code.data(),code.size(),0,0,0);
- bool ok = (progNode != 0);
- delete progNode;
- return ok;
-}
-
-Completion InterpreterImp::evaluate(const UString &code, const Value &thisV)
-{
- // prevent against infinite recursion
- if (recursion >= 20) {
- return Completion(Throw,Error::create(globExec,GeneralError,"Recursion too deep"));
- }
-
- // parse the source code
- int sid;
- int errLine;
- UString errMsg;
- ProgramNode *progNode = Parser::parse(code.data(),code.size(),&sid,&errLine,&errMsg);
-
- // notify debugger that source has been parsed
- if (dbg) {
- bool cont = dbg->sourceParsed(globExec,sid,code,errLine);
- if (!cont)
- return Completion(Break);
- }
-
- // no program node means a syntax occurred
- if (!progNode) {
- Object err = Error::create(globExec,SyntaxError,errMsg.ascii(),errLine);
- err.put(globExec,"sid",Number(sid));
- return Completion(Throw,err);
- }
-
- globExec->clearException();
-
- recursion++;
- progNode->ref();
-
- Object globalObj = globalObject();
- Object thisObj = globalObject();
-
- if (!thisV.isNull()) {
- // "this" must be an object... use same rules as Function.prototype.apply()
- if (thisV.isA(NullType) || thisV.isA(UndefinedType))
- thisObj = globalObject();
- else {
- thisObj = thisV.toObject(globExec);
- }
- }
-
- Completion res;
- if (globExec->hadException()) {
- // the thisArg.toObject() conversion above might have thrown an exception - if so,
- // propagate it back
- res = Completion(Throw,globExec->exception());
- }
- else {
- // execute the code
- ExecState *exec1 = 0;
- ContextImp *ctx = new ContextImp(globalObj, exec1, thisObj);
- ExecState *newExec = new ExecState(m_interpreter,ctx);
-
- res = progNode->execute(newExec);
-
- delete newExec;
- delete ctx;
- }
-
- if (progNode->deref())
- delete progNode;
- recursion--;
-
- return res;
-}
-
-void InterpreterImp::setDebugger(Debugger *d)
-{
- if (d)
- d->detach(m_interpreter);
- dbg = d;
-}
-
-// ------------------------------ InternalFunctionImp --------------------------
-
-const ClassInfo InternalFunctionImp::info = {"Function", 0, 0, 0};
-
-InternalFunctionImp::InternalFunctionImp(FunctionPrototypeImp *funcProto)
- : ObjectImp(Object(funcProto))
-{
-}
-
-bool InternalFunctionImp::implementsHasInstance() const
-{
- return true;
-}
-
-Boolean InternalFunctionImp::hasInstance(ExecState *exec, const Value &value)
-{
- if (value.type() != ObjectType)
- return Boolean(false);
-
- Value prot = get(exec,"prototype");
- if (prot.type() != ObjectType && prot.type() != NullType) {
- Object err = Error::create(exec, TypeError, "Invalid prototype encountered "
- "in instanceof operation.");
- exec->setException(err);
- return Boolean(false);
- }
-
- Object v = Object(static_cast<ObjectImp*>(value.imp()));
- while ((v = Object::dynamicCast(v.prototype())).imp()) {
- if (v.imp() == prot.imp())
- return Boolean(true);
- }
- return Boolean(false);
-}
-
-// ------------------------------ global functions -----------------------------
-
-double KJS::roundValue(ExecState *exec, const Value &v)
-{
- if (v.type() == UndefinedType) /* TODO: see below */
- return 0.0;
- Number n = v.toNumber(exec);
- if (n.value() == 0.0) /* TODO: -0, NaN, Inf */
- return 0.0;
- double d = floor(fabs(n.value()));
- if (n.value() < 0)
- d *= -1;
-
- return d;
-}
-
-#ifndef NDEBUG
-#include <stdio.h>
-void KJS::printInfo(ExecState *exec, const char *s, const Value &o, int lineno)
-{
- if (o.isNull())
- fprintf(stderr, "KJS: %s: (null)", s);
- else {
- Value v = o;
- if (o.isA(ReferenceType))
- v = o.getValue(exec);
-
- UString name;
- switch ( v.type() ) {
- case UnspecifiedType:
- name = "Unspecified";
- break;
- case UndefinedType:
- name = "Undefined";
- break;
- case NullType:
- name = "Null";
- break;
- case BooleanType:
- name = "Boolean";
- break;
- case StringType:
- name = "String";
- break;
- case NumberType:
- name = "Number";
- break;
- case ObjectType:
- name = Object::dynamicCast(v).className();
- if (name.isNull())
- name = "(unknown class)";
- break;
- case ReferenceType:
- name = "Reference";
- break;
- case ListType:
- name = "List";
- break;
- case CompletionType:
- name = "Completion";
- break;
- default:
- break;
- }
- UString vString = v.toString(exec);
- if ( vString.size() > 50 )
- vString = vString.substr( 0, 50 ) + "...";
- // Can't use two UString::ascii() in the same fprintf call
- CString tempString( vString.cstring() );
-
- fprintf(stderr, "KJS: %s: %s : %s (%p)",
- s, tempString.c_str(), name.ascii(), (void*)v.imp());
-
- if (lineno >= 0)
- fprintf(stderr, ", line %d\n",lineno);
- else
- fprintf(stderr, "\n");
- if (!o.isNull())
- if (o.isA(ReferenceType)) {
- fprintf(stderr, "KJS: Was property '%s'\n", o.getPropertyName(exec).ascii());
- printInfo(exec,"of", o.getBase(exec));
- }
- }
-}
-#endif
diff --git a/WebCore/src/kdelibs/kjs/internal.h b/WebCore/src/kdelibs/kjs/internal.h
deleted file mode 100644
index a6d095f..0000000
--- a/WebCore/src/kdelibs/kjs/internal.h
+++ /dev/null
@@ -1,494 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#ifndef _INTERNAL_H_
-#define _INTERNAL_H_
-
-#include "ustring.h"
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-
-#define I18N_NOOP(s) s
-
-namespace KJS {
-
- static const double D16 = 65536.0;
- static const double D32 = 4294967296.0;
-
- class ProgramNode;
- class FunctionBodyNode;
- class FunctionPrototypeImp;
- class FunctionImp;
- class Debugger;
-
- // ---------------------------------------------------------------------------
- // Primitive impls
- // ---------------------------------------------------------------------------
-
- class UndefinedImp : public ValueImp {
- public:
- UndefinedImp() {}
- virtual ~UndefinedImp() { }
-
- Type type() const { return UndefinedType; }
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- static UndefinedImp *staticUndefined;
- };
-
- class NullImp : public ValueImp {
- public:
- NullImp() {}
- virtual ~NullImp() { }
-
- Type type() const { return NullType; }
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- static NullImp *staticNull;
- };
-
- class BooleanImp : public ValueImp {
- public:
- virtual ~BooleanImp() { }
- BooleanImp(bool v = false) : val(v) { }
- bool value() const { return val; }
-
- Type type() const { return BooleanType; }
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- static BooleanImp *staticTrue;
- static BooleanImp *staticFalse;
- private:
- bool val;
- };
-
- class StringImp : public ValueImp {
- public:
- StringImp(const UString& v);
- virtual ~StringImp() { }
- UString value() const { return val; }
-
- Type type() const { return StringType; }
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- private:
- UString val;
- };
-
- class NumberImp : public ValueImp {
- public:
- NumberImp(double v);
- virtual ~NumberImp() { }
- double value() const { return val; }
-
- Type type() const { return NumberType; }
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- private:
- double val;
- };
-
- // ---------------------------------------------------------------------------
- // Internal type impls
- // ---------------------------------------------------------------------------
-
- class ReferenceImp : public ValueImp {
- public:
-
- ReferenceImp(const Value& v, const UString& p);
- virtual ~ReferenceImp() { }
- virtual void mark();
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- Value getBase() const { return Value(base); }
- UString getPropertyName() const { return prop; }
-
- Type type() const { return ReferenceType; }
-
- private:
- ValueImp *base;
- UString prop;
- };
-
- class CompletionImp : public ValueImp {
- public:
- Type type() const { return CompletionType; }
-
- CompletionImp(ComplType c, const Value& v, const UString& t);
- virtual ~CompletionImp();
- virtual void mark();
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- ComplType complType() const { return comp; }
- Value value() const { return Value(val); }
- UString target() const { return tar; }
-
- private:
- ComplType comp;
- ValueImp * val;
- UString tar;
- };
-
- /**
- * @internal
- */
- class ListNode {
- friend class List;
- friend class ListImp;
- friend class ListIterator;
- ListNode(Value val, ListNode *p, ListNode *n)
- : member(val.imp()), prev(p), next(n) {};
- ValueImp *member;
- ListNode *prev, *next;
- };
-
- class ListImp : public ValueImp {
- friend class ListIterator;
- friend class List;
- friend class InterpreterImp;
- public:
- ListImp();
- ~ListImp();
-
- Type type() const { return ListType; }
-
- virtual void mark();
-
- Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- void append(const Value& val);
- void prepend(const Value& val);
- void appendList(const List& lst);
- void prependList(const List& lst);
- void removeFirst();
- void removeLast();
- void remove(const Value &val);
- void clear();
- ListImp *copy() const;
- ListIterator begin() const { return ListIterator(hook->next); }
- ListIterator end() const { return ListIterator(hook); }
- // bool isEmpty() const { return (hook->prev == hook); }
- bool isEmpty() const;
- int size() const;
- Value at(int i) const;
- Value operator[](int i) const { return at(i); }
- static ListImp* empty();
-
-#ifdef KJS_DEBUG_MEM
- static int count;
-#endif
- private:
- void erase(ListNode *n);
- ListNode *hook;
- static ListImp *emptyList;
- };
-
- /**
- * @short The "label set" in Ecma-262 spec
- */
- class LabelStack {
- public:
- LabelStack(): tos(0L) {}
- ~LabelStack();
-
- LabelStack(const LabelStack &other);
- LabelStack &operator=(const LabelStack &other);
-
- /**
- * If id is not empty and is not in the stack already, puts it on top of
- * the stack and returns true, otherwise returns false
- */
- bool push(const UString &id);
- /**
- * Is the id in the stack?
- */
- bool contains(const UString &id) const;
- /**
- * Removes from the stack the last pushed id (what else?)
- */
- void pop();
- private:
- struct StackElem {
- UString id;
- StackElem *prev;
- };
-
- StackElem *tos;
- void clear();
- };
-
-
- // ---------------------------------------------------------------------------
- // Parsing & evaluateion
- // ---------------------------------------------------------------------------
-
- enum CodeType { GlobalCode,
- EvalCode,
- FunctionCode,
- AnonymousCode };
-
- /**
- * @short Execution context.
- */
- class ContextImp {
- public:
- ContextImp(Object &glob, ExecState *exec, Object &thisV, CodeType type = GlobalCode,
- ContextImp *_callingContext = 0L, FunctionImp *func = 0L, const List &args = List());
- virtual ~ContextImp();
-
- const List scopeChain() const { return scope; }
- Object variableObject() const { return variable; }
- void setVariableObject(const Object &v) { variable = v; }
- Object thisValue() const { return thisVal; }
- ContextImp *callingContext() { return callingCon; }
- Object activationObject() { return activation; }
-
- void pushScope(const Object &s);
- void popScope();
- LabelStack *seenLabels() { return &ls; }
-
- private:
-
- List scope;
- Object variable;
- Object thisVal;
- ContextImp *callingCon;
- Object activation;
-
-
- LabelStack ls;
- CodeType codeType;
- };
-
- /**
- * @internal
- *
- * Parses ECMAScript source code and converts into ProgramNode objects, which
- * represent the root of a parse tree. This class provides a conveniant workaround
- * for the problem of the bison parser working in a static context.
- */
- class Parser {
- public:
- static ProgramNode *parse(const UChar *code, unsigned int length, int *sourceId = 0,
- int *errLine = 0, UString *errMsg = 0);
-
- static ProgramNode *progNode;
- static int sid;
- };
-
- class InterpreterImp {
- friend class Collector;
- public:
- static void globalInit();
- static void globalClear();
-
- InterpreterImp(Interpreter *interp, const Object &glob);
- ~InterpreterImp();
-
- Object globalObject() const { return global; }
- Interpreter* interpreter() const { return m_interpreter; }
-
- void mark();
-
- ExecState *globalExec() { return globExec; }
- bool checkSyntax(const UString &code);
- Completion evaluate(const UString &code, const Value &thisV);
- Debugger *debugger() const { return dbg; }
- void setDebugger(Debugger *d);
-
- Object builtinObject() const { return b_Object; }
- Object builtinFunction() const { return b_Function; }
- Object builtinArray() const { return b_Array; }
- Object builtinBoolean() const { return b_Boolean; }
- Object builtinString() const { return b_String; }
- Object builtinNumber() const { return b_Number; }
- Object builtinDate() const { return b_Date; }
- Object builtinRegExp() const { return b_RegExp; }
- Object builtinError() const { return b_Error; }
-
- Object builtinObjectPrototype() const { return b_ObjectPrototype; }
- Object builtinFunctionPrototype() const { return b_FunctionPrototype; }
- Object builtinArrayPrototype() const { return b_ArrayPrototype; }
- Object builtinBooleanPrototype() const { return b_BooleanPrototype; }
- Object builtinStringPrototype() const { return b_StringPrototype; }
- Object builtinNumberPrototype() const { return b_NumberPrototype; }
- Object builtinDatePrototype() const { return b_DatePrototype; }
- Object builtinRegExpPrototype() const { return b_RegExpPrototype; }
- Object builtinErrorPrototype() const { return b_ErrorPrototype; }
-
- Object builtinEvalError() const { return b_evalError; }
- Object builtinRangeError() const { return b_rangeError; }
- Object builtinReferenceError() const { return b_referenceError; }
- Object builtinSyntaxError() const { return b_syntaxError; }
- Object builtinTypeError() const { return b_typeError; }
- Object builtinURIError() const { return b_uriError; }
-
- Object builtinEvalErrorPrototype() const { return b_evalErrorPrototype; }
- Object builtinRangeErrorPrototype() const { return b_rangeErrorPrototype; }
- Object builtinReferenceErrorPrototype() const { return b_referenceErrorPrototype; }
- Object builtinSyntaxErrorPrototype() const { return b_syntaxErrorPrototype; }
- Object builtinTypeErrorPrototype() const { return b_typeErrorPrototype; }
- Object builtinURIErrorPrototype() const { return b_uriErrorPrototype; }
-
- void setCompatMode(Interpreter::CompatMode mode) { m_compatMode = mode; }
- Interpreter::CompatMode compatMode() const { return m_compatMode; }
-
- // Chained list of interpreters (ring)
- static InterpreterImp* firstInterpreter() { return s_hook; }
- InterpreterImp *nextInterpreter() const { return next; }
- InterpreterImp *prevInterpreter() const { return prev; }
-
- private:
- void clear();
- Interpreter *m_interpreter;
- Object global;
- Debugger *dbg;
-
- // Built-in properties of the object prototype. These are accessible
- // from here even if they are replaced by js code (e.g. assigning to
- // Array.prototype)
-
- Object b_Object;
- Object b_Function;
- Object b_Array;
- Object b_Boolean;
- Object b_String;
- Object b_Number;
- Object b_Date;
- Object b_RegExp;
- Object b_Error;
-
- Object b_ObjectPrototype;
- Object b_FunctionPrototype;
- Object b_ArrayPrototype;
- Object b_BooleanPrototype;
- Object b_StringPrototype;
- Object b_NumberPrototype;
- Object b_DatePrototype;
- Object b_RegExpPrototype;
- Object b_ErrorPrototype;
-
- Object b_evalError;
- Object b_rangeError;
- Object b_referenceError;
- Object b_syntaxError;
- Object b_typeError;
- Object b_uriError;
-
- Object b_evalErrorPrototype;
- Object b_rangeErrorPrototype;
- Object b_referenceErrorPrototype;
- Object b_syntaxErrorPrototype;
- Object b_typeErrorPrototype;
- Object b_uriErrorPrototype;
-
- ExecState *globExec;
- Interpreter::CompatMode m_compatMode;
-
- // Chained list of interpreters (ring) - for collector
- static InterpreterImp* s_hook;
- InterpreterImp *next, *prev;
-
- int recursion;
- };
-
- class AttachedInterpreter;
- class DebuggerImp {
- public:
-
- DebuggerImp() {
- interps = 0;
- isAborted = false;
- }
-
- void abort() { isAborted = true; }
- bool aborted() const { return isAborted; }
-
- AttachedInterpreter *interps;
- bool isAborted;
- };
-
-
-
- class InternalFunctionImp : public ObjectImp {
- public:
- InternalFunctionImp(FunctionPrototypeImp *funcProto);
- bool implementsHasInstance() const;
- Boolean hasInstance(ExecState *exec, const Value &value);
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- // helper function for toInteger, toInt32, toUInt32 and toUInt16
- double roundValue(ExecState *exec, const Value &v);
-
-#ifndef NDEBUG
- void printInfo(ExecState *exec, const char *s, const Value &o, int lineno = -1);
-#endif
-
-}; // namespace
-
-
-#endif // _INTERNAL_H_
diff --git a/WebCore/src/kdelibs/kjs/interpreter.cpp b/WebCore/src/kdelibs/kjs/interpreter.cpp
deleted file mode 100644
index 1c97e08..0000000
--- a/WebCore/src/kdelibs/kjs/interpreter.cpp
+++ /dev/null
@@ -1,366 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "internal.h"
-#include "collector.h"
-#include "operations.h"
-#include "error_object.h"
-#include "nodes.h"
-
-using namespace KJS;
-
-// ------------------------------ Context --------------------------------------
-
-Context::Context(ContextImp *c)
-{
- rep = c;
-}
-
-Context::Context(const Context &c)
-{
- rep = c.rep;
-}
-
-Context& Context::operator=(const Context &c)
-{
- rep = c.rep;
- return *this;
-}
-
-Context::~Context()
-{
-}
-
-bool Context::isNull() const
-{
- return (rep == 0);
-}
-
-ContextImp *Context::imp() const
-{
- return rep;
-}
-
-const List Context::scopeChain() const
-{
- return rep->scopeChain();
-}
-
-Object Context::variableObject() const
-{
- return rep->variableObject();
-}
-
-Object Context::thisValue() const
-{
- return rep->thisValue();
-}
-
-const Context Context::callingContext() const
-{
- return rep->callingContext();
-}
-
-// ------------------------------ Interpreter ----------------------------------
-
-Interpreter::Interpreter(const Object &global) : rep(0)
-{
- rep = new InterpreterImp(this,global);
-}
-
-Interpreter::Interpreter()
-{
- Object global(new ObjectImp());
- rep = new InterpreterImp(this,global);
-}
-
-Interpreter::~Interpreter()
-{
- delete rep;
-}
-
-Object Interpreter::globalObject() const
-{
- return rep->globalObject();
-}
-
-ExecState *Interpreter::globalExec()
-{
- return rep->globalExec();
-}
-
-bool Interpreter::checkSyntax(const UString &code)
-{
- return rep->checkSyntax(code);
-}
-
-Completion Interpreter::evaluate(const UString &code, const Value &thisV)
-{
- return rep->evaluate(code,thisV);
-}
-
-InterpreterImp *Interpreter::imp()
-{
- return rep;
-}
-
-Object Interpreter::builtinObject() const
-{
- return rep->builtinObject();
-}
-
-Object Interpreter::builtinFunction() const
-{
- return rep->builtinFunction();
-}
-
-Object Interpreter::builtinArray() const
-{
- return rep->builtinArray();
-}
-
-Object Interpreter::builtinBoolean() const
-{
- return rep->builtinBoolean();
-}
-
-Object Interpreter::builtinString() const
-{
- return rep->builtinString();
-}
-
-Object Interpreter::builtinNumber() const
-{
- return rep->builtinNumber();
-}
-
-Object Interpreter::builtinDate() const
-{
- return rep->builtinDate();
-}
-
-Object Interpreter::builtinRegExp() const
-{
- return rep->builtinRegExp();
-}
-
-Object Interpreter::builtinError() const
-{
- return rep->builtinError();
-}
-
-Object Interpreter::builtinObjectPrototype() const
-{
- return rep->builtinObjectPrototype();
-}
-
-Object Interpreter::builtinFunctionPrototype() const
-{
- return rep->builtinFunctionPrototype();
-}
-
-Object Interpreter::builtinArrayPrototype() const
-{
- return rep->builtinArrayPrototype();
-}
-
-Object Interpreter::builtinBooleanPrototype() const
-{
- return rep->builtinBooleanPrototype();
-}
-
-Object Interpreter::builtinStringPrototype() const
-{
- return rep->builtinStringPrototype();
-}
-
-Object Interpreter::builtinNumberPrototype() const
-{
- return rep->builtinNumberPrototype();
-}
-
-Object Interpreter::builtinDatePrototype() const
-{
- return rep->builtinDatePrototype();
-}
-
-Object Interpreter::builtinRegExpPrototype() const
-{
- return rep->builtinRegExpPrototype();
-}
-
-Object Interpreter::builtinErrorPrototype() const
-{
- return rep->builtinErrorPrototype();
-}
-
-Object Interpreter::builtinEvalError() const
-{
- return rep->builtinEvalError();
-}
-
-Object Interpreter::builtinRangeError() const
-{
- return rep->builtinRangeError();
-}
-
-Object Interpreter::builtinReferenceError() const
-{
- return rep->builtinReferenceError();
-}
-
-Object Interpreter::builtinSyntaxError() const
-{
- return rep->builtinSyntaxError();
-}
-
-Object Interpreter::builtinTypeError() const
-{
- return rep->builtinTypeError();
-}
-
-Object Interpreter::builtinURIError() const
-{
- return rep->builtinURIError();
-}
-
-Object Interpreter::builtinEvalErrorPrototype() const
-{
- return rep->builtinEvalErrorPrototype();
-}
-
-Object Interpreter::builtinRangeErrorPrototype() const
-{
- return rep->builtinRangeErrorPrototype();
-}
-
-Object Interpreter::builtinReferenceErrorPrototype() const
-{
- return rep->builtinReferenceErrorPrototype();
-}
-
-Object Interpreter::builtinSyntaxErrorPrototype() const
-{
- return rep->builtinSyntaxErrorPrototype();
-}
-
-Object Interpreter::builtinTypeErrorPrototype() const
-{
- return rep->builtinTypeErrorPrototype();
-}
-
-Object Interpreter::builtinURIErrorPrototype() const
-{
- return rep->builtinURIErrorPrototype();
-}
-
-void Interpreter::setCompatMode(CompatMode mode)
-{
- rep->setCompatMode(mode);
-}
-
-Interpreter::CompatMode Interpreter::compatMode() const
-{
- return rep->compatMode();
-}
-
-#ifdef KJS_DEBUG_MEM
-void Interpreter::finalCheck()
-{
- fprintf(stderr,"Interpreter::finalCheck()\n");
- // Garbage collect - as many times as necessary
- // (we could delete an object which was holding another object, so
- // the deref() will happen too late for deleting the impl of the 2nd object).
- while( Collector::collect() )
- ;
-
- fprintf(stderr,"ListImp::count = %d\n", KJS::ListImp::count);
- Node::finalCheck();
- Collector::finalCheck();
-}
-#endif
-
-// ------------------------------ ExecState --------------------------------------
-
-namespace KJS {
- class ExecStateImp
- {
- public:
- ExecStateImp(Interpreter *interp, ContextImp *con)
- : interpreter(interp), context(con) {};
- Interpreter *interpreter;
- ContextImp *context;
- Value exception;
- };
-};
-
-ExecState::~ExecState()
-{
- delete rep;
-}
-
-Interpreter *ExecState::interpreter() const
-{
- return rep->interpreter;
-}
-
-const Context ExecState::context() const
-{
- return rep->context;
-}
-
-void ExecState::setException(const Value &e)
-{
- rep->exception = e;
-}
-
-void ExecState::clearException()
-{
- rep->exception = Value();
-}
-
-Value ExecState::exception() const
-{
- return rep->exception;
-}
-
-bool ExecState::hadException() const
-{
- return !rep->exception.isNull();
-}
-
-ExecState::ExecState(Interpreter *interp, ContextImp *con)
-{
- rep = new ExecStateImp(interp,con);
-}
-
diff --git a/WebCore/src/kdelibs/kjs/interpreter.h b/WebCore/src/kdelibs/kjs/interpreter.h
deleted file mode 100644
index 909afd8..0000000
--- a/WebCore/src/kdelibs/kjs/interpreter.h
+++ /dev/null
@@ -1,360 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _KJS_INTERPRETER_H_
-#define _KJS_INTERPRETER_H_
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-
-namespace KJS {
-
- class ContextImp;
- class ExecStateImp;
- class InterpreterImp;
-
- /**
- * Represents an execution context, as specified by section 10 of the ECMA
- * spec.
- *
- * An execution context contains information about the current state of the
- * script - the scope for variable lookup, the value of "this", etc. A new
- * execution context is entered whenever global code is executed (e.g. with
- * @ref Interpreter::evaluate()), a function is called (see @ref
- * Object::call()), or the builtin "eval" function is executed.
- *
- * Most inheritable functions in the KJS api take a @ref ExecState pointer as
- * their first parameter. This can be used to obtain a handle to the current
- * execution context.
- *
- * Note: Context objects are wrapper classes/smart pointers for the internal
- * KJS ContextImp type. When one context variable is assigned to another, it
- * is still referencing the same internal object.
- */
- class Context {
- public:
- Context(ContextImp *);
- Context(const Context &c);
- Context& operator=(const Context &c);
- virtual ~Context();
-
- bool isNull() const;
- ContextImp *imp() const;
-
- /**
- * Returns the scope chain for this execution context. This is used for
- * variable lookup, with the list being searched from start to end until a
- * variable is found.
- *
- * @return The execution context's scope chain
- */
- const List scopeChain() const;
-
- /**
- * Returns the variable object for the execution context. This contains a
- * property for each variable declared in the execution context.
- *
- * @return The execution context's variable object
- */
- Object variableObject() const;
-
- /**
- * Returns the "this" value for the execution context. This is the value
- * returned when a script references the special variable "this". It should
- * always be an Object, unless application-specific code has passed in a
- * different type.
- *
- * The object that is used as the "this" value depends on the type of
- * execution context - for global contexts, the global object is used. For
- * function objewcts, the value is given by the caller (e.g. in the case of
- * obj.func(), obj would be the "this" value). For code executed by the
- * built-in "eval" function, the this value is the same as the calling
- * context.
- *
- * @return The execution context's "this" value
- */
- Object thisValue() const;
-
- /**
- * Returns the context from which the current context was invoked. For
- * global code this will be a null context (i.e. one for which @ref
- * isNull() returns true). You should check @ref isNull() on the returned
- * value before calling any of it's methods.
- *
- * @return The calling execution context
- */
- const Context callingContext() const;
- private:
- ContextImp *rep;
- };
-
- /**
- * Interpreter objects can be used to evaluate ECMAScript code. Each
- * interpreter has a global object which is used for the purposes of code
- * evaluation, and also provides access to built-in properties such as
- " Object" and "Number".
- */
- class Interpreter {
- public:
- /**
- * Creates a new interpreter. The supplied object will be used as the global
- * object for all scripts executed with this interpreter. During
- * constuction, all the standard properties such as "Object" and "Number"
- * will be added to the global object.
- *
- * Note: You should not use the same global object for multiple
- * interpreters.
- *
- * This is due do the fact that the built-in properties are set in the
- * constructor, and if these objects have been modified from another
- * interpreter (e.g. a script modifying String.prototype), the changes will
- * be overridden.
- *
- * @param global The object to use as the global object for this interpreter
- */
- Interpreter(const Object &global);
- /**
- * Creates a new interpreter. A global object will be created and
- * initialized with the standard global properties.
- */
- Interpreter();
- virtual ~Interpreter();
-
- /**
- * Returns the object that is used as the global object during all script
- * execution performed by this interpreter
- */
- Object globalObject() const;
-
- /**
- * Returns the execution state object which can be used to execute
- * scripts using this interpreter at a the "global" level, i.e. one
- * with a execution context that has the global object as the "this"
- * value, and who's scope chain contains only the global object.
- *
- * Note: this pointer remains constant for the life of the interpreter
- * and should not be manually deleted.
- *
- * @return The interpreter global execution state object
- */
- ExecState *globalExec();
-
- /**
- * Parses the supplied ECMAScript code and checks for syntax errors.
- *
- * @param code The code to check
- * @return true if there were no syntax errors in the code, otherwise false
- */
- bool checkSyntax(const UString &code);
-
- /**
- * Evaluates the supplied ECMAScript code.
- *
- * Since this method returns a Completion, you should check the type of
- * completion to detect an error or before attempting to access the returned
- * value. For example, if an error occurs during script execution and is not
- * caught by the script, the completion type will be Throw.
- *
- * If the supplied code is invalid, a SyntaxError will be thrown.
- *
- * @param code The code to evaluate
- * @param thisV The value to pass in as the "this" value for the script
- * execution. This should either be Null() or an Object.
- * @return A completion object representing the result of the execution.
- */
- Completion evaluate(const UString &code, const Value &thisV = Value());
-
- /**
- * @internal
- *
- * Returns the implementation object associated with this interpreter.
- * Only useful for internal KJS operations.
- */
- InterpreterImp *imp();
-
- /**
- * Returns the builtin "Object" object. This is the object that was set
- * as a property of the global object during construction; if the property
- * is replaced by script code, this method will still return the original
- * object.
- *
- * @return The builtin "Object" object
- */
- Object builtinObject() const;
-
- /** Returns the builtin "Function" object. */
- Object builtinFunction() const;
-
- /** Returns the builtin "Array" object. */
- Object builtinArray() const;
-
-
- /** Returns the builtin "Boolean" object. */
- Object builtinBoolean() const;
-
- /** Returns the builtin "String" object. */
- Object builtinString() const;
-
- /** Returns the builtin "Number" object. */
- Object builtinNumber() const;
-
- /** Returns the builtin "Date" object. */
- Object builtinDate() const;
-
- /** Returns the builtin "RegExp" object. */
- Object builtinRegExp() const;
-
- /** Returns the builtin "Error" object. */
- Object builtinError() const;
-
- /** Returns the builtin "Object.prototype" object. */
- Object builtinObjectPrototype() const;
-
- /** Returns the builtin "Function.prototype" object. */
- Object builtinFunctionPrototype() const;
-
- /** Returns the builtin "Array.prototype" object. */
- Object builtinArrayPrototype() const;
-
- /** Returns the builtin "Boolean.prototype" object. */
- Object builtinBooleanPrototype() const;
-
- /** Returns the builtin "String.prototype" object. */
- Object builtinStringPrototype() const;
-
- /** Returns the builtin "Number.prototype" object. */
- Object builtinNumberPrototype() const;
-
- /** Returns the builtin "Date.prototype" object. */
- Object builtinDatePrototype() const;
-
- /** Returns the builtin "RegExp.prototype" object. */
- Object builtinRegExpPrototype() const;
-
- /** Returns the builtin "Error.prototype" object. */
- Object builtinErrorPrototype() const;
-
- /** The initial value of "Error" global property */
- Object builtinEvalError() const;
- Object builtinRangeError() const;
- Object builtinReferenceError() const;
- Object builtinSyntaxError() const;
- Object builtinTypeError() const;
- Object builtinURIError() const;
-
- Object builtinEvalErrorPrototype() const;
- Object builtinRangeErrorPrototype() const;
- Object builtinReferenceErrorPrototype() const;
- Object builtinSyntaxErrorPrototype() const;
- Object builtinTypeErrorPrototype() const;
- Object builtinURIErrorPrototype() const;
-
- enum CompatMode { NativeMode, IECompat, NetscapeCompat };
- /**
- * Call this to enable a compatibility mode with another browser.
- * (by default konqueror is in "native mode").
- * Currently, in KJS, this only changes the behaviour of Date::getYear()
- * which returns the full year under IE.
- */
- void setCompatMode(CompatMode mode);
- CompatMode compatMode() const;
-
- /**
- * Called by InterpreterImp during the mark phase of the garbage collector
- * Default implementation does nothing, this exist for classes that reimplement Interpreter.
- */
- virtual void mark() {}
-
- /**
- * Provides a way to distinguish derived classes.
- * Only useful if you reimplement Interpreter and if different kind of
- * interpreters are created in the same process.
- * The base class returns 0, the ECMA-bindings interpreter returns 1.
- */
- virtual int rtti() { return 0; }
-
-#ifdef KJS_DEBUG_MEM
- /**
- * @internal
- */
- static void finalCheck();
-#endif
- private:
- InterpreterImp *rep;
-
- /**
- * This constructor is not implemented, in order to prevent
- * copy-construction of Interpreter objects. You should always pass around
- * pointers to an interpreter instance instead.
- */
- Interpreter(const Interpreter&);
-
- /**
- * This constructor is not implemented, in order to prevent assignment of
- * Interpreter objects. You should always pass around pointers to an
- * interpreter instance instead.
- */
- Interpreter operator=(const Interpreter&);
- };
-
- /**
- * Represents the current state of script execution. This object allows you
- * obtain a handle the interpreter that is currently executing the script,
- * and also the current execution state context.
- */
- class ExecState {
- friend class InterpreterImp;
- friend class FunctionImp;
- friend class GlobalFuncImp;
- public:
- virtual ~ExecState();
-
- /**
- * Returns the interpreter associated with this execution state
- *
- * @return The interpreter executing the script
- */
- Interpreter *interpreter() const;
-
- /**
- * Returns the execution context associated with this execution state
- *
- * @return The current execution state context
- */
- const Context context() const;
-
- void setException(const Value &e);
- void clearException();
- Value exception() const;
- bool hadException() const;
-
- private:
- ExecState(Interpreter *interp, ContextImp *con);
- ExecStateImp *rep;
- };
-
-}; // namespace
-
-#endif // _KJS_INTERPRETER_H_
diff --git a/WebCore/src/kdelibs/kjs/keywords.table b/WebCore/src/kdelibs/kjs/keywords.table
deleted file mode 100644
index 391aa34..0000000
--- a/WebCore/src/kdelibs/kjs/keywords.table
+++ /dev/null
@@ -1,66 +0,0 @@
-# main keywords
- at begin mainTable 41
-# types
-null NULLTOKEN
-true TRUETOKEN
-false FALSETOKEN
-# keywords
-break BREAK
-case CASE
-catch CATCH
-default DEFAULT
-finally FINALLY
-for FOR
-instanceof INSTANCEOF
-new NEW
-var VAR
-continue CONTINUE
-function FUNCTION
-return RETURN
-void VOID
-delete DELETE
-if IF
-this THIS
-do DO
-while WHILE
-else ELSE
-in IN
-switch SWITCH
-throw THROW
-try TRY
-typeof TYPEOF
-with WITH
-# reserved for future use
-abstract RESERVED
-boolean RESERVED
-byte RESERVED
-char RESERVED
-class RESERVED
-const RESERVED
-debugger RESERVED
-double RESERVED
-enum RESERVED
-export RESERVED
-extends RESERVED
-final RESERVED
-float RESERVED
-goto RESERVED
-implements RESERVED
-import RESERVED
-int RESERVED
-interface RESERVED
-long RESERVED
-native RESERVED
-package RESERVED
-private RESERVED
-protected RESERVED
-public RESERVED
-short RESERVED
-static RESERVED
-super RESERVED
-synchronized RESERVED
-throws RESERVED
-transient RESERVED
-volatile RESERVED
- at end
-
diff --git a/WebCore/src/kdelibs/kjs/kjs-test b/WebCore/src/kdelibs/kjs/kjs-test
deleted file mode 100755
index 255c89f..0000000
--- a/WebCore/src/kdelibs/kjs/kjs-test
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-unset MallocStackLogging
-export MallocStackLogging
-unset MallocScribble
-export MallocScribble
-unset MallocGuardEdges
-export MallocGuardEdges
-unset DYLD_IMAGE_SUFFIX
-export DYLD_IMAGE_SUFFIX
-
-`dirname $0`/testkjs `dirname $0`/test.js 2>&1
-
-if [ $? -eq 1 ]; then
- exit 0;
-fi
\ No newline at end of file
diff --git a/WebCore/src/kdelibs/kjs/kjs-test.chk b/WebCore/src/kdelibs/kjs/kjs-test.chk
deleted file mode 100644
index e5729b7..0000000
--- a/WebCore/src/kdelibs/kjs/kjs-test.chk
+++ /dev/null
@@ -1,16 +0,0 @@
----> inside test()
----> 20
----> 30
----> inside test()
----> 10
----> 50
----> s = 60
----> i = 2
----> a[0] = 11
----> a[1] = 22
----> a[2] = undefined
----> a[3] = undefined
----> a[4] = apple
----> b = [object Boolean]
----> bbbc
-OK.
diff --git a/WebCore/src/kdelibs/kjs/lexer.cpp b/WebCore/src/kdelibs/kjs/lexer.cpp
deleted file mode 100644
index cede3a9..0000000
--- a/WebCore/src/kdelibs/kjs/lexer.cpp
+++ /dev/null
@@ -1,809 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "nodes.h"
-#include "lexer.h"
-#include "ustring.h"
-#include "lookup.h"
-#include "internal.h"
-
-// we can't specify the namespace in yacc's C output, so do it here
-using namespace KJS;
-
-static Lexer *currLexer = 0;
-
-#ifndef KDE_USE_FINAL
-#include "grammar.h"
-#endif
-
-#include "lexer.lut.h"
-
-extern YYLTYPE yylloc; // global bison variable holding token info
-
-// a bridge for yacc from the C world to C++
-int kjsyylex()
-{
- return Lexer::curr()->lex();
-}
-
-Lexer::Lexer()
- : yylineno(0),
- size8(128), size16(128), restrKeyword(false),
- eatNextIdentifier(false), stackToken(-1), lastToken(-1), pos(0),
- code(0), length(0),
-#ifndef KJS_PURE_ECMA
- bol(true),
-#endif
- current(0), next1(0), next2(0), next3(0)
-{
- // allocate space for read buffers
- buffer8 = new char[size8];
- buffer16 = new UChar[size16];
- currLexer = this;
-
-}
-
-Lexer::~Lexer()
-{
- delete [] buffer8;
- delete [] buffer16;
-}
-
-Lexer *Lexer::curr()
-{
- if (!currLexer) {
- // create singleton instance
- currLexer = new Lexer();
- }
- return currLexer;
-}
-
-void Lexer::setCode(const UChar *c, unsigned int len)
-{
- yylineno = 0;
- restrKeyword = false;
- delimited = false;
- eatNextIdentifier = false;
- stackToken = -1;
- lastToken = -1;
- pos = 0;
- code = c;
- length = len;
- skipLF = false;
- skipCR = false;
-#ifndef KJS_PURE_ECMA
- bol = true;
-#endif
-
- // read first characters
- current = (length > 0) ? code[0].unicode() : 0;
- next1 = (length > 1) ? code[1].unicode() : 0;
- next2 = (length > 2) ? code[2].unicode() : 0;
- next3 = (length > 3) ? code[3].unicode() : 0;
-}
-
-void Lexer::shift(unsigned int p)
-{
- while (p--) {
- pos++;
- current = next1;
- next1 = next2;
- next2 = next3;
- next3 = (pos + 3 < length) ? code[pos+3].unicode() : 0;
- }
-}
-
-void Lexer::setDone(State s)
-{
- state = s;
- done = true;
-}
-
-int Lexer::lex()
-{
- int token = 0;
- state = Start;
- unsigned short stringType = 0; // either single or double quotes
- pos8 = pos16 = 0;
- done = false;
- terminator = false;
- skipLF = false;
- skipCR = false;
-
- // did we push a token on the stack previously ?
- // (after an automatic semicolon insertion)
- if (stackToken >= 0) {
- setDone(Other);
- token = stackToken;
- stackToken = 0;
- }
-
- while (!done) {
- if (skipLF && current != '\n') // found \r but not \n afterwards
- skipLF = false;
- if (skipCR && current != '\r') // found \n but not \r afterwards
- skipCR = false;
- if (skipLF || skipCR) // found \r\n or \n\r -> eat the second one
- {
- skipLF = false;
- skipCR = false;
- shift(1);
- }
- switch (state) {
- case Start:
- if (isWhiteSpace()) {
- // do nothing
- } else if (current == '/' && next1 == '/') {
- shift(1);
- state = InSingleLineComment;
- } else if (current == '/' && next1 == '*') {
- shift(1);
- state = InMultiLineComment;
- } else if (current == 0) {
- if (!terminator && !delimited) {
- // automatic semicolon insertion if program incomplete
- token = ';';
- stackToken = 0;
- setDone(Other);
- } else
- setDone(Eof);
- } else if (isLineTerminator()) {
- yylineno++;
-#ifndef KJS_PURE_ECMA
- bol = true;
-#endif
- terminator = true;
- if (restrKeyword) {
- token = ';';
- setDone(Other);
- }
- } else if (current == '"' || current == '\'') {
- state = InString;
- stringType = current;
- } else if (isIdentLetter(current)) {
- record16(current);
- state = InIdentifier;
- } else if (current == '0') {
- record8(current);
- state = InNum0;
- } else if (isDecimalDigit(current)) {
- record8(current);
- state = InNum;
- } else if (current == '.' && isDecimalDigit(next1)) {
- record8(current);
- state = InDecimal;
-#ifndef KJS_PURE_ECMA
- // <!-- marks the beginning of a line comment (for www usage)
- } else if (bol && current == '<' && next1 == '!' &&
- next2 == '-' && next3 == '-') {
- shift(3);
- state = InSingleLineComment;
- // same of -->
- } else if (bol && current == '-' && next1 == '-' && next2 == '>') {
- shift(2);
- state = InSingleLineComment;
-#endif
- } else {
- token = matchPunctuator(current, next1, next2, next3);
- if (token != -1) {
- setDone(Other);
- } else {
- // cerr << "encountered unknown character" << endl;
- setDone(Bad);
- }
- }
- break;
- case InString:
- if (current == stringType) {
- shift(1);
- setDone(String);
- } else if (current == 0 || isLineTerminator()) {
- setDone(Bad);
- } else if (current == '\\') {
- state = InEscapeSequence;
- } else {
- record16(current);
- }
- break;
- // Escape Sequences inside of strings
- case InEscapeSequence:
- if (isOctalDigit(current)) {
- if (current >= '0' && current <= '3' &&
- isOctalDigit(next1) && isOctalDigit(next2)) {
- record16(convertOctal(current, next1, next2));
- shift(2);
- state = InString;
- } else if (isOctalDigit(current) && isOctalDigit(next1)) {
- record16(convertOctal('0', current, next1));
- shift(1);
- state = InString;
- } else if (isOctalDigit(current)) {
- record16(convertOctal('0', '0', current));
- state = InString;
- } else {
- setDone(Bad);
- }
- } else if (current == 'x')
- state = InHexEscape;
- else if (current == 'u')
- state = InUnicodeEscape;
- else {
- record16(singleEscape(current));
- state = InString;
- }
- break;
- case InHexEscape:
- if (isHexDigit(current) && isHexDigit(next1)) {
- state = InString;
- record16(convertHex(current, next1));
- shift(1);
- } else if (current == stringType) {
- record16('x');
- shift(1);
- setDone(String);
- } else {
- record16('x');
- record16(current);
- state = InString;
- }
- break;
- case InUnicodeEscape:
- if (isHexDigit(current) && isHexDigit(next1) &&
- isHexDigit(next2) && isHexDigit(next3)) {
- record16(convertUnicode(current, next1, next2, next3));
- shift(3);
- state = InString;
- } else if (current == stringType) {
- record16('u');
- shift(1);
- setDone(String);
- } else {
- setDone(Bad);
- }
- break;
- case InSingleLineComment:
- if (isLineTerminator()) {
- yylineno++;
- terminator = true;
-#ifndef KJS_PURE_ECMA
- bol = true;
-#endif
- if (restrKeyword) {
- token = ';';
- setDone(Other);
- } else
- state = Start;
- } else if (current == 0) {
- setDone(Eof);
- }
- break;
- case InMultiLineComment:
- if (current == 0) {
- setDone(Bad);
- } else if (isLineTerminator()) {
- yylineno++;
- } else if (current == '*' && next1 == '/') {
- state = Start;
- shift(1);
- }
- break;
- case InIdentifier:
- if (isIdentLetter(current) || isDecimalDigit(current)) {
- record16(current);
- break;
- }
- setDone(Identifier);
- break;
- case InNum0:
- if (current == 'x' || current == 'X') {
- record8(current);
- state = InHex;
- } else if (current == '.') {
- record8(current);
- state = InDecimal;
- } else if (current == 'e' || current == 'E') {
- record8(current);
- state = InExponentIndicator;
- } else if (isOctalDigit(current)) {
- record8(current);
- state = InOctal;
- } else if (isDecimalDigit(current)) {
- record8(current);
- state = InDecimal;
- } else {
- setDone(Number);
- }
- break;
- case InHex:
- if (isHexDigit(current)) {
- record8(current);
- } else {
- setDone(Hex);
- }
- break;
- case InOctal:
- if (isOctalDigit(current)) {
- record8(current);
- }
- else if (isDecimalDigit(current)) {
- record8(current);
- state = InDecimal;
- } else
- setDone(Octal);
- break;
- case InNum:
- if (isDecimalDigit(current)) {
- record8(current);
- } else if (current == '.') {
- record8(current);
- state = InDecimal;
- } else if (current == 'e' || current == 'E') {
- record8(current);
- state = InExponentIndicator;
- } else
- setDone(Number);
- break;
- case InDecimal:
- if (isDecimalDigit(current)) {
- record8(current);
- } else if (current == 'e' || current == 'E') {
- record8(current);
- state = InExponentIndicator;
- } else
- setDone(Number);
- break;
- case InExponentIndicator:
- if (current == '+' || current == '-') {
- record8(current);
- } else if (isDecimalDigit(current)) {
- record8(current);
- state = InExponent;
- } else
- setDone(Bad);
- break;
- case InExponent:
- if (isDecimalDigit(current)) {
- record8(current);
- } else
- setDone(Number);
- break;
- default:
- assert(!"Unhandled state in switch statement");
- }
-
- // move on to the next character
- if (!done)
- shift(1);
-#ifndef KJS_PURE_ECMA
- if (state != Start && state != InSingleLineComment)
- bol = false;
-#endif
- }
-
- // no identifiers allowed directly after numeric literal, e.g. "3in" is bad
- if ((state == Number || state == Octal || state == Hex)
- && isIdentLetter(current))
- state = Bad;
-
- // terminate string
- buffer8[pos8] = '\0';
-
-#ifdef KJS_DEBUG_LEX
- fprintf(stderr, "line: %d ", lineNo());
- fprintf(stderr, "yytext (%x): ", buffer8[0]);
- fprintf(stderr, "%s ", buffer8);
-#endif
-
- double dval = 0;
- if (state == Number) {
- dval = strtod(buffer8, 0L);
- } else if (state == Hex) { // scan hex numbers
- // TODO: support long unsigned int
- unsigned int i;
- sscanf(buffer8, "%x", &i);
- dval = i;
- state = Number;
- } else if (state == Octal) { // scan octal number
- unsigned int ui;
- sscanf(buffer8, "%o", &ui);
- dval = ui;
- state = Number;
- }
-
-#ifdef KJS_DEBUG_LEX
- switch (state) {
- case Eof:
- printf("(EOF)\n");
- break;
- case Other:
- printf("(Other)\n");
- break;
- case Identifier:
- printf("(Identifier)/(Keyword)\n");
- break;
- case String:
- printf("(String)\n");
- break;
- case Number:
- printf("(Number)\n");
- break;
- default:
- printf("(unknown)");
- }
-#endif
-
- if (state != Identifier && eatNextIdentifier)
- eatNextIdentifier = false;
-
- restrKeyword = false;
- delimited = false;
- yylloc.first_line = yylineno; // ???
- yylloc.last_line = yylineno;
-
- switch (state) {
- case Eof:
- token = 0;
- break;
- case Other:
- if(token == '}' || token == ';') {
- delimited = true;
- }
- break;
- case Identifier:
- if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) {
- // Lookup for keyword failed, means this is an identifier
- // Apply anonymous-function hack below (eat the identifier)
- if (eatNextIdentifier) {
- eatNextIdentifier = false;
- UString debugstr(buffer16, pos16); fprintf(stderr,"Anonymous function hack: eating identifier %s\n",debugstr.ascii());
- token = lex();
- break;
- }
- /* TODO: close leak on parse error. same holds true for String */
- kjsyylval.ustr = new UString(buffer16, pos16);
- token = IDENT;
- break;
- }
-
- eatNextIdentifier = false;
- // Hack for "f = function somename() { ... }", too hard to get into the grammar
- if (token == FUNCTION && lastToken == '=' )
- eatNextIdentifier = true;
-
- if (token == CONTINUE || token == BREAK ||
- token == RETURN || token == THROW)
- restrKeyword = true;
- break;
- case String:
- kjsyylval.ustr = new UString(buffer16, pos16);
- token = STRING;
- break;
- case Number:
- kjsyylval.dval = dval;
- token = NUMBER;
- break;
- case Bad:
- fprintf(stderr, "yylex: ERROR.\n");
- return -1;
- default:
- assert(!"unhandled numeration value in switch");
- return -1;
- }
- lastToken = token;
- return token;
-}
-
-bool Lexer::isWhiteSpace() const
-{
- return (current == ' ' || current == '\t' ||
- current == 0x0b || current == 0x0c);
-}
-
-bool Lexer::isLineTerminator()
-{
- bool cr = (current == '\r');
- bool lf = (current == '\n');
- if (cr)
- skipLF = true;
- else if (lf)
- skipCR = true;
- return cr || lf;
-}
-
-bool Lexer::isIdentLetter(unsigned short c)
-{
- /* TODO: allow other legitimate unicode chars */
- return (c >= 'a' && c <= 'z' ||
- c >= 'A' && c <= 'Z' ||
- c == '$' || c == '_');
-}
-
-bool Lexer::isDecimalDigit(unsigned short c)
-{
- return (c >= '0' && c <= '9');
-}
-
-bool Lexer::isHexDigit(unsigned short c) const
-{
- return (c >= '0' && c <= '9' ||
- c >= 'a' && c <= 'f' ||
- c >= 'A' && c <= 'F');
-}
-
-bool Lexer::isOctalDigit(unsigned short c) const
-{
- return (c >= '0' && c <= '7');
-}
-
-int Lexer::matchPunctuator(unsigned short c1, unsigned short c2,
- unsigned short c3, unsigned short c4)
-{
- if (c1 == '>' && c2 == '>' && c3 == '>' && c4 == '=') {
- shift(4);
- return URSHIFTEQUAL;
- } else if (c1 == '=' && c2 == '=' && c3 == '=') {
- shift(3);
- return STREQ;
- } else if (c1 == '!' && c2 == '=' && c3 == '=') {
- shift(3);
- return STRNEQ;
- } else if (c1 == '>' && c2 == '>' && c3 == '>') {
- shift(3);
- return URSHIFT;
- } else if (c1 == '<' && c2 == '<' && c3 == '=') {
- shift(3);
- return LSHIFTEQUAL;
- } else if (c1 == '>' && c2 == '>' && c3 == '=') {
- shift(3);
- return RSHIFTEQUAL;
- } else if (c1 == '<' && c2 == '=') {
- shift(2);
- return LE;
- } else if (c1 == '>' && c2 == '=') {
- shift(2);
- return GE;
- } else if (c1 == '!' && c2 == '=') {
- shift(2);
- return NE;
- } else if (c1 == '+' && c2 == '+') {
- shift(2);
- if (terminator)
- return AUTOPLUSPLUS;
- else
- return PLUSPLUS;
- } else if (c1 == '-' && c2 == '-') {
- shift(2);
- if (terminator)
- return AUTOMINUSMINUS;
- else
- return MINUSMINUS;
- } else if (c1 == '=' && c2 == '=') {
- shift(2);
- return EQEQ;
- } else if (c1 == '+' && c2 == '=') {
- shift(2);
- return PLUSEQUAL;
- } else if (c1 == '-' && c2 == '=') {
- shift(2);
- return MINUSEQUAL;
- } else if (c1 == '*' && c2 == '=') {
- shift(2);
- return MULTEQUAL;
- } else if (c1 == '/' && c2 == '=') {
- shift(2);
- return DIVEQUAL;
- } else if (c1 == '&' && c2 == '=') {
- shift(2);
- return ANDEQUAL;
- } else if (c1 == '^' && c2 == '=') {
- shift(2);
- return XOREQUAL;
- } else if (c1 == '%' && c2 == '=') {
- shift(2);
- return MODEQUAL;
- } else if (c1 == '|' && c2 == '=') {
- shift(2);
- return OREQUAL;
- } else if (c1 == '<' && c2 == '<') {
- shift(2);
- return LSHIFT;
- } else if (c1 == '>' && c2 == '>') {
- shift(2);
- return RSHIFT;
- } else if (c1 == '&' && c2 == '&') {
- shift(2);
- return AND;
- } else if (c1 == '|' && c2 == '|') {
- shift(2);
- return OR;
- }
-
- switch(c1) {
- case '=':
- case '>':
- case '<':
- case ',':
- case '!':
- case '~':
- case '?':
- case ':':
- case '.':
- case '+':
- case '-':
- case '*':
- case '/':
- case '&':
- case '|':
- case '^':
- case '%':
- case '(':
- case ')':
- case '{':
- case '}':
- case '[':
- case ']':
- case ';':
- shift(1);
- return static_cast<int>(c1);
- default:
- return -1;
- }
-}
-
-unsigned short Lexer::singleEscape(unsigned short c) const
-{
- switch(c) {
- case 'b':
- return 0x08;
- case 't':
- return 0x09;
- case 'n':
- return 0x0A;
- case 'v':
- return 0x0B;
- case 'f':
- return 0x0C;
- case 'r':
- return 0x0D;
- case '"':
- return 0x22;
- case '\'':
- return 0x27;
- case '\\':
- return 0x5C;
- default:
- return c;
- }
-}
-
-unsigned short Lexer::convertOctal(unsigned short c1, unsigned short c2,
- unsigned short c3) const
-{
- return ((c1 - '0') * 64 + (c2 - '0') * 8 + c3 - '0');
-}
-
-unsigned char Lexer::convertHex(unsigned short c)
-{
- if (c >= '0' && c <= '9')
- return (c - '0');
- else if (c >= 'a' && c <= 'f')
- return (c - 'a' + 10);
- else
- return (c - 'A' + 10);
-}
-
-unsigned char Lexer::convertHex(unsigned short c1, unsigned short c2)
-{
- return ((convertHex(c1) << 4) + convertHex(c2));
-}
-
-UChar Lexer::convertUnicode(unsigned short c1, unsigned short c2,
- unsigned short c3, unsigned short c4)
-{
- return UChar((convertHex(c1) << 4) + convertHex(c2),
- (convertHex(c3) << 4) + convertHex(c4));
-}
-
-void Lexer::record8(unsigned short c)
-{
- assert(c <= 0xff);
-
- // enlarge buffer if full
- if (pos8 >= size8 - 1) {
- char *tmp = new char[2 * size8];
- memcpy(tmp, buffer8, size8 * sizeof(char));
- delete [] buffer8;
- buffer8 = tmp;
- size8 *= 2;
- }
-
- buffer8[pos8++] = (char) c;
-}
-
-void Lexer::record16(UChar c)
-{
- // enlarge buffer if full
- if (pos16 >= size16 - 1) {
- UChar *tmp = new UChar[2 * size16];
- memcpy(tmp, buffer16, size16 * sizeof(UChar));
- delete [] buffer16;
- buffer16 = tmp;
- size16 *= 2;
- }
-
- buffer16[pos16++] = c;
-}
-
-bool Lexer::scanRegExp()
-{
- pos16 = 0;
- bool lastWasEscape = false;
- bool inBrackets = false;
-
- while (1) {
- if (isLineTerminator() || current == 0)
- return false;
- else if (current != '/' || lastWasEscape == true || inBrackets == true)
- {
- // keep track of '[' and ']'
- if ( !lastWasEscape ) {
- if ( current == '[' && !inBrackets )
- inBrackets = true;
- if ( current == ']' && inBrackets )
- inBrackets = false;
- }
- record16(current);
- lastWasEscape =
- !lastWasEscape && (current == '\\');
- }
- else { // end of regexp
- pattern = UString(buffer16, pos16);
- pos16 = 0;
- shift(1);
- break;
- }
- shift(1);
- }
-
- while (isIdentLetter(current)) {
- record16(current);
- shift(1);
- }
- flags = UString(buffer16, pos16);
-
- return true;
-}
diff --git a/WebCore/src/kdelibs/kjs/lexer.h b/WebCore/src/kdelibs/kjs/lexer.h
deleted file mode 100644
index ad0f01a..0000000
--- a/WebCore/src/kdelibs/kjs/lexer.h
+++ /dev/null
@@ -1,136 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _KJSLEXER_H_
-#define _KJSLEXER_H_
-
-#include "ustring.h"
-
-namespace KJS {
-
- class RegExp;
-
- class Lexer {
- public:
- Lexer();
- ~Lexer();
- static Lexer *curr();
-
- void setCode(const UChar *c, unsigned int len);
- int lex();
-
- int lineNo() const { return yylineno + 1; }
-
- bool prevTerminator() const { return terminator; }
-
- enum State { Start,
- Identifier,
- InIdentifier,
- InSingleLineComment,
- InMultiLineComment,
- InNum,
- InNum0,
- InHex,
- InOctal,
- InDecimal,
- InExponentIndicator,
- InExponent,
- Hex,
- Octal,
- Number,
- String,
- Eof,
- InString,
- InEscapeSequence,
- InHexEscape,
- InUnicodeEscape,
- Other,
- Bad };
-
- bool scanRegExp();
- UString pattern, flags;
-
- private:
- int yylineno;
- bool done;
- char *buffer8;
- UChar *buffer16;
- unsigned int size8, size16;
- unsigned int pos8, pos16;
- bool terminator;
- bool restrKeyword;
- // encountered delimiter like "'" and "}" on last run
- bool delimited;
- bool skipLF;
- bool skipCR;
- bool eatNextIdentifier;
- int stackToken;
- int lastToken;
-
- State state;
- void setDone(State s);
- unsigned int pos;
- void shift(unsigned int p);
- int lookupKeyword(const char *);
-
- bool isWhiteSpace() const;
- bool isLineTerminator();
- bool isHexDigit(unsigned short c) const;
- bool isOctalDigit(unsigned short c) const;
-
- int matchPunctuator(unsigned short c1, unsigned short c2,
- unsigned short c3, unsigned short c4);
- unsigned short singleEscape(unsigned short c) const;
- unsigned short convertOctal(unsigned short c1, unsigned short c2,
- unsigned short c3) const;
- public:
- static unsigned char convertHex(unsigned short c1);
- static unsigned char convertHex(unsigned short c1, unsigned short c2);
- static UChar convertUnicode(unsigned short c1, unsigned short c2,
- unsigned short c3, unsigned short c4);
- static bool isIdentLetter(unsigned short c);
- static bool isDecimalDigit(unsigned short c);
-
- private:
-
- void record8(unsigned short c);
- void record16(UChar c);
-
- const UChar *code;
- unsigned int length;
- int yycolumn;
-#ifndef KJS_PURE_ECMA
- int bol; // begin of line
-#endif
-
- // current and following unicode characters
- unsigned short current, next1, next2, next3;
-
- // for future extensions
- class LexerPrivate;
- LexerPrivate *priv;
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/lookup.cpp b/WebCore/src/kdelibs/kjs/lookup.cpp
deleted file mode 100644
index 774b221..0000000
--- a/WebCore/src/kdelibs/kjs/lookup.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include "lookup.h"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-using namespace KJS;
-
-const HashEntry* Lookup::findEntry( const struct HashTable *table,
- const UChar *c, unsigned int len )
-{
- if (table->type != 2) {
- fprintf(stderr, "KJS: Unknown hash table version.\n");
- return 0;
- }
- char *ascii = new char[len+1];
- unsigned int i;
- for(i = 0; i < len; i++, c++) {
- if (!c->high())
- ascii[i] = c->low();
- else
- break;
- }
- ascii[i] = '\0';
-
- int h = hash(ascii) % table->hashSize;
- const HashEntry *e = &table->entries[h];
-
- // empty bucket ?
- if (!e->s) {
- delete [] ascii;
- return 0;
- }
-
- do {
- // compare strings
- if (strcmp(ascii, e->s) == 0) {
- delete [] ascii;
- return e;
- }
- // try next bucket
- e = e->next;
- } while (e);
-
- delete [] ascii;
- return 0;
-}
-
-const HashEntry* Lookup::findEntry( const struct HashTable *table,
- const UString &s )
-{
- return findEntry( table, s.data(), s.size() );
-}
-
-int Lookup::find(const struct HashTable *table,
- const UChar *c, unsigned int len)
-{
- const HashEntry *entry = findEntry( table, c, len );
- if (entry)
- return entry->value;
- return -1;
-}
-
-int Lookup::find(const struct HashTable *table, const UString &s)
-{
- return find(table, s.data(), s.size());
-}
-
-unsigned int Lookup::hash(const UChar *c, unsigned int len)
-{
- unsigned int val = 0;
- // ignoring higher byte
- for (unsigned int i = 0; i < len; i++, c++)
- val += c->low();
-
- return val;
-}
-
-unsigned int Lookup::hash(const UString &key)
-{
- return hash(key.data(), key.size());
-}
-
-unsigned int Lookup::hash(const char *s)
-{
- unsigned int val = 0;
- while (*s)
- val += *s++;
-
- return val;
-}
diff --git a/WebCore/src/kdelibs/kjs/lookup.h b/WebCore/src/kdelibs/kjs/lookup.h
deleted file mode 100644
index 0c4da25..0000000
--- a/WebCore/src/kdelibs/kjs/lookup.h
+++ /dev/null
@@ -1,233 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _KJSLOOKUP_H_
-#define _KJSLOOKUP_H_
-
-#include "ustring.h"
-#include "value.h"
-#include <stdio.h>
-
-namespace KJS {
-
- /**
- * An entry in a hash table.
- */
- struct HashEntry {
- /** s is the key (e.g. a property name) */
- const char *s;
- /** value is the result value (usually an enum value) */
- int value;
- /** attr is a set for flags (e.g. the property flags, see object.h) */
- short int attr;
- /** params is another number. For property hashtables, it is used to
- denote the number of argument of the function */
- short int params;
- /** next is the pointer to the next entry for the same hash value */
- const HashEntry *next;
- };
-
- /**
- * A hash table
- * Usually the hashtable is generated by the create_hash_table script, from a .table file.
- *
- * The implementation uses an array of entries, "size" is the total size of that array.
- * The entries between 0 and hashSize-1 are the entry points
- * for each hash value, and the entries between hashSize and size-1
- * are the overflow entries for the hash values that need one.
- * The "next" pointer of the entry links entry points to overflow entries,
- * and links overflow entries between them.
- */
- struct HashTable {
- /** type is a version number. Currently always 2 */
- int type;
- /** size is the total number of entries in the hashtable, including the null entries,
- * i.e. the size of the "entries" array.
- * Used to iterate over all entries in the table */
- int size;
- /** pointer to the array of entries
- * Mind that some entries in the array are null (0,0,0,0). */
- const HashEntry *entries;
- /** the maximum value for the hash. Always smaller than size. */
- int hashSize;
- };
-
- /**
- * @short Fast keyword lookup.
- */
- class Lookup {
- public:
- /** Find an entry in the table, and return its value (i.e. the value field of HashEntry) */
- static int find(const struct HashTable *table, const UString &s);
- static int find(const struct HashTable *table,
- const UChar *c, unsigned int len);
-
- /**
- * Find an entry in the table, and return the entry
- * This variant gives access to the other attributes of the entry,
- * especially the attr field.
- */
- static const HashEntry* findEntry(const struct HashTable *table,
- const UString &s);
- static const HashEntry* findEntry(const struct HashTable *table,
- const UChar *c, unsigned int len);
-
- /** Calculate the hash value for a given key */
- static unsigned int hash(const UString &key);
- static unsigned int hash(const UChar *c, unsigned int len);
- static unsigned int hash(const char *s);
- };
-
- class ExecState;
- class UString;
- /** @internal
- * Helper for lookupFunction and lookupValueOrFunction */
- template <class FuncImp>
- inline Value lookupOrCreateFunction(ExecState *exec, const UString &propertyName,
- const ObjectImp *thisObj, int token, int params, int attr)
- {
- // Look for cached value in dynamic map of properties (in ObjectImp)
- ValueImp * cachedVal = thisObj->ObjectImp::getDirect(propertyName);
- /*if (cachedVal)
- fprintf(stderr, "lookupOrCreateFunction: Function -> looked up in ObjectImp, found type=%d\n", cachedVal->type());*/
- if (cachedVal)
- return Value(cachedVal);
-
- Value val = Value(new FuncImp(exec,token, params));
- ObjectImp *thatObj = const_cast<ObjectImp *>(thisObj);
- thatObj->ObjectImp::put(exec, propertyName, val, attr);
- return val;
- }
-
- /**
- * Helper method for property lookups
- *
- * This method does it all (looking in the hashtable, checking for function
- * overrides, creating the function or retrieving from cache, calling
- * getValueProperty in case of a non-function property, forwarding to parent if
- * unknown property).
- *
- * Template arguments:
- * @param FuncImp the class which implements this object's functions
- * @param ThisImp the class of "this". It must implement the getValueProperty(exec,token) method,
- * for non-function properties.
- * @param ParentImp the class of the parent, to propagate the lookup.
- *
- * Method arguments:
- * @param exec execution state, as usual
- * @param propertyName the property we're looking for
- * @param table the static hashtable for this class
- * @param thisObj "this"
- */
- template <class FuncImp, class ThisImp, class ParentImp>
- inline Value lookupGet(ExecState *exec, const UString &propertyName,
- const HashTable* table, const ThisImp* thisObj)
- {
- const HashEntry* entry = Lookup::findEntry(table, propertyName);
-
- if (!entry) // not found, forward to parent
- return thisObj->ParentImp::get(exec, propertyName);
-
- //fprintf(stderr, "lookupGet: found value=%d attr=%d\n", entry->value, entry->attr);
- if (entry->attr & Function)
- return lookupOrCreateFunction<FuncImp>(exec, propertyName, thisObj, entry->value, entry->params, entry->attr);
- return thisObj->getValueProperty(exec, entry->value);
- }
-
- /**
- * Simplified version of lookupGet in case there are only functions.
- * Using this instead of lookupGet prevents 'this' from implementing a dummy getValueProperty.
- */
- template <class FuncImp, class ParentImp>
- inline Value lookupGetFunction(ExecState *exec, const UString &propertyName,
- const HashTable* table, const ObjectImp* thisObj)
- {
- const HashEntry* entry = Lookup::findEntry(table, propertyName);
-
- if (!entry) // not found, forward to parent
- return static_cast<const ParentImp *>(thisObj)->ParentImp::get(exec, propertyName);
-
- if (entry->attr & Function)
- return lookupOrCreateFunction<FuncImp>(exec, propertyName, thisObj, entry->value, entry->params, entry->attr);
-
- fprintf(stderr, "Function bit not set! Shouldn't happen in lookupGetFunction!\n" );
- return Undefined();
- };
-
- /**
- * Simplified version of lookupGet in case there are no functions, only "values".
- * Using this instead of lookupGet removes the need for a FuncImp class.
- */
- template <class ThisImp, class ParentImp>
- inline Value lookupGetValue(ExecState *exec, const UString &propertyName,
- const HashTable* table, const ThisImp* thisObj)
- {
- const HashEntry* entry = Lookup::findEntry(table, propertyName);
-
- if (!entry) // not found, forward to parent
- return thisObj->ParentImp::get(exec, propertyName);
-
- if (entry->attr & Function)
- fprintf(stderr, "Function bit set! Shouldn't happen in lookupGetValue! propertyName was %s\n", propertyName.ascii() );
- return thisObj->getValueProperty(exec, entry->value);
- }
-
- /**
- * This one is for "put".
- * Lookup hash entry for property to be set, and set the value.
- */
- template <class ThisImp, class ParentImp>
- inline void lookupPut(ExecState *exec, const UString &propertyName,
- const Value& value, int attr,
- const HashTable* table, const ThisImp* thisObj)
- {
- const HashEntry* entry = Lookup::findEntry(table, propertyName);
-
- if (!entry) // not found: forward to parent
- thisObj->ParentImp::put(exec, propertyName, value, attr);
- else if (entry->attr & Function) // function: put as override property
- thisObj->ObjectImp::put(exec, propertyName, value, attr);
- else if (entry->attr & ReadOnly) // readonly! Can't put!
-#ifdef KJS_VERBOSE
- fprintf(stderr,"WARNING: Attempt to change value of readonly property '%s'\n",propertyName.ascii());
-#else
- ; // do nothing
-#endif
- else
- thisObj->putValueProperty(exec, entry->value, value, attr);
- }
-
- /*
- * List of things to do when porting an objectimp to the 'static hashtable' mechanism:
- * - write the hashtable source, between @begin and @end
- * - add a rule to build the .lut.h
- * - include the .lut.h
- * - mention the table in the classinfo (add a classinfo if necessary)
- * - write/update the class enum (for the tokens)
- * - turn get() into getValueProperty(), put() into putValueProperty(), using a switch and removing funcs
- * - write get() and/or put() using a template method
- * - cleanup old stuff (e.g. hasProperty)
- * - compile, test, commit ;)
- */
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/math_object.cpp b/WebCore/src/kdelibs/kjs/math_object.cpp
deleted file mode 100644
index 1111016..0000000
--- a/WebCore/src/kdelibs/kjs/math_object.cpp
+++ /dev/null
@@ -1,263 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "math_object.h"
-
-#include "math_object.lut.h"
-
-using namespace KJS;
-
-// ------------------------------ MathObjectImp --------------------------------
-
-const ClassInfo MathObjectImp::info = { "Math", 0, &mathTable, 0 };
-
-/* Source for math_object.lut.h
- at begin mathTable 21
- E MathObjectImp::Euler DontEnum
- LN2 MathObjectImp::Ln2 DontEnum
- LN10 MathObjectImp::Ln10 DontEnum
- LOG2E MathObjectImp::Log2E DontEnum
- LOG10E MathObjectImp::Log10E DontEnum
- PI MathObjectImp::Pi DontEnum
- SQRT1_2 MathObjectImp::Sqrt1_2 DontEnum
- SQRT2 MathObjectImp::Sqrt2 DontEnum
- abs MathObjectImp::Abs DontEnum|Function 1
- acos MathObjectImp::ACos DontEnum|Function 1
- asin MathObjectImp::ASin DontEnum|Function 1
- atan MathObjectImp::ATan DontEnum|Function 1
- atan2 MathObjectImp::ATan2 DontEnum|Function 2
- ceil MathObjectImp::Ceil DontEnum|Function 1
- cos MathObjectImp::Cos DontEnum|Function 1
- exp MathObjectImp::Exp DontEnum|Function 1
- floor MathObjectImp::Floor DontEnum|Function 1
- log MathObjectImp::Log DontEnum|Function 1
- max MathObjectImp::Max DontEnum|Function 2
- min MathObjectImp::Min DontEnum|Function 2
- pow MathObjectImp::Pow DontEnum|Function 2
- random MathObjectImp::Random DontEnum|Function 0
- round MathObjectImp::Round DontEnum|Function 1
- sin MathObjectImp::Sin DontEnum|Function 1
- sqrt MathObjectImp::Sqrt DontEnum|Function 1
- tan MathObjectImp::Tan DontEnum|Function 1
- at end
-*/
-
-MathObjectImp::MathObjectImp(ExecState * /*exec*/,
- ObjectPrototypeImp *objProto)
- : ObjectImp(Object(objProto))
-{
-}
-
-// ECMA 15.8
-Value MathObjectImp::get(ExecState *exec, const UString &propertyName) const
-{
- return lookupGet<MathFuncImp, MathObjectImp, ObjectImp>( exec, propertyName, &mathTable, this );
-}
-
-Value MathObjectImp::getValueProperty(ExecState *, int token) const
-{
- double d = -42; // ;)
- switch (token) {
- case Euler:
- d = exp(1.0);
- break;
- case Ln2:
- d = log(2.0);
- break;
- case Ln10:
- d = log(10.0);
- break;
- case Log2E:
- d = 1.0/log(2.0);
- break;
- case Log10E:
- d = 1.0/log(10.0);
- break;
- case Pi:
- d = 2.0 * asin(1.0);
- break;
- case Sqrt1_2:
- d = sqrt(0.5);
- break;
- case Sqrt2:
- d = sqrt(2.0);
- break;
- default:
- fprintf( stderr, "Internal error in MathObjectImp: unhandled token %d\n", token );
- break;
- }
-
- return Number(d);
-}
-
-// ------------------------------ MathObjectImp --------------------------------
-
-MathFuncImp::MathFuncImp(ExecState *exec, int i, int l)
- : InternalFunctionImp(
- static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
- ), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(l),DontDelete|ReadOnly|DontEnum);
-}
-
-bool MathFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value MathFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- Value v = args[0];
- Number n = v.toNumber(exec);
- double arg = n.value();
-
- Value v2 = args[1];
- Number n2 = v2.toNumber(exec);
- double arg2 = n2.value();
- double result;
-
- switch (id) {
- case MathObjectImp::Abs:
- result = ( arg < 0 || arg == -0) ? (-arg) : arg;
- break;
- case MathObjectImp::ACos:
- result = ::acos(arg);
- break;
- case MathObjectImp::ASin:
- result = ::asin(arg);
- break;
- case MathObjectImp::ATan:
- result = ::atan(arg);
- break;
- case MathObjectImp::ATan2:
- result = ::atan2(arg, arg2);
- break;
- case MathObjectImp::Ceil:
- result = ::ceil(arg);
- break;
- case MathObjectImp::Cos:
- result = ::cos(arg);
- break;
- case MathObjectImp::Exp:
- result = ::exp(arg);
- break;
- case MathObjectImp::Floor:
- result = ::floor(arg);
- break;
- case MathObjectImp::Log:
- result = ::log(arg);
- break;
- case MathObjectImp::Max: {
- unsigned int argsCount = args.size();
- result = -Inf;
- for ( unsigned int k = 0 ; k < argsCount ; ++k ) {
- double val = args[k].toNumber(exec);
- if ( isNaN( val ) )
- {
- result = NaN;
- break;
- }
- if ( val > result )
- result = val;
- }
- break;
- }
- case MathObjectImp::Min: {
- unsigned int argsCount = args.size();
- result = +Inf;
- for ( unsigned int k = 0 ; k < argsCount ; ++k ) {
- double val = args[k].toNumber(exec);
- if ( isNaN( val ) )
- {
- result = NaN;
- break;
- }
- if ( val < result )
- result = val;
- }
- break;
- }
- case MathObjectImp::Pow:
- // ECMA 15.8.2.1.13 (::pow takes care of most of the critera)
- if (KJS::isNaN(arg2))
- result = NaN;
- else if (arg2 == 0)
- result = 1;
- else if (KJS::isNaN(arg) && arg2 != 0)
- result = NaN;
- else if (::fabs(arg) > 1 && KJS::isPosInf(arg2))
- result = Inf;
- else if (::fabs(arg) > 1 && KJS::isNegInf(arg2))
- result = +0;
- else if (::fabs(arg) == 1 && KJS::isPosInf(arg2))
- result = NaN;
- else if (::fabs(arg) == 1 && KJS::isNegInf(arg2))
- result = NaN;
- else if (::fabs(arg) < 1 && KJS::isPosInf(arg2))
- result = +0;
- else if (::fabs(arg) < 1 && KJS::isNegInf(arg2))
- result = Inf;
- else
- result = ::pow(arg, arg2);
- break;
- case MathObjectImp::Random:
- result = ::rand();
- result = result / RAND_MAX;
- break;
- case MathObjectImp::Round:
- if (isNaN(arg))
- result = arg;
- if (isInf(arg) || isInf(-arg))
- result = arg;
- else if (arg == -0.5)
- result = 0;
- else
- result = (double)(arg >= 0.0 ? int(arg + 0.5) : int(arg - 0.5));
- break;
- case MathObjectImp::Sin:
- result = ::sin(arg);
- break;
- case MathObjectImp::Sqrt:
- result = ::sqrt(arg);
- break;
- case MathObjectImp::Tan:
- result = ::tan(arg);
- break;
-
- default:
- result = 0.0;
- assert(0);
- }
-
- return Number(result);
-}
diff --git a/WebCore/src/kdelibs/kjs/math_object.h b/WebCore/src/kdelibs/kjs/math_object.h
deleted file mode 100644
index aa2d236..0000000
--- a/WebCore/src/kdelibs/kjs/math_object.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _MATH_OBJECT_H_
-#define _MATH_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class MathObjectImp : public ObjectImp {
- public:
- MathObjectImp(ExecState *exec,
- ObjectPrototypeImp *objProto);
- Value get(ExecState *exec, const UString &p) const;
- Value getValueProperty(ExecState *exec, int token) const;
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- enum { Euler, Ln2, Ln10, Log2E, Log10E, Pi, Sqrt1_2, Sqrt2,
- Abs, ACos, ASin, ATan, ATan2, Ceil, Cos, Pow,
- Exp, Floor, Log, Max, Min, Random, Round, Sin, Sqrt, Tan };
- };
-
- class MathFuncImp : public InternalFunctionImp {
- public:
- MathFuncImp(ExecState *exec, int i, int l);
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
- private:
- int id;
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/nodes.cpp b/WebCore/src/kdelibs/kjs/nodes.cpp
deleted file mode 100644
index 183b4c8..0000000
--- a/WebCore/src/kdelibs/kjs/nodes.cpp
+++ /dev/null
@@ -1,3182 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#include "nodes.h"
-
-#include <assert.h>
-#include <iostream.h>
-#include <math.h>
-#include <stdio.h>
-#ifdef KJS_DEBUG_MEM
-#include <typeinfo>
-#endif
-
-#include "collector.h"
-#include "debugger.h"
-#include "function_object.h"
-#include "internal.h"
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "lexer.h"
-#include "operations.h"
-#include "ustring.h"
-
-using namespace KJS;
-
-#define KJS_BREAKPOINT \
- if (!hitStatement(exec)) \
- return Completion(Normal);
-
-#define KJS_ABORTPOINT \
- if (exec->interpreter()->imp()->debugger() && \
- exec->interpreter()->imp()->debugger()->imp()->aborted()) \
- return Completion(Normal);
-
-#define KJS_CHECKEXCEPTION \
- if (exec->hadException()) \
- return Completion(Throw, exec->exception()); \
- if (Collector::outOfMemory()) \
- return Completion(Throw, Error::create(exec,GeneralError,"Out of memory"));
-
-#define KJS_CHECKEXCEPTIONVALUE \
- if (exec->hadException()) \
- return exec->exception(); \
- if (Collector::outOfMemory()) \
- return Undefined(); // will be picked up by KJS_CHECKEXCEPTION
-
-#define KJS_CHECKEXCEPTIONLIST \
- if (exec->hadException()) \
- return List(); \
- if (Collector::outOfMemory()) \
- return List(); // will be picked up by KJS_CHECKEXCEPTION
-
-#ifdef KJS_DEBUG_MEM
-std::list<Node *> Node::s_nodes;
-#endif
-// ------------------------------ Node -----------------------------------------
-
-Node::Node()
-{
- line = Lexer::curr()->lineNo();
- refcount = 0;
-#ifdef KJS_DEBUG_MEM
- s_nodes.push_back( this );
-#endif
-}
-
-Node::~Node()
-{
-#ifdef KJS_DEBUG_MEM
- s_nodes.remove( this );
-#endif
-}
-
-#ifdef KJS_DEBUG_MEM
-void Node::finalCheck()
-{
- fprintf( stderr, "Node::finalCheck(): list count : %d\n", s_nodes.size() );
- std::list<Node *>::iterator it = s_nodes.begin();
- for ( uint i = 0; it != s_nodes.end() ; ++it, ++i )
- fprintf( stderr, "[%d] Still having node %p (%s) (refcount %d)\n", i, (void*)*it, typeid( **it ).name(), (*it)->refcount );
-}
-#endif
-
-Value Node::throwError(ExecState *exec, ErrorType e, const char *msg)
-{
- Object err = Error::create(exec, e, msg, lineNo(), sourceId());
- exec->setException(err);
- return err;
-}
-
-// ------------------------------ StatementNode --------------------------------
-StatementNode::StatementNode() : l0(-1), l1(-1), sid(-1), breakPoint(false)
-{
-}
-
-StatementNode::~StatementNode()
-{
-}
-
-void StatementNode::setLoc(int line0, int line1, int sourceId)
-{
- l0 = line0;
- l1 = line1;
- sid = sourceId;
-}
-
-// return true if the debugger wants us to stop at this point
-bool StatementNode::hitStatement(ExecState *exec)
-{
- Debugger *dbg = exec->interpreter()->imp()->debugger();
- if (dbg)
- return dbg->atStatement(exec,sid,l0,l1);
- else
- return true; // continue
-}
-
-// return true if the debugger wants us to stop at this point
-bool StatementNode::abortStatement(ExecState *exec)
-{
- Debugger *dbg = exec->interpreter()->imp()->debugger();
- if (dbg)
- return dbg->imp()->aborted();
- else
- return false;
-}
-
-// ------------------------------ NullNode -------------------------------------
-
-Value NullNode::evaluate(ExecState */*exec*/)
-{
- return Null();
-}
-
-// ------------------------------ BooleanNode ----------------------------------
-
-Value BooleanNode::evaluate(ExecState */*exec*/)
-{
- return Boolean(value);
-}
-
-// ------------------------------ NumberNode -----------------------------------
-
-Value NumberNode::evaluate(ExecState */*exec*/)
-{
- return Number(value);
-}
-
-// ------------------------------ StringNode -----------------------------------
-
-Value StringNode::evaluate(ExecState */*exec*/)
-{
- return String(value);
-}
-
-// ------------------------------ RegExpNode -----------------------------------
-
-Value RegExpNode::evaluate(ExecState *exec)
-{
- List list;
- String p(pattern);
- String f(flags);
- list.append(p);
- list.append(f);
-
- Object reg = exec->interpreter()->imp()->builtinRegExp();
- return reg.construct(exec,list);
-}
-
-// ------------------------------ ThisNode -------------------------------------
-
-// ECMA 11.1.1
-Value ThisNode::evaluate(ExecState *exec)
-{
- return exec->context().thisValue();
-}
-
-// ------------------------------ ResolveNode ----------------------------------
-
-// ECMA 11.1.2 & 10.1.4
-Value ResolveNode::evaluate(ExecState *exec)
-{
- const List chain = exec->context().scopeChain();
- ListIterator scope = chain.begin();
-
- while (scope != chain.end()) {
- ObjectImp *o = static_cast<ObjectImp*>((*scope).imp());
-
- //cout << "Resolve: looking at '" << ident.ascii() << "'"
- // << " in " << (void*)o << " " << o->classInfo()->className << endl;
- if (o->hasProperty(exec,ident)) {
- //cout << "Resolve: FOUND '" << ident.ascii() << "'"
- // << " in " << (void*)o << " " << o->classInfo()->className << endl;
- return Reference(Object(o), ident);
- }
- scope++;
- }
-
- // identifier not found
- //cout << "Resolve: didn't find '" << ident.ascii() << "'" << endl;
- return Reference(Null(), ident);
-}
-
-// ------------------------------ GroupNode ------------------------------------
-
-GroupNode::~GroupNode()
-{
-}
-
-void GroupNode::ref()
-{
- Node::ref();
- if ( group )
- group->ref();
-}
-
-bool GroupNode::deref()
-{
- if ( group && group->deref() )
- delete group;
- return Node::deref();
-}
-
-// ECMA 11.1.6
-Value GroupNode::evaluate(ExecState *exec)
-{
- return group->evaluate(exec);
-}
-
-// ------------------------------ ElisionNode ----------------------------------
-
-ElisionNode::~ElisionNode()
-{
-}
-
-void ElisionNode::ref()
-{
- Node::ref();
- if ( elision )
- elision->ref();
-}
-
-bool ElisionNode::deref()
-{
- if ( elision && elision->deref() )
- delete elision;
- return Node::deref();
-}
-
-// ECMA 11.1.4
-Value ElisionNode::evaluate(ExecState *exec)
-{
- if (elision)
- return Number(elision->evaluate(exec).toNumber(exec) + 1);
- else
- return Number(1);
-}
-
-// ------------------------------ ElementNode ----------------------------------
-
-ElementNode::~ElementNode()
-{
-}
-
-void ElementNode::ref()
-{
- Node::ref();
- if ( list )
- list->ref();
- if ( elision )
- elision->ref();
- if ( node )
- node->ref();
-}
-
-bool ElementNode::deref()
-{
- if ( list && list->deref() )
- delete list;
- if ( elision && elision->deref() )
- delete elision;
- if ( node && node->deref() )
- delete node;
- return Node::deref();
-}
-
-// ECMA 11.1.4
-Value ElementNode::evaluate(ExecState *exec)
-{
- Object array;
- Value val;
- int length = 0;
- int elisionLen = elision ? elision->evaluate(exec).toInt32(exec) : 0;
- KJS_CHECKEXCEPTIONVALUE
-
- if (list) {
- array = Object(static_cast<ObjectImp*>(list->evaluate(exec).imp()));
- KJS_CHECKEXCEPTIONVALUE
- val = node->evaluate(exec).getValue(exec);
- length = array.get(exec,"length").toInt32(exec);
- } else {
- Value newArr = exec->interpreter()->builtinArray().construct(exec,List::empty());
- array = Object(static_cast<ObjectImp*>(newArr.imp()));
- val = node->evaluate(exec).getValue(exec);
- KJS_CHECKEXCEPTIONVALUE
- }
-
- array.put(exec, UString::from(elisionLen + length), val);
-
- return array;
-}
-
-// ------------------------------ ArrayNode ------------------------------------
-
-ArrayNode::~ArrayNode()
-{
-}
-
-void ArrayNode::ref()
-{
- Node::ref();
- if ( element )
- element->ref();
- if ( elision )
- elision->ref();
-}
-
-bool ArrayNode::deref()
-{
- if ( element && element->deref() )
- delete element;
- if ( elision && elision->deref() )
- delete elision;
- return Node::deref();
-}
-
-// ECMA 11.1.4
-Value ArrayNode::evaluate(ExecState *exec)
-{
- Object array;
- int length;
- int elisionLen = elision ? elision->evaluate(exec).toInt32(exec) : 0;
- KJS_CHECKEXCEPTIONVALUE
-
- if (element) {
- array = Object(static_cast<ObjectImp*>(element->evaluate(exec).imp()));
- KJS_CHECKEXCEPTIONVALUE
- length = opt ? array.get(exec,"length").toInt32(exec) : 0;
- } else {
- Value newArr = exec->interpreter()->builtinArray().construct(exec,List::empty());
- array = Object(static_cast<ObjectImp*>(newArr.imp()));
- length = 0;
- }
-
- if (opt)
- array.put(exec,"length", Number(elisionLen + length), DontEnum | DontDelete);
-
- return array;
-}
-
-// ------------------------------ ObjectLiteralNode ----------------------------
-
-ObjectLiteralNode::~ObjectLiteralNode()
-{
-}
-
-void ObjectLiteralNode::ref()
-{
- Node::ref();
- if ( list )
- list->ref();
-}
-
-bool ObjectLiteralNode::deref()
-{
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-// ECMA 11.1.5
-Value ObjectLiteralNode::evaluate(ExecState *exec)
-{
- if (list)
- return list->evaluate(exec);
-
- return exec->interpreter()->builtinObject().construct(exec,List::empty());
-}
-
-// ------------------------------ PropertyValueNode ----------------------------
-
-PropertyValueNode::~PropertyValueNode()
-{
-}
-
-void PropertyValueNode::ref()
-{
- Node::ref();
- if ( name )
- name->ref();
- if ( assign )
- assign->ref();
- if ( list )
- list->ref();
-}
-
-bool PropertyValueNode::deref()
-{
- if ( name && name->deref() )
- delete name;
- if ( assign && assign->deref() )
- delete assign;
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-// ECMA 11.1.5
-Value PropertyValueNode::evaluate(ExecState *exec)
-{
- Object obj;
- if (list) {
- obj = Object(static_cast<ObjectImp*>(list->evaluate(exec).imp()));
- KJS_CHECKEXCEPTIONVALUE
- }
- else {
- Value newObj = exec->interpreter()->builtinObject().construct(exec,List::empty());
- obj = Object(static_cast<ObjectImp*>(newObj.imp()));
- }
- Value n = name->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value a = assign->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = a.getValue(exec);
-
- obj.put(exec,n.toString(exec), v);
-
- return obj;
-}
-
-// ------------------------------ PropertyNode ---------------------------------
-
-// ECMA 11.1.5
-Value PropertyNode::evaluate(ExecState */*exec*/)
-{
- Value s;
-
- if (str.isNull()) {
- s = String(UString::from(numeric));
- } else
- s = String(str);
-
- return s;
-}
-
-// ------------------------------ AccessorNode1 --------------------------------
-
-AccessorNode1::~AccessorNode1()
-{
-}
-
-void AccessorNode1::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
-}
-
-bool AccessorNode1::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- return Node::deref();
-}
-
-// ECMA 11.2.1a
-Value AccessorNode1::evaluate(ExecState *exec)
-{
- Value e1 = expr1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = e1.getValue(exec);
- Value e2 = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = e2.getValue(exec);
- Object o = v1.toObject(exec);
- String s = v2.toString(exec);
- return Reference(o, s.value());
-}
-
-// ------------------------------ AccessorNode2 --------------------------------
-
-AccessorNode2::~AccessorNode2()
-{
-}
-
-void AccessorNode2::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool AccessorNode2::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.2.1b
-Value AccessorNode2::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- Object o = v.toObject(exec);
- return Reference(o, ident);
-}
-
-// ------------------------------ ArgumentListNode -----------------------------
-
-ArgumentListNode::ArgumentListNode(Node *e) : list(0L), expr(e)
-{
-}
-
-ArgumentListNode::ArgumentListNode(ArgumentListNode *l, Node *e)
- : list(l), expr(e)
-{
-}
-
-ArgumentListNode::~ArgumentListNode()
-{
-}
-
-void ArgumentListNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
- if ( list )
- list->ref();
-}
-
-bool ArgumentListNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-Value ArgumentListNode::evaluate(ExecState */*exec*/)
-{
- assert(0);
- return Value(); // dummy, see evaluateList()
-}
-
-// ECMA 11.2.4
-List ArgumentListNode::evaluateList(ExecState *exec)
-{
- List l;
- if (list) {
- l = list->evaluateList(exec);
- KJS_CHECKEXCEPTIONLIST
- }
-
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONLIST
- Value v = e.getValue(exec);
-
- l.append(v);
-
- return l;
-}
-
-// ------------------------------ ArgumentsNode --------------------------------
-
-ArgumentsNode::ArgumentsNode(ArgumentListNode *l) : list(l)
-{
-}
-
-ArgumentsNode::~ArgumentsNode()
-{
-}
-
-void ArgumentsNode::ref()
-{
- Node::ref();
- if ( list )
- list->ref();
-}
-
-bool ArgumentsNode::deref()
-{
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-Value ArgumentsNode::evaluate(ExecState */*exec*/)
-{
- assert(0);
- return Value(); // dummy, see evaluateList()
-}
-
-// ECMA 11.2.4
-List ArgumentsNode::evaluateList(ExecState *exec)
-{
- if (!list)
- return List();
-
- return list->evaluateList(exec);
-}
-
-// ------------------------------ NewExprNode ----------------------------------
-
-// ECMA 11.2.2
-
-NewExprNode::~NewExprNode()
-{
-}
-
-void NewExprNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
- if ( args )
- args->ref();
-}
-
-bool NewExprNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- if ( args && args->deref() )
- delete args;
- return Node::deref();
-}
-
-Value NewExprNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
-
- List argList;
- if (args) {
- argList = args->evaluateList(exec);
- KJS_CHECKEXCEPTIONVALUE
- }
-
- if (v.type() != ObjectType) {
- return throwError(exec, TypeError, "Expression is no object. Cannot be new'ed");
- }
-
- Object constr = Object(static_cast<ObjectImp*>(v.imp()));
- if (!constr.implementsConstruct()) {
- return throwError(exec, TypeError, "Expression is no constructor.");
- }
-
- Value res = constr.construct(exec,argList);
-
- return res;
-}
-
-// ------------------------------ FunctionCallNode -----------------------------
-
-FunctionCallNode::~FunctionCallNode()
-{
-}
-
-void FunctionCallNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
- if ( args )
- args->ref();
-}
-
-bool FunctionCallNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- if ( args && args->deref() )
- delete args;
- return Node::deref();
-}
-
-// ECMA 11.2.3
-Value FunctionCallNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
-
- List argList = args->evaluateList(exec);
-
- KJS_CHECKEXCEPTIONVALUE
-
- Value v = e.getValue(exec);
-
- if (v.type() != ObjectType) {
-#ifndef NDEBUG
- printInfo(exec, "WARNING: Failed function call attempt on", e, line);
-#endif
- return throwError(exec, TypeError, "Expression is no object. Cannot be called.");
- }
-
- Object func = Object(static_cast<ObjectImp*>(v.imp()));
-
- if (!func.implementsCall()) {
-#ifndef NDEBUG
- printInfo(exec, "Failed function call attempt on", e, line);
-#endif
- return throwError(exec, TypeError, "Expression does not allow calls.");
- }
-
- Value thisVal;
- if (e.type() == ReferenceType)
- thisVal = e.getBase(exec);
- else
- thisVal = Null();
-
- if (thisVal.type() == ObjectType &&
- Object::dynamicCast(thisVal).inherits(&ActivationImp::info))
- thisVal = Null();
-
- if (thisVal.type() != ObjectType) {
- // ECMA 11.2.3 says that in this situation the this value should be null.
- // However, section 10.2.3 says that in the case where the value provided
- // by the caller is null, the global object should be used. It also says
- // that the section does not apply to interal functions, but for simplicity
- // of implementation we use the global object anyway here. This guarantees
- // that in host objects you always get a valid object for this.
- // thisVal = Null();
- thisVal = exec->interpreter()->globalObject();
- }
-
- Object thisObj = Object::dynamicCast(thisVal);
- Value result = func.call(exec,thisObj, argList);
-
- return result;
-}
-
-// ------------------------------ PostfixNode ----------------------------------
-
-PostfixNode::~PostfixNode()
-{
-}
-
-void PostfixNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool PostfixNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.3
-Value PostfixNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- Number n = v.toNumber(exec);
-
- double newValue = (oper == OpPlusPlus) ? n.value() + 1 : n.value() - 1;
- Value n2 = Number(newValue);
-
- e.putValue(exec,n2);
-
- return n;
-}
-
-// ------------------------------ DeleteNode -----------------------------------
-
-DeleteNode::~DeleteNode()
-{
-}
-
-void DeleteNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool DeleteNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.1
-Value DeleteNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- if (e.type() != ReferenceType)
- return Boolean(true);
- Value b = e.getBase(exec);
- UString n = e.getPropertyName(exec);
-
- // The spec doesn't mention what to do if the base is null... just return true
- if (b.type() != ObjectType) {
- assert(b.type() == NullType);
- return Boolean(true);
- }
-
- Object o = Object(static_cast<ObjectImp*>(b.imp()));
-
- bool ret = o.deleteProperty(exec,n);
-
- return Boolean(ret);
-}
-
-// ------------------------------ VoidNode -------------------------------------
-
-VoidNode::~VoidNode()
-{
-}
-
-void VoidNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool VoidNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.2
-Value VoidNode::evaluate(ExecState *exec)
-{
- Value dummy1 = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value dummy2 = dummy1.getValue(exec);
-
- return Undefined();
-}
-
-// ------------------------------ TypeOfNode -----------------------------------
-
-TypeOfNode::~TypeOfNode()
-{
-}
-
-void TypeOfNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool TypeOfNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.3
-Value TypeOfNode::evaluate(ExecState *exec)
-{
- const char *s = 0L;
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- if (e.type() == ReferenceType) {
- Value b = e.getBase(exec);
- if (b.type() == NullType)
- return String("undefined");
- }
- Value v = e.getValue(exec);
- switch (v.type())
- {
- case UndefinedType:
- s = "undefined";
- break;
- case NullType:
- s = "object";
- break;
- case BooleanType:
- s = "boolean";
- break;
- case NumberType:
- s = "number";
- break;
- case StringType:
- s = "string";
- break;
- default:
- if (v.type() == ObjectType && static_cast<ObjectImp*>(v.imp())->implementsCall())
- s = "function";
- else
- s = "object";
- break;
- }
-
- return String(s);
-}
-
-// ------------------------------ PrefixNode -----------------------------------
-
-PrefixNode::~PrefixNode()
-{
-}
-
-void PrefixNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool PrefixNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.4 and 11.4.5
-Value PrefixNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- Number n = v.toNumber(exec);
-
- double newValue = (oper == OpPlusPlus) ? n.value() + 1 : n.value() - 1;
- Value n2 = Number(newValue);
-
- e.putValue(exec,n2);
-
- return n2;
-}
-
-// ------------------------------ UnaryPlusNode --------------------------------
-
-UnaryPlusNode::~UnaryPlusNode()
-{
-}
-
-void UnaryPlusNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool UnaryPlusNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.6
-Value UnaryPlusNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
-
- return Number(v.toNumber(exec)); /* TODO: optimize */
-}
-
-// ------------------------------ NegateNode -----------------------------------
-
-NegateNode::~NegateNode()
-{
-}
-
-void NegateNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool NegateNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.7
-Value NegateNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- Number n = v.toNumber(exec);
-
- double d = -n.value();
-
- return Number(d);
-}
-
-// ------------------------------ BitwiseNotNode -------------------------------
-
-BitwiseNotNode::~BitwiseNotNode()
-{
-}
-
-void BitwiseNotNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool BitwiseNotNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.8
-Value BitwiseNotNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- int i32 = v.toInt32(exec);
-
- return Number(~i32);
-}
-
-// ------------------------------ LogicalNotNode -------------------------------
-
-LogicalNotNode::~LogicalNotNode()
-{
-}
-
-void LogicalNotNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool LogicalNotNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.4.9
-Value LogicalNotNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- bool b = v.toBoolean(exec);
-
- return Boolean(!b);
-}
-
-// ------------------------------ MultNode -------------------------------------
-
-MultNode::~MultNode()
-{
-}
-
-void MultNode::ref()
-{
- Node::ref();
- if ( term1 )
- term1->ref();
- if ( term2 )
- term2->ref();
-}
-
-bool MultNode::deref()
-{
- if ( term1 && term1->deref() )
- delete term1;
- if ( term2 && term2->deref() )
- delete term2;
- return Node::deref();
-}
-
-// ECMA 11.5
-Value MultNode::evaluate(ExecState *exec)
-{
- Value t1 = term1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = t1.getValue(exec);
-
- Value t2 = term2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = t2.getValue(exec);
-
- return mult(exec,v1, v2, oper);
-}
-
-// ------------------------------ AddNode --------------------------------------
-
-AddNode::~AddNode()
-{
-}
-
-void AddNode::ref()
-{
- Node::ref();
- if ( term1 )
- term1->ref();
- if ( term2 )
- term2->ref();
-}
-
-bool AddNode::deref()
-{
- if ( term1 && term1->deref() )
- delete term1;
- if ( term2 && term2->deref() )
- delete term2;
- return Node::deref();
-}
-
-// ECMA 11.6
-Value AddNode::evaluate(ExecState *exec)
-{
- Value t1 = term1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = t1.getValue(exec);
-
- Value t2 = term2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = t2.getValue(exec);
-
- return add(exec,v1, v2, oper);
-}
-
-// ------------------------------ ShiftNode ------------------------------------
-
-ShiftNode::~ShiftNode()
-{
-}
-
-void ShiftNode::ref()
-{
- Node::ref();
- if ( term1 )
- term1->ref();
- if ( term2 )
- term2->ref();
-}
-
-bool ShiftNode::deref()
-{
- if ( term1 && term1->deref() )
- delete term1;
- if ( term2 && term2->deref() )
- delete term2;
- return Node::deref();
-}
-
-// ECMA 11.7
-Value ShiftNode::evaluate(ExecState *exec)
-{
- Value t1 = term1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = t1.getValue(exec);
- Value t2 = term2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = t2.getValue(exec);
- unsigned int i2 = v2.toUInt32(exec);
- i2 &= 0x1f;
-
- long result;
- switch (oper) {
- case OpLShift:
- result = v1.toInt32(exec) << i2;
- break;
- case OpRShift:
- result = v1.toInt32(exec) >> i2;
- break;
- case OpURShift:
- result = v1.toUInt32(exec) >> i2;
- break;
- default:
- assert(!"ShiftNode: unhandled switch case");
- result = 0L;
- }
-
- return Number(static_cast<double>(result));
-}
-
-// ------------------------------ RelationalNode -------------------------------
-
-RelationalNode::~RelationalNode()
-{
-}
-
-void RelationalNode::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
-}
-
-bool RelationalNode::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- return Node::deref();
-}
-
-// ECMA 11.8
-Value RelationalNode::evaluate(ExecState *exec)
-{
- Value e1 = expr1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = e1.getValue(exec);
- Value e2 = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = e2.getValue(exec);
-
- bool b;
- if (oper == OpLess || oper == OpGreaterEq) {
- int r = relation(exec, v1, v2);
- if (r < 0)
- b = false;
- else
- b = (oper == OpLess) ? (r == 1) : (r == 0);
- } else if (oper == OpGreater || oper == OpLessEq) {
- int r = relation(exec, v2, v1);
- if (r < 0)
- b = false;
- else
- b = (oper == OpGreater) ? (r == 1) : (r == 0);
- } else if (oper == OpIn) {
- // Is all of this OK for host objects?
- if (v2.type() != ObjectType)
- return throwError(exec, TypeError,
- "Shift expression not an object into IN expression." );
- Object o2(static_cast<ObjectImp*>(v2.imp()));
- b = o2.hasProperty(exec,v1.toString(exec));
- } else {
- if (v2.type() != ObjectType)
- return throwError(exec, TypeError,
- "Called instanceof operator on non-object." );
-
- Object o2(static_cast<ObjectImp*>(v2.imp()));
- if (!o2.implementsHasInstance()) {
- // According to the spec, only some types of objects "imlement" the [[HasInstance]] property.
- // But we are supposed to throw an exception where the object does not "have" the [[HasInstance]]
- // property. It seems that all object have the property, but not all implement it, so in this
- // case we return false (consistent with mozilla)
- return Boolean(false);
- // return throwError(exec, TypeError,
- // "Object does not implement the [[HasInstance]] method." );
- }
- return o2.hasInstance(exec, v1);
- }
-
- return Boolean(b);
-}
-
-// ------------------------------ EqualNode ------------------------------------
-
-EqualNode::~EqualNode()
-{
-}
-
-void EqualNode::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
-}
-
-bool EqualNode::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- return Node::deref();
-}
-
-// ECMA 11.9
-Value EqualNode::evaluate(ExecState *exec)
-{
- Value e1 = expr1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value e2 = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = e1.getValue(exec);
- Value v2 = e2.getValue(exec);
-
- bool result;
- if (oper == OpEqEq || oper == OpNotEq) {
- // == and !=
- bool eq = equal(exec,v1, v2);
- result = oper == OpEqEq ? eq : !eq;
- } else {
- // === and !==
- bool eq = strictEqual(exec,v1, v2);
- result = oper == OpStrEq ? eq : !eq;
- }
- return Boolean(result);
-}
-
-// ------------------------------ BitOperNode ----------------------------------
-
-BitOperNode::~BitOperNode()
-{
-}
-
-void BitOperNode::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
-}
-
-bool BitOperNode::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- return Node::deref();
-}
-
-// ECMA 11.10
-Value BitOperNode::evaluate(ExecState *exec)
-{
- Value e1 = expr1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = e1.getValue(exec);
- Value e2 = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = e2.getValue(exec);
- int i1 = v1.toInt32(exec);
- int i2 = v2.toInt32(exec);
- int result;
- if (oper == OpBitAnd)
- result = i1 & i2;
- else if (oper == OpBitXOr)
- result = i1 ^ i2;
- else
- result = i1 | i2;
-
- return Number(result);
-}
-
-// ------------------------------ BinaryLogicalNode ----------------------------
-
-BinaryLogicalNode::~BinaryLogicalNode()
-{
-}
-
-void BinaryLogicalNode::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
-}
-
-bool BinaryLogicalNode::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- return Node::deref();
-}
-
-// ECMA 11.11
-Value BinaryLogicalNode::evaluate(ExecState *exec)
-{
- Value e1 = expr1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = e1.getValue(exec);
- bool b1 = v1.toBoolean(exec);
- if ((!b1 && oper == OpAnd) || (b1 && oper == OpOr))
- return v1;
-
- Value e2 = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = e2.getValue(exec);
-
- return v2;
-}
-
-// ------------------------------ ConditionalNode ------------------------------
-
-ConditionalNode::~ConditionalNode()
-{
-}
-
-void ConditionalNode::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
- if ( logical )
- logical->ref();
-}
-
-bool ConditionalNode::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- if ( logical && logical->deref() )
- delete logical;
- return Node::deref();
-}
-
-// ECMA 11.12
-Value ConditionalNode::evaluate(ExecState *exec)
-{
- Value e = logical->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
- bool b = v.toBoolean(exec);
-
- if (b)
- e = expr1->evaluate(exec);
- else
- e = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
-
- return e.getValue(exec);
-}
-
-// ------------------------------ AssignNode -----------------------------------
-
-AssignNode::~AssignNode()
-{
-}
-
-void AssignNode::ref()
-{
- Node::ref();
- if ( left )
- left->ref();
- if ( expr )
- expr->ref();
-}
-
-bool AssignNode::deref()
-{
- if ( left && left->deref() )
- delete left;
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 11.13
-Value AssignNode::evaluate(ExecState *exec)
-{
-
- Value l, e, v;
- if (oper == OpEqual) {
- l = left->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- v = e.getValue(exec);
- } else {
- l = left->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v1 = l.getValue(exec);
- e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v2 = e.getValue(exec);
- int i1 = v1.toInt32(exec);
- int i2 = v2.toInt32(exec);
- unsigned int ui;
- switch (oper) {
- case OpMultEq:
- v = mult(exec, v1, v2, '*');
- break;
- case OpDivEq:
- v = mult(exec, v1, v2, '/');
- break;
- case OpPlusEq:
- v = add(exec, v1, v2, '+');
- break;
- case OpMinusEq:
- v = add(exec, v1, v2, '-');
- break;
- case OpLShift:
- v = Number(i1 <<= i2);
- break;
- case OpRShift:
- v = Number(i1 >>= i2);
- break;
- case OpURShift:
- ui = v1.toUInt32(exec);
- v = Number(ui >>= i2);
- break;
- case OpAndEq:
- v = Number(i1 &= i2);
- break;
- case OpXOrEq:
- v = Number(i1 ^= i2);
- break;
- case OpOrEq:
- v = Number(i1 |= i2);
- break;
- case OpModEq: {
- double d1 = v1.toNumber(exec);
- double d2 = v2.toNumber(exec);
- v = Number(fmod(d1,d2));
- }
- break;
- default:
- v = Undefined();
- }
- };
- l.putValue(exec,v);
-
- KJS_CHECKEXCEPTIONVALUE
-
- return v;
-}
-
-// ------------------------------ CommaNode ------------------------------------
-
-CommaNode::~CommaNode()
-{
-}
-
-void CommaNode::ref()
-{
- Node::ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
-}
-
-bool CommaNode::deref()
-{
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- return Node::deref();
-}
-
-// ECMA 11.14
-Value CommaNode::evaluate(ExecState *exec)
-{
- Value e = expr1->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value dummy = e.getValue(exec); // ignore return value
- e = expr2->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
-
- return e.getValue(exec);
-}
-
-// ------------------------------ StatListNode ---------------------------------
-
-StatListNode::~StatListNode()
-{
-}
-
-void StatListNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( list )
- list->ref();
-}
-
-bool StatListNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-// ECMA 12.1
-Completion StatListNode::execute(ExecState *exec)
-{
- if (!list) {
- Completion c = statement->execute(exec);
- KJS_ABORTPOINT
- if (exec->hadException()) {
- Value ex = exec->exception();
- exec->clearException();
- return Completion(Throw, ex);
- }
- else
- return c;
- }
-
- Completion l = list->execute(exec);
- KJS_ABORTPOINT
- if (l.complType() != Normal)
- return l;
- Completion e = statement->execute(exec);
- KJS_ABORTPOINT;
-
- if (exec->hadException()) {
- Value ex = exec->exception();
- exec->clearException();
- return Completion(Throw, ex);
- }
-
- Value v = e.isValueCompletion() ? e.value() : l.value();
-
- return Completion(e.complType(), v, e.target() );
-}
-
-void StatListNode::processVarDecls(ExecState *exec)
-{
- statement->processVarDecls(exec);
-
- if (list)
- list->processVarDecls(exec);
-}
-
-// ------------------------------ AssignExprNode -------------------------------
-
-AssignExprNode::~AssignExprNode()
-{
-}
-
-void AssignExprNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool AssignExprNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.2
-Value AssignExprNode::evaluate(ExecState *exec)
-{
- return expr->evaluate(exec);
-}
-
-// ------------------------------ VarDeclNode ----------------------------------
-
-VarDeclNode::VarDeclNode(const UString *id, AssignExprNode *in)
- : ident(*id), init(in)
-{
-}
-
-VarDeclNode::~VarDeclNode()
-{
-}
-
-void VarDeclNode::ref()
-{
- Node::ref();
- if ( init )
- init->ref();
-}
-
-bool VarDeclNode::deref()
-{
- if ( init && init->deref() )
- delete init;
- return Node::deref();
-}
-
-// ECMA 12.2
-Value VarDeclNode::evaluate(ExecState *exec)
-{
- Object variable = Object::dynamicCast(exec->context().variableObject());
-
- Value val, tmp;
- if (init) {
- tmp = init->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- val = tmp.getValue(exec);
- } else {
- if ( variable.hasProperty(exec, ident ) ) // already declared ?
- return Value();
- val = Undefined();
- }
-
-#ifdef KJS_VERBOSE
- printInfo(exec,(UString("new variable ")+ident).cstring().c_str(),val);
-#endif
- // We use Internal to bypass all checks in derived objects, e.g. so that
- // "var location" creates a dynamic property instead of activating window.location.
- variable.put(exec, ident, val, DontDelete | Internal);
-
- return String(ident);
-}
-
-void VarDeclNode::processVarDecls(ExecState *exec)
-{
- Object variable = exec->context().variableObject();
- variable.put(exec,ident, Undefined(), DontDelete);
-}
-
-// ------------------------------ VarDeclListNode ------------------------------
-
-VarDeclListNode::~VarDeclListNode()
-{
-}
-
-void VarDeclListNode::ref()
-{
- Node::ref();
- if ( list )
- list->ref();
- if ( var )
- var->ref();
-}
-
-bool VarDeclListNode::deref()
-{
- if ( list && list->deref() )
- delete list;
- if ( var && var->deref() )
- delete var;
- return Node::deref();
-}
-
-
-// ECMA 12.2
-Value VarDeclListNode::evaluate(ExecState *exec)
-{
- if (list)
- (void) list->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
-
- (void) var->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
-
- return Undefined();
-}
-
-void VarDeclListNode::processVarDecls(ExecState *exec)
-{
- if (list)
- list->processVarDecls(exec);
-
- var->processVarDecls(exec);
-}
-
-// ------------------------------ VarStatementNode -----------------------------
-
-VarStatementNode::~VarStatementNode()
-{
-}
-
-void VarStatementNode::ref()
-{
- Node::ref();
- if ( list )
- list->ref();
-}
-
-bool VarStatementNode::deref()
-{
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-// ECMA 12.2
-Completion VarStatementNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- (void) list->evaluate(exec); // returns 0L
- KJS_CHECKEXCEPTION
-
- return Completion(Normal);
-}
-
-void VarStatementNode::processVarDecls(ExecState *exec)
-{
- list->processVarDecls(exec);
-}
-
-// ------------------------------ BlockNode ------------------------------------
-
-BlockNode::~BlockNode()
-{
-}
-
-void BlockNode::ref()
-{
- Node::ref();
- if ( source )
- source->ref();
-}
-
-bool BlockNode::deref()
-{
- if ( source && source->deref() )
- delete source;
- return Node::deref();
-}
-
-// ECMA 12.1
-Completion BlockNode::execute(ExecState *exec)
-{
- if (!source)
- return Completion(Normal);
-
- source->processFuncDecl(exec);
-
- return source->execute(exec);
-}
-
-void BlockNode::processVarDecls(ExecState *exec)
-{
- if (source)
- source->processVarDecls(exec);
-}
-
-// ------------------------------ EmptyStatementNode ---------------------------
-
-// ECMA 12.3
-Completion EmptyStatementNode::execute(ExecState */*exec*/)
-{
- return Completion(Normal);
-}
-
-// ------------------------------ ExprStatementNode ----------------------------
-
-ExprStatementNode::~ExprStatementNode()
-{
-}
-
-void ExprStatementNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool ExprStatementNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.4
-Completion ExprStatementNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- Value v = e.getValue(exec);
-
- return Completion(Normal, v);
-}
-
-// ------------------------------ IfNode ---------------------------------------
-
-IfNode::~IfNode()
-{
-}
-
-void IfNode::ref()
-{
- Node::ref();
- if ( statement1 )
- statement1->ref();
- if ( statement2 )
- statement2->ref();
- if ( expr )
- expr->ref();
-}
-
-bool IfNode::deref()
-{
- if ( statement1 && statement1->deref() )
- delete statement1;
- if ( statement2 && statement2->deref() )
- delete statement2;
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.5
-Completion IfNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- Value v = e.getValue(exec);
- bool b = v.toBoolean(exec);
-
- // if ... then
- if (b)
- return statement1->execute(exec);
-
- // no else
- if (!statement2)
- return Completion(Normal);
-
- // else
- return statement2->execute(exec);
-}
-
-void IfNode::processVarDecls(ExecState *exec)
-{
- statement1->processVarDecls(exec);
-
- if (statement2)
- statement2->processVarDecls(exec);
-}
-
-// ------------------------------ DoWhileNode ----------------------------------
-
-DoWhileNode::~DoWhileNode()
-{
-}
-
-void DoWhileNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( expr )
- expr->ref();
-}
-
-bool DoWhileNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.6.1
-Completion DoWhileNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value be, bv;
- Completion c;
- Value value;
-
- do {
- // bail out on error
- KJS_CHECKEXCEPTION
-
- c = statement->execute(exec);
- if (!((c.complType() == Continue) && ls.contains(c.target()))) {
- if ((c.complType() == Break) && ls.contains(c.target()))
- return Completion(Normal, value);
- if (c.complType() != Normal)
- return c;
- }
- be = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- bv = be.getValue(exec);
- } while (bv.toBoolean(exec));
-
- return Completion(Normal, value);
-}
-
-void DoWhileNode::processVarDecls(ExecState *exec)
-{
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ WhileNode ------------------------------------
-
-WhileNode::~WhileNode()
-{
-}
-
-void WhileNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( expr )
- expr->ref();
-}
-
-bool WhileNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.6.2
-Completion WhileNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value be, bv;
- Completion c;
- bool b(false);
- Value value;
-
- while (1) {
- be = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- bv = be.getValue(exec);
- b = bv.toBoolean(exec);
-
- // bail out on error
- KJS_CHECKEXCEPTION
-
- if (!b)
- return Completion(Normal, value);
-
- c = statement->execute(exec);
- if (c.isValueCompletion())
- value = c.value();
-
- if ((c.complType() == Continue) && ls.contains(c.target()))
- continue;
- if ((c.complType() == Break) && ls.contains(c.target()))
- return Completion(Normal, value);
- if (c.complType() != Normal)
- return c;
- }
-}
-
-void WhileNode::processVarDecls(ExecState *exec)
-{
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ ForNode --------------------------------------
-
-ForNode::~ForNode()
-{
-}
-
-void ForNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( expr1 )
- expr1->ref();
- if ( expr2 )
- expr2->ref();
- if ( expr3 )
- expr3->ref();
-}
-
-bool ForNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( expr1 && expr1->deref() )
- delete expr1;
- if ( expr2 && expr2->deref() )
- delete expr2;
- if ( expr3 && expr3->deref() )
- delete expr3;
- return Node::deref();
-}
-
-// ECMA 12.6.3
-Completion ForNode::execute(ExecState *exec)
-{
- Value e, v, cval;
- bool b;
-
- if (expr1) {
- e = expr1->evaluate(exec);
- KJS_CHECKEXCEPTION
- v = e.getValue(exec);
- }
- while (1) {
- if (expr2) {
- e = expr2->evaluate(exec);
- KJS_CHECKEXCEPTION
- v = e.getValue(exec);
- b = v.toBoolean(exec);
- if (b == false)
- return Completion(Normal, cval);
- }
- // bail out on error
- KJS_CHECKEXCEPTION
-
- Completion c = statement->execute(exec);
- if (c.isValueCompletion())
- cval = c.value();
- if (!((c.complType() == Continue) && ls.contains(c.target()))) {
- if ((c.complType() == Break) && ls.contains(c.target()))
- return Completion(Normal, cval);
- if (c.complType() != Normal)
- return c;
- }
- if (expr3) {
- e = expr3->evaluate(exec);
- KJS_CHECKEXCEPTION
- v = e.getValue(exec);
- }
- }
-}
-
-void ForNode::processVarDecls(ExecState *exec)
-{
- if (expr1)
- expr1->processVarDecls(exec);
-
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ ForInNode ------------------------------------
-
-ForInNode::ForInNode(Node *l, Node *e, StatementNode *s)
- : init(0L), lexpr(l), expr(e), varDecl(0L), statement(s)
-{
-}
-
-ForInNode::ForInNode(const UString *i, AssignExprNode *in, Node *e, StatementNode *s)
- : ident(*i), init(in), expr(e), statement(s)
-{
- // for( var foo = bar in baz )
- varDecl = new VarDeclNode(&ident, init);
- lexpr = new ResolveNode(&ident);
-}
-
-ForInNode::~ForInNode()
-{
-}
-
-void ForInNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( expr )
- expr->ref();
- if ( lexpr )
- lexpr->ref();
- if ( init )
- init->ref();
- if ( varDecl )
- varDecl->ref();
-}
-
-bool ForInNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( expr && expr->deref() )
- delete expr;
- if ( lexpr && lexpr->deref() )
- delete lexpr;
- if ( init && init->deref() )
- delete init;
- if ( varDecl && varDecl->deref() )
- delete varDecl;
- return Node::deref();
-}
-
-// ECMA 12.6.4
-Completion ForInNode::execute(ExecState *exec)
-{
- Value e, retval;
- Object v;
- Completion c;
- List propList;
-
- if ( varDecl ) {
- varDecl->evaluate(exec);
- KJS_CHECKEXCEPTION
- }
-
- e = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- v = e.getValue(exec).toObject(exec);
- propList = v.propList(exec);
-
- ListIterator propIt = propList.begin();
-
- while (propIt != propList.end()) {
- UString name = propIt->getPropertyName(exec);
- if (!v.hasProperty(exec,name)) {
- propIt++;
- continue;
- }
-
- e = lexpr->evaluate(exec);
- KJS_CHECKEXCEPTION
- e.putValue(exec,String(name));
-
- c = statement->execute(exec);
- if (c.isValueCompletion())
- retval = c.value();
-
- if (!((c.complType() == Continue) && ls.contains(c.target()))) {
- if ((c.complType() == Break) && ls.contains(c.target()))
- break;
- if (c.complType() != Normal) {
- return c;
- }
- }
-
- propIt++;
- }
-
- // bail out on error
- KJS_CHECKEXCEPTION
-
- return Completion(Normal, retval);
-}
-
-void ForInNode::processVarDecls(ExecState *exec)
-{
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ ContinueNode ---------------------------------
-
-// ECMA 12.7
-Completion ContinueNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value dummy;
- return exec->context().imp()->seenLabels()->contains(ident) ?
- Completion(Continue, dummy, ident) :
- Completion(Throw,
- throwError(exec, SyntaxError, "Label not found in containing block"));
-}
-
-// ------------------------------ BreakNode ------------------------------------
-
-// ECMA 12.8
-Completion BreakNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value dummy;
- return exec->context().imp()->seenLabels()->contains(ident) ?
- Completion(Break, dummy, ident) :
- Completion(Throw,
- throwError(exec, SyntaxError, "Label not found in containing block"));
-}
-
-// ------------------------------ ReturnNode -----------------------------------
-
-ReturnNode::~ReturnNode()
-{
-}
-
-void ReturnNode::ref()
-{
- Node::ref();
- if ( value )
- value->ref();
-}
-
-bool ReturnNode::deref()
-{
- if ( value && value->deref() )
- delete value;
- return Node::deref();
-}
-
-// ECMA 12.9
-Completion ReturnNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- if (!value)
- return Completion(ReturnValue, Undefined());
-
- Value e = value->evaluate(exec);
- KJS_CHECKEXCEPTION
- Value v = e.getValue(exec);
-
- return Completion(ReturnValue, v);
-}
-
-// ------------------------------ WithNode -------------------------------------
-
-WithNode::~WithNode()
-{
-}
-
-void WithNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( expr )
- expr->ref();
-}
-
-bool WithNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.10
-Completion WithNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- Value v = e.getValue(exec);
- Object o = v.toObject(exec);
- KJS_CHECKEXCEPTION
- exec->context().imp()->pushScope(o);
- Completion res = statement->execute(exec);
- exec->context().imp()->popScope();
-
- return res;
-}
-
-void WithNode::processVarDecls(ExecState *exec)
-{
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ CaseClauseNode -------------------------------
-
-CaseClauseNode::~CaseClauseNode()
-{
-}
-
-void CaseClauseNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
- if ( list )
- list->ref();
-}
-
-bool CaseClauseNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- if ( list && list->deref() )
- delete list;
- return Node::deref();
-}
-
-// ECMA 12.11
-Value CaseClauseNode::evaluate(ExecState *exec)
-{
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTIONVALUE
- Value v = e.getValue(exec);
-
- return v;
-}
-
-// ECMA 12.11
-Completion CaseClauseNode::evalStatements(ExecState *exec)
-{
- if (list)
- return list->execute(exec);
- else
- return Completion(Normal, Undefined());
-}
-
-void CaseClauseNode::processVarDecls(ExecState *exec)
-{
- if (list)
- list->processVarDecls(exec);
-}
-
-// ------------------------------ ClauseListNode -------------------------------
-
-ClauseListNode::~ClauseListNode()
-{
-}
-
-void ClauseListNode::ref()
-{
- Node::ref();
- if ( cl )
- cl->ref();
- if ( nx )
- nx->ref();
-}
-
-bool ClauseListNode::deref()
-{
- if ( cl && cl->deref() )
- delete cl;
- if ( nx && nx->deref() )
- delete nx;
- return Node::deref();
-}
-
-Value ClauseListNode::evaluate(ExecState */*exec*/)
-{
- /* should never be called */
- assert(false);
- return Value();
-}
-
-// ECMA 12.11
-ClauseListNode* ClauseListNode::append(CaseClauseNode *c)
-{
- ClauseListNode *l = this;
- while (l->nx)
- l = l->nx;
- l->nx = new ClauseListNode(c);
-
- return this;
-}
-
-void ClauseListNode::processVarDecls(ExecState *exec)
-{
- if (cl)
- cl->processVarDecls(exec);
- if (nx)
- nx->processVarDecls(exec);
-}
-
-// ------------------------------ CaseBlockNode --------------------------------
-
-CaseBlockNode::~CaseBlockNode()
-{
-}
-
-void CaseBlockNode::ref()
-{
- Node::ref();
- if ( def )
- def->ref();
- if ( list1 )
- list1->ref();
- if ( list2 )
- list2->ref();
-}
-
-bool CaseBlockNode::deref()
-{
- if ( def && def->deref() )
- delete def;
- if ( list1 && list1->deref() )
- delete list1;
- if ( list2 && list2->deref() )
- delete list2;
- return Node::deref();
-}
-
-Value CaseBlockNode::evaluate(ExecState */*exec*/)
-{
- /* should never be called */
- assert(false);
- return Value();
-}
-
-// ECMA 12.11
-Completion CaseBlockNode::evalBlock(ExecState *exec, const Value& input)
-{
- Value v;
- Completion res;
- ClauseListNode *a = list1, *b = list2;
- CaseClauseNode *clause;
-
- if (a) {
- while (a) {
- clause = a->clause();
- a = a->next();
- v = clause->evaluate(exec);
- KJS_CHECKEXCEPTION
- if (strictEqual(exec, input, v)) {
- res = clause->evalStatements(exec);
- if (res.complType() != Normal)
- return res;
- while (a) {
- res = a->clause()->evalStatements(exec);
- if (res.complType() != Normal)
- return res;
- a = a->next();
- }
- break;
- }
- }
- }
-
- while (b) {
- clause = b->clause();
- b = b->next();
- v = clause->evaluate(exec);
- KJS_CHECKEXCEPTION
- if (strictEqual(exec, input, v)) {
- res = clause->evalStatements(exec);
- if (res.complType() != Normal)
- return res;
- goto step18;
- }
- }
-
- // default clause
- if (def) {
- res = def->evalStatements(exec);
- if (res.complType() != Normal)
- return res;
- }
- b = list2;
- step18:
- while (b) {
- clause = b->clause();
- res = clause->evalStatements(exec);
- if (res.complType() != Normal)
- return res;
- b = b->next();
- }
-
- // bail out on error
- KJS_CHECKEXCEPTION
-
- return Completion(Normal);
-}
-
-void CaseBlockNode::processVarDecls(ExecState *exec)
-{
- if (list1)
- list1->processVarDecls(exec);
- if (def)
- def->processVarDecls(exec);
- if (list2)
- list2->processVarDecls(exec);
-}
-
-// ------------------------------ SwitchNode -----------------------------------
-
-SwitchNode::~SwitchNode()
-{
-}
-
-void SwitchNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
- if ( block )
- block->ref();
-}
-
-bool SwitchNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- if ( block && block->deref() )
- delete block;
- return Node::deref();
-}
-
-// ECMA 12.11
-Completion SwitchNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- Value v = e.getValue(exec);
- Completion res = block->evalBlock(exec,v);
-
- if ((res.complType() == Break) && ls.contains(res.target()))
- return Completion(Normal, res.value());
- else
- return res;
-}
-
-void SwitchNode::processVarDecls(ExecState *exec)
-{
- block->processVarDecls(exec);
-}
-
-// ------------------------------ LabelNode ------------------------------------
-
-LabelNode::~LabelNode()
-{
-}
-
-void LabelNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
-}
-
-bool LabelNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- return Node::deref();
-}
-
-// ECMA 12.12
-Completion LabelNode::execute(ExecState *exec)
-{
- Completion e;
-
- if (!exec->context().imp()->seenLabels()->push(label)) {
- return Completion( Throw,
- throwError(exec, SyntaxError, "Duplicated label found" ));
- };
- e = statement->execute(exec);
- exec->context().imp()->seenLabels()->pop();
-
- if ((e.complType() == Break) && (e.target() == label))
- return Completion(Normal, e.value());
- else
- return e;
-}
-
-void LabelNode::processVarDecls(ExecState *exec)
-{
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ ThrowNode ------------------------------------
-
-ThrowNode::~ThrowNode()
-{
-}
-
-void ThrowNode::ref()
-{
- Node::ref();
- if ( expr )
- expr->ref();
-}
-
-bool ThrowNode::deref()
-{
- if ( expr && expr->deref() )
- delete expr;
- return Node::deref();
-}
-
-// ECMA 12.13
-Completion ThrowNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Value e = expr->evaluate(exec);
- KJS_CHECKEXCEPTION
- Value v = e.getValue(exec);
-
- // bail out on error
- KJS_CHECKEXCEPTION
-
- return Completion(Throw, v);
-}
-
-// ------------------------------ CatchNode ------------------------------------
-
-CatchNode::~CatchNode()
-{
-}
-
-void CatchNode::ref()
-{
- Node::ref();
- if ( block )
- block->ref();
-}
-
-bool CatchNode::deref()
-{
- if ( block && block->deref() )
- delete block;
- return Node::deref();
-}
-
-Completion CatchNode::execute(ExecState */*exec*/)
-{
- // should never be reached. execute(exec, arg) is used instead
- assert(0L);
- return Completion();
-}
-
-// ECMA 12.14
-Completion CatchNode::execute(ExecState *exec, const Value &arg)
-{
- /* TODO: correct ? Not part of the spec */
-
- exec->clearException();
-
- Object obj(new ObjectImp());
- obj.put(exec, ident, arg, DontDelete);
- exec->context().imp()->pushScope(obj);
- Completion c = block->execute(exec);
- exec->context().imp()->popScope();
-
- return c;
-}
-
-void CatchNode::processVarDecls(ExecState *exec)
-{
- block->processVarDecls(exec);
-}
-
-// ------------------------------ FinallyNode ----------------------------------
-
-FinallyNode::~FinallyNode()
-{
-}
-
-void FinallyNode::ref()
-{
- Node::ref();
- if ( block )
- block->ref();
-}
-
-bool FinallyNode::deref()
-{
- if ( block && block->deref() )
- delete block;
- return Node::deref();
-}
-
-// ECMA 12.14
-Completion FinallyNode::execute(ExecState *exec)
-{
- return block->execute(exec);
-}
-
-void FinallyNode::processVarDecls(ExecState *exec)
-{
- block->processVarDecls(exec);
-}
-
-// ------------------------------ TryNode --------------------------------------
-
-TryNode::~TryNode()
-{
-}
-
-void TryNode::ref()
-{
- Node::ref();
- if ( block )
- block->ref();
- if ( _final )
- _final->ref();
- if ( _catch )
- _catch->ref();
-}
-
-bool TryNode::deref()
-{
- if ( block && block->deref() )
- delete block;
- if ( _final && _final->deref() )
- delete _final;
- if ( _catch && _catch->deref() )
- delete _catch;
- return Node::deref();
-}
-
-// ECMA 12.14
-Completion TryNode::execute(ExecState *exec)
-{
- KJS_BREAKPOINT;
-
- Completion c, c2;
-
- c = block->execute(exec);
-
- if (!_final) {
- if (c.complType() != Throw)
- return c;
- return _catch->execute(exec,c.value());
- }
-
- if (!_catch) {
- c2 = _final->execute(exec);
- return (c2.complType() == Normal) ? c : c2;
- }
-
- if (c.complType() == Throw)
- c = _catch->execute(exec,c.value());
-
- c2 = _final->execute(exec);
- return (c2.complType() == Normal) ? c : c2;
-}
-
-void TryNode::processVarDecls(ExecState *exec)
-{
- block->processVarDecls(exec);
- if (_final)
- _final->processVarDecls(exec);
- if (_catch)
- _catch->processVarDecls(exec);
-}
-
-// ------------------------------ ParameterNode --------------------------------
-
-ParameterNode::~ParameterNode()
-{
-}
-
-void ParameterNode::ref()
-{
- Node::ref();
- if ( next )
- next->ref();
-}
-
-bool ParameterNode::deref()
-{
- if ( next && next->deref() )
- delete next;
- return Node::deref();
-}
-
-ParameterNode* ParameterNode::append(const UString *i)
-{
- ParameterNode *p = this;
- while (p->next)
- p = p->next;
-
- p->next = new ParameterNode(i);
-
- return this;
-}
-
-// ECMA 13
-Value ParameterNode::evaluate(ExecState */*exec*/)
-{
- return Undefined();
-}
-
-// ------------------------------ FunctionBodyNode -----------------------------
-
-
-FunctionBodyNode::FunctionBodyNode(SourceElementsNode *s)
- : source(s)
-{
- setLoc(-1, -1, -1);
- //fprintf(stderr,"FunctionBodyNode::FunctionBodyNode %p\n",this);
-}
-
-FunctionBodyNode::~FunctionBodyNode()
-{
- //fprintf(stderr,"FunctionBodyNode::~FunctionBodyNode %p\n",this);
-}
-
-void FunctionBodyNode::ref()
-{
- Node::ref();
- if ( source )
- source->ref();
- //fprintf( stderr, "FunctionBodyNode::ref() %p. Refcount now %d\n", (void*)this, refcount);
-}
-
-bool FunctionBodyNode::deref()
-{
- if ( source && source->deref() )
- delete source;
- //fprintf( stderr, "FunctionBodyNode::deref() %p. Refcount now %d\n", (void*)this, refcount-1);
- return Node::deref();
-}
-
-// ECMA 13 + 14 for ProgramNode
-Completion FunctionBodyNode::execute(ExecState *exec)
-{
- /* TODO: workaround for empty body which I don't see covered by the spec */
- if (!source)
- return Completion(ReturnValue, Undefined());
-
- source->processFuncDecl(exec);
-
- return source->execute(exec);
-}
-
-void FunctionBodyNode::processFuncDecl(ExecState *exec)
-{
- if (source)
- source->processFuncDecl(exec);
-}
-
-void FunctionBodyNode::processVarDecls(ExecState *exec)
-{
- if (source)
- source->processVarDecls(exec);
-}
-
-// ------------------------------ FuncDeclNode ---------------------------------
-
-FuncDeclNode::~FuncDeclNode()
-{
-}
-
-void FuncDeclNode::ref()
-{
- Node::ref();
- if ( param )
- param->ref();
- if ( body )
- body->ref();
-}
-
-bool FuncDeclNode::deref()
-{
- if ( param && param->deref() )
- delete param;
- if ( body && body->deref() )
- delete body;
- return Node::deref();
-}
-
-// ECMA 13
-void FuncDeclNode::processFuncDecl(ExecState *exec)
-{
- const List sc = exec->context().imp()->scopeChain();
-
- // TODO: let this be an object with [[Class]] property "Function"
- FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, sc);
- Object func(fimp); // protect from GC
-
- // Value proto = exec->interpreter()->builtinObject().construct(exec,List::empty());
- List empty;
- Value proto = exec->interpreter()->builtinObject().construct(exec,empty);
- func.put(exec, "prototype", proto, Internal|DontDelete);
-
- int plen = 0;
- for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)
- fimp->addParameter(p->ident());
-
- func.put(exec, "length", Number(plen), ReadOnly|DontDelete|DontEnum);
-
- exec->context().imp()->variableObject().put(exec,ident,func);
-
- if (body) {
- // hack the scope so that the function gets put as a property of func, and it's scope
- // contains the func as well as our current scope
- Object oldVar = exec->context().imp()->variableObject();
- exec->context().imp()->setVariableObject(func);
- exec->context().imp()->pushScope(func);
- body->processFuncDecl(exec);
- exec->context().imp()->popScope();
- exec->context().imp()->setVariableObject(oldVar);
- }
-}
-
-// ------------------------------ FuncExprNode ---------------------------------
-
-FuncExprNode::~FuncExprNode()
-{
-}
-
-void FuncExprNode::ref()
-{
- Node::ref();
- if ( param )
- param->ref();
- if ( body )
- body->ref();
-}
-
-bool FuncExprNode::deref()
-{
- if ( param && param->deref() )
- delete param;
- if ( body && body->deref() )
- delete body;
- return Node::deref();
-}
-
-
-// ECMA 13
-Value FuncExprNode::evaluate(ExecState *exec)
-{
- const List sc = exec->context().scopeChain();
- FunctionImp *fimp = new DeclaredFunctionImp(exec, UString::null, body, sc);
- Value ret(fimp);
- List empty;
- Value proto = exec->interpreter()->builtinObject().construct(exec,empty);
- fimp->put(exec, "prototype", proto, Internal|DontDelete);
-
- int plen = 0;
- for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)
- fimp->addParameter(p->ident());
- fimp->put(exec,"length", Number(plen), ReadOnly|DontDelete|DontEnum);
-
- return ret;
-}
-
-// ------------------------------ SourceElementNode ----------------------------
-
-SourceElementNode::~SourceElementNode()
-{
-}
-
-void SourceElementNode::ref()
-{
- Node::ref();
- if ( statement )
- statement->ref();
- if ( function )
- function->ref();
-}
-
-bool SourceElementNode::deref()
-{
- if ( statement && statement->deref() )
- delete statement;
- if ( function && function->deref() )
- delete function;
- return Node::deref();
-}
-
-// ECMA 14
-Completion SourceElementNode::execute(ExecState *exec)
-{
- if (statement)
- return statement->execute(exec);
-
- return Completion(Normal);
-}
-
-// ECMA 14
-void SourceElementNode::processFuncDecl(ExecState *exec)
-{
- if (function)
- function->processFuncDecl(exec);
-}
-
-void SourceElementNode::processVarDecls(ExecState *exec)
-{
- if (statement)
- statement->processVarDecls(exec);
-}
-
-// ------------------------------ SourceElementsNode ---------------------------
-
-SourceElementsNode::~SourceElementsNode()
-{
-}
-
-void SourceElementsNode::ref()
-{
- Node::ref();
- if ( element )
- element->ref();
- if ( elements )
- elements->ref();
-}
-
-bool SourceElementsNode::deref()
-{
- if ( element && element->deref() )
- delete element;
- if ( elements && elements->deref() )
- delete elements;
- return Node::deref();
-}
-
-// ECMA 14
-Completion SourceElementsNode::execute(ExecState *exec)
-{
- KJS_CHECKEXCEPTION
-
- if (!elements)
- return element->execute(exec);
-
- Completion c1 = elements->execute(exec);
- KJS_CHECKEXCEPTION
- if (c1.complType() != Normal)
- return c1;
-
- Completion c2 = element->execute(exec);
- KJS_CHECKEXCEPTION
-
- // The spec says to return c2 here, but it seems that mozilla returns c1 if
- // c2 doesn't have a value
- if (c2.complType() == Normal && c2.value().isNull())
- return c1;
- else
- return c2;
-}
-
-// ECMA 14
-void SourceElementsNode::processFuncDecl(ExecState *exec)
-{
- if (elements)
- elements->processFuncDecl(exec);
-
- element->processFuncDecl(exec);
-}
-
-void SourceElementsNode::processVarDecls(ExecState *exec)
-{
- if (elements)
- elements->processVarDecls(exec);
-
- element->processVarDecls(exec);
-}
-
-ProgramNode::ProgramNode(SourceElementsNode *s): FunctionBodyNode(s) {
- //fprintf(stderr,"ProgramNode::ProgramNode %p\n",this);
-}
-
-ProgramNode::~ProgramNode() {
- //fprintf(stderr,"ProgramNode::~ProgramNode %p\n",this);
-}
diff --git a/WebCore/src/kdelibs/kjs/nodes.h b/WebCore/src/kdelibs/kjs/nodes.h
deleted file mode 100644
index 1ccac86..0000000
--- a/WebCore/src/kdelibs/kjs/nodes.h
+++ /dev/null
@@ -1,1006 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _NODES_H_
-#define _NODES_H_
-
-#include "internal.h"
-//#include "debugger.h"
-#ifndef NDEBUG
-#ifndef __osf__
-#include <list>
-#endif
-#endif
-
-namespace KJS {
-
- class RegExp;
- class SourceElementsNode;
- class ProgramNode;
-
- enum Operator { OpEqual,
- OpEqEq,
- OpNotEq,
- OpStrEq,
- OpStrNEq,
- OpPlusEq,
- OpMinusEq,
- OpMultEq,
- OpDivEq,
- OpPlusPlus,
- OpMinusMinus,
- OpLess,
- OpLessEq,
- OpGreater,
- OpGreaterEq,
- OpAndEq,
- OpXOrEq,
- OpOrEq,
- OpModEq,
- OpAnd,
- OpOr,
- OpBitAnd,
- OpBitXOr,
- OpBitOr,
- OpLShift,
- OpRShift,
- OpURShift,
- OpIn,
- OpInstanceOf
- };
-
- class Node {
- public:
- Node();
- virtual ~Node();
- virtual Value evaluate(ExecState *exec) = 0;
- virtual void processVarDecls(ExecState */*exec*/) {}
- int lineNo() const { return line; }
-
- public:
- // reference counting mechanism
- virtual void ref() { refcount++; }
-#ifdef KJS_DEBUG_MEM
- virtual bool deref() { assert( refcount > 0 ); return (!--refcount); }
-#else
- virtual bool deref() { return (!--refcount); }
-#endif
-
-
-#ifdef KJS_DEBUG_MEM
- static void finalCheck();
-#endif
- protected:
- Value throwError(ExecState *exec, ErrorType e, const char *msg);
- int line;
- unsigned int refcount;
- virtual int sourceId() const { return -1; }
- private:
-#ifdef KJS_DEBUG_MEM
- // List of all nodes, for debugging purposes. Don't remove!
- static std::list<Node *> s_nodes;
-#endif
- // disallow assignment
- Node& operator=(const Node&);
- Node(const Node &other);
- };
-
- class StatementNode : public Node {
- public:
- StatementNode();
- ~StatementNode();
- void setLoc(int line0, int line1, int sourceId);
- int firstLine() const { return l0; }
- int lastLine() const { return l1; }
- int sourceId() const { return sid; }
- bool hitStatement(ExecState *exec);
- bool abortStatement(ExecState *exec);
- virtual Completion execute(ExecState *exec) = 0;
- void pushLabel(const UString *id) {
- if (id) ls.push(*id);
- }
- protected:
- LabelStack ls;
- private:
- Value evaluate(ExecState */*exec*/) { return Undefined(); }
- int l0, l1;
- int sid;
- bool breakPoint;
- };
-
- class NullNode : public Node {
- public:
- NullNode() {}
- Value evaluate(ExecState *exec);
- };
-
- class BooleanNode : public Node {
- public:
- BooleanNode(bool v) : value(v) {}
- Value evaluate(ExecState *exec);
- private:
- bool value;
- };
-
- class NumberNode : public Node {
- public:
- NumberNode(double v) : value(v) { }
- Value evaluate(ExecState *exec);
- private:
- double value;
- };
-
- class StringNode : public Node {
- public:
- StringNode(const UString *v) { value = *v; }
- Value evaluate(ExecState *exec);
- private:
- UString value;
- };
-
- class RegExpNode : public Node {
- public:
- RegExpNode(const UString &p, const UString &f)
- : pattern(p), flags(f) { }
- Value evaluate(ExecState *exec);
- private:
- UString pattern, flags;
- };
-
- class ThisNode : public Node {
- public:
- ThisNode() {}
- Value evaluate(ExecState *exec);
- };
-
- class ResolveNode : public Node {
- public:
- ResolveNode(const UString *s) : ident(*s) { }
- Value evaluate(ExecState *exec);
- private:
- UString ident;
- };
-
- class GroupNode : public Node {
- public:
- GroupNode(Node *g) : group(g) { }
- virtual void ref();
- virtual bool deref();
- virtual ~GroupNode();
- Value evaluate(ExecState *exec);
- private:
- Node *group;
- };
-
- class ElisionNode : public Node {
- public:
- ElisionNode(ElisionNode *e) : elision(e) { }
- virtual void ref();
- virtual bool deref();
- virtual ~ElisionNode();
- Value evaluate(ExecState *exec);
- private:
- ElisionNode *elision;
- };
-
- class ElementNode : public Node {
- public:
- ElementNode(ElisionNode *e, Node *n) : list(0l), elision(e), node(n) { }
- ElementNode(ElementNode *l, ElisionNode *e, Node *n)
- : list(l), elision(e), node(n) { }
- virtual void ref();
- virtual bool deref();
- virtual ~ElementNode();
- Value evaluate(ExecState *exec);
- private:
- ElementNode *list;
- ElisionNode *elision;
- Node *node;
- };
-
- class ArrayNode : public Node {
- public:
- ArrayNode(ElisionNode *e) : element(0L), elision(e), opt(true) { }
- ArrayNode(ElementNode *ele)
- : element(ele), elision(0), opt(false) { }
- ArrayNode(ElisionNode *eli, ElementNode *ele)
- : element(ele), elision(eli), opt(true) { }
- virtual void ref();
- virtual bool deref();
- virtual ~ArrayNode();
- Value evaluate(ExecState *exec);
- private:
- ElementNode *element;
- ElisionNode *elision;
- bool opt;
- };
-
- class ObjectLiteralNode : public Node {
- public:
- ObjectLiteralNode(Node *l) : list(l) { }
- virtual void ref();
- virtual bool deref();
- virtual ~ObjectLiteralNode();
- Value evaluate(ExecState *exec);
- private:
- Node *list;
- };
-
- class PropertyValueNode : public Node {
- public:
- PropertyValueNode(Node *n, Node *a, Node *l = 0L)
- : name(n), assign(a), list(l) { }
- virtual void ref();
- virtual bool deref();
- virtual ~PropertyValueNode();
- Value evaluate(ExecState *exec);
- private:
- Node *name, *assign, *list;
- };
-
- class PropertyNode : public Node {
- public:
- PropertyNode(double d) : numeric(d) { }
- PropertyNode(const UString *s) : str(*s) { }
- Value evaluate(ExecState *exec);
- private:
- double numeric;
- UString str;
- };
-
- class AccessorNode1 : public Node {
- public:
- AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
- virtual void ref();
- virtual bool deref();
- virtual ~AccessorNode1();
- Value evaluate(ExecState *exec);
- private:
- Node *expr1;
- Node *expr2;
- };
-
- class AccessorNode2 : public Node {
- public:
- AccessorNode2(Node *e, const UString *s) : expr(e), ident(*s) { }
- virtual void ref();
- virtual bool deref();
- virtual ~AccessorNode2();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- UString ident;
- };
-
- class ArgumentListNode : public Node {
- public:
- ArgumentListNode(Node *e);
- ArgumentListNode(ArgumentListNode *l, Node *e);
- virtual void ref();
- virtual bool deref();
- virtual ~ArgumentListNode();
- Value evaluate(ExecState *exec);
- List evaluateList(ExecState *exec);
- private:
- ArgumentListNode *list;
- Node *expr;
- };
-
- class ArgumentsNode : public Node {
- public:
- ArgumentsNode(ArgumentListNode *l);
- virtual void ref();
- virtual bool deref();
- virtual ~ArgumentsNode();
- Value evaluate(ExecState *exec);
- List evaluateList(ExecState *exec);
- private:
- ArgumentListNode *list;
- };
-
- class NewExprNode : public Node {
- public:
- NewExprNode(Node *e) : expr(e), args(0L) {}
- NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
- virtual void ref();
- virtual bool deref();
- virtual ~NewExprNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- ArgumentsNode *args;
- };
-
- class FunctionCallNode : public Node {
- public:
- FunctionCallNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
- virtual void ref();
- virtual bool deref();
- virtual ~FunctionCallNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- ArgumentsNode *args;
- };
-
- class PostfixNode : public Node {
- public:
- PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
- virtual void ref();
- virtual bool deref();
- virtual ~PostfixNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- Operator oper;
- };
-
- class DeleteNode : public Node {
- public:
- DeleteNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~DeleteNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class VoidNode : public Node {
- public:
- VoidNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~VoidNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class TypeOfNode : public Node {
- public:
- TypeOfNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~TypeOfNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class PrefixNode : public Node {
- public:
- PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~PrefixNode();
- Value evaluate(ExecState *exec);
- private:
- Operator oper;
- Node *expr;
- };
-
- class UnaryPlusNode : public Node {
- public:
- UnaryPlusNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~UnaryPlusNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class NegateNode : public Node {
- public:
- NegateNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~NegateNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class BitwiseNotNode : public Node {
- public:
- BitwiseNotNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~BitwiseNotNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class LogicalNotNode : public Node {
- public:
- LogicalNotNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~LogicalNotNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class MultNode : public Node {
- public:
- MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
- virtual void ref();
- virtual bool deref();
- virtual ~MultNode();
- Value evaluate(ExecState *exec);
- private:
- Node *term1, *term2;
- char oper;
- };
-
- class AddNode : public Node {
- public:
- AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
- virtual void ref();
- virtual bool deref();
- virtual ~AddNode();
- Value evaluate(ExecState *exec);
- private:
- Node *term1, *term2;
- char oper;
- };
-
- class ShiftNode : public Node {
- public:
- ShiftNode(Node *t1, Operator o, Node *t2)
- : term1(t1), term2(t2), oper(o) {}
- virtual void ref();
- virtual bool deref();
- virtual ~ShiftNode();
- Value evaluate(ExecState *exec);
- private:
- Node *term1, *term2;
- Operator oper;
- };
-
- class RelationalNode : public Node {
- public:
- RelationalNode(Node *e1, Operator o, Node *e2) :
- expr1(e1), expr2(e2), oper(o) {}
- virtual void ref();
- virtual bool deref();
- virtual ~RelationalNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr1, *expr2;
- Operator oper;
- };
-
- class EqualNode : public Node {
- public:
- EqualNode(Node *e1, Operator o, Node *e2)
- : expr1(e1), expr2(e2), oper(o) {}
- virtual void ref();
- virtual bool deref();
- virtual ~EqualNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr1, *expr2;
- Operator oper;
- };
-
- class BitOperNode : public Node {
- public:
- BitOperNode(Node *e1, Operator o, Node *e2) :
- expr1(e1), expr2(e2), oper(o) {}
- virtual void ref();
- virtual bool deref();
- virtual ~BitOperNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr1, *expr2;
- Operator oper;
- };
-
- /** expr1 && expr2, expr1 || expr2 */
- class BinaryLogicalNode : public Node {
- public:
- BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
- expr1(e1), expr2(e2), oper(o) {}
- virtual void ref();
- virtual bool deref();
- virtual ~BinaryLogicalNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr1, *expr2;
- Operator oper;
- };
-
- /** The ternary operator, "logical ? expr1 : expr2" */
- class ConditionalNode : public Node {
- public:
- ConditionalNode(Node *l, Node *e1, Node *e2) :
- logical(l), expr1(e1), expr2(e2) {}
- virtual void ref();
- virtual bool deref();
- virtual ~ConditionalNode();
- Value evaluate(ExecState *exec);
- private:
- Node *logical, *expr1, *expr2;
- };
-
- class AssignNode : public Node {
- public:
- AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~AssignNode();
- Value evaluate(ExecState *exec);
- private:
- Node *left;
- Operator oper;
- Node *expr;
- };
-
- class CommaNode : public Node {
- public:
- CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
- virtual void ref();
- virtual bool deref();
- virtual ~CommaNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr1, *expr2;
- };
-
- class StatListNode : public StatementNode {
- public:
- StatListNode(StatementNode *s) : statement(s), list(0L) { }
- StatListNode(StatListNode *l, StatementNode *s) : statement(s), list(l) { }
- virtual void ref();
- virtual bool deref();
- virtual ~StatListNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- StatementNode *statement;
- StatListNode *list;
- };
-
- class AssignExprNode : public Node {
- public:
- AssignExprNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~AssignExprNode();
- Value evaluate(ExecState *exec);
- private:
- Node *expr;
- };
-
- class VarDeclNode : public Node {
- public:
- VarDeclNode(const UString *id, AssignExprNode *in);
- virtual void ref();
- virtual bool deref();
- virtual ~VarDeclNode();
- Value evaluate(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- UString ident;
- AssignExprNode *init;
- };
-
- class VarDeclListNode : public Node {
- public:
- VarDeclListNode(VarDeclNode *v) : list(0L), var(v) {}
- VarDeclListNode(Node *l, VarDeclNode *v) : list(l), var(v) {}
- virtual void ref();
- virtual bool deref();
- virtual ~VarDeclListNode();
- Value evaluate(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *list;
- VarDeclNode *var;
- };
-
- class VarStatementNode : public StatementNode {
- public:
- VarStatementNode(VarDeclListNode *l) : list(l) {}
- virtual void ref();
- virtual bool deref();
- virtual ~VarStatementNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- VarDeclListNode *list;
- };
-
- class BlockNode : public StatementNode {
- public:
- BlockNode(SourceElementsNode *s) : source(s) {}
- virtual void ref();
- virtual bool deref();
- virtual ~BlockNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- SourceElementsNode *source;
- };
-
- class EmptyStatementNode : public StatementNode {
- public:
- EmptyStatementNode() { } // debug
- virtual Completion execute(ExecState *exec);
- };
-
- class ExprStatementNode : public StatementNode {
- public:
- ExprStatementNode(Node *e) : expr(e) { }
- virtual void ref();
- virtual bool deref();
- virtual ~ExprStatementNode();
- virtual Completion execute(ExecState *exec);
- private:
- Node *expr;
- };
-
- class IfNode : public StatementNode {
- public:
- IfNode(Node *e, StatementNode *s1, StatementNode *s2)
- : expr(e), statement1(s1), statement2(s2) {}
- virtual void ref();
- virtual bool deref();
- virtual ~IfNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *expr;
- StatementNode *statement1, *statement2;
- };
-
- class DoWhileNode : public StatementNode {
- public:
- DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~DoWhileNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- StatementNode *statement;
- Node *expr;
- };
-
- class WhileNode : public StatementNode {
- public:
- WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
- virtual void ref();
- virtual bool deref();
- virtual ~WhileNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *expr;
- StatementNode *statement;
- };
-
- class ForNode : public StatementNode {
- public:
- ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) :
- expr1(e1), expr2(e2), expr3(e3), statement(s) {}
- virtual void ref();
- virtual bool deref();
- virtual ~ForNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *expr1, *expr2, *expr3;
- StatementNode *statement;
- };
-
- class ForInNode : public StatementNode {
- public:
- ForInNode(Node *l, Node *e, StatementNode *s);
- ForInNode(const UString *i, AssignExprNode *in, Node *e, StatementNode *s);
- virtual void ref();
- virtual bool deref();
- virtual ~ForInNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- UString ident;
- AssignExprNode *init;
- Node *lexpr, *expr;
- VarDeclNode *varDecl;
- StatementNode *statement;
- };
-
- class ContinueNode : public StatementNode {
- public:
- ContinueNode() { }
- ContinueNode(const UString *i) : ident(*i) { }
- virtual Completion execute(ExecState *exec);
- private:
- UString ident;
- };
-
- class BreakNode : public StatementNode {
- public:
- BreakNode() { }
- BreakNode(const UString *i) : ident(*i) { }
- virtual Completion execute(ExecState *exec);
- private:
- UString ident;
- };
-
- class ReturnNode : public StatementNode {
- public:
- ReturnNode(Node *v) : value(v) {}
- virtual void ref();
- virtual bool deref();
- virtual ~ReturnNode();
- virtual Completion execute(ExecState *exec);
- private:
- Node *value;
- };
-
- class WithNode : public StatementNode {
- public:
- WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
- virtual void ref();
- virtual bool deref();
- virtual ~WithNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *expr;
- StatementNode *statement;
- };
-
- class CaseClauseNode: public Node {
- public:
- CaseClauseNode(Node *e, StatListNode *l) : expr(e), list(l) { }
- virtual void ref();
- virtual bool deref();
- virtual ~CaseClauseNode();
- Value evaluate(ExecState *exec);
- Completion evalStatements(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *expr;
- StatListNode *list;
- };
-
- class ClauseListNode : public Node {
- public:
- ClauseListNode(CaseClauseNode *c) : cl(c), nx(0L) { }
- virtual void ref();
- virtual bool deref();
- virtual ~ClauseListNode();
- ClauseListNode* append(CaseClauseNode *c);
- Value evaluate(ExecState *exec);
- CaseClauseNode *clause() const { return cl; }
- ClauseListNode *next() const { return nx; }
- virtual void processVarDecls(ExecState *exec);
- private:
- CaseClauseNode *cl;
- ClauseListNode *nx;
- };
-
- class CaseBlockNode: public Node {
- public:
- CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2)
- : list1(l1), def(d), list2(l2) { }
- virtual void ref();
- virtual bool deref();
- virtual ~CaseBlockNode();
- Value evaluate(ExecState *exec);
- Completion evalBlock(ExecState *exec, const Value& input);
- virtual void processVarDecls(ExecState *exec);
- private:
- ClauseListNode *list1;
- CaseClauseNode *def;
- ClauseListNode *list2;
- };
-
- class SwitchNode : public StatementNode {
- public:
- SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
- virtual void ref();
- virtual bool deref();
- virtual ~SwitchNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- Node *expr;
- CaseBlockNode *block;
- };
-
- class LabelNode : public StatementNode {
- public:
- LabelNode(const UString *l, StatementNode *s) : label(*l), statement(s) { }
- virtual void ref();
- virtual bool deref();
- virtual ~LabelNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- UString label;
- StatementNode *statement;
- };
-
- class ThrowNode : public StatementNode {
- public:
- ThrowNode(Node *e) : expr(e) {}
- virtual void ref();
- virtual bool deref();
- virtual ~ThrowNode();
- virtual Completion execute(ExecState *exec);
- private:
- Node *expr;
- };
-
- class CatchNode : public StatementNode {
- public:
- CatchNode(const UString *i, StatementNode *b) : ident(*i), block(b) {}
- virtual void ref();
- virtual bool deref();
- virtual ~CatchNode();
- virtual Completion execute(ExecState *exec);
- Completion execute(ExecState *exec, const Value &arg);
- virtual void processVarDecls(ExecState *exec);
- private:
- UString ident;
- StatementNode *block;
- };
-
- class FinallyNode : public StatementNode {
- public:
- FinallyNode(StatementNode *b) : block(b) {}
- virtual void ref();
- virtual bool deref();
- virtual ~FinallyNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- StatementNode *block;
- };
-
- class TryNode : public StatementNode {
- public:
- TryNode(StatementNode *b, Node *c = 0L, Node *f = 0L)
- : block(b), _catch((CatchNode*)c), _final((FinallyNode*)f) {}
- virtual void ref();
- virtual bool deref();
- virtual ~TryNode();
- virtual Completion execute(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- StatementNode *block;
- CatchNode *_catch;
- FinallyNode *_final;
- };
-
- class ParameterNode : public Node {
- public:
- ParameterNode(const UString *i) : id(*i), next(0L) { }
- ParameterNode *append(const UString *i);
- virtual void ref();
- virtual bool deref();
- virtual ~ParameterNode();
- Value evaluate(ExecState *exec);
- UString ident() { return id; }
- ParameterNode *nextParam() { return next; }
- private:
- UString id;
- ParameterNode *next;
- };
-
- // inherited by ProgramNode
- class FunctionBodyNode : public StatementNode {
- public:
- FunctionBodyNode(SourceElementsNode *s);
- virtual void ref();
- virtual bool deref();
- virtual ~FunctionBodyNode();
- Completion execute(ExecState *exec);
- virtual void processFuncDecl(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- protected:
- SourceElementsNode *source;
- };
-
- class FuncDeclNode : public StatementNode {
- public:
- FuncDeclNode(const UString *i, ParameterNode *p, FunctionBodyNode *b)
- : ident(*i), param(p), body(b) { }
- virtual void ref();
- virtual bool deref();
- virtual ~FuncDeclNode();
- Completion execute(ExecState */*exec*/)
- { /* empty */ return Completion(); }
- void processFuncDecl(ExecState *exec);
- private:
- UString ident;
- ParameterNode *param;
- FunctionBodyNode *body;
- };
-
- class FuncExprNode : public Node {
- public:
- FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
- : param(p), body(b) { }
- virtual void ref();
- virtual bool deref();
- virtual ~FuncExprNode();
- Value evaluate(ExecState *exec);
- private:
- ParameterNode *param;
- FunctionBodyNode *body;
- };
-
- class SourceElementNode : public StatementNode {
- public:
- SourceElementNode(StatementNode *s) { statement = s; function = 0L; }
- SourceElementNode(FuncDeclNode *f) { function = f; statement = 0L;}
- virtual void ref();
- virtual bool deref();
- virtual ~SourceElementNode();
- Completion execute(ExecState *exec);
- virtual void processFuncDecl(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- StatementNode *statement;
- FuncDeclNode *function;
- };
-
- // A linked list of source element nodes
- class SourceElementsNode : public StatementNode {
- public:
- SourceElementsNode(SourceElementNode *s1) { element = s1; elements = 0L; }
- SourceElementsNode(SourceElementsNode *s1, SourceElementNode *s2)
- { elements = s1; element = s2; }
- virtual void ref();
- virtual bool deref();
- virtual ~SourceElementsNode();
- Completion execute(ExecState *exec);
- virtual void processFuncDecl(ExecState *exec);
- virtual void processVarDecls(ExecState *exec);
- private:
- SourceElementNode *element; // 'this' element
- SourceElementsNode *elements; // pointer to next
- };
-
- class ProgramNode : public FunctionBodyNode {
- public:
- ProgramNode(SourceElementsNode *s);
- ~ProgramNode();
- private:
- // Disallow copy
- ProgramNode(const ProgramNode &other);
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/nodes2string.cpp b/WebCore/src/kdelibs/kjs/nodes2string.cpp
deleted file mode 100644
index 617813a..0000000
--- a/WebCore/src/kdelibs/kjs/nodes2string.cpp
+++ /dev/null
@@ -1,596 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 2002 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#include "nodes.h"
-
-namespace KJS {
- /**
- * A simple text streaming class that helps with code indentation.
- */
- class SourceStream {
- public:
- enum Format {
- Endl, Indent, Unindent
- };
-
- UString toString() const { return str; }
- SourceStream& operator<<(const KJS::UString &);
- SourceStream& operator<<(Format f);
- SourceStream& operator<<(const Node *);
- private:
- UString str; /* TODO: buffer */
- UString ind;
- };
-};
-
-using namespace KJS;
-
-SourceStream& SourceStream::operator<<(const KJS::UString &s)
-{
- str += s;
- return *this;
-}
-
-SourceStream& SourceStream::operator<<(const Node *n)
-{
- if (n)
- n->streamTo(*this);
- return *this;
-}
-
-SourceStream& SourceStream::operator<<(Format f)
-{
- if (f == Endl)
- str += "\n" + ind;
- else if (f == Indent)
- ind += " ";
- else
- ind = ind.substr(0, ind.size() - 2);
-
- return *this;
-}
-
-UString Node::toString() const
-{
- SourceStream str;
- streamTo(str);
-
- return str.toString();
-}
-
-void NullNode::streamTo(SourceStream &s) const { s << "null"; }
-
-void BooleanNode::streamTo(SourceStream &s) const
-{
- s << (value ? "true" : "false");
-}
-
-void NumberNode::streamTo(SourceStream &s) const { s << UString::from(value); }
-
-void StringNode::streamTo(SourceStream &s) const
-{
- s << '"' << value << '"';
-}
-
-void RegExpNode::streamTo(SourceStream &s) const { s << pattern; }
-
-void ThisNode::streamTo(SourceStream &s) const { s << "this"; }
-
-void ResolveNode::streamTo(SourceStream &s) const { s << ident; }
-
-void ElisionNode::streamTo(SourceStream &s) const
-{
- if (elision)
- s << elision << ",";
- else
- s << ",";
-}
-
-void ElementNode::streamTo(SourceStream &s) const
-{
- if (list)
- s << list << ",";
- s << elision << node;
-}
-
-void ArrayNode::streamTo(SourceStream &s) const
-{
- s << "[" << element << elision << "]";
-}
-
-void ObjectLiteralNode::streamTo(SourceStream &s) const
-{
- if (list)
- s << "{ " << list << " }";
- else
- s << "{ }";
-}
-
-void PropertyValueNode::streamTo(SourceStream &s) const
-{
- if (list)
- s << list << ", ";
- s << name << ": " << assign;
-}
-
-void PropertyNode::streamTo(SourceStream &s) const
-{
- if (str.isNull())
- s << UString::from(numeric);
- else
- s << str;
-}
-
-void AccessorNode1::streamTo(SourceStream &s) const
-{
- s << expr1 << "[" << expr2 << "]";
-}
-
-void AccessorNode2::streamTo(SourceStream &s) const
-{
- s << expr << "." << ident;
-}
-
-void ArgumentListNode::streamTo(SourceStream &s) const
-{
- if (list)
- s << list << ", ";
- s << expr;
-}
-
-void ArgumentsNode::streamTo(SourceStream &s) const
-{
- s << "(" << list << ")";
-}
-
-void NewExprNode::streamTo(SourceStream &s) const
-{
- s << "new " << expr << args;
-}
-
-void FunctionCallNode::streamTo(SourceStream &s) const
-{
- s << expr << args;
-}
-
-void PostfixNode::streamTo(SourceStream &s) const
-{
- s << expr;
- if (oper == OpPlusPlus)
- s << "++";
- else
- s << "--";
-}
-
-void DeleteNode::streamTo(SourceStream &s) const
-{
- s << "delete " << expr;
-}
-
-void VoidNode::streamTo(SourceStream &s) const
-{
- s << "void " << expr;
-}
-
-void TypeOfNode::streamTo(SourceStream &s) const
-{
- s << "typeof " << expr;
-}
-
-void PrefixNode::streamTo(SourceStream &s) const
-{
- s << expr << (oper == OpPlusPlus ? "++" : "--");
-}
-
-void UnaryPlusNode::streamTo(SourceStream &s) const
-{
- s << "+" << expr;
-}
-
-void NegateNode::streamTo(SourceStream &s) const
-{
- s << "-" << expr;
-}
-
-void BitwiseNotNode::streamTo(SourceStream &s) const
-{
- s << "~" << expr;
-}
-
-void LogicalNotNode::streamTo(SourceStream &s) const
-{
- s << "!" << expr;
-}
-
-void MultNode::streamTo(SourceStream &s) const
-{
- s << term1 << oper << term2;
-}
-
-void AddNode::streamTo(SourceStream &s) const
-{
- s << term1 << oper << term2;
-}
-
-void ShiftNode::streamTo(SourceStream &s) const
-{
- s << term1;
- if (oper == OpLShift)
- s << "<<";
- else if (oper == OpRShift)
- s << ">>";
- else
- s << ">>>";
- s << term2;
-}
-
-void RelationalNode::streamTo(SourceStream &s) const
-{
- s << expr1;
- switch (oper) {
- case OpLess:
- s << " < ";
- break;
- case OpGreater:
- s << " > ";
- break;
- case OpLessEq:
- s << " <= ";
- break;
- case OpGreaterEq:
- s << " >= ";
- break;
- case OpInstanceOf:
- s << " instanceof ";
- break;
- case OpIn:
- s << " in ";
- break;
- default:
- ;
- }
- s << expr2;
-}
-
-void EqualNode::streamTo(SourceStream &s) const
-{
- s << expr1;
- switch (oper) {
- case OpEqEq:
- s << " == ";
- break;
- case OpNotEq:
- s << " != ";
- break;
- case OpStrEq:
- s << " === ";
- break;
- case OpStrNEq:
- s << " !== ";
- break;
- default:
- ;
- }
- s << expr2;
-}
-
-void BitOperNode::streamTo(SourceStream &s) const
-{
- s << expr1;
- if (oper == OpBitAnd)
- s << " & ";
- else if (oper == OpBitXOr)
- s << " ^ ";
- else
- s << " | ";
- s << expr2;
-}
-
-void BinaryLogicalNode::streamTo(SourceStream &s) const
-{
- s << expr1 << (oper == OpAnd ? " && " : " || ") << expr2;
-}
-
-void ConditionalNode::streamTo(SourceStream &s) const
-{
- s << logical << " ? " << expr1 << " : " << expr2;
-}
-
-void AssignNode::streamTo(SourceStream &s) const
-{
- s << left;
- const char *opStr;
- switch (oper) {
- case OpEqual:
- opStr = " = ";
- break;
- case OpMultEq:
- opStr = " *= ";
- break;
- case OpDivEq:
- opStr = " /= ";
- break;
- case OpPlusEq:
- opStr = " += ";
- break;
- case OpMinusEq:
- opStr = " -= ";
- break;
- case OpLShift:
- opStr = " <<= ";
- break;
- case OpRShift:
- opStr = " >>= ";
- break;
- case OpURShift:
- opStr = " >>= ";
- break;
- case OpAndEq:
- opStr = " &= ";
- break;
- case OpXOrEq:
- opStr = " ^= ";
- break;
- case OpOrEq:
- opStr = " |= ";
- break;
- case OpModEq:
- opStr = " %= ";
- break;
- default:
- opStr = " ?= ";
- }
- s << opStr << expr;
-}
-
-void CommaNode::streamTo(SourceStream &s) const
-{
- s << expr1 << ", " << expr2;
-}
-
-void StatListNode::streamTo(SourceStream &s) const
-{
- s << list << statement;
-}
-
-void AssignExprNode::streamTo(SourceStream &s) const
-{
- s << " = " << expr;
-}
-
-void VarDeclNode::streamTo(SourceStream &s) const
-{
- s << ident << init;
-}
-
-void VarDeclListNode::streamTo(SourceStream &s) const
-{
- if (list)
- s << list << ", ";
- s << var;
-}
-
-void VarStatementNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "var " << list << ";";
-}
-
-void BlockNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "{" << SourceStream::Indent
- << source << SourceStream::Unindent << SourceStream::Endl << "}";
-}
-
-void EmptyStatementNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << ";";
-}
-
-void ExprStatementNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << expr << ";";
-}
-
-void IfNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "if (" << expr << ")" << SourceStream::Indent
- << statement1 << SourceStream::Unindent;
- if (statement2)
- s << SourceStream::Endl << "else" << SourceStream::Indent
- << statement2 << SourceStream::Unindent;
-}
-
-void DoWhileNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "do " << SourceStream::Indent
- << statement << SourceStream::Unindent << SourceStream::Endl
- << "while (" << expr << ");";
-}
-
-void WhileNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "while (" << expr << ")" << SourceStream::Indent
- << statement << SourceStream::Unindent;
-}
-
-void ForNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "for ("
- << expr1 // TODO: doesn't properly do "var i = 0"
- << "; " << expr2
- << "; " << expr3
- << ")" << SourceStream::Indent << statement << SourceStream::Unindent;
-}
-
-void ForInNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "for (";
- if (varDecl)
- s << "var " << varDecl;
- if (init)
- s << " = " << init;
- s << " in " << expr << ")" << SourceStream::Indent
- << statement << SourceStream::Unindent;
-}
-
-void ContinueNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "continue";
- if (!ident.isNull())
- s << " " << ident;
- s << ";";
-}
-
-void BreakNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "break";
- if (!ident.isNull())
- s << " " << ident;
- s << ";";
-}
-
-void ReturnNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "return";
- if (value)
- s << " " << value;
- s << ";";
-}
-
-void WithNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "with (" << expr << ") "
- << statement;
-}
-
-void CaseClauseNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl;
- if (expr)
- s << "case " << expr;
- else
- s << "default";
- s << ":" << SourceStream::Indent;
- if (list)
- s << list;
- s << SourceStream::Unindent;
-}
-
-void ClauseListNode::streamTo(SourceStream &s) const
-{
- const ClauseListNode *l = this;
- do {
- s << l;
- l = l->nx;
- } while (l);
-}
-
-void CaseBlockNode::streamTo(SourceStream &s) const
-{
- const ClauseListNode *cl = list1;
- while (cl) {
- s << cl->clause();
- cl = cl->next();
- }
- if (def)
- s << def;
- cl = list2;
- while (cl) {
- s << cl->clause();
- cl = cl->next();
- }
-}
-
-void SwitchNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "switch (" << expr << ") {"
- << SourceStream::Indent << block << SourceStream::Unindent
- << SourceStream::Endl << "}";
-}
-
-void LabelNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << label << ":" << SourceStream::Indent
- << statement << SourceStream::Unindent;
-}
-
-void ThrowNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "throw " << expr << ";";
-}
-
-void CatchNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "catch (" << ident << ")" << block;
-}
-
-void FinallyNode::streamTo(SourceStream &s) const
-{
- s << SourceStream::Endl << "finally " << block;
-}
-
-void TryNode::streamTo(SourceStream &s) const
-{
- s << "try " << block
- << _catch
- << _final;
-}
-
-void ParameterNode::streamTo(SourceStream &s) const
-{
- s << id;
- if (next)
- s << ", " << next;
-}
-
-void FunctionBodyNode::streamTo(SourceStream &s) const {
- s << SourceStream::Endl << "{" << SourceStream::Indent
- << source << SourceStream::Unindent << SourceStream::Endl << "}";
-}
-
-void FuncDeclNode::streamTo(SourceStream &s) const {
- s << "function " << ident << "(";
- if (param)
- s << param;
- s << ")" << body;
-}
-
-void FuncExprNode::streamTo(SourceStream &s) const
-{
- s << "function " << "("
- << param
- << ")" << body;
-}
-
-void SourceElementNode::streamTo(SourceStream &s) const
-{
- if (statement)
- s << statement;
- else
- s << function;
-}
-
-void SourceElementsNode::streamTo(SourceStream &s) const
-{
- s << elements << element;
-}
-
diff --git a/WebCore/src/kdelibs/kjs/number_object.cpp b/WebCore/src/kdelibs/kjs/number_object.cpp
deleted file mode 100644
index b041b14..0000000
--- a/WebCore/src/kdelibs/kjs/number_object.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "number_object.h"
-#include "error_object.h"
-
-#include "number_object.lut.h"
-
-using namespace KJS;
-
-
-// ------------------------------ NumberInstanceImp ----------------------------
-
-const ClassInfo NumberInstanceImp::info = {"Number", 0, 0, 0};
-
-NumberInstanceImp::NumberInstanceImp(const Object &proto)
- : ObjectImp(proto)
-{
-}
-// ------------------------------ NumberPrototypeImp ---------------------------
-
-// ECMA 15.7.4
-
-NumberPrototypeImp::NumberPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto,
- FunctionPrototypeImp *funcProto)
- : NumberInstanceImp(Object(objProto))
-{
- Value protect(this);
- setInternalValue(Number(0));
-
- // The constructor will be added later, after NumberObjectImp has been constructed
-
- put(exec,"toString", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToString, 1)), DontEnum);
- put(exec,"toLocaleString", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ToLocaleString, 0)), DontEnum);
- put(exec,"valueOf", Object(new NumberProtoFuncImp(exec,funcProto,NumberProtoFuncImp::ValueOf, 0)), DontEnum);
-}
-
-
-// ------------------------------ NumberProtoFuncImp ---------------------------
-
-NumberProtoFuncImp::NumberProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto, int i, int len)
- : InternalFunctionImp(funcProto), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-
-bool NumberProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.7.4.2 - 15.7.4.7
-Value NumberProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)
-{
- Value result;
-
- // no generic function. "this" has to be a Number object
- if (!thisObj.inherits(&NumberInstanceImp::info)) {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
- // execute "toString()" or "valueOf()", respectively
- Value v = thisObj.internalValue();
- switch (id) {
- case ToString:
- case ToLocaleString: /* TODO */
- result = String(v.toString(exec));
- break;
- case ValueOf:
- result = Number(v.toNumber(exec));
- break;
- }
-
- return result;
-}
-
-// ------------------------------ NumberObjectImp ------------------------------
-
-const ClassInfo NumberObjectImp::info = {"Number", &InternalFunctionImp::info, &numberTable, 0};
-//const ClassInfo NumberObjectImp::info = {"Number", 0, &numberTable, 0};
-
-/* Source for number_object.lut.h
- at begin numberTable 5
- NaN NumberObjectImp::NaNValue DontEnum
- NEGATIVE_INFINITY NumberObjectImp::NegInfinity DontEnum
- POSITIVE_INFINITY NumberObjectImp::PosInfinity DontEnum
- MAX_VALUE NumberObjectImp::MaxValue DontEnum
- MIN_VALUE NumberObjectImp::MinValue DontEnum
- at end
-*/
-NumberObjectImp::NumberObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- NumberPrototypeImp *numberProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- // Number.Prototype
- put(exec,"prototype", Value(numberProto),DontEnum|DontDelete|ReadOnly);
-
- // no. of arguments for constructor
- put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
-}
-
-Value NumberObjectImp::get(ExecState *exec, const UString &propertyName) const
-{
- return lookupGetValue<NumberObjectImp, InternalFunctionImp>( exec, propertyName, &numberTable, this );
-}
-
-Value NumberObjectImp::getValueProperty(ExecState *, int token) const
-{
- // ECMA 15.7.3
- switch(token) {
- case NaNValue:
- return Number(NaN);
- case NegInfinity:
- return Number(-Inf);
- case PosInfinity:
- return Number(Inf);
- case MaxValue:
- return Number(1.7976931348623157E+308);
- case MinValue:
- return Number(5E-324);
- }
- return Null();
-}
-
-bool NumberObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-
-// ECMA 15.7.1
-Object NumberObjectImp::construct(ExecState *exec, const List &args)
-{
- Object proto = exec->interpreter()->builtinNumberPrototype();
- Object obj(new NumberInstanceImp(proto));
-
- Number n;
- if (args.isEmpty())
- n = Number(0);
- else
- n = args[0].toNumber(exec);
-
- obj.setInternalValue(n);
-
- return obj;
-}
-
-bool NumberObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.7.2
-Value NumberObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- if (args.isEmpty())
- return Number(0);
- else
- return Number(args[0].toNumber(exec));
-}
diff --git a/WebCore/src/kdelibs/kjs/number_object.h b/WebCore/src/kdelibs/kjs/number_object.h
deleted file mode 100644
index b094541..0000000
--- a/WebCore/src/kdelibs/kjs/number_object.h
+++ /dev/null
@@ -1,100 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _NUMBER_OBJECT_H_
-#define _NUMBER_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class NumberInstanceImp : public ObjectImp {
- public:
- NumberInstanceImp(const Object &proto);
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- /**
- * @internal
- *
- * The initial value of Number.prototype (and thus all objects created
- * with the Number constructor
- */
- class NumberPrototypeImp : public NumberInstanceImp {
- public:
- NumberPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto,
- FunctionPrototypeImp *funcProto);
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * Number.prototype object
- */
- class NumberProtoFuncImp : public InternalFunctionImp {
- public:
- NumberProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { ToString, ToLocaleString, ValueOf };
- private:
- int id;
- };
-
- /**
- * @internal
- *
- * The initial value of the the global variable's "Number" property
- */
- class NumberObjectImp : public InternalFunctionImp {
- public:
- NumberObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- NumberPrototypeImp *numberProto);
-
- 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);
-
- Value get(ExecState *exec, const UString &p) const;
- Value getValueProperty(ExecState *exec, int token) const;
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- enum { NaNValue, NegInfinity, PosInfinity, MaxValue, MinValue };
-
- Completion execute(const List &);
- Object construct(const List &);
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/object.cpp b/WebCore/src/kdelibs/kjs/object.cpp
deleted file mode 100644
index 28c43d3..0000000
--- a/WebCore/src/kdelibs/kjs/object.cpp
+++ /dev/null
@@ -1,674 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "lookup.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "internal.h"
-#include "collector.h"
-#include "operations.h"
-#include "error_object.h"
-#include "nodes.h"
-#include "property_map.h"
-
-using namespace KJS;
-
-// ------------------------------ Object ---------------------------------------
-
-Object::Object() : Value()
-{
-}
-
-Object::Object(ObjectImp *v) : Value(v)
-{
-}
-
-Object::Object(const Object &v) : Value(v)
-{
-}
-
-Object::~Object()
-{
-}
-
-Object& Object::operator=(const Object &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-const ClassInfo *Object::classInfo() const
-{
- return static_cast<ObjectImp*>(rep)->classInfo();
-}
-
-bool Object::inherits(const ClassInfo *cinfo) const
-{
- return static_cast<ObjectImp*>(rep)->inherits(cinfo);
-}
-
-Object Object::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != ObjectType)
- return Object(0);
-
- return Object(static_cast<ObjectImp*>(v.imp()));
-}
-
-Value Object::prototype() const
-{
- return Value(static_cast<ObjectImp*>(rep)->prototype());
-}
-
-UString Object::className() const
-{
- return static_cast<ObjectImp*>(rep)->className();
-}
-
-Value Object::get(ExecState *exec, const UString &propertyName) const
-{
- return static_cast<ObjectImp*>(rep)->get(exec,propertyName);
-}
-
-void Object::put(ExecState *exec, const UString &propertyName, const Value &value, int attr)
-{
- static_cast<ObjectImp*>(rep)->put(exec,propertyName,value,attr);
-}
-
-bool Object::canPut(ExecState *exec, const UString &propertyName) const
-{
- return static_cast<ObjectImp*>(rep)->canPut(exec,propertyName);
-}
-
-bool Object::hasProperty(ExecState *exec, const UString &propertyName, bool recursive) const
-{
- return static_cast<ObjectImp*>(rep)->hasProperty(exec,propertyName,recursive);
-}
-
-bool Object::deleteProperty(ExecState *exec, const UString &propertyName)
-{
- return static_cast<ObjectImp*>(rep)->deleteProperty(exec,propertyName);
-}
-
-Value Object::defaultValue(ExecState *exec, Type hint) const
-{
- return static_cast<ObjectImp*>(rep)->defaultValue(exec,hint);
-}
-
-bool Object::implementsConstruct() const
-{
- return static_cast<ObjectImp*>(rep)->implementsConstruct();
-}
-
-Object Object::construct(ExecState *exec, const List &args)
-{
- return static_cast<ObjectImp*>(rep)->construct(exec,args);
-}
-
-bool Object::implementsCall() const
-{
- return static_cast<ObjectImp*>(rep)->implementsCall();
-}
-
-Value Object::call(ExecState *exec, Object &thisObj, const List &args)
-{
- return static_cast<ObjectImp*>(rep)->call(exec,thisObj,args);
-}
-
-bool Object::implementsHasInstance() const
-{
- return static_cast<ObjectImp*>(rep)->implementsHasInstance();
-}
-
-Boolean Object::hasInstance(ExecState *exec, const Value &value)
-{
- return static_cast<ObjectImp*>(rep)->hasInstance(exec,value);
-}
-
-const List Object::scope() const
-{
- return static_cast<ObjectImp*>(rep)->scope();
-}
-
-void Object::setScope(const List &s)
-{
- static_cast<ObjectImp*>(rep)->setScope(s);
-}
-
-List Object::propList(ExecState *exec, bool recursive)
-{
- return static_cast<ObjectImp*>(rep)->propList(exec,recursive);
-}
-
-Value Object::internalValue() const
-{
- return static_cast<ObjectImp*>(rep)->internalValue();
-}
-
-void Object::setInternalValue(const Value &v)
-{
- static_cast<ObjectImp*>(rep)->setInternalValue(v);
-}
-
-// ------------------------------ ObjectImp ------------------------------------
-
-ObjectImp::ObjectImp(const Object &proto)
- : _prop(0), _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(0)
-{
- //fprintf(stderr,"ObjectImp::ObjectImp %p %s\n",(void*)this);
- _scope = ListImp::empty();
- _prop = new PropertyMap();
-}
-
-ObjectImp::ObjectImp()
-{
- //fprintf(stderr,"ObjectImp::ObjectImp %p %s\n",(void*)this);
- _prop = 0;
- _proto = NullImp::staticNull;
- _internalValue = 0L;
- _scope = ListImp::empty();
- _prop = new PropertyMap();
-}
-
-ObjectImp::~ObjectImp()
-{
- //fprintf(stderr,"ObjectImp::~ObjectImp %p\n",(void*)this);
- if (_proto)
- _proto->setGcAllowed();
- if (_internalValue)
- _internalValue->setGcAllowed();
- if (_scope)
- _scope->setGcAllowed();
- delete _prop;
-}
-
-void ObjectImp::mark()
-{
- //fprintf(stderr,"ObjectImp::mark() %p\n",(void*)this);
- ValueImp::mark();
-
- if (_proto && !_proto->marked())
- _proto->mark();
-
- PropertyMapNode *node = _prop->first();
- while (node) {
- if (!node->value->marked())
- node->value->mark();
- node = node->next();
- }
-
- if (_internalValue && !_internalValue->marked())
- _internalValue->mark();
- if (_scope && !_scope->marked())
- _scope->mark();
-}
-
-const ClassInfo *ObjectImp::classInfo() const
-{
- return 0;
-}
-
-bool ObjectImp::inherits(const ClassInfo *info) const
-{
- if (!info)
- return false;
-
- const ClassInfo *ci = classInfo();
- if (!ci)
- return false;
-
- while (ci && ci != info)
- ci = ci->parentClass;
-
- return (ci == info);
-}
-
-Type ObjectImp::type() const
-{
- return ObjectType;
-}
-
-Value ObjectImp::prototype() const
-{
- return Value(_proto);
-}
-
-void ObjectImp::setPrototype(const Value &proto)
-{
- _proto = proto.imp();
-}
-
-UString ObjectImp::className() const
-{
- const ClassInfo *ci = classInfo();
- if ( ci )
- return ci->className;
- return "Object";
-}
-
-Value ObjectImp::get(ExecState *exec, const UString &propertyName) const
-{
- if (propertyName == "__proto__") {
- Object proto = Object::dynamicCast(prototype());
- // non-standard netscape extension
- if (proto.isNull())
- return Null();
- else
- return proto;
- }
-
- ValueImp *imp = getDirect(propertyName);
- if ( imp )
- return Value(imp);
-
- Object proto = Object::dynamicCast(prototype());
- if (proto.isNull())
- return Undefined();
-
- return proto.get(exec,propertyName);
-}
-
-// This get method only looks at the property map.
-// A bit like hasProperty(recursive=false), this doesn't go to the prototype.
-// This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
-// to look up in the prototype, it might already exist there)
-ValueImp* ObjectImp::getDirect(const UString& propertyName) const
-{
- return _prop->get(propertyName);
-}
-
-// ECMA 8.6.2.2
-void ObjectImp::put(ExecState *exec, const UString &propertyName,
- const Value &value, int attr)
-{
- assert(!value.isNull());
- assert(value.type() != ReferenceType);
- assert(value.type() != CompletionType);
- assert(value.type() != ListType);
-
- /* TODO: check for write permissions directly w/o this call */
- /* Doesn't look very easy with the PropertyMap API - David */
- // putValue() is used for JS assignemnts. It passes no attribute.
- // Assume that a C++ implementation knows what it is doing
- // and let it override the canPut() check.
- if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName)) {
-#ifdef KJS_VERBOSE
- fprintf( stderr, "WARNING: canPut %s said NO\n", propertyName.ascii() );
-#endif
- return;
- }
-
- if (propertyName == "__proto__") {
- // non-standard netscape extension
- setPrototype(value);
- return;
- }
-
- _prop->put(propertyName,value.imp(),attr);
-}
-
-// ECMA 8.6.2.3
-bool ObjectImp::canPut(ExecState *, const UString &propertyName) const
-{
- PropertyMapNode *node = _prop->getNode(propertyName);
- if (node)
- return!(node->attr & ReadOnly);
-
- // Look in the static hashtable of properties
- const HashEntry* e = findPropertyHashEntry(propertyName);
- if (e)
- return !(e->attr & ReadOnly);
-
- // Don't look in the prototype here. We can always put an override
- // in the object, even if the prototype has a ReadOnly property.
- return true;
-}
-
-// ECMA 8.6.2.4
-bool ObjectImp::hasProperty(ExecState *exec, const UString &propertyName, bool recursive) const
-{
- if (propertyName == "__proto__")
- return true;
- if (_prop->get(propertyName))
- return true;
-
- // Look in the static hashtable of properties
- if (findPropertyHashEntry(propertyName))
- return true;
-
- // Look in the prototype
- Object proto = Object::dynamicCast(prototype());
- if (proto.isNull() || !recursive)
- return false;
-
- return proto.hasProperty(exec,propertyName);
-}
-
-// ECMA 8.6.2.5
-bool ObjectImp::deleteProperty(ExecState */*exec*/, const UString &propertyName)
-{
- PropertyMapNode *node = _prop->getNode(propertyName);
- if (node) {
- if ((node->attr & DontDelete))
- return false;
- _prop->remove(propertyName);
- return true;
- }
-
- // Look in the static hashtable of properties
- if (findPropertyHashEntry(propertyName))
- return false; // No builtin property can be deleted
- return true;
-}
-
-void ObjectImp::deleteAllProperties( ExecState * )
-{
- _prop->clear();
-}
-
-// ECMA 8.6.2.6
-Value ObjectImp::defaultValue(ExecState *exec, Type hint) const
-{
- if (hint != StringType && hint != NumberType) {
- /* Prefer String for Date objects */
- if (_proto == exec->interpreter()->builtinDatePrototype().imp())
- hint = StringType;
- else
- hint = NumberType;
- }
-
- Value v;
- if (hint == StringType)
- v = get(exec,"toString");
- else
- v = get(exec,"valueOf");
-
- if (v.type() == ObjectType) {
- Object o = Object(static_cast<ObjectImp*>(v.imp()));
- if (o.implementsCall()) { // spec says "not primitive type" but ...
- Object thisObj = Object(const_cast<ObjectImp*>(this));
- Value def = o.call(exec,thisObj,List::empty());
- Type defType = def.type();
- if (defType == UnspecifiedType || defType == UndefinedType ||
- defType == NullType || defType == BooleanType ||
- defType == StringType || defType == NumberType) {
- return def;
- }
- }
- }
-
- if (hint == StringType)
- v = get(exec,"valueOf");
- else
- v = get(exec,"toString");
-
- if (v.type() == ObjectType) {
- Object o = Object(static_cast<ObjectImp*>(v.imp()));
- if (o.implementsCall()) { // spec says "not primitive type" but ...
- Object thisObj = Object(const_cast<ObjectImp*>(this));
- Value def = o.call(exec,thisObj,List::empty());
- Type defType = def.type();
- if (defType == UnspecifiedType || defType == UndefinedType ||
- defType == NullType || defType == BooleanType ||
- defType == StringType || defType == NumberType) {
- return def;
- }
- }
- }
-
- Object err = Error::create(exec, TypeError, I18N_NOOP("No default value"));
- exec->setException(err);
- return err;
-}
-
-const HashEntry* ObjectImp::findPropertyHashEntry( const UString& propertyName ) const
-{
- const ClassInfo *info = classInfo();
- while (info) {
- if (info->propHashTable) {
- const HashEntry *e = Lookup::findEntry(info->propHashTable, propertyName);
- if (e)
- return e;
- }
- info = info->parentClass;
- }
- return 0L;
-}
-
-bool ObjectImp::implementsConstruct() const
-{
- return false;
-}
-
-Object ObjectImp::construct(ExecState */*exec*/, const List &/*args*/)
-{
- assert(false);
- return Object(0);
-}
-
-bool ObjectImp::implementsCall() const
-{
- return false;
-}
-
-Value ObjectImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)
-{
- assert(false);
- return Object(0);
-}
-
-bool ObjectImp::implementsHasInstance() const
-{
- return false;
-}
-
-Boolean ObjectImp::hasInstance(ExecState */*exec*/, const Value &/*value*/)
-{
- assert(false);
- return Boolean(false);
-}
-
-const List ObjectImp::scope() const
-{
- return _scope;
-}
-
-void ObjectImp::setScope(const List &s)
-{
- if (_scope) _scope->setGcAllowed();
- _scope = static_cast<ListImp*>(s.imp());
-}
-
-List ObjectImp::propList(ExecState *exec, bool recursive)
-{
- List list;
- if (_proto && _proto->type() == ObjectType && recursive)
- list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive);
-
-
- PropertyMapNode *node = _prop->first();
- while (node) {
- if (!(node->attr & DontEnum))
- list.append(Reference(Object(this), node->name));
- node = node->next();
- }
-
- // Add properties from the static hashtable of properties
- const ClassInfo *info = classInfo();
- while (info) {
- if (info->propHashTable) {
- int size = info->propHashTable->size;
- const HashEntry *e = info->propHashTable->entries;
- for (int i = 0; i < size; ++i, ++e) {
- if ( e->s && !(e->attr & DontEnum) )
- list.append(Reference(Object(this), e->s)); /// ######### check for duplicates with the propertymap
- }
- }
- info = info->parentClass;
- }
-
- return list;
-}
-
-Value ObjectImp::internalValue() const
-{
- return Value(_internalValue);
-}
-
-void ObjectImp::setInternalValue(const Value &v)
-{
- _internalValue = v.imp();
-}
-
-// The following functions simply call the corresponding functions in ValueImp
-// but are overridden in case of future needs
-
-Value ObjectImp::toPrimitive(ExecState *exec, Type preferredType) const
-{
- return defaultValue(exec,preferredType);
-}
-
-bool ObjectImp::toBoolean(ExecState */*exec*/) const
-{
- return true;
-}
-
-double ObjectImp::toNumber(ExecState *exec) const
-{
- Value prim = toPrimitive(exec,NumberType);
- if (exec->hadException()) // should be picked up soon in nodes.cpp
- return 0.0;
- return prim.toNumber(exec);
-}
-
-int ObjectImp::toInteger(ExecState *exec) const
-{
- return ValueImp::toInteger(exec);
-}
-
-int ObjectImp::toInt32(ExecState *exec) const
-{
- return ValueImp::toInt32(exec);
-}
-
-unsigned int ObjectImp::toUInt32(ExecState *exec) const
-{
- return ValueImp::toUInt32(exec);
-}
-
-unsigned short ObjectImp::toUInt16(ExecState *exec) const
-{
- return ValueImp::toUInt16(exec);
-}
-
-UString ObjectImp::toString(ExecState *exec) const
-{
- Value prim = toPrimitive(exec,StringType);
- if (exec->hadException()) // should be picked up soon in nodes.cpp
- return "";
- return prim.toString(exec);
-}
-
-Object ObjectImp::toObject(ExecState */*exec*/) const
-{
- return Object(const_cast<ObjectImp*>(this));
-}
-
-
-// ------------------------------ Error ----------------------------------------
-
-const char * const errorNamesArr[] = {
- I18N_NOOP("Error"), // GeneralError
- I18N_NOOP("Evaluation error"), // EvalError
- I18N_NOOP("Range error"), // RangeError
- I18N_NOOP("Reference error"), // ReferenceError
- I18N_NOOP("Syntax error"), // SyntaxError
- I18N_NOOP("Type error"), // TypeError
- I18N_NOOP("URI error"), // URIError
-};
-
-const char * const * const Error::errorNames = errorNamesArr;
-
-Object Error::create(ExecState *exec, ErrorType errtype, const char *message,
- int lineno, int sourceId)
-{
- Object cons;
-
- switch (errtype) {
- case EvalError:
- cons = exec->interpreter()->builtinEvalError();
- break;
- case RangeError:
- cons = exec->interpreter()->builtinRangeError();
- break;
- case ReferenceError:
- cons = exec->interpreter()->builtinReferenceError();
- break;
- case SyntaxError:
- cons = exec->interpreter()->builtinSyntaxError();
- break;
- case TypeError:
- cons = exec->interpreter()->builtinTypeError();
- break;
- case URIError:
- cons = exec->interpreter()->builtinURIError();
- break;
- default:
- cons = exec->interpreter()->builtinError();
- break;
- }
-
- if (!message)
- message = errorNames[errtype];
- List args;
- args.append(String(message));
- Object err = Object::dynamicCast(cons.construct(exec,args));
-
- if (lineno != -1)
- err.put(exec, "line", Number(lineno));
- if (sourceId != -1)
- err.put(exec, "sourceId", Number(sourceId));
-
- return err;
-
-/*
-#ifndef NDEBUG
- const char *msg = err.get("message").toString().value().ascii();
- if (l >= 0)
- fprintf(stderr, "KJS: %s at line %d. %s\n", estr, l, msg);
- else
- fprintf(stderr, "KJS: %s. %s\n", estr, msg);
-#endif
-
- return err;
-*/
-}
-
diff --git a/WebCore/src/kdelibs/kjs/object.h b/WebCore/src/kdelibs/kjs/object.h
deleted file mode 100644
index e96df7c..0000000
--- a/WebCore/src/kdelibs/kjs/object.h
+++ /dev/null
@@ -1,614 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-
-#ifndef _KJS_OBJECT_H_
-#define _KJS_OBJECT_H_
-
-// Objects
-
-#include "value.h"
-#include "types.h"
-
-namespace KJS {
-
- class ObjectImpPrivate;
- class PropertyMap;
- class HashTable;
- class HashEntry;
- class ListImp;
-
- // ECMA 262-3 8.6.1
- // Attributes (only applicable to the Object type)
- enum Attribute { None = 0,
- ReadOnly = 1 << 1, // property can be only read, not written
- DontEnum = 1 << 2, // property doesn't appear in (for .. in ..)
- DontDelete = 1 << 3, // property can't be deleted
- Internal = 1 << 4, // an internal property, set to by pass checks
- Function = 1 << 5 }; // property is a function - only used by static hashtables
-
- /**
- * Class Information
- */
- struct ClassInfo {
- /**
- * A string denoting the class name. Example: "Window".
- */
- const char* className;
- /**
- * Pointer to the class information of the base class.
- * 0L if there is none.
- */
- const ClassInfo *parentClass;
- /**
- * Static hash-table of properties.
- */
- const HashTable *propHashTable;
- /**
- * Reserved for future extension.
- */
- void *dummy;
- };
-
- /**
- * Represents an Object. This is a wrapper for ObjectImp
- */
- class Object : public Value {
- public:
- Object();
- explicit Object(ObjectImp *v);
- Object(const Object &v);
- virtual ~Object();
-
- Object& operator=(const Object &v);
-
- virtual const ClassInfo *classInfo() const;
- bool inherits(const ClassInfo *cinfo) const;
-
- /**
- * Converts a Value into an Object. If the value's type is not ObjectType,
- * a null object will be returned (i.e. one with it's internal pointer set
- * to 0). If you do not know for sure whether the value is of type
- * ObjectType, you should check the @ref isNull() methods afterwards before
- * calling any methods on the Object.
- *
- * @return The value converted to an object
- */
- static Object dynamicCast(const Value &v);
-
- /**
- * Returns the prototype of this object. Note that this is not the same as
- * the "prototype" property.
- *
- * See ECMA 8.6.2
- *
- * @return The object's prototype
- */
- Value prototype() const;
-
- /**
- * Returns the class name of the object
- *
- * See ECMA 8.6.2
- *
- * @return The object's class name
- */
- UString className() const;
-
- /**
- * Retrieves the specified property from the object. If neither the object
- * or any other object in it's prototype chain have the property, this
- * function will return Undefined.
- *
- * See ECMA 8.6.2.1
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to retrieve
- *
- * @return The specified property, or Undefined
- */
- Value get(ExecState *exec, const UString &propertyName) const;
-
- /**
- * Sets the specified property.
- *
- * See ECMA 8.6.2.2
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to set
- * @param propertyValue The value to set
- */
- void put(ExecState *exec, const UString &propertyName,
- const Value &value, int attr = None);
-
- /**
- * Used to check whether or not a particular property is allowed to be set
- * on an object
- *
- * See ECMA 8.6.2.3
- *
- * @param exec The current execution state
- * @param propertyName The name of the property
- * @return true if the property can be set, otherwise false
- */
- bool canPut(ExecState *exec, const UString &propertyName) const;
-
- /**
- * Checks to see whether the object (or any object in it's prototype chain)
- * has a property with the specified name.
- *
- * See ECMA 8.6.2.4
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to check for
- * @return true if the object has the property, otherwise false
- */
- bool hasProperty(ExecState *exec, const UString &propertyName,
- bool recursive = true) const;
-
- /**
- * Removes the specified property from the object.
- *
- * See ECMA 8.6.2.5
- *
- * @param exec The current execution state
- * @param propertyName The name of the property to delete
- * @return true if the property was successfully deleted or did not
- * exist on the object. false if deleting the specified property is not
- * allowed.
- */
- bool deleteProperty(ExecState *exec, const UString &propertyName);
-
- /**
- * Converts the object into a primitive value. The value return may differ
- * depending on the supplied hint
- *
- * See ECMA 8.6.2.6
- *
- * @param exec The current execution state
- * @param hint The desired primitive type to convert to
- * @return A primitive value converted from the objetc. Note that the
- * type of primitive value returned may not be the same as the requested
- * hint.
- */
- Value defaultValue(ExecState *exec, Type hint) const;
-
- /**
- * Whether or not the object implements the construct() method. If this
- * returns false you should not call the construct() method on this
- * object (typically, an assertion will fail to indicate this).
- *
- * @return true if this object implements the construct() method, otherwise
- * false
- */
- bool implementsConstruct() const;
-
- /**
- * Creates a new object based on this object. Typically this means the
- * following:
- * 1. A new object is created
- * 2. The prototype of the new object is set to the value of this object's
- * "prototype" property
- * 3. The call() method of this object is called, with the new object
- * passed as the this value
- * 4. The new object is returned
- *
- * In some cases, Host objects may differ from these semantics, although
- * this is discouraged.
- *
- * If an error occurs during construction, the execution state's exception
- * will be set. This can be tested for with @ref ExecState::hadException().
- * Under some circumstances, the exception object may also be returned.
- *
- * Note: This function should not be called if implementsConstruct() returns
- * false, in which case it will result in an assertion failure.
- *
- * @param exec The current execution state
- * @param args The arguments to be passed to call() once the new object has
- * been created
- * @return The newly created & initialized object
- */
- Object construct(ExecState *exec, const List &args);
-
- /**
- * Whether or not the object implements the call() method. If this returns
- * false you should not call the call() method on this object (typically,
- * an assertion will fail to indicate this).
- *
- * @return true if this object implements the call() method, otherwise
- * false
- */
- bool implementsCall() const;
-
-
- /**
- * Calls this object as if it is a function.
- *
- * Note: This function should not be called if implementsCall() returns
- * false, in which case it will result in an assertion failure.
- *
- * See ECMA 8.6.2.3
- *
- * @param exec The current execution state
- * @param thisObj The obj to be used as "this" within function execution.
- * Note that in most cases this will be different from the C++ "this"
- * object. For example, if the ECMAScript code "window.location.toString()"
- * is executed, call() will be invoked on the C++ object which implements
- * the toString method, with the thisObj being window.location
- * @param args List of arguments to be passed to the function
- * @return The return value from the function
- */
- Value call(ExecState *exec, Object &thisObj, const List &args);
-
- /**
- * Whether or not the object implements the hasInstance() method. If this
- * returns false you should not call the hasInstance() method on this
- * object (typically, an assertion will fail to indicate this).
- *
- * @return true if this object implements the hasInstance() method,
- * otherwise false
- */
- bool implementsHasInstance() const;
-
- /**
- * Checks whether value delegates behaviour to this object. Used by the
- * instanceof operator.
- *
- * @param exec The current execution state
- * @param value The value to check
- * @return true if value delegates behaviour to this object, otherwise
- * false
- */
- Boolean hasInstance(ExecState *exec, const Value &value);
-
- /**
- * Returns the scope of this object. This is used when execution declared
- * functions - the execution context for the function is initialized with
- * extra object in it's scope. An example of this is functions declared
- * inside other functions:
- *
- * function f() {
- *
- * function b() {
- * return prototype;
- * }
- *
- * var x = 4;
- * // do some stuff
- * }
- * f.prototype = new String();
- *
- * When the function f.b is executed, its scope will include properties of
- * f. So in the example above the return value of f.b() would be the new
- * String object that was assigned to f.prototype.
- *
- * @param exec The current execution state
- * @return The function's scope
- */
- const List scope() const;
- void setScope(const List &s);
-
- /**
- * Returns a List of References to all the properties of the object. Used
- * in "for x in y" statements. The list is created new, so it can be freely
- * modified without affecting the object's properties. It should be deleted
- * by the caller.
- *
- * Subclasses can override this method in ObjectImpl to provide the
- * appearance of
- * having extra properties other than those set specifically with put().
- *
- * @param exec The current execution state
- * @param recursive Whether or not properties in the object's prototype
- * chain should be
- * included in the list.
- * @return A List of References to properties of the object.
- **/
- List propList(ExecState *exec, bool recursive = true);
-
- /**
- * Returns the internal value of the object. This is used for objects such
- * as String and Boolean which are wrappers for native types. The interal
- * value is the actual value represented by the wrapper objects.
- *
- * @see ECMA 8.6.2
- * @return The internal value of the object
- */
- Value internalValue() const;
-
- /**
- * Sets the internal value of the object
- *
- * @see internalValue()
- *
- * @param v The new internal value
- */
- void setInternalValue(const Value &v);
- };
-
- class ObjectImp : public ValueImp {
- public:
- /**
- * Creates a new ObjectImp with the specified prototype
- *
- * @param proto The prototype
- */
- ObjectImp(const Object &proto);
-
- /**
- * Creates a new ObjectImp with a prototype of Null()
- * (that is, the ECMAScript "null" value, not a null Object).
- *
- */
- ObjectImp();
-
- virtual ~ObjectImp();
-
- virtual void mark();
-
- Type type() const;
-
- /**
- * A pointer to a ClassInfo struct for this class. This provides a basic
- * facility for run-time type information, and can be used to check an
- * object's class an inheritance (see @ref inherits()). This should
- * always return a statically declared pointer, or 0 to indicate that
- * there is no class information.
- *
- * This is primarily useful if you have application-defined classes that you
- * wish to check against for casting purposes.
- *
- * For example, to specify the class info for classes FooImp and BarImp,
- * where FooImp inherits from BarImp, you would add the following in your
- * class declarations:
- *
- * class BarImp : public ObjectImp {
- * virtual const ClassInfo *classInfo() const { return &info; }
- * static const ClassInfo info;
- * // ...
- * };
- *
- * class FooImp : public ObjectImp {
- * virtual const ClassInfo *classInfo() const { return &info; }
- * static const ClassInfo info;
- * // ...
- * };
- *
- * And in your source file:
- *
- * const ClassInfo BarImp::info = {0, 0, 0}; // no parent class
- * const ClassInfo FooImp::info = {&BarImp::info, 0, 0};
- *
- * @see inherits()
- */
- virtual const ClassInfo *classInfo() const;
-
- /**
- * Checks whether this object inherits from the class with the specified
- * classInfo() pointer. This requires that both this class and the other
- * class return a non-NULL pointer for their classInfo() methods (otherwise
- * it will return false).
- *
- * For example, for two ObjectImp pointers obj1 and obj2, you can check
- * if obj1's class inherits from obj2's class using the following:
- *
- * if (obj1->inherits(obj2->classInfo())) {
- * // ...
- * }
- *
- * If you have a handle to a statically declared ClassInfo, such as in the
- * @ref classInfo() example, you can check for inheritance without needing
- * an instance of the other class:
- *
- * if (obj1->inherits(FooImp::info)) {
- * // ...
- * }
- *
- * @param cinfo The ClassInfo pointer for the class you want to check
- * inheritance against.
- * @return true if this object's class inherits from class with the
- * ClassInfo pointer specified in cinfo
- */
- bool inherits(const ClassInfo *cinfo) const;
-
- // internal properties (ECMA 262-3 8.6.2)
-
- /**
- * Implementation of the [[Prototype]] internal property (implemented by
- * all Objects)
- *
- * @see Object::prototype()
- */
- Value prototype() const;
- void setPrototype(const Value &proto);
-
- /**
- * Implementation of the [[Class]] internal property (implemented by all
- * Objects)
- *
- * The default implementation uses classInfo().
- * You should either implement @ref classInfo(), or
- * if you simply need a classname, you can reimplement @ref className()
- * instead.
- *
- * @see Object::className()
- */
- virtual UString className() const;
-
- /**
- * Implementation of the [[Get]] internal property (implemented by all
- * Objects)
- *
- * @see Object::get()
- */
- // [[Get]] - must be implemented by all Objects
- virtual Value get(ExecState *exec, const UString &propertyName) const;
-
- /**
- * Implementation of the [[Put]] internal property (implemented by all
- * Objects)
- *
- * @see Object::put()
- */
- virtual void put(ExecState *exec, const UString &propertyName,
- const Value &value, int attr = None);
-
- /**
- * Implementation of the [[CanPut]] internal property (implemented by all
- * Objects)
- *
- * @see Object::canPut()
- */
- virtual bool canPut(ExecState *exec, const UString &propertyName) const;
-
- /**
- * Implementation of the [[HasProperty]] internal property (implemented by
- * all Objects)
- *
- * @see Object::hasProperty()
- */
- virtual bool hasProperty(ExecState *exec, const UString &propertyName,
- bool recursive = true) const;
-
- /**
- * Implementation of the [[Delete]] internal property (implemented by all
- * Objects)
- *
- * @see Object::deleteProperty()
- */
- virtual bool deleteProperty(ExecState *exec,
- const UString &propertyName);
-
- /**
- * Remove all properties from this object.
- * This doesn't take DontDelete into account, and isn't in the ECMA spec.
- * It's simply a quick way to remove everything before destroying.
- */
- void deleteAllProperties( ExecState * );
-
- /**
- * Implementation of the [[DefaultValue]] internal property (implemented by
- * all Objects)
- *
- * @see Object::defaultValue()
- */
- virtual Value defaultValue(ExecState *exec, Type hint) const;
-
- virtual bool implementsConstruct() const;
- /**
- * Implementation of the [[Construct]] internal property
- *
- * @see Object::construct()
- */
- virtual Object construct(ExecState *exec, const List &args);
-
- virtual bool implementsCall() const;
- /**
- * Implementation of the [[Call]] internal property
- *
- * @see Object::call()
- */
- virtual Value call(ExecState *exec, Object &thisObj,
- const List &args);
-
- virtual bool implementsHasInstance() const;
- /**
- * Implementation of the [[HasInstance]] internal property
- *
- * @see Object::hasInstance()
- */
- virtual Boolean hasInstance(ExecState *exec, const Value &value);
-
- /**
- * Implementation of the [[Scope]] internal property
- *
- * @see Object::scope()
- */
- const List scope() const;
- void setScope(const List &s);
-
- List propList(ExecState *exec, bool recursive = true);
-
- Value internalValue() const;
- void setInternalValue(const Value &v);
-
- Value toPrimitive(ExecState *exec,
- Type preferredType = UnspecifiedType) const;
- bool toBoolean(ExecState *exec) const;
- double toNumber(ExecState *exec) const;
- int toInteger(ExecState *exec) const;
- int toInt32(ExecState *exec) const;
- unsigned int toUInt32(ExecState *exec) const;
- unsigned short toUInt16(ExecState *exec) const;
- UString toString(ExecState *exec) const;
- Object toObject(ExecState *exec) const;
-
- ValueImp* getDirect(const UString& propertyName) const;
- private:
- const HashEntry* findPropertyHashEntry( const UString& propertyName ) const;
- ObjectImpPrivate *_od;
- PropertyMap *_prop;
- ValueImp *_proto;
- ValueImp *_internalValue;
- ListImp *_scope;
- };
-
- /**
- * Types of Native Errors available. For custom errors, GeneralError
- * should be used.
- */
- enum ErrorType { GeneralError = 0,
- EvalError = 1,
- RangeError = 2,
- ReferenceError = 3,
- SyntaxError = 4,
- TypeError = 5,
- URIError = 6};
-
- /**
- * @short Factory methods for error objects.
- */
- class Error {
- public:
- /**
- * Factory method for error objects.
- *
- * @param exec The current execution state
- * @param errtype Type of error.
- * @param message Optional error message.
- * @param lineno Optional line number.
- * @param lineno Optional source id.
- */
- static Object create(ExecState *exec, ErrorType errtype = GeneralError,
- const char *message = 0, int lineno = -1,
- int sourceId = -1);
-
- /**
- * Array of error names corresponding to @ref ErrorType
- */
- static const char * const * const errorNames;
- };
-
-}; // namespace
-
-#endif // _KJS_OBJECT_H_
diff --git a/WebCore/src/kdelibs/kjs/object_object.cpp b/WebCore/src/kdelibs/kjs/object_object.cpp
deleted file mode 100644
index 9d19cb3..0000000
--- a/WebCore/src/kdelibs/kjs/object_object.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "object_object.h"
-#include "function_object.h"
-#include <stdio.h>
-#include <assert.h>
-
-using namespace KJS;
-
-// ------------------------------ ObjectPrototypeImp --------------------------------
-
-ObjectPrototypeImp::ObjectPrototypeImp(ExecState *exec,
- FunctionPrototypeImp *funcProto)
- : ObjectImp() // [[Prototype]] is Null()
-{
- Value protect(this);
- put(exec,"toString", Object(new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString, 0)), DontEnum);
- put(exec,"valueOf", Object(new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ValueOf, 0)), DontEnum);
-}
-
-
-// ------------------------------ ObjectProtoFuncImp --------------------------------
-
-ObjectProtoFuncImp::ObjectProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- int i, int len)
- : InternalFunctionImp(funcProto), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-
-bool ObjectProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.2.4.2 + 15.2.4.3
-
-Value ObjectProtoFuncImp::call(ExecState */*exec*/, Object &thisObj, const List &/*args*/)
-{
- if (id == ValueOf)
- return thisObj;
- else /* ToString */
- return String("[object "+thisObj.className()+"]");
-}
-
-// ------------------------------ ObjectObjectImp --------------------------------
-
-ObjectObjectImp::ObjectObjectImp(ExecState *exec,
- ObjectPrototypeImp *objProto,
- FunctionPrototypeImp *funcProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- // ECMA 15.2.3.1
- put(exec,"prototype", Object(objProto), DontEnum|DontDelete|ReadOnly);
-
- // no. of arguments for constructor
- put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
-}
-
-
-bool ObjectObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.2.2
-Object ObjectObjectImp::construct(ExecState *exec, const List &args)
-{
- // if no arguments have been passed ...
- if (args.isEmpty()) {
- Object proto = exec->interpreter()->builtinObjectPrototype();
- Object result(new ObjectImp(proto));
- return result;
- }
-
- Value arg = *(args.begin());
- Object obj = Object::dynamicCast(arg);
- if (!obj.isNull()) {
- return obj;
- }
-
- switch (arg.type()) {
- case StringType:
- case BooleanType:
- case NumberType:
- return arg.toObject(exec);
- default:
- assert(!"unhandled switch case in ObjectConstructor");
- case NullType:
- case UndefinedType:
- Object proto = exec->interpreter()->builtinObjectPrototype();
- return Object(new ObjectImp(proto));
- }
-}
-
-bool ObjectObjectImp::implementsCall() const
-{
- return true;
-}
-
-Value ObjectObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- Value result;
-
- List argList;
- // Construct a new Object
- if (args.isEmpty()) {
- result = construct(exec,argList);
- } else {
- Value arg = args[0];
- if (arg.type() == NullType || arg.type() == UndefinedType) {
- argList.append(arg);
- result = construct(exec,argList);
- } else
- result = arg.toObject(exec);
- }
- return result;
-}
-
diff --git a/WebCore/src/kdelibs/kjs/object_object.h b/WebCore/src/kdelibs/kjs/object_object.h
deleted file mode 100644
index 3e8938e..0000000
--- a/WebCore/src/kdelibs/kjs/object_object.h
+++ /dev/null
@@ -1,82 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _OBJECT_OBJECT_H_
-#define _OBJECT_OBJECT_H_
-
-#include "internal.h"
-
-namespace KJS {
-
- class FunctionPrototypeImp;
-
- /**
- * @internal
- *
- * The initial value of Object.prototype (and thus all objects created
- * with the Object constructor
- */
- class ObjectPrototypeImp : public ObjectImp {
- public:
- ObjectPrototypeImp(ExecState *exec, FunctionPrototypeImp *funcProto);
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * Object.prototype object
- */
- class ObjectProtoFuncImp : public InternalFunctionImp {
- public:
- ObjectProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto,
- int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { ToString, ValueOf };
- private:
- int id;
- };
-
- /**
- * @internal
- *
- * The initial value of the the global variable's "Object" property
- */
- class ObjectObjectImp : public InternalFunctionImp {
- public:
-
- ObjectObjectImp(ExecState *exec,
- ObjectPrototypeImp *objProto,
- FunctionPrototypeImp *funcProto);
-
- 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
diff --git a/WebCore/src/kdelibs/kjs/operations.cpp b/WebCore/src/kdelibs/kjs/operations.cpp
deleted file mode 100644
index f47e2b9..0000000
--- a/WebCore/src/kdelibs/kjs/operations.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#ifndef HAVE_FLOAT_H /* just for !Windows */
-#define HAVE_FLOAT_H 0
-#define HAVE_FUNC__FINITE 0
-#endif
-
-#include <stdio.h>
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-
-#ifndef HAVE_FUNC_ISINF
-#ifdef HAVE_IEEEFP_H
-#include <ieeefp.h>
-#endif
-#endif /* HAVE_FUNC_ISINF */
-
-#if HAVE_FLOAT_H
-#include <float.h>
-#endif
-
-#include "operations.h"
-#include "object.h"
-
-using namespace KJS;
-
-bool KJS::isNaN(double d)
-{
-#ifdef HAVE_FUNC_ISNAN
- return isnan(d);
-#elif defined HAVE_FLOAT_H
- return _isnan(d) != 0;
-#else
- return !(d == d);
-#endif
-}
-
-bool KJS::isInf(double d)
-{
-#if defined(HAVE_FUNC_ISINF)
- return isinf(d);
-#elif HAVE_FUNC_FINITE
- return finite(d) == 0 && d == d;
-#elif HAVE_FUNC__FINITE
- return _finite(d) == 0 && d == d;
-#else
- return false;
-#endif
-}
-
-bool KJS::isPosInf(double d)
-{
-#if defined(HAVE_FUNC_ISINF)
- return (isinf(d) == 1);
-#elif HAVE_FUNC_FINITE
- return finite(d) == 0 && d == d; // ### can we distinguish between + and - ?
-#elif HAVE_FUNC__FINITE
- return _finite(d) == 0 && d == d; // ###
-#else
- return false;
-#endif
-}
-
-bool KJS::isNegInf(double d)
-{
-#if defined(HAVE_FUNC_ISINF)
- return (isinf(d) == -1);
-#elif HAVE_FUNC_FINITE
- return finite(d) == 0 && d == d; // ###
-#elif HAVE_FUNC__FINITE
- return _finite(d) == 0 && d == d; // ###
-#else
- return false;
-#endif
-}
-
-// ECMA 11.9.3
-bool KJS::equal(ExecState *exec, const Value& v1, const Value& v2)
-{
- Type t1 = v1.type();
- Type t2 = v2.type();
-
- if (t1 == t2) {
- if (t1 == UndefinedType || t1 == NullType)
- return true;
- if (t1 == NumberType)
- {
- double d1 = v1.toNumber(exec);
- double d2 = v2.toNumber(exec);
- if ( isNaN( d1 ) || isNaN( d2 ) )
- return false;
- return ( d1 == d2 ); /* TODO: +0, -0 ? */
- }
- if (t1 == StringType)
- return (v1.toString(exec) == v2.toString(exec));
- if (t1 == BooleanType)
- return (v1.toBoolean(exec) == v2.toBoolean(exec));
-
- // types are Object
- return (v1.imp() == v2.imp());
- }
-
- // different types
- if ((t1 == NullType && t2 == UndefinedType) || (t1 == UndefinedType && t2 == NullType))
- return true;
- if (t1 == NumberType && t2 == StringType) {
- Number n2 = v2.toNumber(exec);
- return equal(exec,v1, n2);
- }
- if ((t1 == StringType && t2 == NumberType) || t1 == BooleanType) {
- Number n1 = v1.toNumber(exec);
- return equal(exec,n1, v2);
- }
- if (t2 == BooleanType) {
- Number n2 = v2.toNumber(exec);
- return equal(exec,v1, n2);
- }
- if ((t1 == StringType || t1 == NumberType) && t2 >= ObjectType) {
- Value p2 = v2.toPrimitive(exec);
- return equal(exec,v1, p2);
- }
- if (t1 >= ObjectType && (t2 == StringType || t2 == NumberType)) {
- Value p1 = v1.toPrimitive(exec);
- return equal(exec,p1, v2);
- }
-
- return false;
-}
-
-bool KJS::strictEqual(ExecState *exec, const Value &v1, const Value &v2)
-{
- Type t1 = v1.type();
- Type t2 = v2.type();
-
- if (t1 != t2)
- return false;
- if (t1 == UndefinedType || t1 == NullType)
- return true;
- if (t1 == NumberType) {
- double n1 = v1.toNumber(exec);
- double n2 = v2.toNumber(exec);
- if (isNaN(n1) || isNaN(n2))
- return false;
- if (n1 == n2)
- return true;
- /* TODO: +0 and -0 */
- return false;
- } else if (t1 == StringType) {
- return v1.toString(exec) == v2.toString(exec);
- } else if (t2 == BooleanType) {
- return v1.toBoolean(exec) == v2.toBoolean(exec);
- }
- if (v1.imp() == v2.imp())
- return true;
- /* TODO: joined objects */
-
- return false;
-}
-
-int KJS::relation(ExecState *exec, const Value& v1, const Value& v2)
-{
- Value p1 = v1.toPrimitive(exec,NumberType);
- Value p2 = v2.toPrimitive(exec,NumberType);
-
- if (p1.type() == StringType && p2.type() == StringType)
- return p1.toString(exec) < p2.toString(exec) ? 1 : 0;
-
- double n1 = p1.toNumber(exec);
- double n2 = p2.toNumber(exec);
- if ( isNaN( n1 ) || isNaN( n2 ) )
- return -1; // means undefined
- if (n1 == n2)
- return 0;
- /* TODO: +0, -0 */
- if ( isPosInf( n1 ) )
- return 0;
- if ( isPosInf( n2 ) )
- return 1;
- if ( isNegInf( n2 ) )
- return 0;
- if ( isNegInf( n1 ) )
- return 1;
- return (n1 < n2) ? 1 : 0;
-}
-
-int KJS::maxInt(int d1, int d2)
-{
- return (d1 > d2) ? d1 : d2;
-}
-
-int KJS::minInt(int d1, int d2)
-{
- return (d1 < d2) ? d1 : d2;
-}
-
-// ECMA 11.6
-Value KJS::add(ExecState *exec, const Value &v1, const Value &v2, char oper)
-{
- Value p1 = v1.toPrimitive(exec);
- Value p2 = v2.toPrimitive(exec);
-
- if ((p1.type() == StringType || p2.type() == StringType) && oper == '+') {
- UString s1 = p1.toString(exec);
- UString s2 = p2.toString(exec);
-
- return String(s1 + s2);
- }
-
- double n1 = p1.toNumber(exec);
- double n2 = p2.toNumber(exec);
-
- if (oper == '+')
- return Number(n1 + n2);
- else
- return Number(n1 - n2);
-}
-
-// ECMA 11.5
-Value KJS::mult(ExecState *exec, const Value &v1, const Value &v2, char oper)
-{
- Number n1 = v1.toNumber(exec);
- Number n2 = v2.toNumber(exec);
-
- double result;
-
- if (oper == '*')
- result = n1.value() * n2.value();
- else if (oper == '/')
- result = n1.value() / n2.value();
- else
- result = fmod(n1.value(), n2.value());
-
- return Number(result);
-}
diff --git a/WebCore/src/kdelibs/kjs/operations.h b/WebCore/src/kdelibs/kjs/operations.h
deleted file mode 100644
index da2d1b5..0000000
--- a/WebCore/src/kdelibs/kjs/operations.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _KJS_OPERATIONS_H_
-#define _KJS_OPERATIONS_H_
-
-#include "value.h"
-
-namespace KJS {
-
- class ExecState;
-
- /**
- * @return True if d is not a number (platform support required).
- */
- bool isNaN(double d);
- /**
- * @return True if d is infinite (platform support required).
- */
- bool isInf(double d);
- bool isPosInf(double d);
- bool isNegInf(double d);
- bool equal(ExecState *exec, const Value& v1, const Value& v2);
- bool strictEqual(ExecState *exec, const Value &v1, const Value &v2);
- /**
- * This operator performs an abstract relational comparision of the two
- * arguments that can be of arbitrary type. If possible, conversions to the
- * string or number type will take place before the comparison.
- *
- * @return 1 if v1 is "less-than" v2, 0 if the relation is "greater-than-or-
- * equal". -1 if the result is undefined.
- */
- int relation(ExecState *exec, const Value& v1, const Value& v2);
- int maxInt(int d1, int d2);
- int minInt(int d1, int d2);
- /**
- * Additive operator. Either performs an addition or substraction of v1
- * and v2.
- * @param oper '+' or '-' for an addition or substraction, respectively.
- * @return The result of the operation.
- */
- Value add(ExecState *exec, const Value &v1, const Value &v2, char oper);
- /**
- * Multiplicative operator. Either multiplies/divides v1 and v2 or
- * calculates the remainder from an division.
- * @param oper '*', '/' or '%' for a multiplication, division or
- * modulo operation.
- * @return The result of the operation.
- */
- Value mult(ExecState *exec, const Value &v1, const Value &v2, char oper);
-
-};
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/property_map.cpp b/WebCore/src/kdelibs/kjs/property_map.cpp
deleted file mode 100644
index 978a367..0000000
--- a/WebCore/src/kdelibs/kjs/property_map.cpp
+++ /dev/null
@@ -1,550 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-
-#include "property_map.h"
-
-#include <string.h>
-#include <assert.h>
-#include <stdio.h>
-
-using namespace KJS;
-
-// ------------------------------ PropertyMapNode ------------------------------
-
-void PropertyMapNode::setLeft(PropertyMapNode *newLeft)
-{
- if (left)
- left->setParent(0);
- left = newLeft;
- if (left)
- left->setParent(this);
-}
-
-void PropertyMapNode::setRight(PropertyMapNode *newRight)
-{
- if (right)
- right->setParent(0);
- right = newRight;
- if (right)
- right->setParent(this);
-}
-
-void PropertyMapNode::setParent(PropertyMapNode *newParent)
-{
- if (parent) {
- //assert(this == parent->left || this == parent->right);
- if (this == parent->left)
- parent->left = 0;
- else
- parent->right = 0;
- }
- parent = newParent;
-}
-
-PropertyMapNode *PropertyMapNode::findMax()
-{
- PropertyMapNode *max = this;
- while (max->right)
- max = max->right;
- return max;
-}
-
-PropertyMapNode *PropertyMapNode::findMin()
-{
- PropertyMapNode *min = this;
- while (min->left)
- min = min->left;
- return min;
-}
-
-PropertyMapNode *PropertyMapNode::next()
-{
- // find the next node, going from lowest name to highest name
-
- // We have a right node. Starting from our right node, keep going left as far as we can
- if (right) {
- PropertyMapNode *n = right;
- while (n->left)
- n = n->left;
- return n;
- }
-
- // We have no right node. Keep going up to the left, until we find a node that has a parent
- // to the right. If we find one, go to it. Otherwise, we have reached the end.
- PropertyMapNode *n = this;
- while (n->parent && n->parent->right == n) {
- // parent is to our left
- n = n->parent;
- }
- if (n->parent && n->parent->left == n) {
- // parent is to our right
- return n->parent;
- }
-
- return 0;
-}
-
-// ------------------------------ PropertyMap ----------------------------------
-
-int KJS::uscompare(const UString &s1, const UString &s2)
-{
- int len1 = s1.size();
- int len2 = s2.size();
- if (len1 < len2)
- return -1;
- else if (len1 > len2)
- return 1;
- else
- return memcmp(s1.data(), s2.data(), len1*sizeof(UChar));
-}
-
-PropertyMap::PropertyMap()
-{
- root = 0;
-}
-
-PropertyMap::~PropertyMap()
-{
-}
-
-void PropertyMap::put(const UString &name, ValueImp *value, int attr)
-{
- // if not root; make the root the new node
- if (!root) {
- root = new PropertyMapNode(name, value, attr, 0);
- return;
- }
-
- // try to find the parent node
- PropertyMapNode *parent = root;
- int isLeft = false;
- while (true) {
- int cmp = uscompare(name, parent->name);
- if (cmp < 0) {
- // traverse to left node (if any)
- isLeft = true;
- if (!parent->left)
- break;
- else
- parent = parent->left;
- }
- else if (cmp > 0) {
- // traverse to right node (if any)
- isLeft = false;
- if (!parent->right)
- break;
- else
- parent = parent->right;
- }
- else {
- // a node with this name already exists; just replace the value
- parent->value = value;
- return;
- }
- }
-
- // we found the parent
- //assert(parent);
-
- if (isLeft) {
- //assert(!parent->left);
- parent->left = new PropertyMapNode(name, value, attr, parent);
- }
- else {
- //assert(!parent->right);
- parent->right = new PropertyMapNode(name, value, attr, parent);
- }
- updateHeight(parent);
-
-
- PropertyMapNode *node = parent;
- while (node) {
- PropertyMapNode *p = node->parent;
- balance(node); // may change node
- node = p;
- }
-}
-
-void PropertyMap::remove(const UString &name)
-{
- PropertyMapNode *node = getNode(name);
- if (!node) // name not in tree
- return;
-
- PropertyMapNode *removed = remove(node);
- if (removed)
- delete node;
-}
-
-ValueImp *PropertyMap::get(const UString &name) const
-{
- const PropertyMapNode *n = getNode(name);
- return n ? n->value : 0;
-}
-
-void PropertyMap::clear(PropertyMapNode *node)
-{
- if (node == 0)
- node = root;
- if (node == 0) // nothing to do
- return;
-
- if (node->left)
- clear(node->left);
- if (node->right)
- clear(node->right);
- if (node == root)
- root = 0;
- delete node;
-}
-
-void PropertyMap::dump(const PropertyMapNode *node, int indent) const
-{
- if (!node && indent > 0)
- return;
- if (!node)
- node = root;
- if (!node)
- return;
-
- assert(!node->right || node->right->parent == node);
- dump(node->right, indent+1);
- for (int i = 0; i < indent; i++) {
- printf(" ");
- }
- printf("[%d] %s\n", node->height, node->name.ascii());
- assert(!node->left || node->left->parent == node);
- dump(node->left, indent+1);
-}
-
-void PropertyMap::checkTree(const PropertyMapNode *node) const
-{
- if (!root)
- return;
- if (node == 0)
- node = root;
- if (node == root) {
- assert(!node->parent);
- }
- assert(!node->right || node->right->parent == node);
- assert(!node->left || node->left->parent == node);
- assert(node->left != node);
- assert(node->right != node);
- if (node->left && node->right)
- assert(node->left != node->right);
-
- PropertyMapNode *n = node->parent;
- while (n) {
- assert(n != node);
- n = n->parent;
- }
-
- if (node->right)
- checkTree(node->right);
- if (node->left)
- checkTree(node->left);
-}
-
-PropertyMapNode *PropertyMap::getNode(const UString &name) const
-{
- PropertyMapNode *node = root;
-
- while (true) {
- if (!node)
- return 0;
-
- int cmp = uscompare(name, node->name);
- if (cmp < 0)
- node = node->left;
- else if (cmp > 0)
- node = node->right;
- else
- return node;
- }
-}
-
-PropertyMapNode *PropertyMap::first() const
-{
- if (!root)
- return 0;
-
- PropertyMapNode *node = root;
- while (node->left)
- node = node->left;
- return node;
-}
-
-PropertyMapNode * PropertyMap::remove(PropertyMapNode *node)
-{
- PropertyMapNode *parent = node->parent;
- //assert(!parent || (node == parent->left || node == parent->right));
- bool isLeft = (parent && node == parent->left);
-
- PropertyMapNode *replace = 0;
- if (node->left && node->right) {
- PropertyMapNode *maxLeft = node->left->findMax();
- if (maxLeft == node->left) {
- maxLeft->setRight(node->right);
- replace = maxLeft;
- }
- else {
- remove(maxLeft);
-
- maxLeft->setLeft(node->left);
- maxLeft->setRight(node->right);
- replace = maxLeft;
- }
- // removing maxLeft could have re-balanced the tree, so recalculate
- // parent again
- parent = node->parent;
- //assert(!parent || (node == parent->left || node == parent->right));
- isLeft = (parent && node == parent->left);
- }
- else if (node->left) {
- replace = node->left;
- }
- else if (node->right) {
- replace = node->right;
- }
- else {
- replace = 0;
- }
-
- if (parent) {
- if (isLeft)
- parent->setLeft(replace);
- else
- parent->setRight(replace);
- }
- else {
- root = replace;
- if (replace)
- replace->parent = 0;
- }
-
- if (replace)
- updateHeight(replace); // will also update parent's height
- else if (parent)
- updateHeight(parent);
- else if (root)
- updateHeight(root);
-
-
- // balance the tree
- PropertyMapNode *bal = parent;
- while (bal) {
- PropertyMapNode *p = bal->parent;
- balance(bal); // may change bal
- bal = p;
- }
-
- return node;
-}
-
-void PropertyMap::balance(PropertyMapNode* node)
-{
- int lheight = node->left ? node->left->height : 0;
- int rheight = node->right ? node->right->height : 0;
-
- int bal = rheight-lheight;
-
- if (bal < -1) {
- //assert(node->left);
- int llheight = node->left->left ? node->left->left->height : 0;
- int lrheight = node->left->right ? node->left->right->height : 0;
- int lbal = lrheight - llheight;
-
- if (lbal < 0) {
- rotateLL(node); // LL rotation
- }
- else {
- // lbal >= 0
- rotateLR(node);
- }
- }
- else if (bal > 1) {
- int rlheight = node->right->left ? node->right->left->height : 0;
- int rrheight = node->right->right ? node->right->right->height : 0;
- int rbal = rrheight - rlheight;
- if (rbal < 0) {
- rotateRL(node);
- }
- else {
- // rbal >= 0
- rotateRR(node); // RR rotateion
- }
- }
-}
-
-void PropertyMap::updateHeight(PropertyMapNode* &node)
-{
- int lheight = node->left ? node->left->height : 0;
- int rheight = node->right ? node->right->height : 0;
- if (lheight > rheight)
- node->height = lheight+1;
- else
- node->height = rheight+1;
- //assert(node->parent != node);
- if (node->parent)
- updateHeight(node->parent);
-}
-
-void PropertyMap::rotateRR(PropertyMapNode* &node)
-{
- /*
- Perform a RR ("single left") rotation, e.g.
-
- a b
- / \ / \
- X b --> a Z
- / \ / \
- Y Z X Y
- */
-
- // Here, node is initially a, will be replaced with b
-
- PropertyMapNode *a = node;
- PropertyMapNode *b = node->right;
-
- PropertyMapNode *parent = a->parent;
- //assert(!parent || (a == parent->left || a == parent->right));
- bool isLeft = (parent && a == parent->left);
-
- // do the rotation
- a->setRight(b->left);
- b->setLeft(a);
-
- // now node is b
- node = b;
- if (parent) {
- if (isLeft)
- parent->setLeft(b);
- else
- parent->setRight(b);
- }
- else {
- // a was the root node
- root = b;
- }
-
- updateHeight(a);
- updateHeight(b);
-}
-
-
-void PropertyMap::rotateLL(PropertyMapNode* &node)
-{
- /*
- Perform a LL ("single right") rotation, e.g.
-
-
- a b
- / \ / \
- b Z --> X a
- / \ / \
- X Y Y Z
- */
-
- // Here, node is initially a, will be replaced with b
-
- PropertyMapNode *a = node;
- PropertyMapNode *b = node->left;
-
- PropertyMapNode *parent = a->parent;
- //assert(!parent || (a == parent->left || a == parent->right));
- bool isLeft = (parent && a == parent->left);
-
- // do the rotation
- a->setLeft(b->right);
- b->setRight(a);
-
- // now node is b
- node = b;
- if (parent) {
- if (isLeft)
- parent->setLeft(b);
- else
- parent->setRight(b);
- }
- else {
- // a was the root node
- root = b;
- }
-
- updateHeight(a);
- updateHeight(b);
-}
-
-void PropertyMap::rotateRL(PropertyMapNode* &node)
-{
- /*
- Perform a RL ("double left") rotation, e.g.
-
- a a b
- / \ LL on c / \ RR on b / \
- W c --> W b --> a c
- / \ / \ / \ / \
- b Z X c W X Y Z
- / \ / \
- X Y Y Z
-
- */
-
- PropertyMapNode *a = node;
- PropertyMapNode *c = node->right;
- PropertyMapNode *b = node->right->left;
-
- rotateLL(c);
- rotateRR(b);
-
- updateHeight(a);
- updateHeight(c);
- updateHeight(b);
-}
-
-void PropertyMap::rotateLR(PropertyMapNode* &node)
-{
- /*
- Perform a LR ("double right") rotation, e.g.
-
- a a b
- / \ RR on c / \ LL on a / \
- c Z --> b Z --> c a
- / \ / \ / \ / \
- W b c Y W X Y Z
- / \ / \
- X Y W X
- */
-
- PropertyMapNode *a = node;
- PropertyMapNode *c = node->left;
- PropertyMapNode *b = node->left->right;
-
- rotateRR(c);
- rotateLL(a);
-
- updateHeight(c);
- updateHeight(a);
- updateHeight(b);
-}
diff --git a/WebCore/src/kdelibs/kjs/property_map.h b/WebCore/src/kdelibs/kjs/property_map.h
deleted file mode 100644
index 32a4a5b..0000000
--- a/WebCore/src/kdelibs/kjs/property_map.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-
-#ifndef _KJS_PROPERTY_MAP_H_
-#define _KJS_PROPERTY_MAP_H_
-
-#include "ustring.h"
-#include "value.h"
-
-namespace KJS {
-
- class PropertyMapNode {
- public:
- PropertyMapNode(const UString &n, ValueImp *v, int att, PropertyMapNode *p)
- : name(n), value(v), attr(att), left(0), right(0), parent(p), height(1) {}
-
- UString name;
- ValueImp *value;
- int attr;
-
- void setLeft(PropertyMapNode *newLeft);
- void setRight(PropertyMapNode *newRight);
- PropertyMapNode *findMax();
- PropertyMapNode *findMin();
-
- PropertyMapNode *next();
-
- PropertyMapNode *left;
- PropertyMapNode *right;
- PropertyMapNode *parent;
- int height;
-
- private:
- void setParent(PropertyMapNode *newParent);
- };
-
- /**
- * @internal
- *
- * Provides a name/value map for storing properties based on UString keys. The
- * map is implemented using an AVL tree, which provides O(log2 n) performance
- * for insertion and deletion, and retrieval.
- *
- * For a description of AVL tree operations, see
- * http://www.cis.ksu.edu/~howell/300f99/minavl/rotations.html
- * http://www.cgc.cs.jhu.edu/~jkloss/htmls/structures/avltree.html
- */
- class PropertyMap {
- public:
- PropertyMap();
- ~PropertyMap();
-
- void put(const UString &name, ValueImp *value, int attr);
- void remove(const UString &name);
- ValueImp *get(const UString &name) const;
-
- void clear(PropertyMapNode *node = 0);
- void dump(const PropertyMapNode *node = 0, int indent = 0) const;
- void checkTree(const PropertyMapNode *node = 0) const;
-
- PropertyMapNode *getNode(const UString &name) const;
- PropertyMapNode *first() const;
-
- private:
-
- PropertyMapNode *remove(PropertyMapNode *node);
- void balance(PropertyMapNode* node);
- void updateHeight(PropertyMapNode* &node);
-
- void rotateRR(PropertyMapNode* &node);
- void rotateLL(PropertyMapNode* &node);
- void rotateRL(PropertyMapNode* &node);
- void rotateLR(PropertyMapNode* &node);
-
- PropertyMapNode *root;
- };
-
- int uscompare(const UString &s1, const UString &s2);
-
-}; // namespace
-
-#endif // _KJS_PROPERTY_MAP_H_
diff --git a/WebCore/src/kdelibs/kjs/regexp.cpp b/WebCore/src/kdelibs/kjs/regexp.cpp
deleted file mode 100644
index 123610d..0000000
--- a/WebCore/src/kdelibs/kjs/regexp.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "regexp.h"
-
-using namespace KJS;
-
-RegExp::RegExp(const UString &p, int f)
- : pattern(p), flags(f)
-{
-
-#ifdef HAVE_PCREPOSIX
- int pcreflags = 0;
- const char *perrormsg;
- int errorOffset;
-
- if (flags & IgnoreCase)
- pcreflags |= PCRE_CASELESS;
-
- if (flags & Multiline)
- pcreflags |= PCRE_MULTILINE;
-
- pcregex = pcre_compile(p.ascii(), pcreflags,
- &perrormsg, &errorOffset, NULL);
-
-#ifdef PCRE_INFO_CAPTURECOUNT
- // Get number of subpatterns that will be returned
- int rc = pcre_fullinfo( pcregex, NULL, PCRE_INFO_CAPTURECOUNT, &nrSubPatterns);
- if (rc != 0)
-#endif
- nrSubPatterns = 0; // fallback. We always need the first pair of offsets.
-
-#else /* HAVE_PCREPOSIX */
-
- nrSubPatterns = 0; // not implemented with POSIX regex.
- int regflags = 0;
-#ifdef REG_EXTENDED
- regflags |= REG_EXTENDED;
-#endif
-#ifdef REG_ICASE
- if ( f & IgnoreCase )
- regflags |= REG_ICASE;
-#endif
-
- //NOTE: Multiline is not feasible with POSIX regex.
- //if ( f & Multiline )
- // ;
- // Note: the Global flag is already handled by RegExpProtoFunc::execute
-
- regcomp(&preg, p.ascii(), regflags);
- /* TODO check for errors */
-#endif
-
-}
-
-RegExp::~RegExp()
-{
-#ifdef HAVE_PCREPOSIX
- pcre_free(pcregex);
-
-#else
- /* TODO: is this really okay after an error ? */
- regfree(&preg);
-#endif
-}
-
-UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
-{
-
-#ifdef HAVE_PCREPOSIX
- CString buffer(s.cstring());
- int ovecsize = (nrSubPatterns+1)*3; // see pcre docu
- if (ovector) *ovector = new int[ovecsize];
-
- if (i < 0)
- i = 0;
-
- if (i > s.size() || s.isNull() ||
- pcre_exec(pcregex, NULL, buffer.c_str(), buffer.size(), i,
- 0, ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH) {
-
- if (pos)
- *pos = -1;
- return UString::null;
- }
-
- if (!ovector)
- return UString::null; // don't rely on the return value if you pass ovector==0
- if (pos)
- *pos = (*ovector)[0];
- return s.substr((*ovector)[0], (*ovector)[1] - (*ovector)[0]);
-
-#else
- regmatch_t rmatch[10];
-
- if (i < 0)
- i = 0;
-
- char *str = strdup(s.ascii());
- if (i > s.size() || s.isNull() ||
- regexec(&preg, str + i, 10, rmatch, 0)) {
- if (pos)
- *pos = -1;
- return UString::null;
- }
- free(str);
-
- if (pos)
- *pos = rmatch[0].rm_so + i;
- // TODO copy from rmatch to ovector
- return s.substr(rmatch[0].rm_so + i, rmatch[0].rm_eo - rmatch[0].rm_so);
-#endif
-}
-
-#if 0 // unused
-bool RegExp::test(const UString &s, int)
-{
-#ifdef HAVE_PCREPOSIX
- int ovector[300];
- CString buffer(s.cstring());
-
- if (s.isNull() ||
- pcre_exec(pcregex, NULL, buffer.c_str(), buffer.size(), 0,
- 0, ovector, 300) == PCRE_ERROR_NOMATCH)
- return false;
- else
- return true;
-
-#else
-
- char *str = strdup(s.ascii());
- int r = regexec(&preg, str, 0, 0, 0);
- free(str);
-
- return r == 0;
-#endif
-}
-#endif
diff --git a/WebCore/src/kdelibs/kjs/regexp.h b/WebCore/src/kdelibs/kjs/regexp.h
deleted file mode 100644
index 8a66755..0000000
--- a/WebCore/src/kdelibs/kjs/regexp.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _KJS_REGEXP_H_
-#define _KJS_REGEXP_H_
-
-#include <sys/types.h>
-
-#include "config.h"
-
-#ifdef HAVE_PCREPOSIX
-#include <pcreposix.h>
-#include <pcre.h>
-#else // POSIX regex - not so good...
-extern "C" { // bug with some libc5 distributions
-#include <regex.h>
-}
-#endif //HAVE_PCREPOSIX
-
-#include "ustring.h"
-
-namespace KJS {
-
- class RegExp {
- public:
- enum { None = 0, Global = 1, IgnoreCase = 2, Multiline = 4 };
- RegExp(const UString &p, int f = None);
- ~RegExp();
- UString match(const UString &s, int i = -1, int *pos = 0L, int **ovector = 0L);
- // test is unused. The JS spec says that RegExp.test should use
- // RegExp.exec, so it has to store $1 etc.
- // bool test(const UString &s, int i = -1);
- uint subPatterns() const { return nrSubPatterns; }
- private:
- const UString &pattern;
- int flags;
-
-#ifndef HAVE_PCREPOSIX
- regex_t preg;
-#else
- pcre *pcregex;
-#endif
- uint nrSubPatterns;
-
- RegExp();
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/regexp_object.cpp b/WebCore/src/kdelibs/kjs/regexp_object.cpp
deleted file mode 100644
index 7da0f00..0000000
--- a/WebCore/src/kdelibs/kjs/regexp_object.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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$
- */
-
-#include <stdio.h>
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "internal.h"
-#include "regexp.h"
-#include "regexp_object.h"
-#include "error_object.h"
-
-using namespace KJS;
-
-// ------------------------------ RegExpPrototypeImp ---------------------------
-
-// ECMA 15.9.4
-
-RegExpPrototypeImp::RegExpPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto,
- FunctionPrototypeImp *funcProto)
- : ObjectImp(Object(objProto))
-{
- Value protect(this);
- setInternalValue(String(""));
-
- // The constructor will be added later in RegExpObject's constructor (?)
-
- put(exec, "exec", Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::Exec, 0)), DontEnum);
- put(exec, "test", Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::Test, 0)), DontEnum);
- put(exec, "toString", Object(new RegExpProtoFuncImp(exec,funcProto,RegExpProtoFuncImp::ToString, 0)), DontEnum);
-}
-
-// ------------------------------ RegExpProtoFuncImp ---------------------------
-
-RegExpProtoFuncImp::RegExpProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto, int i, int len)
- : InternalFunctionImp(funcProto), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-bool RegExpProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value RegExpProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)
-{
- if (!thisObj.inherits(&RegExpImp::info)) {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
- RegExpImp *reimp = static_cast<RegExpImp*>(thisObj.imp());
- RegExp *re = reimp->regExp();
- String s;
- UString str;
- switch (id) {
- case Exec: // 15.10.6.2
- case Test:
- {
- s = args[0].toString(exec);
- int length = s.value().size();
- Value lastIndex = thisObj.get(exec,"lastIndex");
- int i = lastIndex.isNull() ? 0 : lastIndex.toInt32(exec);
- bool globalFlag = thisObj.get(exec,"global").toBoolean(exec);
- if (!globalFlag)
- i = 0;
- if (i < 0 || i > length) {
- thisObj.put(exec,"lastIndex", Number(0), DontDelete | DontEnum);
- return Null();
- }
- RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp());
- int **ovector = regExpObj->registerRegexp( re, s.value() );
-
- str = re->match(s.value(), i, 0L, ovector);
-
- if (id == Test)
- return Boolean(!str.isNull());
-
- if (str.isNull()) // no match
- {
- if (globalFlag)
- thisObj.put(exec,"lastIndex",Number(0), DontDelete | DontEnum);
- return Null();
- }
- else // success
- {
- if (globalFlag)
- thisObj.put(exec,"lastIndex",Number( (*ovector)[1] ), DontDelete | DontEnum);
- return regExpObj->arrayOfMatches(exec,str);
- }
- }
- break;
- case ToString:
- s = thisObj.get(exec,"source").toString(exec);
- str = "/";
- str += s.value();
- str += "/";
- // TODO append the flags
- return String(str);
- }
-
- return Undefined();
-}
-
-// ------------------------------ RegExpImp ------------------------------------
-
-const ClassInfo RegExpImp::info = {"RegExp", 0, 0, 0};
-
-RegExpImp::RegExpImp(RegExpPrototypeImp *regexpProto)
- : ObjectImp(Object(regexpProto)), reg(0L)
-{
-}
-
-RegExpImp::~RegExpImp()
-{
- delete reg;
-}
-
-// ------------------------------ RegExpObjectImp ------------------------------
-
-RegExpObjectImp::RegExpObjectImp(ExecState *exec,
- RegExpPrototypeImp *regProto,
- FunctionPrototypeImp *funcProto)
- : InternalFunctionImp(funcProto), lastOvector(0L), lastNrSubPatterns(0)
-{
- Value protect(this);
- // ECMA 15.10.5.1 RegExp.prototype
- put(exec,"prototype", Object(regProto), DontEnum|DontDelete|ReadOnly);
-
- // no. of arguments for constructor
- put(exec,"length", Number(2), ReadOnly|DontDelete|DontEnum);
-}
-
-RegExpObjectImp::~RegExpObjectImp()
-{
- if (lastOvector)
- delete [] lastOvector;
-}
-
-int **RegExpObjectImp::registerRegexp( const RegExp* re, const UString& s )
-{
- lastString = s;
- if (lastOvector)
- delete [] lastOvector;
- lastOvector = 0;
- lastNrSubPatterns = re->subPatterns();
- return &lastOvector;
-}
-
-Value RegExpObjectImp::arrayOfMatches(ExecState *exec, const UString &result) const
-{
- List list;
- // The returned array contains 'result' as first item, followed by the list of matches
- list.append(String(result));
- if ( lastOvector )
- for ( uint i = 1 ; i < lastNrSubPatterns + 1 ; ++i )
- {
- UString substring = lastString.substr( lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i] );
- list.append(String(substring));
- }
- return exec->interpreter()->builtinArray().construct(exec, list);
-}
-
-Value RegExpObjectImp::get(ExecState *, const UString &p) const
-{
- if (p[0] == '$' && lastOvector)
- {
- bool ok;
- unsigned long i = p.substr(1).toULong(&ok);
- if (ok)
- {
- if (i < lastNrSubPatterns + 1)
- {
- UString substring = lastString.substr( lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i] );
- return String(substring);
- }
- return String("");
- }
- }
- return Undefined();
-}
-
-bool RegExpObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.10.4
-Object RegExpObjectImp::construct(ExecState *exec, const List &args)
-{
- String p = args[0].toString(exec);
- String f = args[1].toString(exec);
- UString flags = f.value();
-
- RegExpPrototypeImp *proto = static_cast<RegExpPrototypeImp*>(exec->interpreter()->builtinRegExpPrototype().imp());
- RegExpImp *dat = new RegExpImp(proto);
- Object obj(dat); // protect from GC
-
- bool global = (flags.find("g") >= 0);
- bool ignoreCase = (flags.find("i") >= 0);
- bool multiline = (flags.find("m") >= 0);
- // TODO: throw a syntax error on invalid flags
-
- dat->put(exec, "global", Boolean(global));
- dat->put(exec, "ignoreCase", Boolean(ignoreCase));
- dat->put(exec, "multiline", Boolean(multiline));
-
- dat->put(exec, "source", String(p.value()));
- dat->put(exec, "lastIndex", Number(0), DontDelete | DontEnum);
-
- int reflags = RegExp::None;
- if (global)
- reflags |= RegExp::Global;
- if (ignoreCase)
- reflags |= RegExp::IgnoreCase;
- if (multiline)
- reflags |= RegExp::Multiline;
- dat->setRegExp(new RegExp(p.value(), reflags));
-
- return obj;
-}
-
-bool RegExpObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.10.3
-Value RegExpObjectImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)
-{
- // TODO: implement constructor
- return Undefined();
-}
diff --git a/WebCore/src/kdelibs/kjs/regexp_object.h b/WebCore/src/kdelibs/kjs/regexp_object.h
deleted file mode 100644
index 2528cea..0000000
--- a/WebCore/src/kdelibs/kjs/regexp_object.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _REGEXP_OBJECT_H_
-#define _REGEXP_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-#include "regexp.h"
-
-namespace KJS {
- class ExecState;
- class RegExpPrototypeImp : public ObjectImp {
- public:
- RegExpPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto,
- FunctionPrototypeImp *funcProto);
- };
-
- class RegExpProtoFuncImp : public InternalFunctionImp {
- public:
- RegExpProtoFuncImp(ExecState *exec,
- FunctionPrototypeImp *funcProto, int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { Exec, Test, ToString };
- private:
- int id;
- };
-
- class RegExpImp : public ObjectImp {
- public:
- RegExpImp(RegExpPrototypeImp *regexpProto);
- ~RegExpImp();
- void setRegExp(RegExp *r) { reg = r; }
- RegExp* regExp() const { return reg; }
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- private:
- RegExp *reg;
- };
-
- class RegExpObjectImp : public InternalFunctionImp {
- public:
- RegExpObjectImp(ExecState *exec,
- RegExpPrototypeImp *regProto,
- FunctionPrototypeImp *funcProto);
- virtual ~RegExpObjectImp();
- 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);
-
- Value get(ExecState *exec, const UString &p) const;
- int ** registerRegexp( const RegExp* re, const UString& s );
- Value arrayOfMatches(ExecState *exec, const UString &result) const;
- private:
- UString lastString;
- int *lastOvector;
- uint lastNrSubPatterns;
- };
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/string_object.cpp b/WebCore/src/kdelibs/kjs/string_object.cpp
deleted file mode 100644
index 5f47f0f..0000000
--- a/WebCore/src/kdelibs/kjs/string_object.cpp
+++ /dev/null
@@ -1,540 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-#include "operations.h"
-#include "regexp.h"
-#include "regexp_object.h"
-#include "string_object.h"
-#include "error_object.h"
-#include <stdio.h>
-#include "string_object.lut.h"
-
-using namespace KJS;
-
-// ------------------------------ StringInstanceImp ----------------------------
-
-const ClassInfo StringInstanceImp::info = {"String", 0, 0, 0};
-
-StringInstanceImp::StringInstanceImp(const Object &proto)
- : ObjectImp(proto)
-{
- setInternalValue(String(""));
-}
-
-// ------------------------------ StringPrototypeImp ---------------------------
-const ClassInfo StringPrototypeImp::info = {"String", &StringInstanceImp::info, &stringTable, 0};
-/* Source for string_object.lut.h
- at begin stringTable 26
- toString StringProtoFuncImp::ToString DontEnum|Function 0
- valueOf StringProtoFuncImp::ValueOf DontEnum|Function 0
- charAt StringProtoFuncImp::CharAt DontEnum|Function 1
- charCodeAt StringProtoFuncImp::CharCodeAt DontEnum|Function 1
- concat StringProtoFuncImp::Concat DontEnum|Function 1
- indexOf StringProtoFuncImp::IndexOf DontEnum|Function 2
- lastIndexOf StringProtoFuncImp::LastIndexOf DontEnum|Function 2
- match StringProtoFuncImp::Match DontEnum|Function 1
- replace StringProtoFuncImp::Replace DontEnum|Function 2
- search StringProtoFuncImp::Search DontEnum|Function 1
- slice StringProtoFuncImp::Slice DontEnum|Function 0
- split StringProtoFuncImp::Split DontEnum|Function 1
- substr StringProtoFuncImp::Substr DontEnum|Function 2
- substring StringProtoFuncImp::Substring DontEnum|Function 2
- toLowerCase StringProtoFuncImp::ToLowerCase DontEnum|Function 0
- toUpperCase StringProtoFuncImp::ToUpperCase DontEnum|Function 0
-#
-# Under here: html extension, should only exist if KJS_PURE_ECMA is not defined
-# I guess we need to generate two hashtables in the .lut.h file, and use #ifdef
-# to select the right one... TODO. #####
- big StringProtoFuncImp::Big DontEnum|Function 0
- small StringProtoFuncImp::Small DontEnum|Function 0
- blink StringProtoFuncImp::Blink DontEnum|Function 0
- bold StringProtoFuncImp::Bold DontEnum|Function 0
- fixed StringProtoFuncImp::Fixed DontEnum|Function 0
- italics StringProtoFuncImp::Italics DontEnum|Function 0
- strike StringProtoFuncImp::Strike DontEnum|Function 0
- sub StringProtoFuncImp::Sub DontEnum|Function 0
- sup StringProtoFuncImp::Sup DontEnum|Function 0
- fontcolor StringProtoFuncImp::Fontcolor DontEnum|Function 1
- fontsize StringProtoFuncImp::Fontsize DontEnum|Function 1
- anchor StringProtoFuncImp::Anchor DontEnum|Function 1
- link StringProtoFuncImp::Link DontEnum|Function 1
- at end
-*/
-// ECMA 15.5.4
-StringPrototypeImp::StringPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto)
- : StringInstanceImp(Object(objProto))
-{
- Value protect(this);
- // The constructor will be added later, after StringObjectImp has been built
- put(exec,"length",Number(0),DontDelete|ReadOnly|DontEnum);
-
-}
-
-Value StringPrototypeImp::get(ExecState *exec, const UString &propertyName) const
-{
- return lookupGetFunction<StringProtoFuncImp, StringInstanceImp>( exec, propertyName, &stringTable, this );
-}
-
-// ------------------------------ StringProtoFuncImp ---------------------------
-
-StringProtoFuncImp::StringProtoFuncImp(ExecState *exec, int i, int len)
- : InternalFunctionImp(
- static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
- ), id(i)
-{
- Value protect(this);
- put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
-}
-
-bool StringProtoFuncImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.5.4.2 - 15.5.4.20
-Value StringProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)
-{
- Value result;
-
- // toString and valueOf are no generic function.
- if (id == ToString || id == ValueOf) {
- if (thisObj.isNull() || !thisObj.inherits(&StringInstanceImp::info)) {
- Object err = Error::create(exec,TypeError);
- exec->setException(err);
- return err;
- }
-
- return String(thisObj.internalValue().toString(exec));
- }
-
- int n, m;
- UString u, u2, u3;
- int pos, p0, i;
- double d = 0.0;
-
- UString s = thisObj.toString(exec);
-
- int len = s.size();
- Value a0 = args[0];
- Value a1 = args[1];
-
- switch (id) {
- case ToString:
- case ValueOf:
- // handled above
- break;
- case CharAt:
- pos = a0.toInteger(exec);
- if (pos < 0 || pos >= len)
- u = "";
- else
- u = s.substr(pos, 1);
- result = String(u);
- break;
- case CharCodeAt:
- pos = a0.toInteger(exec);
- if (pos < 0 || pos >= len)
- d = NaN;
- else {
- UChar c = s[pos];
- d = (c.high() << 8) + c.low();
- }
- result = Number(d);
- break;
- case Concat: {
- ListIterator it = args.begin();
- for ( ; it != args.end() ; ++it) {
- s += it->toString(exec);
- }
- result = String(s);
- break;
- }
- case IndexOf:
- u2 = a0.toString(exec);
- if (a1.type() == UndefinedType)
- pos = 0;
- else
- pos = a1.toInteger(exec);
- d = s.find(u2, pos);
- result = Number(d);
- break;
- case LastIndexOf:
- u2 = a0.toString(exec);
- d = a1.toNumber(exec);
- if (a1.type() == UndefinedType || KJS::isNaN(d) || KJS::isPosInf(d))
- pos = len;
- else
- pos = a1.toInteger(exec);
- if (pos < 0)
- pos = 0;
- d = s.rfind(u2, pos);
- result = Number(d);
- break;
- case Match:
- case Search: {
- u = s;
- RegExp* reg = 0;
- if (a0.isA(ObjectType) && a0.toObject(exec).inherits(&RegExpImp::info))
- {
- RegExpImp* imp = static_cast<RegExpImp *>( a0.toObject(exec).imp() );
- reg = imp->regExp();
- }
- else if (a0.isA(StringType))
- {
- reg = new RegExp(a0.toString(exec), RegExp::None);
- }
- else
- {
-#ifndef NDEBUG
- printf("KJS: Match/Search. Argument is not a RegExp nor a String - returning Undefined\n");
-#endif
- result = Undefined();
- break;
- }
- RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp());
- int **ovector = regExpObj->registerRegexp( reg, u );
- UString mstr = reg->match(u, -1, &pos, ovector);
- if (a0.isA(StringType))
- delete reg;
- if (id == Search) {
- result = Number(pos);
- break;
- }
- if (mstr.isNull())
- result = Null();
- else
- result = regExpObj->arrayOfMatches(exec,mstr);
- }
- break;
- case Replace:
- u = s;
- if (a0.type() == ObjectType && a0.toObject(exec).inherits(&RegExpImp::info)) {
- RegExpImp* imp = static_cast<RegExpImp *>( a0.toObject(exec).imp() );
- RegExp *reg = imp->regExp();
- bool global = false;
- Value tmp = imp->get(exec,"global");
- if (tmp.type() != UndefinedType && tmp.toBoolean(exec) == true)
- global = true;
-
- RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp());
- int **ovector = regExpObj->registerRegexp( reg, u );
- int lastIndex = 0;
- u3 = a1.toString(exec); // replacement string
- // This is either a loop (if global is set) or a one-way (if not).
- do {
- UString mstr = reg->match(u, lastIndex, &pos, ovector);
- len = mstr.size();
- lastIndex = pos + u3.size();
- if ( pos != -1 )
- u = u.substr(0, pos) + u3 + u.substr(pos + len);
- //fprintf(stderr,"pos=%d,len=%d,lastIndex=%d,u=%s\n",pos,len,lastIndex,u.ascii());
- } while ( global && pos != -1 );
-
- result = String(u);
- } else { // First arg is a string
- u2 = a0.toString(exec);
- pos = u.find(u2);
- len = u2.size();
- // Do the replacement
- if (pos == -1)
- result = String(s);
- else {
- u3 = u.substr(0, pos) + a1.toString(exec) +
- u.substr(pos + len);
- result = String(u3);
- }
- }
- break;
- case Slice: // http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm#1194366
- {
- // The arg processing is very much like ArrayProtoFunc::Slice
- // We return a new array
- result = exec->interpreter()->builtinArray().construct(exec,List::empty());
- int begin = args[0].toUInt32(exec);
- int end = len;
- if (args[1].type() != UndefinedType)
- {
- end = args[1].toUInt32(exec);
- if ( end < 0 )
- end += len;
- }
- // safety tests
- if ( begin < 0 || end < 0 || begin >= end ) {
- result = String();
- break;
- }
- //printf( "Slicing from %d to %d \n", begin, end );
- result = String(s.substr(begin, end-begin));
- break;
- }
- case Split: {
- Object constructor = exec->interpreter()->builtinArray();
- Object res = Object::dynamicCast(constructor.construct(exec,List::empty()));
- result = res;
- u = s;
- i = p0 = 0;
- d = (a1.type() != UndefinedType) ? a1.toInteger(exec) : -1; // optional max number
- if (a0.type() == ObjectType && Object::dynamicCast(a0).inherits(&RegExpImp::info)) {
- Object obj0 = Object::dynamicCast(a0);
- RegExp reg(obj0.get(exec,"source").toString(exec));
- if (u.isEmpty() && !reg.match(u, 0).isNull()) {
- // empty string matched by regexp -> empty array
- res.put(exec,"length", Number(0));
- break;
- }
- int *ovector;
- int mpos;
- pos = 0;
- while (1) {
- // TODO: back references
- UString mstr = reg.match(u, pos, &mpos, &ovector);
- if (mpos < 0)
- break;
- pos = mpos + (mstr.isEmpty() ? 1 : mstr.size());
- if (mpos != p0 || !mstr.isEmpty()) {
- res.put(exec,UString::from(i), String(u.substr(p0, mpos-p0)));
- p0 = mpos + mstr.size();
- i++;
- }
- }
- delete ovector;
- } else if (a0.type() != UndefinedType) {
- u2 = a0.toString(exec);
- if (u2.isEmpty()) {
- if (u.isEmpty()) {
- // empty separator matches empty string -> empty array
- put(exec,"length", Number(0));
- break;
- } else {
- while (i != d && i < u.size()-1)
- res.put(exec,UString::from(i++), String(u.substr(p0++, 1)));
- }
- } else {
- while (i != d && (pos = u.find(u2, p0)) >= 0) {
- res.put(exec,UString::from(i), String(u.substr(p0, pos-p0)));
- p0 = pos + u2.size();
- i++;
- }
- }
- }
- // add remaining string, if any
- if (i != d)
- res.put(exec,UString::from(i++), String(u.substr(p0)));
- res.put(exec,"length", Number(i));
- }
- break;
- case Substr: {
- n = a0.toInteger(exec);
- m = a1.toInteger(exec);
- int d, d2;
- if (n >= 0)
- d = n;
- else
- d = maxInt(len + n, 0);
- if (a1.type() == UndefinedType)
- d2 = len - d;
- else
- d2 = minInt(maxInt(m, 0), len - d);
- result = String(s.substr(d, d2));
- break;
- }
- case Substring: {
- double start = a0.toNumber(exec);
- double end = a1.toNumber(exec);
- if (KJS::isNaN(start))
- start = 0;
- if (KJS::isNaN(end))
- end = 0;
- if (start < 0)
- start = 0;
- if (end < 0)
- end = 0;
- if (start > len)
- start = len;
- if (end > len)
- end = len;
- if (a1.type() == UndefinedType)
- end = len;
- if (start > end) {
- double temp = end;
- end = start;
- start = temp;
- }
- result = String(s.substr((int)start, (int)end-(int)start));
- }
- break;
- case ToLowerCase:
- u = s;
- for (i = 0; i < len; i++)
- u[i] = u[i].toLower();
- result = String(u);
- break;
- case ToUpperCase:
- u = s;
- for (i = 0; i < len; i++)
- u[i] = u[i].toUpper();
- result = String(u);
- break;
-#ifndef KJS_PURE_ECMA
- case Big:
- result = String("<BIG>" + s + "</BIG>");
- break;
- case Small:
- result = String("<SMALL>" + s + "</SMALL>");
- break;
- case Blink:
- result = String("<BLINK>" + s + "</BLINK>");
- break;
- case Bold:
- result = String("<B>" + s + "</B>");
- break;
- case Fixed:
- result = String("<TT>" + s + "</TT>");
- break;
- case Italics:
- result = String("<I>" + s + "</I>");
- break;
- case Strike:
- result = String("<STRIKE>" + s + "</STRIKE>");
- break;
- case Sub:
- result = String("<SUB>" + s + "</SUB>");
- break;
- case Sup:
- result = String("<SUP>" + s + "</SUP>");
- break;
- case Fontcolor:
- result = String("<FONT COLOR=" + a0.toString(exec) + ">"
- + s + "</FONT>");
- break;
- case Fontsize:
- result = String("<FONT SIZE=" + a0.toString(exec) + ">"
- + s + "</FONT>");
- break;
- case Anchor:
- result = String("<a name=" + a0.toString(exec) + ">"
- + s + "</a>");
- break;
- case Link:
- result = String("<a href=" + a0.toString(exec) + ">"
- + s + "</a>");
- break;
-#endif
- }
-
- return result;
-}
-
-// ------------------------------ StringObjectImp ------------------------------
-
-StringObjectImp::StringObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- StringPrototypeImp *stringProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- // ECMA 15.5.3.1 String.prototype
- put(exec,"prototype", Object(stringProto), DontEnum|DontDelete|ReadOnly);
-
- put(exec,"fromCharCode", Object(new StringObjectFuncImp(exec,funcProto)), DontEnum);
-
- // no. of arguments for constructor
- put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
-}
-
-
-bool StringObjectImp::implementsConstruct() const
-{
- return true;
-}
-
-// ECMA 15.5.2
-Object StringObjectImp::construct(ExecState *exec, const List &args)
-{
- Object proto = exec->interpreter()->builtinStringPrototype();
- Object obj(new StringInstanceImp(proto ));
-
- UString s;
- if (args.size() > 0)
- s = args.begin()->toString(exec);
- else
- s = UString("");
-
- obj.setInternalValue(String(s));
- obj.put(exec, "length", Number(s.size()), ReadOnly|DontEnum|DontDelete);
-
- return obj;
-}
-
-bool StringObjectImp::implementsCall() const
-{
- return true;
-}
-
-// ECMA 15.5.1
-Value StringObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- if (args.isEmpty())
- return String("");
- else {
- Value v = args[0];
- return String(v.toString(exec));
- }
-}
-
-// ------------------------------ StringObjectFuncImp --------------------------
-
-// ECMA 15.5.3.2 fromCharCode()
-StringObjectFuncImp::StringObjectFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto)
- : InternalFunctionImp(funcProto)
-{
- Value protect(this);
- put(exec,"length",Number(1),DontDelete|ReadOnly|DontEnum);
-}
-
-bool StringObjectFuncImp::implementsCall() const
-{
- return true;
-}
-
-Value StringObjectFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- UString s;
- if (args.size()) {
- UChar *buf = new UChar[args.size()];
- UChar *p = buf;
- ListIterator it = args.begin();
- while (it != args.end()) {
- unsigned short u = it->toUInt16(exec);
- *p++ = UChar(u);
- it++;
- }
- s = UString(buf, args.size(), false);
- } else
- s = "";
-
- return String(s);
-}
diff --git a/WebCore/src/kdelibs/kjs/string_object.h b/WebCore/src/kdelibs/kjs/string_object.h
deleted file mode 100644
index 1e60dd5..0000000
--- a/WebCore/src/kdelibs/kjs/string_object.h
+++ /dev/null
@@ -1,112 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * 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 _STRING_OBJECT_H_
-#define _STRING_OBJECT_H_
-
-#include "internal.h"
-#include "function_object.h"
-
-namespace KJS {
-
- class StringInstanceImp : public ObjectImp {
- public:
- StringInstanceImp(const Object &proto);
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- /**
- * @internal
- *
- * The initial value of String.prototype (and thus all objects created
- * with the String constructor
- */
- class StringPrototypeImp : public StringInstanceImp {
- public:
- StringPrototypeImp(ExecState *exec,
- ObjectPrototypeImp *objProto);
- Value get(ExecState *exec, const UString &p) const;
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * String.prototype object
- */
- class StringProtoFuncImp : public InternalFunctionImp {
- public:
- StringProtoFuncImp(ExecState *exec, int i, int len);
-
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-
- enum { ToString, ValueOf, CharAt, CharCodeAt, Concat, IndexOf, LastIndexOf,
- Match, Replace, Search, Slice, Split,
- Substr, Substring, FromCharCode, ToLowerCase, ToUpperCase
-#ifndef KJS_PURE_ECMA
- , Big, Small, Blink, Bold, Fixed, Italics, Strike, Sub, Sup,
- Fontcolor, Fontsize, Anchor, Link
-#endif
- };
- private:
- int id;
- };
-
- /**
- * @internal
- *
- * The initial value of the the global variable's "String" property
- */
- class StringObjectImp : public InternalFunctionImp {
- public:
- StringObjectImp(ExecState *exec,
- FunctionPrototypeImp *funcProto,
- StringPrototypeImp *stringProto);
-
- 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);
- };
-
- /**
- * @internal
- *
- * Class to implement all methods that are properties of the
- * String object
- */
- class StringObjectFuncImp : public InternalFunctionImp {
- public:
- StringObjectFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto);
- virtual bool implementsCall() const;
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
- };
-
-}; // namespace
-
-#endif
-
diff --git a/WebCore/src/kdelibs/kjs/test.js b/WebCore/src/kdelibs/kjs/test.js
deleted file mode 100644
index f5bbf5b..0000000
--- a/WebCore/src/kdelibs/kjs/test.js
+++ /dev/null
@@ -1,29 +0,0 @@
-var i = 0;
-
-function sum(a, b)
-{
- debug("inside test()");
- i = i + 1;
- debug(a);
- debug(b);
- return a + b;
-}
-
-s = sum(10, sum(20, 30));
-debug("s = " + s);
-debug("i = " + i);
-
-var a = new Array(11, 22, 33, 44);
-a.length = 2;
-a[4] = 'apple';
-
-for(i = 0; i != a.length; i++)
- debug("a[" + i + "] = " + a[i]);
-
-var b = new Boolean(1==1);
-b.toString=Object.prototype.toString;
-debug("b = " + b.toString());
-
-// regular expression
-rx = /b*c/;
-debug(rx.exec("abbbcd"));
diff --git a/WebCore/src/kdelibs/kjs/testkjs.cpp b/WebCore/src/kdelibs/kjs/testkjs.cpp
deleted file mode 100644
index b9434e9..0000000
--- a/WebCore/src/kdelibs/kjs/testkjs.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#include <stdio.h>
-#include <iostream.h>
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-
-using namespace KJS;
-
-class TestFunctionImp : public ObjectImp {
-public:
- TestFunctionImp() : ObjectImp() {}
- virtual bool implementsCall() const { return true; }
- virtual Value call(ExecState *exec, Object &thisObj, const List &args);
-};
-
-Value TestFunctionImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
-{
- fprintf(stderr,"--> %s\n",args[0].toString(exec).ascii());
- return Undefined();
-}
-
-class GlobalImp : public ObjectImp {
-public:
- virtual UString className() const { return "global"; }
-};
-
-int main(int argc, char **argv)
-{
- // expecting a filename
- if (argc < 2) {
- fprintf(stderr, "You have to specify at least one filename\n");
- return -1;
- }
-
- bool ret = true;
- {
- Object global(new GlobalImp());
-
- // create interpreter
- Interpreter interp(global);
- global.put(interp.globalExec(),"debug", Object(new TestFunctionImp()));
- // add "print" for compatibility with the mozilla js shell
- global.put(interp.globalExec(),"print", Object(new TestFunctionImp()));
-
- // add debug() function
- // kjs->enableDebug();
-
- const int BufferSize = 200000;
- char code[BufferSize];
-
- for (int i = 1; i < argc; i++) {
- const char *file = argv[i];
- FILE *f = fopen(file, "r");
- if (!f) {
- fprintf(stderr, "Error opening %s.\n", file);
- return -1;
- }
- int num = fread(code, 1, BufferSize, f);
- code[num] = '\0';
- if(num >= BufferSize)
- fprintf(stderr, "Warning: File may have been too long.\n");
-
- // run
- Completion comp(interp.evaluate(code));
-
- fclose(f);
-
- if (comp.complType() == Throw) {
- ExecState *exec = interp.globalExec();
- Value exVal = comp.value();
- char *msg = exVal.toString(exec).ascii();
- int lineno = -1;
- if (exVal.type() == ObjectType) {
- Value lineVal = Object::dynamicCast(exVal).get(exec,"line");
- if (lineVal.type() == NumberType)
- lineno = int(lineVal.toNumber(exec));
- }
- if (lineno != -1)
- fprintf(stderr,"Exception, line %d: %s\n",lineno,msg);
- else
- fprintf(stderr,"Exception: %s\n",msg);
- ret = false;
- }
- else if (comp.complType() == ReturnValue) {
- char *msg = comp.value().toString(interp.globalExec()).ascii();
- fprintf(stderr,"Return value: %s\n",msg);
- }
- }
-
- // delete kjs;
- } // end block, so that Interpreter and global get deleted
-
- if (ret)
- fprintf(stderr, "OK.\n");
-
-#ifdef KJS_DEBUG_MEM
- Interpreter::finalCheck();
-#endif
- return ret;
-}
diff --git a/WebCore/src/kdelibs/kjs/types.cpp b/WebCore/src/kdelibs/kjs/types.cpp
deleted file mode 100644
index 9a9ec79..0000000
--- a/WebCore/src/kdelibs/kjs/types.cpp
+++ /dev/null
@@ -1,324 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-
-#include "internal.h"
-#include "collector.h"
-#include "operations.h"
-#include "error_object.h"
-#include "nodes.h"
-
-using namespace KJS;
-
-// ------------------------------ Reference ------------------------------------
-
-Reference::Reference(const Object& b, const UString& p)
- : Value(new ReferenceImp(b,p))
-{
-}
-
-Reference::Reference(const Null& b, const UString& p)
- : Value(new ReferenceImp(b,p))
-{
-}
-
-Reference::Reference(ReferenceImp *v) : Value(v)
-{
-}
-
-Reference::Reference(const Reference &v) : Value(v)
-{
-}
-
-Reference::~Reference()
-{
-}
-
-Reference& Reference::operator=(const Reference &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-Reference Reference::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != ReferenceType)
- return 0;
-
- return static_cast<ReferenceImp*>(v.imp());
-}
-
-// ------------------------------ ListIterator ---------------------------------
-
-//d dont add ListIterator();
-
-ListIterator::ListIterator(ListNode *n) : node(n)
-{
-}
-
-ListIterator::ListIterator(const List &l)
- : node(static_cast<ListImp*>(l.imp())->hook->next)
-{
-}
-
-ListIterator& ListIterator::operator=(const ListIterator &iterator)
-{
- node=iterator.node;
- return *this;
-}
-
-ListIterator::ListIterator(const ListIterator &i) : node(i.node)
-{
-}
-
-ListIterator::~ListIterator()
-{
-}
-
-ValueImp* ListIterator::operator->() const
-{
- return node->member;
-}
-
- // operator Value* () const { return node->member; }
-Value ListIterator::operator*() const
-{
- return Value(node->member);
-}
-
- // operator Value*() const { return node->member; }
-Value ListIterator::operator++()
-{
- node = node->next;
- return Value(node->member);
-}
-
-Value ListIterator::operator++(int)
-{
- const ListNode *n = node;
- ++*this;
- return Value(n->member);
-}
-
-Value ListIterator::operator--()
-{
- node = node->prev;
- return Value(node->member);
-}
-
-Value ListIterator::operator--(int)
-{
- const ListNode *n = node;
- --*this;
- return Value(n->member);
-}
-
-bool ListIterator::operator==(const ListIterator &it) const
-{
- return (node==it.node);
-}
-
-bool ListIterator::operator!=(const ListIterator &it) const
-{
- return (node!=it.node);
-}
-
-// ------------------------------ List -----------------------------------------
-
-List::List()
- : Value(new ListImp())
-{
- //fprintf(stderr,"List::List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount);
-}
-
-List::List(ListImp *v) : Value(v)
-{
- //fprintf(stderr,"List::List(imp) this=%p imp=%p refcount=%d\n",this,v,v?v->refcount:0);
-}
-
-List::List(const List &v) : Value(v)
-{
- //fprintf(stderr,"List::List(List) this=%p imp=%p refcount=%d\n",this,rep,rep?rep->refcount:0);
-}
-
-List::~List()
-{
- //fprintf(stderr,"List::~List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount-1);
-}
-
-List& List::operator=(const List &v)
-{
- //fprintf(stderr,"List::operator=() this=%p\n",this);
- Value::operator=(v);
- return *this;
-}
-
-List List::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != ListType)
- return 0;
-
- return static_cast<ListImp*>(v.imp());
-}
-
-void List::append(const Value& val)
-{
- static_cast<ListImp*>(rep)->append(val);
-}
-
-void List::prepend(const Value& val)
-{
- static_cast<ListImp*>(rep)->prepend(val);
-}
-
-void List::appendList(const List& lst)
-{
- static_cast<ListImp*>(rep)->appendList(lst);
-}
-
-void List::prependList(const List& lst)
-{
- static_cast<ListImp*>(rep)->prependList(lst);
-}
-
-void List::removeFirst()
-{
- static_cast<ListImp*>(rep)->removeFirst();
-}
-
-void List::removeLast()
-{
- static_cast<ListImp*>(rep)->removeLast();
-}
-
-void List::remove(const Value &val)
-{
- static_cast<ListImp*>(rep)->remove(val);
-}
-
-void List::clear()
-{
- static_cast<ListImp*>(rep)->clear();
-}
-
-List List::copy() const
-{
- return static_cast<ListImp*>(rep)->copy();
-}
-
-ListIterator List::begin() const
-{
- return static_cast<ListImp*>(rep)->begin();
-}
-
-ListIterator List::end() const
-{
- return static_cast<ListImp*>(rep)->end();
-}
-
-bool List::isEmpty() const
-{
- return static_cast<ListImp*>(rep)->isEmpty();
-}
-
-int List::size() const
-{
- return static_cast<ListImp*>(rep)->size();
-}
-
-Value List::at(int i) const
-{
- return static_cast<ListImp*>(rep)->at(i);
-}
-
-Value List::operator[](int i) const
-{
- return static_cast<ListImp*>(rep)->at(i);
-}
-
-const List List::empty()
-{
- return ListImp::empty();
-}
-
-// ------------------------------ Completion -----------------------------------
-
-Completion::Completion(ComplType c, const Value& v, const UString &t)
- : Value(new CompletionImp(c,v,t))
-{
-}
-
-Completion::Completion(CompletionImp *v) : Value(v)
-{
-}
-
-Completion::Completion(const Completion &v) : Value(v)
-{
-}
-
-Completion::~Completion()
-{
-}
-
-Completion& Completion::operator=(const Completion &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-Completion Completion::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != CompletionType)
- return 0;
-
- return static_cast<CompletionImp*>(v.imp());
-}
-
-ComplType Completion::complType() const
-{
- return static_cast<CompletionImp*>(rep)->complType();
-}
-
-Value Completion::value() const
-{
- return static_cast<CompletionImp*>(rep)->value();
-}
-
-UString Completion::target() const
-{
- return static_cast<CompletionImp*>(rep)->target();
-}
-
-bool Completion::isValueCompletion() const
-{
- return !value().isNull();
-}
diff --git a/WebCore/src/kdelibs/kjs/types.h b/WebCore/src/kdelibs/kjs/types.h
deleted file mode 100644
index 3cf6505..0000000
--- a/WebCore/src/kdelibs/kjs/types.h
+++ /dev/null
@@ -1,279 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _KJS_TYPES_H_
-#define _KJS_TYPES_H_
-
-// internal data types
-
-#include "value.h"
-
-namespace KJS {
-
- class Reference : public Value {
- public:
- Reference(const Object& b, const UString& p);
- Reference(const Null& b, const UString& p);
- Reference(ReferenceImp *v);
- Reference(const Reference &v);
- virtual ~Reference();
-
- Reference& operator=(const Reference &v);
-
- /**
- * Converts a Value into an Reference. If the value's type is not
- * ReferenceType, a null object will be returned (i.e. one with it's
- * internal pointer set to 0). If you do not know for sure whether the
- * value is of type ReferenceType, you should check the @ref isNull()
- * methods afterwards before calling any methods on the returned value.
- *
- * @return The value converted to an Reference
- */
- static Reference dynamicCast(const Value &v);
- };
-
- class List;
- class ListIterator;
- class ListNode;
-
- /**
- * @short Iterator for @ref KJS::List objects.
- */
- class ListIterator {
- friend class List;
- friend class ListImp;
- ListIterator();
- ListIterator(ListNode *n);
- public:
- /**
- * Construct an iterator that points to the first element of the list.
- * @param l The list the iterator will operate on.
- */
- ListIterator(const List &l);
- /**
- * Assignment constructor.
- */
- ListIterator& operator=(const ListIterator &iterator);
- /**
- * Copy constructor.
- */
- ListIterator(const ListIterator &i);
- ~ListIterator();
- /**
- * Dereference the iterator.
- * @return A pointer to the element the iterator operates on.
- */
- ValueImp* operator->() const;
- // operator Value* () const { return node->member; }
- Value operator*() const;
- /**
- * Conversion to @ref KJS::Value*
- * @return A pointer to the element the iterator operates on.
- */
- // operator Value*() const { return node->member; }
- /**
- * Postfix increment operator.
- * @return The element after the increment.
- */
- Value operator++();
- /**
- * Prefix increment operator.
- */
- Value operator++(int);
- /**
- * Postfix decrement operator.
- */
- Value operator--();
- /**
- * Prefix decrement operator.
- */
- Value operator--(int);
- /**
- * Compare the iterator with another one.
- * @return True if the two iterators operate on the same list element.
- * False otherwise.
- */
- bool operator==(const ListIterator &it) const;
- /**
- * Check for inequality with another iterator.
- * @return True if the two iterators operate on different list elements.
- */
- bool operator!=(const ListIterator &it) const;
- private:
- ListNode *node;
- };
-
- /**
- * @short Native list type.
- *
- * List is a native ECMAScript type. List values are only used for
- * intermediate results of expression evaluation and cannot be stored
- * as properties of objects.
- *
- * The list is explicitly shared. Note that while copy() returns a deep
- * copy of the list the referenced objects are still shared.
- */
- class List : public Value {
- friend class ListIterator;
- public:
- List();
- List(ListImp *v);
- List(const List &v);
- virtual ~List();
-
- List& operator=(const List &v);
-
- /**
- * Converts a Value into an List. If the value's type is not
- * ListType, a null object will be returned (i.e. one with it's
- * internal pointer set to 0). If you do not know for sure whether the
- * value is of type List, you should check the @ref isNull()
- * methods afterwards before calling any methods on the returned value.
- *
- * @return The value converted to an List
- */
- static List dynamicCast(const Value &v);
- /**
- * Append an object to the end of the list.
- *
- * @param val Pointer to object.
- */
- void append(const Value& val);
- /**
- * Insert an object at the beginning of the list.
- *
- * @param val Pointer to object.
- */
- void prepend(const Value& val);
- /**
- * Appends the items of another list at the end of this one.
- */
- void appendList(const List& lst);
- /**
- * Prepend the items of another list to this one.
- * The first item of @p lst will become the first item of the list.
- */
- void prependList(const List& lst);
- /**
- * Remove the element at the beginning of the list.
- */
- void removeFirst();
- /**
- * Remove the element at the end of the list.
- */
- void removeLast();
- /*
- * Remove val from list.
- */
- void remove(const Value &val);
- /**
- * Remove all elements from the list.
- */
- void clear();
- /**
- * Returns a deep copy of the list. Ownership is passed to the user
- * who is responsible for deleting the list then.
- */
- List copy() const;
- /**
- * @return A @ref KJS::ListIterator pointing to the first element.
- */
- ListIterator begin() const;
- /**
- * @return A @ref KJS::ListIterator pointing to the last element.
- */
- ListIterator end() const;
- /**
- * @return true if the list is empty. false otherwise.
- */
- bool isEmpty() const;
- /**
- * @return the current size of the list.
- */
- int size() const;
- /**
- * Retrieve an element at an indexed position. If you want to iterate
- * trough the whole list using @ref KJS::ListIterator will be faster.
- *
- * @param i List index.
- * @return Return the element at position i. @ref KJS::Undefined if the
- * index is out of range.
- */
- Value at(int i) const;
- /**
- * Equivalent to @ref at.
- */
- Value operator[](int i) const;
- /**
- * Returns a pointer to a static instance of an empty list. Useful if a
- * function has a @ref KJS::List parameter.
- */
- static const List empty();
- };
-
- /**
- * Completion types.
- */
- enum ComplType { Normal, Break, Continue, ReturnValue, Throw };
-
- /**
- * Completion objects are used to convey the return status and value
- * from functions.
- *
- * See @ref FunctionImp::execute()
- *
- * @see FunctionImp
- *
- * @short Handle for a Completion type.
- */
- class Completion : public Value {
- public:
- Completion(ComplType c = Normal, const Value& v = Value(),
- const UString &t = UString::null);
- Completion(CompletionImp *v);
- Completion(const Completion &v);
- virtual ~Completion();
-
- Completion& operator=(const Completion &v);
-
- /**
- * Converts a Value into an Completion. If the value's type is not
- * CompletionType, a null object will be returned (i.e. one with it's
- * internal pointer set to 0). If you do not know for sure whether the
- * value is of type CompletionType, you should check the @ref isNull()
- * methods afterwards before calling any methods on the returned value.
- *
- * @return The value converted to an Completion
- */
- static Completion dynamicCast(const Value &v);
-
- ComplType complType() const;
- Value value() const;
- UString target() const;
- bool isValueCompletion() const;
- };
-
-}; // namespace
-
-#endif // _KJS_TYPES_H_
diff --git a/WebCore/src/kdelibs/kjs/ustring.cpp b/WebCore/src/kdelibs/kjs/ustring.cpp
deleted file mode 100644
index ef294cc..0000000
--- a/WebCore/src/kdelibs/kjs/ustring.cpp
+++ /dev/null
@@ -1,549 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#include "ustring.h"
-#include "operations.h"
-#include <math.h>
-
-namespace KJS {
- extern const double NaN;
- extern const double Inf;
-};
-
-using namespace KJS;
-
-CString::CString(const char *c)
-{
- data = new char[strlen(c)+1];
- strcpy(data, c);
-}
-
-CString::CString(const CString &b)
-{
- data = new char[b.size()+1];
- strcpy(data, b.c_str());
-}
-
-CString::~CString()
-{
- delete [] data;
-}
-
-CString &CString::append(const CString &t)
-{
- char *n;
- if (data) {
- n = new char[strlen(data)+t.size()+1];
- strcpy(n, data);
- } else {
- n = new char[t.size()+1];
- n[0] = '\0';
- }
- strcat(n, t.c_str());
-
- delete [] data;
- data = n;
-
- return *this;
-}
-
-CString &CString::operator=(const char *c)
-{
- if (data)
- delete [] data;
- data = new char[strlen(c)+1];
- strcpy(data, c);
-
- return *this;
-}
-
-CString &CString::operator=(const CString &str)
-{
- if (this == &str)
- return *this;
-
- if (data)
- delete [] data;
- data = new char[str.size()+1];
- strcpy(data, str.c_str());
-
- return *this;
-}
-
-CString &CString::operator+=(const CString &str)
-{
- return append(str.c_str());
-}
-
-int CString::size() const
-{
- return strlen(data);
-}
-
-bool KJS::operator==(const KJS::CString& c1, const KJS::CString& c2)
-{
- return (strcmp(c1.c_str(), c2.c_str()) == 0);
-}
-
-UChar UChar::null;
-UString::Rep UString::Rep::null = { 0, 0, 1 };
-UString UString::null;
-static char *statBuffer = 0L;
-
-UChar::UChar(const UCharReference &c)
- : uc( c.unicode() )
-{
-}
-
-UChar UChar::toLower() const
-{
- // ### properly supprot unicode tolower
- if (uc >= 256 || islower(uc))
- return *this;
-
- return UChar(tolower(uc));
-}
-
-UChar UChar::toUpper() const
-{
- if (uc >= 256 || isupper(uc))
- return *this;
-
- return UChar(toupper(uc));
-}
-
-UCharReference& UCharReference::operator=(UChar c)
-{
- str->detach();
- if (offset < str->rep->len)
- *(str->rep->dat + offset) = c;
- /* TODO: lengthen string ? */
- return *this;
-}
-
-UChar& UCharReference::ref() const
-{
- if (offset < str->rep->len)
- return *(str->rep->dat + offset);
- else
- return UChar::null;
-}
-
-UString::Rep *UString::Rep::create(UChar *d, int l)
-{
- Rep *r = new Rep;
- r->dat = d;
- r->len = l;
- r->rc = 1;
-
- return r;
-}
-
-UString::UString()
-{
- null.rep = &Rep::null;
- attach(&Rep::null);
-}
-
-UString::UString(char c)
-{
- rep = Rep::create(new UChar(0, c), 1);
-}
-
-UString::UString(const char *c)
-{
- attach(&Rep::null);
- operator=(c);
-}
-
-UString::UString(const UChar *c, int length)
-{
- UChar *d = new UChar[length];
- memcpy(d, c, length * sizeof(UChar));
- rep = Rep::create(d, length);
-}
-
-UString::UString(UChar *c, int length, bool copy)
-{
- UChar *d;
- if (copy) {
- d = new UChar[length];
- memcpy(d, c, length * sizeof(UChar));
- } else
- d = c;
- rep = Rep::create(d, length);
-}
-
-UString::UString(const UString &b)
-{
- attach(b.rep);
-}
-
-UString::~UString()
-{
- release();
-}
-
-UString UString::from(int i)
-{
- char buf[40];
- sprintf(buf, "%d", i);
-
- return UString(buf);
-}
-
-UString UString::from(unsigned int u)
-{
- char buf[40];
- sprintf(buf, "%u", u);
-
- return UString(buf);
-}
-
-UString UString::from(double d)
-{
- char buf[40];
-
- if (d == -0)
- strcpy(buf,"0");
- else if (KJS::isNaN(d))
- strcpy(buf,"NaN");
- else if (KJS::isPosInf(d))
- strcpy(buf,"Infinity");
- else if (KJS::isNegInf(d))
- strcpy(buf,"-Infinity");
- else
- sprintf(buf, "%.16g", d); // does the right thing
-
- // ECMA 3rd ed. 9.8.1 9 e: "with no leading zeros"
- int buflen = strlen(buf);
- if (buflen >= 4 && buf[buflen-4] == 'e' && buf[buflen-2] == '0') {
- buf[buflen-2] = buf[buflen-1];
- buf[buflen-1] = 0;
- }
-
- return UString(buf);
-}
-
-UString &UString::append(const UString &t)
-{
- int l = size();
- UChar *n = new UChar[l+t.size()];
- memcpy(n, data(), l * sizeof(UChar));
- memcpy(n+l, t.data(), t.size() * sizeof(UChar));
- release();
- rep = Rep::create(n, l + t.size());
-
- return *this;
-}
-
-CString UString::cstring() const
-{
- return CString(ascii());
-}
-
-char *UString::ascii() const
-{
- if (statBuffer)
- delete [] statBuffer;
-
- statBuffer = new char[size()+1];
- for(int i = 0; i < size(); i++)
- statBuffer[i] = data()[i].low();
- statBuffer[size()] = '\0';
-
- return statBuffer;
-}
-
-UString &UString::operator=(const char *c)
-{
- release();
- int l = c ? strlen(c) : 0;
- UChar *d = new UChar[l];
- for (int i = 0; i < l; i++)
- d[i].uc = c[i];
- rep = Rep::create(d, l);
-
- return *this;
-}
-
-UString &UString::operator=(const UString &str)
-{
- str.rep->ref();
- release();
- rep = str.rep;
-
- return *this;
-}
-
-UString &UString::operator+=(const UString &s)
-{
- return append(s);
-}
-
-bool UString::is8Bit() const
-{
- const UChar *u = data();
- for(int i = 0; i < size(); i++, u++)
- if (u->uc > 0xFF)
- return false;
-
- return true;
-}
-
-UChar UString::operator[](int pos) const
-{
- if (pos >= size())
- return UChar::null;
-
- return ((UChar *)data())[pos];
-}
-
-UCharReference UString::operator[](int pos)
-{
- /* TODO: boundary check */
- return UCharReference(this, pos);
-}
-
-double UString::toDouble( bool tolerant ) const
-{
- double d;
-
- if (!is8Bit())
- return NaN;
-
- CString str = cstring();
- const char *c = str.c_str();
-
- // skip leading white space
- while (isspace(*c))
- c++;
-
- // empty string ?
- if (*c == '\0')
- return 0.0;
-
- // hex number ?
- if (*c == '0' && (*(c+1) == 'x' || *(c+1) == 'X')) {
- c++;
- d = 0.0;
- while (*(++c)) {
- if (*c >= '0' && *c <= '9')
- d = d * 16.0 + *c - '0';
- else if ((*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f'))
- d = d * 16.0 + (*c & 0xdf) - 'A' + 10.0;
- else
- break;
- }
- } else {
- // regular number ?
- char *end;
- d = strtod(c, &end);
- if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) {
- c = end;
- } else {
- // infinity ?
- d = 1.0;
- if (*c == '+')
- c++;
- else if (*c == '-') {
- d = -1.0;
- c++;
- }
- if (strncmp(c, "Infinity", 8) != 0)
- return NaN;
- d = d * Inf;
- c += 8;
- }
- }
-
- // allow trailing white space
- while (isspace(*c))
- c++;
- // don't allow anything after - unless tolerant=true
- if ( !tolerant && *c != '\0')
- d = NaN;
-
- return d;
-}
-
-unsigned long UString::toULong(bool *ok) const
-{
- double d = toDouble();
- bool b = true;
-
- if (isNaN(d) || d != static_cast<unsigned long>(d)) {
- b = false;
- d = 0;
- }
-
- if (ok)
- *ok = b;
-
- return static_cast<unsigned long>(d);
-}
-
-int UString::find(const UString &f, int pos) const
-{
- if (isNull())
- return -1;
- long fsize = f.size() * sizeof(UChar);
- if (pos < 0)
- pos = 0;
- const UChar *end = data() + size() - f.size();
- for (const UChar *c = data() + pos; c <= end; c++)
- if (!memcmp((void*)c, (void*)f.data(), fsize))
- return (c-data());
-
- return -1;
-}
-
-int UString::rfind(const UString &f, int pos) const
-{
- if (isNull())
- return -1;
- if (pos + f.size() >= size())
- pos = size() - f.size();
- long fsize = f.size() * sizeof(UChar);
- for (const UChar *c = data() + pos; c >= data(); c--) {
- if (!memcmp((void*)c, (void*)f.data(), fsize))
- return (c-data());
- }
-
- return -1;
-}
-
-UString UString::substr(int pos, int len) const
-{
- if (isNull())
- return UString();
- if (pos < 0)
- pos = 0;
- else if (pos >= (int) size())
- pos = size();
- if (len < 0)
- len = size();
- if (pos + len >= (int) size())
- len = size() - pos;
-
- UChar *tmp = new UChar[len];
- memcpy(tmp, data()+pos, len * sizeof(UChar));
- UString result(tmp, len);
- delete [] tmp;
-
- return result;
-}
-
-void UString::attach(Rep *r)
-{
- rep = r;
- rep->ref();
-}
-
-void UString::detach()
-{
- if (rep->rc > 1) {
- int l = size();
- UChar *n = new UChar[l];
- memcpy(n, data(), l * sizeof(UChar));
- release();
- rep = Rep::create(n, l);
- }
-}
-
-void UString::release()
-{
- if (!rep->deref()) {
- delete [] rep->dat;
- delete rep;
- }
-}
-
-bool KJS::operator==(const UString& s1, const UString& s2)
-{
- if (s1.rep->len != s2.rep->len)
- return false;
-
- return (memcmp(s1.rep->dat, s2.rep->dat,
- s1.rep->len * sizeof(UChar)) == 0);
-}
-
-bool KJS::operator==(const UString& s1, const char *s2)
-{
- if (s2 == 0L && s1.isNull())
- return true;
-
- if (s1.size() != (int) strlen(s2))
- return false;
-
- const UChar *u = s1.data();
- while (*s2) {
- if (u->uc != *s2 )
- return false;
- s2++;
- u++;
- }
-
- return true;
-}
-
-bool KJS::operator<(const UString& s1, const UString& s2)
-{
- int l1 = s1.size();
- int l2 = s2.size();
- const UChar *c1 = s1.data();
- const UChar *c2 = s2.data();
- int l = 0;
- int le = l1 < l2 ? l1 : l2;
- while (l < le && *c1 == *c2) {
- c1++;
- c2++;
- l++;
- }
- if (l != le)
- return (c1->unicode() < c2->unicode());
-
- return (l1 < l2 && !(*c1 == *c2));
-}
-
-UString KJS::operator+(const UString& s1, const UString& s2)
-{
- UString tmp(s1);
- tmp.append(s2);
-
- return tmp;
-}
diff --git a/WebCore/src/kdelibs/kjs/ustring.h b/WebCore/src/kdelibs/kjs/ustring.h
deleted file mode 100644
index 0f0790b..0000000
--- a/WebCore/src/kdelibs/kjs/ustring.h
+++ /dev/null
@@ -1,413 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef _KJS_USTRING_H_
-#define _KJS_USTRING_H_
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef APPLE_CHANGES
-#include <KWQDef.h>
-#endif
-
-/**
- * @internal
- */
-namespace DOM {
- class DOMString;
-};
-class KJScript;
-class QString;
-class QConstString;
-
-namespace KJS {
-
- class UCharReference;
- class UString;
-
- /**
- * @short Unicode character.
- *
- * UChar represents a 16 bit Unicode character. It's internal data
- * representation is compatible to XChar2b and QChar. It's therefore
- * possible to exchange data with X and Qt with shallow copies.
- */
- struct UChar {
- /**
- * Construct a character with value 0.
- */
- UChar();
- /**
- * Construct a character with the value denoted by the arguments.
- * @param h higher byte
- * @param l lower byte
- */
- UChar(unsigned char h , unsigned char l);
- /**
- * Construct a character with the given value.
- * @param u 16 bit Unicode value
- */
- UChar(unsigned short u);
- UChar(const UCharReference &c);
- /**
- * @return The higher byte of the character.
- */
- unsigned char high() const { return uc >> 8; }
- /**
- * @return The lower byte of the character.
- */
- unsigned char low() const { return uc & 0xFF; }
- /**
- * @return the 16 bit Unicode value of the character
- */
- unsigned short unicode() const { return uc; }
- public:
- /**
- * @return The character converted to lower case.
- */
- UChar toLower() const;
- /**
- * @return The character converted to upper case.
- */
- UChar toUpper() const;
- /**
- * A static instance of UChar(0).
- */
- static UChar null;
- private:
- friend class UCharReference;
- friend class UString;
- friend bool operator==(const UChar &c1, const UChar &c2);
- friend bool operator==(const UString& s1, const char *s2);
- friend bool operator<(const UString& s1, const UString& s2);
-
- ushort uc;
- };
-
- inline UChar::UChar() : uc(0) { }
- inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
- inline UChar::UChar(unsigned short u) : uc(u) { }
-
- /**
- * @short Dynamic reference to a string character.
- *
- * UCharReference is the dynamic counterpart of @ref UChar. It's used when
- * characters retrieved via index from a @ref UString are used in an
- * assignment expression (and therefore can't be treated as being const):
- * <pre>
- * UString s("hello world");
- * s[0] = 'H';
- * </pre>
- *
- * If that sounds confusing your best bet is to simply forget about the
- * existance of this class and treat is as being identical to @ref UChar.
- */
- class UCharReference {
- friend class UString;
- UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
- public:
- /**
- * Set the referenced character to c.
- */
- UCharReference& operator=(UChar c);
- /**
- * Same operator as above except the argument that it takes.
- */
- UCharReference& operator=(char c) { return operator=(UChar(c)); }
- /**
- * @return Unicode value.
- */
- unsigned short unicode() const { return ref().unicode(); }
- /**
- * @return Lower byte.
- */
- unsigned char low() const { return ref().uc & 0xFF; }
- /**
- * @return Higher byte.
- */
- unsigned char high() const { return ref().uc >> 8; }
- /**
- * @return Character converted to lower case.
- */
- UChar toLower() const { return ref().toLower(); }
- /**
- * @return Character converted to upper case.
- */
- UChar toUpper() const { return ref().toUpper(); }
- private:
- // not implemented, can only be constructed from UString
- UCharReference();
-
- UChar& ref() const;
- UString *str;
- int offset;
- };
-
- /**
- * @short 8 bit char based string class
- */
- class CString {
- public:
- CString() : data(0L) { }
- CString(const char *c);
- CString(const CString &);
-
- ~CString();
-
- CString &append(const CString &);
- CString &operator=(const char *c);
- CString &operator=(const CString &);
- CString &operator+=(const CString &);
-
- int size() const;
- const char *c_str() const { return data; }
- private:
- char *data;
- };
-
- /**
- * @short Unicode string class
- */
- class UString {
- friend bool operator==(const UString&, const UString&);
- friend class UCharReference;
- /**
- * @internal
- */
- struct Rep {
- friend class UString;
- friend bool operator==(const UString&, const UString&);
- static Rep *create(UChar *d, int l);
- inline UChar *data() const { return dat; }
- inline int size() const { return len; }
-
- inline void ref() { rc++; }
- inline int deref() { return --rc; }
-
- UChar *dat;
- int len;
- int rc;
- static Rep null;
- };
-
- public:
- /**
- * Constructs a null string.
- */
- UString();
- /**
- * Constructs a string from the single character c.
- */
- UString(char c);
- /**
- * Constructs a string from a classical zero determined char string.
- */
- UString(const char *c);
- /**
- * Constructs a string from an array of Unicode characters of the specified
- * length.
- */
- UString(const UChar *c, int length);
- /**
- * If copy is false a shallow copy of the string will be created. That
- * means that the data will NOT be copied and you'll have to guarantee that
- * it doesn't get deleted during the lifetime of the UString object.
- * Behaviour defaults to a deep copy if copy is true.
- */
- UString(UChar *c, int length, bool copy);
- /**
- * Copy constructor. Makes a shallow copy only.
- */
- UString(const UString &);
- /**
- * Convenience declaration only ! You'll be on your own to write the
- * implementation for a construction from QString.
- *
- * Note: feel free to contact me if you want to see a dummy header for
- * your favourite FooString class here !
- */
- UString(const QString &);
- /**
- * Convenience declaration only ! See @ref UString(const QString&).
- */
- UString(const DOM::DOMString &);
- /**
- * Destructor. If this handle was the only one holding a reference to the
- * string the data will be freed.
- */
- ~UString();
-
- /**
- * Constructs a string from an int.
- */
- static UString from(int i);
- /**
- * Constructs a string from an unsigned int.
- */
- static UString from(unsigned int u);
- /**
- * Constructs a string from a double.
- */
- static UString from(double d);
-
- /**
- * Append another string.
- */
- UString &append(const UString &);
-
- /**
- * @return The string converted to the 8-bit string type @ref CString().
- */
- CString cstring() const;
- /**
- * Convert the Unicode string to plain ASCII chars chopping of any higher
- * bytes. This method should only be used for *debugging* purposes as it
- * is neither Unicode safe nor free from side effects. In order not to
- * waste any memory the char buffer is static and *shared* by all UString
- * instances.
- */
- char *ascii() const;
- /**
- * @see UString(const QString&).
- */
- DOM::DOMString string() const;
- /**
- * @see UString(const QString&).
- */
- QString qstring() const;
- /**
- * @see UString(const QString&).
- */
- QConstString qconststring() const;
-
- /**
- * Assignment operator.
- */
- UString &operator=(const char *c);
- /**
- * Assignment operator.
- */
- UString &operator=(const UString &);
- /**
- * Appends the specified string.
- */
- UString &operator+=(const UString &s);
-
- /**
- * @return A pointer to the internal Unicode data.
- */
- const UChar* data() const { return rep->data(); }
- /**
- * @return True if null.
- */
- bool isNull() const { return (rep == &Rep::null); }
- /**
- * @return True if null or zero length.
- */
- bool isEmpty() const { return (!rep->len); }
- /**
- * Use this if you want to make sure that this string is a plain ASCII
- * string. For example, if you don't want to lose any information when
- * using @ref cstring() or @ref ascii().
- *
- * @return True if the string doesn't contain any non-ASCII characters.
- */
- bool is8Bit() const;
- /**
- * @return The length of the string.
- */
- int size() const { return rep->size(); }
- /**
- * Const character at specified position.
- */
- UChar operator[](int pos) const;
- /**
- * Writable reference to character at specified position.
- */
- UCharReference operator[](int pos);
-
- /**
- * Attempts an conversion to a number. Apart from floating point numbers,
- * the algorithm will recognize hexadecimal representations (as
- * indicated by a 0x or 0X prefix) and +/- Infinity.
- * Returns NaN if the conversion failed.
- * @param tolerant if true, toDouble can tolerate garbage after the number.
- */
- double toDouble(bool tolerant=false) const;
- /**
- * Attempts an conversion to an unsigned long integer. ok will be set
- * according to the success.
- */
- unsigned long toULong(bool *ok = 0L) const;
- /**
- * @return Position of first occurence of f starting at position pos.
- * -1 if the search was not successful.
- */
- int find(const UString &f, int pos = 0) const;
- /**
- * @return Position of first occurence of f searching backwards from
- * position pos.
- * -1 if the search was not successful.
- */
- int rfind(const UString &f, int pos) const;
- /**
- * @return The sub string starting at position pos and length len.
- */
- UString substr(int pos = 0, int len = -1) const;
- /**
- * Static instance of a null string.
- */
- static UString null;
- private:
- void attach(Rep *r);
- void detach();
- void release();
- Rep *rep;
- };
-
- inline bool operator==(const UChar &c1, const UChar &c2) {
- return (c1.uc == c2.uc);
- }
- bool operator==(const UString& s1, const UString& s2);
- inline bool operator!=(const UString& s1, const UString& s2) {
- return !KJS::operator==(s1, s2);
- }
- bool operator<(const UString& s1, const UString& s2);
- bool operator==(const UString& s1, const char *s2);
- inline bool operator!=(const UString& s1, const char *s2) {
- return !KJS::operator==(s1, s2);
- }
- inline bool operator==(const char *s1, const UString& s2) {
- return operator==(s2, s1);
- }
- inline bool operator!=(const char *s1, const UString& s2) {
- return !KJS::operator==(s1, s2);
- }
- bool operator==(const CString& s1, const CString& s2);
- UString operator+(const UString& s1, const UString& s2);
-
-}; // namespace
-
-#endif
diff --git a/WebCore/src/kdelibs/kjs/value.cpp b/WebCore/src/kdelibs/kjs/value.cpp
deleted file mode 100644
index f14ec3f..0000000
--- a/WebCore/src/kdelibs/kjs/value.cpp
+++ /dev/null
@@ -1,536 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#include "value.h"
-#include "object.h"
-#include "types.h"
-#include "interpreter.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "internal.h"
-#include "collector.h"
-#include "operations.h"
-#include "error_object.h"
-#include "nodes.h"
-
-using namespace KJS;
-
-// ------------------------------ ValueImp -------------------------------------
-
-ValueImp::ValueImp() : refcount(0), _flags(0)
-{
- // Tell the garbage collector that this memory block corresponds to a real object now
- _flags |= VI_CREATED;
- //fprintf(stderr,"ValueImp::ValueImp %p\n",(void*)this);
-}
-
-ValueImp::~ValueImp()
-{
- //fprintf(stderr,"ValueImp::~ValueImp %p\n",(void*)this);
-}
-
-void ValueImp::mark()
-{
- //fprintf(stderr,"ValueImp::mark %p\n",(void*)this);
- _flags |= VI_MARKED;
-}
-
-bool ValueImp::marked() const
-{
- return (_flags & VI_MARKED);
-}
-
-void ValueImp::setGcAllowed()
-{
- _flags |= VI_GCALLOWED;
-}
-
-void* ValueImp::operator new(size_t s)
-{
- return Collector::allocate(s);
-}
-
-void ValueImp::operator delete(void*)
-{
- // Do nothing. So far.
-}
-
-// ECMA 9.4
-int ValueImp::toInteger(ExecState *exec) const
-{
- return int(roundValue(exec, Value(const_cast<ValueImp*>(this))));
-}
-
-int ValueImp::toInt32(ExecState *exec) const
-{
- double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
- double d32 = fmod(d, D32);
-
- if (d32 >= D32 / 2.0)
- d32 -= D32;
-
- return static_cast<int>(d32);
-}
-
-unsigned int ValueImp::toUInt32(ExecState *exec) const
-{
- double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
- double d32 = fmod(d, D32);
-
- return static_cast<unsigned int>(d32);
-}
-
-unsigned short ValueImp::toUInt16(ExecState *exec) const
-{
- double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
- double d16 = fmod(d, D16);
-
- return static_cast<unsigned short>(d16);
-}
-
-// ECMA 8.7.1
-Value ValueImp::getBase(ExecState *exec) const
-{
- if (type() != ReferenceType) {
- Object err = Error::create(exec, ReferenceError, I18N_NOOP("Invalid reference base"));
- exec->setException(err);
- return err;
- }
-
- return (static_cast<const ReferenceImp*>(this))->getBase();
-}
-
-// ECMA 8.7.2
-UString ValueImp::getPropertyName(ExecState * /*exec*/) const
-{
- if (type() != ReferenceType)
- // the spec wants a runtime error here. But getValue() and putValue()
- // will catch this case on their own earlier. When returning a Null
- // string we should be on the safe side.
- return UString();
-
- return (static_cast<const ReferenceImp*>(this))->getPropertyName();
-}
-
-// ECMA 8.7.1
-Value ValueImp::getValue(ExecState *exec) const
-{
- if (type() != ReferenceType)
- return Value(const_cast<ValueImp*>(this));
-
- Value o = getBase(exec);
-
- if (o.isNull() || o.type() == NullType) {
- UString m = I18N_NOOP("Can't find variable: ") + getPropertyName(exec);
- Object err = Error::create(exec, ReferenceError, m.ascii());
- exec->setException(err);
- return err;
- }
-
- if (o.type() != ObjectType) {
- UString m = I18N_NOOP("Base is not an object");
- Object err = Error::create(exec, ReferenceError, m.ascii());
- exec->setException(err);
- return err;
- }
-
- return static_cast<ObjectImp*>(o.imp())->get(exec,getPropertyName(exec));
-}
-
-void ValueImp::putValue(ExecState *exec, const Value w)
-{
- if (type() != ReferenceType) {
- Object err = Error::create(exec,ReferenceError);
- exec->setException(err);
- return;
- }
-
-#ifdef KJS_VERBOSE
- printInfo(exec,(UString("setting property ")+getPropertyName(exec)).cstring().c_str(),w);
-#endif
- Value o = getBase(exec);
- if (o.type() == NullType)
- exec->interpreter()->globalObject().put(exec,getPropertyName(exec), w);
- else {
- static_cast<ObjectImp*>(o.imp())->put(exec,getPropertyName(exec), w);
- }
-
- return;
-}
-
-bool KJS::operator==(const Value &v1, const Value &v2)
-{
- return (v1.imp() == v2.imp());
-}
-
-bool KJS::operator!=(const Value &v1, const Value &v2)
-{
- return (v1.imp() != v2.imp());
-}
-
-
-
-
-// ------------------------------ Value ----------------------------------------
-
-Value::Value()
-{
- rep = 0;
-}
-
-Value::Value(ValueImp *v)
-{
- rep = v;
- if (rep)
- {
- rep->ref();
- //fprintf(stderr, "Value::Value(%p) imp=%p ref=%d\n", this, rep, rep->refcount);
- v->setGcAllowed();
- }
-}
-
-Value::Value(const Value &v)
-{
- rep = v.imp();
- if (rep)
- {
- rep->ref();
- //fprintf(stderr, "Value::Value(%p)(copying %p) imp=%p ref=%d\n", this, &v, rep, rep->refcount);
- }
-}
-
-Value::~Value()
-{
- if (rep)
- {
- rep->deref();
- //fprintf(stderr, "Value::~Value(%p) imp=%p ref=%d\n", this, rep, rep->refcount);
- }
-}
-
-Value& Value::operator=(const Value &v)
-{
- if (rep) {
- rep->deref();
- //fprintf(stderr, "Value::operator=(%p)(copying %p) old imp=%p ref=%d\n", this, &v, rep, rep->refcount);
- }
- rep = v.imp();
- if (rep)
- {
- rep->ref();
- //fprintf(stderr, "Value::operator=(%p)(copying %p) imp=%p ref=%d\n", this, &v, rep, rep->refcount);
- }
- return *this;
-}
-
-bool Value::isNull() const
-{
- return (rep == 0);
-}
-
-ValueImp *Value::imp() const
-{
- return rep;
-}
-
-Type Value::type() const
-{
- return rep->type();
-}
-
-bool Value::isA(Type t) const
-{
- return (type() == t);
-}
-
-Value Value::toPrimitive(ExecState *exec, Type preferredType) const
-{
- return rep->toPrimitive(exec,preferredType);
-}
-
-bool Value::toBoolean(ExecState *exec) const
-{
- return rep->toBoolean(exec);
-}
-
-double Value::toNumber(ExecState *exec) const
-{
- return rep->toNumber(exec);
-}
-
-int Value::toInteger(ExecState *exec) const
-{
- return rep->toInteger(exec);
-}
-
-int Value::toInt32(ExecState *exec) const
-{
- return rep->toInt32(exec);
-}
-
-unsigned int Value::toUInt32(ExecState *exec) const
-{
- return rep->toUInt32(exec);
-}
-
-unsigned short Value::toUInt16(ExecState *exec) const
-{
- return rep->toUInt16(exec);
-}
-
-UString Value::toString(ExecState *exec) const
-{
- return rep->toString(exec);
-}
-
-Object Value::toObject(ExecState *exec) const
-{
- return rep->toObject(exec);
-}
-
-Value Value::getBase(ExecState *exec) const
-{
- return rep->getBase(exec);
-}
-
-UString Value::getPropertyName(ExecState *exec) const
-{
- return rep->getPropertyName(exec);
-}
-
-Value Value::getValue(ExecState *exec) const
-{
- return rep->getValue(exec);
-}
-
-void Value::putValue(ExecState *exec, const Value w)
-{
- rep->putValue(exec,w);
-}
-
-// ------------------------------ Undefined ------------------------------------
-
-Undefined::Undefined() : Value(UndefinedImp::staticUndefined)
-{
-}
-
-Undefined::~Undefined() {
-}
-
-Undefined::Undefined(UndefinedImp *v) : Value(v)
-{
-}
-
-Undefined::Undefined(const Undefined &v) : Value(v)
-{
-}
-
-Undefined& Undefined::operator=(const Undefined &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-Undefined Undefined::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != UndefinedType)
- return Undefined(0);
-
- return Undefined(static_cast<UndefinedImp*>(v.imp()));
-}
-
-// ------------------------------ Null -----------------------------------------
-
-Null::Null() : Value(NullImp::staticNull)
-{
-}
-
-Null::~Null() {
-}
-
-
-Null::Null(NullImp *v) : Value(v)
-{
-}
-
-Null::Null(const Null &v) : Value(v)
-{
-}
-
-Null& Null::operator=(const Null &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-Null Null::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != NullType)
- return Null(0);
-
- return Null(static_cast<NullImp*>(v.imp()));
-}
-
-// ------------------------------ Boolean --------------------------------------
-
-Boolean::Boolean(bool b)
- : Value(b ? BooleanImp::staticTrue : BooleanImp::staticFalse)
-{
-}
-
-Boolean::~Boolean() { }
-
-
-
-Boolean::Boolean(BooleanImp *v) : Value(v)
-{
-}
-
-Boolean::Boolean(const Boolean &v) : Value(v)
-{
-}
-
-Boolean& Boolean::operator=(const Boolean &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-
-bool Boolean::value() const
-{
- assert(rep);
- return ((BooleanImp*)rep)->value();
-}
-
-Boolean Boolean::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != BooleanType)
- return static_cast<BooleanImp*>(0);
-
- return static_cast<BooleanImp*>(v.imp());
-}
-
-// ------------------------------ String ---------------------------------------
-
-String::String(const UString &s) : Value(new StringImp(UString(s)))
-{
-}
-
-String::~String() { }
-
-String::String(StringImp *v) : Value(v)
-{
-}
-
-String::String(const String &v) : Value(v)
-{
-}
-
-String& String::operator=(const String &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-UString String::value() const
-{
- assert(rep);
- return ((StringImp*)rep)->value();
-}
-
-String String::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != StringType)
- return String(0);
-
- return String(static_cast<StringImp*>(v.imp()));
-}
-
-// ------------------------------ Number ---------------------------------------
-
-Number::Number(int i)
- : Value(new NumberImp(static_cast<double>(i))) { }
-
-Number::Number(unsigned int u)
- : Value(new NumberImp(static_cast<double>(u))) { }
-
-Number::Number(double d)
- : Value(new NumberImp(d)) { }
-
-Number::Number(long int l)
- : Value(new NumberImp(static_cast<double>(l))) { }
-
-Number::Number(long unsigned int l)
- : Value(new NumberImp(static_cast<double>(l))) { }
-
-Number::~Number() { }
-
-Number::Number(NumberImp *v) : Value(v)
-{
-}
-
-Number::Number(const Number &v) : Value(v)
-{
-}
-
-Number& Number::operator=(const Number &v)
-{
- Value::operator=(v);
- return *this;
-}
-
-Number Number::dynamicCast(const Value &v)
-{
- if (v.isNull() || v.type() != NumberType)
- return Number((NumberImp*)0);
-
- return Number(static_cast<NumberImp*>(v.imp()));
-}
-
-double Number::value() const
-{
- assert(rep);
- return ((NumberImp*)rep)->value();
-}
-
-int Number::intValue() const
-{
- assert(rep);
- return (int)((NumberImp*)rep)->value();
-}
-
-bool Number::isNaN() const
-{
- return KJS::isNaN(((NumberImp*)rep)->value());
-}
-
-bool Number::isInf() const
-{
- return KJS::isInf(((NumberImp*)rep)->value());
-}
-
diff --git a/WebCore/src/kdelibs/kjs/value.h b/WebCore/src/kdelibs/kjs/value.h
deleted file mode 100644
index 0fb9df0..0000000
--- a/WebCore/src/kdelibs/kjs/value.h
+++ /dev/null
@@ -1,427 +0,0 @@
-// -*- c-basic-offset: 2 -*-
-/*
- * This file is part of the KDE libraries
- * Copyright (C) 1999-2001 Harri Porten (porten at kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk at post.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#ifndef _KJS_VALUE_H_
-#define _KJS_VALUE_H_
-
-#ifndef NDEBUG // protection against problems if committing with KJS_VERBOSE on
-
-// Uncomment this to enable very verbose output from KJS
-//#define KJS_VERBOSE
-// Uncomment this to debug memory allocation and garbage collection
-//#define KJS_DEBUG_MEM
-
-#endif
-
-#include "ustring.h"
-
-#if APPLE_CHANGES
-#include <stdlib.h>
-#endif
-
-// Primitive data types
-
-namespace KJS {
-
- class Value;
- class ValueImp;
- class ValueImpPrivate;
- class Undefined;
- class UndefinedImp;
- class Null;
- class NullImp;
- class Boolean;
- class BooleanImp;
- class String;
- class StringImp;
- class Number;
- class NumberImp;
- class Object;
- class ObjectImp;
- class Reference;
- class ReferenceImp;
- class List;
- class ListImp;
- class Completion;
- class CompletionImp;
- class ExecState;
-
- /**
- * Primitive types
- */
- enum Type {
- UnspecifiedType = 0,
- UndefinedType = 1,
- NullType = 2,
- BooleanType = 3,
- StringType = 4,
- NumberType = 5,
- ObjectType = 6,
- ReferenceType = 7,
- ListType = 8,
- CompletionType = 9
- };
-
- /**
- * ValueImp is the base type for all primitives (Undefined, Null, Boolean,
- * String, Number) and objects in ECMAScript.
- *
- * Note: you should never inherit from ValueImp as it is for primitive types
- * only (all of which are provided internally by KJS). Instead, inherit from
- * ObjectImp.
- */
- class ValueImp {
- friend class Collector;
- public:
- ValueImp();
- virtual ~ValueImp();
-
- inline ValueImp* ref() { refcount++; return this; }
- inline bool deref() { return (!--refcount); }
- unsigned int refcount;
-
- virtual void mark();
- bool marked() const;
- void* operator new(size_t);
- void operator delete(void*);
-
- /**
- * @internal
- *
- * set by Object() so that the collector is allowed to delete us
- */
- void setGcAllowed();
-
- virtual Type type() const = 0;
-
- // The conversion operations
-
- virtual Value toPrimitive(ExecState *exec,
- Type preferredType = UnspecifiedType) const = 0;
- virtual bool toBoolean(ExecState *exec) const = 0;
- virtual double toNumber(ExecState *exec) const = 0;
- virtual int toInteger(ExecState *exec) const;
- virtual int toInt32(ExecState *exec) const;
- virtual unsigned int toUInt32(ExecState *exec) const;
- virtual unsigned short toUInt16(ExecState *exec) const;
- virtual UString toString(ExecState *exec) const = 0;
- virtual Object toObject(ExecState *exec) const = 0;
-
- // Reference operations
-
- virtual Value getBase(ExecState *exec) const;
- virtual UString getPropertyName(ExecState *exec) const;
- virtual Value getValue(ExecState *exec) const;
- virtual void putValue(ExecState *exec, const Value w);
-
- private:
- enum {
- VI_MARKED = 1,
- VI_GCALLOWED = 2,
- VI_CREATED = 4
- }; // VI means VALUEIMPL
-
- ValueImpPrivate *_vd;
- unsigned int _flags;
- };
-
- /**
- * Value objects are act as wrappers ("smart pointers") around ValueImp
- * objects and their descendents. Instead of using ValueImps
- * (and derivatives) during normal program execution, you should use a
- * Value-derived class.
- *
- * Value maintains a pointer to a ValueImp object and uses a reference
- * counting scheme to ensure that the ValueImp object is not deleted or
- * garbage collected.
- *
- * Note: The conversion operations all return values of various types -
- * if an error occurs during conversion, an error object will instead
- * be returned (where possible), and the execution state's exception
- * will be set appropriately.
- */
- class Value {
- public:
- Value();
- explicit Value(ValueImp *v);
- Value(const Value &v);
- virtual ~Value();
-
- Value& operator=(const Value &v);
- bool isNull() const;
- ValueImp *imp() const;
-
- /**
- * Returns the type of value. This is one of UndefinedType, NullType,
- * BooleanType, StringType NumberType, ObjectType, ReferenceType,
- * ListType or CompletionType.
- *
- * @return The type of value
- */
- Type type() const;
-
- /**
- * Checks whether or not the value is of a particular tpye
- *
- * @param The type to compare with
- * @return true if the value is of the specified type, otherwise false
- */
- bool isA(Type t) const;
-
- /**
- * Performs the ToPrimitive type conversion operation on this value
- * (ECMA 9.1)
- */
- Value toPrimitive(ExecState *exec,
- Type preferredType = UnspecifiedType) const;
-
- /**
- * Performs the ToBoolean type conversion operation on this value (ECMA 9.2)
- */
- bool toBoolean(ExecState *exec) const;
-
- /**
- * Performs the ToNumber type conversion operation on this value (ECMA 9.3)
- */
- double toNumber(ExecState *exec) const;
-
- /**
- * Performs the ToInteger type conversion operation on this value (ECMA 9.4)
- */
- int toInteger(ExecState *exec) const;
-
- /**
- * Performs the ToInt32 type conversion operation on this value (ECMA 9.5)
- */
- int toInt32(ExecState *exec) const;
-
- /**
- * Performs the ToUint32 type conversion operation on this value (ECMA 9.6)
- */
- uint toUInt32(ExecState *exec) const;
-
- /**
- * Performs the ToUint16 type conversion operation on this value (ECMA 9.7)
- */
- unsigned short toUInt16(ExecState *exec) const;
-
- /**
- * Performs the ToString type conversion operation on this value (ECMA 9.8)
- */
- UString toString(ExecState *exec) const;
-
- /**
- * Performs the ToObject type conversion operation on this value (ECMA 9.9)
- */
- Object toObject(ExecState *exec) const;
-
- /**
- * Performs the GetBase type conversion operation on this value (ECMA 8.7)
- *
- * Since references are supposed to have an Object or null as their base,
- * this method is guaranteed to return either Null() or an Object value.
- */
- Value getBase(ExecState *exec) const;
-
- /**
- * Performs the GetPropertyName type conversion operation on this value
- * (ECMA 8.7)
- */
- UString getPropertyName(ExecState *exec) const;
-
- /**
- * Performs the GetValue type conversion operation on this value
- * (ECMA 8.7.1)
- */
- Value getValue(ExecState *exec) const;
-
- /**
- * Performs the PutValue type conversion operation on this value
- * (ECMA 8.7.1)
- */
- void putValue(ExecState *exec, const Value w);
-
- protected:
- ValueImp *rep;
- };
-
- bool operator==(const Value &v1, const Value &v2);
- bool operator!=(const Value &v1, const Value &v2);
-
- // Primitive types
-
- /**
- * Represents an primitive Undefined value. All instances of this class
- * share the same implementation object, so == will always return true
- * for any comparison between two Undefined objects.
- */
- class Undefined : public Value {
- public:
- Undefined();
- Undefined(const Undefined &v);
- virtual ~Undefined();
-
- Undefined& operator=(const Undefined &v);
-
- /**
- * Converts a Value into an Undefined. If the value's type is not
- * UndefinedType, a null object will be returned (i.e. one with it's
- * internal pointer set to 0). If you do not know for sure whether the
- * value is of type UndefinedType, you should check the @ref isNull()
- * methods afterwards before calling any methods on the returned value.
- *
- * @return The value converted to an Undefined
- */
- static Undefined dynamicCast(const Value &v);
- private:
- friend class UndefinedImp;
- explicit Undefined(UndefinedImp *v);
-
- };
-
- /**
- * Represents an primitive Null value. All instances of this class
- * share the same implementation object, so == will always return true
- * for any comparison between two Null objects.
- */
- class Null : public Value {
- public:
- Null();
- Null(const Null &v);
- virtual ~Null();
-
- Null& operator=(const Null &v);
-
- /**
- * Converts a Value into an Null. If the value's type is not NullType,
- * a null object will be returned (i.e. one with it's internal pointer set
- * to 0). If you do not know for sure whether the value is of type
- * NullType, you should check the @ref isNull() methods afterwards before
- * calling any methods on the returned value.
- *
- * @return The value converted to a Null
- */
- static Null dynamicCast(const Value &v);
- private:
- friend class NullImp;
- explicit Null(NullImp *v);
- };
-
- /**
- * Represents an primitive Null value
- */
- class Boolean : public Value {
- public:
- Boolean(bool b = false);
- Boolean(const Boolean &v);
- virtual ~Boolean();
-
- Boolean& operator=(const Boolean &v);
-
- /**
- * Converts a Value into an Boolean. If the value's type is not BooleanType,
- * a null object will be returned (i.e. one with it's internal pointer set
- * to 0). If you do not know for sure whether the value is of type
- * BooleanType, you should check the @ref isNull() methods afterwards before
- * calling any methods on the returned value.
- *
- * @return The value converted to a Boolean
- */
- static Boolean dynamicCast(const Value &v);
-
- bool value() const;
- private:
- friend class BooleanImp;
- explicit Boolean(BooleanImp *v);
- };
-
- /**
- * Represents an primitive Null value
- */
- class String : public Value {
- public:
- String(const UString &s = "");
- String(const String &v);
- virtual ~String();
-
- String& operator=(const String &v);
-
- /**
- * Converts a Value into an String. If the value's type is not StringType,
- * a null object will be returned (i.e. one with it's internal pointer set
- * to 0). If you do not know for sure whether the value is of type
- * StringType, you should check the @ref isNull() methods afterwards before
- * calling any methods on the returned value.
- *
- * @return The value converted to a String
- */
- static String dynamicCast(const Value &v);
-
- UString value() const;
- private:
- friend class StringImp;
- explicit String(StringImp *v);
- };
-
- extern const double NaN;
- extern const double Inf;
-
- /**
- * Represents an primitive Number value
- */
- class Number : public Value {
- public:
- Number(int i);
- Number(unsigned int u);
- Number(double d = 0.0);
- Number(long int l);
- Number(long unsigned int l);
- Number(const Number &v);
- virtual ~Number();
-
- Number& operator=(const Number &v);
-
- double value() const;
- int intValue() const;
-
- bool isNaN() const;
- bool isInf() const;
-
- /**
- * Converts a Value into an Number. If the value's type is not NumberType,
- * a null object will be returned (i.e. one with it's internal pointer set
- * to 0). If you do not know for sure whether the value is of type
- * NumberType, you should check the @ref isNull() methods afterwards before
- * calling any methods on the returned value.
- *
- * @return The value converted to a Number
- */
- static Number dynamicCast(const Value &v);
- private:
- friend class NumberImp;
- explicit Number(NumberImp *v);
- };
-
-}; // namespace
-
-#endif // _KJS_VALUE_H_
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 46d0891..df046aa 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,8 @@
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
+ * WebKit.pbproj/project.pbxproj: Fixed to build with standalone
+ libJavaScriptCore.dylib.
+
2002-03-26 Kenneth Kocienda <kocienda at apple.com>
Changes to help the transition to the new build system which unifies
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 46d0891..df046aa 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,8 @@
+2002-03-26 Maciej Stachowiak <mjs at apple.com>
+
+ * WebKit.pbproj/project.pbxproj: Fixed to build with standalone
+ libJavaScriptCore.dylib.
+
2002-03-26 Kenneth Kocienda <kocienda at apple.com>
Changes to help the transition to the new build system which unifies
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index c37d22b..f07fee2 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 36;
+ objectVersion = 38;
objects = {
014CEA440018CDF011CA2923 = {
buildRules = (
@@ -131,7 +131,7 @@
INSTALL_PATH = "";
LIBRARY_SEARCH_PATHS = "";
OTHER_CFLAGS = "-Werror -Wall -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wsign-compare -DHAVE_CONFIG_H -DQT_NO_DATASTREAM -D_KWQ_ -I.. -I../WebCore/src/kdelibs/khtml -I../WebCore/src/kwq -I../WebCore/src/kwq/kparts -I../WebCore/include -I../WebCore/include/private -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks/ -F/System/Library/Frameworks/CoreServices.framework/Frameworks/ -F/System/Library/Frameworks/Carbon.framework/Frameworks/";
- OTHER_LDFLAGS = "-lwebcore -framework WebFoundation -seg1addr 0x4000000";
+ OTHER_LDFLAGS = "-lwebcore -lJavaScriptCore -framework WebFoundation -seg1addr 0x4000000";
PRODUCT_NAME = WebKit;
SECTORDER_FLAGS = "";
WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas";
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list