Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

auto import from //depot/cupcake/@135843

  • Loading branch information...
commit 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 1 parent 648161b
The Android Open Source Project authored
Showing with 113,094 additions and 0 deletions.
  1. +198 −0 Android.mk
  2. +2,862 −0 ChangeLog
  3. +487 −0 GNUmakefile.am
  4. +111 −0 JavaScriptCore/API/APICast.h
  5. +116 −0 JavaScriptCore/API/JSBase.cpp
  6. +130 −0 JavaScriptCore/API/JSBase.h
  7. +52 −0 JavaScriptCore/API/JSBasePrivate.h
  8. +79 −0 JavaScriptCore/API/JSCallbackConstructor.cpp
  9. +57 −0 JavaScriptCore/API/JSCallbackConstructor.h
  10. +70 −0 JavaScriptCore/API/JSCallbackFunction.cpp
  11. +58 −0 JavaScriptCore/API/JSCallbackFunction.h
  12. +41 −0 JavaScriptCore/API/JSCallbackObject.cpp
  13. +115 −0 JavaScriptCore/API/JSCallbackObject.h
  14. +507 −0 JavaScriptCore/API/JSCallbackObjectFunctions.h
  15. +244 −0 JavaScriptCore/API/JSClassRef.cpp
  16. +122 −0 JavaScriptCore/API/JSClassRef.h
  17. +130 −0 JavaScriptCore/API/JSContextRef.cpp
  18. +131 −0 JavaScriptCore/API/JSContextRef.h
  19. +507 −0 JavaScriptCore/API/JSObjectRef.cpp
  20. +694 −0 JavaScriptCore/API/JSObjectRef.h
  21. +46 −0 JavaScriptCore/API/JSProfilerPrivate.cpp
  22. +63 −0 JavaScriptCore/API/JSProfilerPrivate.h
  23. +173 −0 JavaScriptCore/API/JSRetainPtr.h
  24. +109 −0 JavaScriptCore/API/JSStringRef.cpp
  25. +144 −0 JavaScriptCore/API/JSStringRef.h
  26. +42 −0 JavaScriptCore/API/JSStringRefBSTR.cpp
  27. +62 −0 JavaScriptCore/API/JSStringRefBSTR.h
  28. +52 −0 JavaScriptCore/API/JSStringRefCF.cpp
  29. +60 −0 JavaScriptCore/API/JSStringRefCF.h
  30. +270 −0 JavaScriptCore/API/JSValueRef.cpp
  31. +278 −0 JavaScriptCore/API/JSValueRef.h
  32. +36 −0 JavaScriptCore/API/JavaScript.h
  33. +32 −0 JavaScriptCore/API/JavaScriptCore.h
  34. +55 −0 JavaScriptCore/API/OpaqueJSString.cpp
  35. +81 −0 JavaScriptCore/API/OpaqueJSString.h
  36. +761 −0 JavaScriptCore/API/WebKitAvailability.h
  37. +196 −0 JavaScriptCore/API/tests/JSNode.c
  38. +37 −0 JavaScriptCore/API/tests/JSNode.h
  39. +123 −0 JavaScriptCore/API/tests/JSNodeList.c
  40. +34 −0 JavaScriptCore/API/tests/JSNodeList.h
  41. +85 −0 JavaScriptCore/API/tests/Node.c
  42. +50 −0 JavaScriptCore/API/tests/Node.h
  43. +81 −0 JavaScriptCore/API/tests/NodeList.c
  44. +42 −0 JavaScriptCore/API/tests/NodeList.h
  45. +126 −0 JavaScriptCore/API/tests/minidom.c
  46. +9 −0 JavaScriptCore/API/tests/minidom.html
  47. +110 −0 JavaScriptCore/API/tests/minidom.js
  48. +1,026 −0 JavaScriptCore/API/tests/testapi.c
  49. +132 −0 JavaScriptCore/API/tests/testapi.js
  50. +2 −0  JavaScriptCore/AUTHORS
  51. +106 −0 JavaScriptCore/AllInOneFile.cpp
  52. +214 −0 JavaScriptCore/Android.mk
  53. +488 −0 JavaScriptCore/COPYING.LIB
  54. +14,651 −0 JavaScriptCore/ChangeLog
  55. +2,271 −0 JavaScriptCore/ChangeLog-2002-12-03
  56. +1,483 −0 JavaScriptCore/ChangeLog-2003-10-25
  57. +26,221 −0 JavaScriptCore/ChangeLog-2007-10-14
  58. +31,482 −0 JavaScriptCore/ChangeLog-2008-08-10
  59. +68 −0 JavaScriptCore/Configurations/Base.xcconfig
  60. +14 −0 JavaScriptCore/Configurations/DebugRelease.xcconfig
  61. +20 −0 JavaScriptCore/Configurations/JavaScriptCore.xcconfig
  62. +34 −0 JavaScriptCore/Configurations/Version.xcconfig
  63. +73 −0 JavaScriptCore/DerivedSources.make
  64. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/APICast.h
  65. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSBase.h
  66. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSContextRef.h
  67. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSLock.h
  68. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSObjectRef.h
  69. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSRetainPtr.h
  70. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSStringRef.h
  71. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSStringRefCF.h
  72. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JSValueRef.h
  73. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JavaScript.h
  74. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/JavaScriptCore.h
  75. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/OpaqueJSString.h
  76. +1 −0  JavaScriptCore/ForwardingHeaders/JavaScriptCore/WebKitAvailability.h
  77. +492 −0 JavaScriptCore/GNUmakefile.am
  78. +24 −0 JavaScriptCore/Info.plist
  79. +365 −0 JavaScriptCore/JavaScriptCore.exp
  80. +1,526 −0 JavaScriptCore/JavaScriptCore.order
  81. +173 −0 JavaScriptCore/JavaScriptCore.pri
  82. +69 −0 JavaScriptCore/JavaScriptCore.pro
  83. +13 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore.make
  84. +62 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore.sln
  85. +1,380 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
  86. +25 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreGenerated.make
  87. +53 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreGenerated.vcproj
  88. +37 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/build-generated-files.sh
  89. +42 −0 JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCoreSubmit.sln
  90. +440 −0 JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
  91. +237 −0 JavaScriptCore/JavaScriptCore.vcproj/jsc/jsc.vcproj
  92. +287 −0 JavaScriptCore/JavaScriptCore.vcproj/testapi/testapi.vcproj
  93. +2,244 −0 JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
  94. +44 −0 JavaScriptCore/JavaScriptCorePrefix.h
  95. +167 −0 JavaScriptCore/JavaScriptCoreSources.bkl
  96. +2 −0  JavaScriptCore/Makefile
  97. +8 −0 JavaScriptCore/THANKS
  98. +3,532 −0 JavaScriptCore/VM/CTI.cpp
  99. +475 −0 JavaScriptCore/VM/CTI.h
  100. +1,184 −0 JavaScriptCore/VM/CodeBlock.cpp
  101. +399 −0 JavaScriptCore/VM/CodeBlock.h
  102. +1,684 −0 JavaScriptCore/VM/CodeGenerator.cpp
  103. +451 −0 JavaScriptCore/VM/CodeGenerator.h
  104. +228 −0 JavaScriptCore/VM/ExceptionHelpers.cpp
  105. +56 −0 JavaScriptCore/VM/ExceptionHelpers.h
  106. +74 −0 JavaScriptCore/VM/Instruction.h
  107. +118 −0 JavaScriptCore/VM/LabelID.h
  108. +6,046 −0 JavaScriptCore/VM/Machine.cpp
  109. +374 −0 JavaScriptCore/VM/Machine.h
  110. +186 −0 JavaScriptCore/VM/Opcode.cpp
  111. +219 −0 JavaScriptCore/VM/Opcode.h
  112. +299 −0 JavaScriptCore/VM/Register.h
  113. +46 −0 JavaScriptCore/VM/RegisterFile.cpp
  114. +185 −0 JavaScriptCore/VM/RegisterFile.h
  115. +123 −0 JavaScriptCore/VM/RegisterID.h
  116. +298 −0 JavaScriptCore/VM/SamplingTool.cpp
  117. +214 −0 JavaScriptCore/VM/SamplingTool.h
  118. +170 −0 JavaScriptCore/VM/SegmentedVector.h
  119. +54 −0 JavaScriptCore/debugger/Debugger.cpp
  120. +59 −0 JavaScriptCore/debugger/Debugger.h
  121. +82 −0 JavaScriptCore/debugger/DebuggerCallFrame.cpp
  122. +67 −0 JavaScriptCore/debugger/DebuggerCallFrame.h
  123. +42 −0 JavaScriptCore/docs/make-bytecode-docs.pl
  124. +9 −0 JavaScriptCore/headers.pri
  125. +25 −0 JavaScriptCore/icu/LICENSE
  126. +4 −0 JavaScriptCore/icu/README
  127. +88 −0 JavaScriptCore/icu/unicode/parseerr.h
  128. +267 −0 JavaScriptCore/icu/unicode/platform.h
  129. +180 −0 JavaScriptCore/icu/unicode/putil.h
Sorry, we could not display the entire diff because too many files (6,885) changed.
View
198 Android.mk
@@ -0,0 +1,198 @@
+##
+##
+## Copyright 2007, The Android Open Source Project
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+
+BASE_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# if you need to make webcore huge (for debugging), enable this line
+#LOCAL_PRELINK_MODULE := false
+
+# Define our module and find the intermediates directory
+LOCAL_MODULE := libwebcore
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+base_intermediates := $(call local-intermediates-dir)
+
+# Using := here prevents recursive expansion
+WEBKIT_SRC_FILES :=
+
+# We have to use bison 2.3
+include $(BASE_PATH)/bison_check.mk
+
+# Include source files for JavaScriptCore
+d := JavaScriptCore
+LOCAL_PATH := $(BASE_PATH)/$d
+intermediates := $(base_intermediates)/$d
+include $(LOCAL_PATH)/Android.mk
+WEBKIT_SRC_FILES += $(addprefix $d/,$(LOCAL_SRC_FILES))
+
+# Include source files for WebCore
+d := WebCore
+LOCAL_PATH := $(BASE_PATH)/$d
+intermediates := $(base_intermediates)/$d
+include $(LOCAL_PATH)/Android.mk
+WEBKIT_SRC_FILES += $(addprefix $d/,$(LOCAL_SRC_FILES))
+
+# Include the derived source files for WebCore. Uses the same path as
+# WebCore
+include $(LOCAL_PATH)/Android.derived.mk
+WEBKIT_SRC_FILES += $(addprefix $d/,$(LOCAL_SRC_FILES))
+
+# Include source files for android WebKit port
+d := WebKit
+LOCAL_PATH := $(BASE_PATH)/$d
+intermediates := $(base_intermediates)/$d
+include $(LOCAL_PATH)/Android.mk
+WEBKIT_SRC_FILES += $(addprefix $d/,$(LOCAL_SRC_FILES))
+
+# Redefine LOCAL_PATH here so the build system is not confused
+LOCAL_PATH := $(BASE_PATH)
+
+# Define our compiler flags
+LOCAL_CFLAGS += -Wno-endif-labels -Wno-import -Wno-format
+LOCAL_CFLAGS += -fno-strict-aliasing
+LOCAL_CFLAGS += -include "WebCorePrefixAndroid.h"
+
+ifeq ($(TARGET_ARCH),arm)
+LOCAL_CFLAGS += -Darm -fvisibility=hidden
+endif
+
+ifeq ($(WEBCORE_INSTRUMENTATION),true)
+LOCAL_CFLAGS += -DANDROID_INSTRUMENT
+endif
+
+# LOCAL_LDLIBS is used in simulator builds only and simulator builds are only
+# valid on Linux
+LOCAL_LDLIBS += -lpthread -ldl
+
+# Build our list of include paths
+LOCAL_C_INCLUDES := \
+ $(call include-path-for, corecg graphics) \
+ $(JNI_H_INCLUDE) \
+ external/icu4c/common \
+ external/libxml2/include \
+ external/skia/include/effects \
+ external/skia/include/images \
+ external/skia/include/ports \
+ external/skia/include/utils \
+ external/skia/src/ports \
+ external/sqlite/dist \
+ frameworks/base/core/jni/android/graphics \
+ $(LOCAL_PATH)/WebCore \
+ $(LOCAL_PATH)/WebCore/bindings/js \
+ $(LOCAL_PATH)/WebCore/bridge \
+ $(LOCAL_PATH)/WebCore/bridge/c \
+ $(LOCAL_PATH)/WebCore/bridge/jni \
+ $(LOCAL_PATH)/WebCore/css \
+ $(LOCAL_PATH)/WebCore/dom \
+ $(LOCAL_PATH)/WebCore/editing \
+ $(LOCAL_PATH)/WebCore/history \
+ $(LOCAL_PATH)/WebCore/html \
+ $(LOCAL_PATH)/WebCore/inspector \
+ $(LOCAL_PATH)/WebCore/loader \
+ $(LOCAL_PATH)/WebCore/loader/appcache \
+ $(LOCAL_PATH)/WebCore/loader/icon \
+ $(LOCAL_PATH)/WebCore/page \
+ $(LOCAL_PATH)/WebCore/page/android \
+ $(LOCAL_PATH)/WebCore/page/animation \
+ $(LOCAL_PATH)/WebCore/platform \
+ $(LOCAL_PATH)/WebCore/platform/android \
+ $(LOCAL_PATH)/WebCore/platform/graphics \
+ $(LOCAL_PATH)/WebCore/platform/graphics/android \
+ $(LOCAL_PATH)/WebCore/platform/graphics/network \
+ $(LOCAL_PATH)/WebCore/platform/image-decoders \
+ $(LOCAL_PATH)/WebCore/platform/network \
+ $(LOCAL_PATH)/WebCore/platform/network/android \
+ $(LOCAL_PATH)/WebCore/platform/sql \
+ $(LOCAL_PATH)/WebCore/platform/text \
+ $(LOCAL_PATH)/WebCore/plugins \
+ $(LOCAL_PATH)/WebCore/rendering \
+ $(LOCAL_PATH)/WebCore/rendering/style \
+ $(LOCAL_PATH)/WebCore/storage \
+ $(LOCAL_PATH)/WebCore/xml \
+ $(LOCAL_PATH)/WebKit/android \
+ $(LOCAL_PATH)/WebKit/android/WebCoreSupport \
+ $(LOCAL_PATH)/WebKit/android/jni \
+ $(LOCAL_PATH)/WebKit/android/nav \
+ $(LOCAL_PATH)/WebKit/android/plugins \
+ $(LOCAL_PATH)/WebKit/android/stl \
+ $(LOCAL_PATH)/JavaScriptCore \
+ $(LOCAL_PATH)/JavaScriptCore/API \
+ $(LOCAL_PATH)/JavaScriptCore/VM \
+ $(LOCAL_PATH)/JavaScriptCore/debugger \
+ $(LOCAL_PATH)/JavaScriptCore/kjs \
+ $(LOCAL_PATH)/JavaScriptCore/icu \
+ $(LOCAL_PATH)/JavaScriptCore/pcre \
+ $(LOCAL_PATH)/JavaScriptCore/profiler \
+ $(LOCAL_PATH)/JavaScriptCore/runtime \
+ $(LOCAL_PATH)/JavaScriptCore/wtf \
+ $(LOCAL_PATH)/JavaScriptCore/wtf/unicode \
+ $(LOCAL_PATH)/JavaScriptCore/wtf/unicode/icu \
+ $(LOCAL_PATH)/JavaScriptCore/ForwardingHeaders \
+ $(base_intermediates)/JavaScriptCore \
+ $(base_intermediates)/JavaScriptCore/kjs \
+ $(base_intermediates)/JavaScriptCore/runtime \
+ $(base_intermediates)/WebCore/ \
+ $(base_intermediates)/WebCore/bindings/js \
+ $(base_intermediates)/WebCore/css \
+ $(base_intermediates)/WebCore/dom \
+ $(base_intermediates)/WebCore/html \
+ $(base_intermediates)/WebCore/inspector \
+ $(base_intermediates)/WebCore/loader/appcache \
+ $(base_intermediates)/WebCore/page \
+ $(base_intermediates)/WebCore/platform \
+ $(base_intermediates)/WebCore/plugins \
+ $(base_intermediates)/WebCore/xml
+
+# Build the list of shared libraries
+LOCAL_SHARED_LIBRARIES := \
+ libandroid_runtime \
+ libnativehelper \
+ libsqlite \
+ libsgl \
+ libcorecg \
+ libutils \
+ libui \
+ libcutils \
+ libicuuc \
+ libicudata \
+ libicui18n \
+ libmedia
+
+# We have to use the android version of libdl when we are not on the simulator
+ifneq ($(TARGET_SIMULATOR),true)
+LOCAL_SHARED_LIBRARIES += libdl
+endif
+
+# Build the list of static libraries
+LOCAL_STATIC_LIBRARIES := libxml2
+
+# Redefine LOCAL_SRC_FILES to be all the WebKit source files
+LOCAL_SRC_FILES := $(WEBKIT_SRC_FILES)
+
+# Build the library all at once
+include $(BUILD_SHARED_LIBRARY)
+
+# Build the plugin test separately from libwebcore
+include $(BASE_PATH)/WebKit/android/plugins/sample/Android.mk
+
+# Build the wds client
+include $(BASE_PATH)/WebKit/android/wds/client/Android.mk
+
+# Build the performance command line tool.
+# XXX: Uncomment this include to build webcore_test. In order for the test to
+# link with libwebcore, remove -fvisibility=hidden from LOCAL_CFLAGS above
+#include $(BASE_PATH)/perf/Android.mk
View
2,862 ChangeLog
2,862 additions, 0 deletions not shown
View
487 GNUmakefile.am
@@ -0,0 +1,487 @@
+# Top-level Makefile rule for automake
+#
+# Variable conventions:
+#
+# _h_api = API headers that will be installed and included in the distribution
+# _cppflags = flags that will be passed to the C/CXX Preprocessor
+# _sources = sources that will be compiled and included in the distribution
+# _built_sources = files that will be autogenerated by the build system and
+# will be part of the _SOURCES primary
+# _built_nosources = files that are autogenerated but are not part of the
+# _SOURCES primary
+# _cleanfiles = files that will be removed by the clean target
+#
+# Sources, headers, flags, etc... should be added to the respective variables
+# with the above suffix, e.g, webcore-specific sources should go to
+# webcore_sources, gtk port API and WebCoreSupport parts to webkitgtk_sources,
+# etc... The only exceptions are the global variables. See Global Variables
+# below.
+#
+# Global Variables
+#
+# global_cppflags = CPPFLAGS that apply to JSC, WebCore, and to any
+# specific port
+# global_cflags = CFLAGS that apply to JSC, WebCore, and to
+# any specific port
+# global_cxxflags = CXXFLAGS that apply to JSC, WebCore, and to any
+# specific port
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+# Directory for autogenerated sources
+GENSOURCES := $(top_builddir)/DerivedSources
+GENPROGRAMS := $(top_builddir)/Programs
+
+# Script for creating hash tables
+CREATE_HASH_TABLE = $(srcdir)/JavaScriptCore/kjs/create_hash_table
+
+# Libraries and support components
+bin_PROGRAMS :=
+
+noinst_PROGRAMS :=
+
+noinst_HEADERS :=
+
+lib_LIBRARIES :=
+
+IDL_BINDINGS :=
+
+# Global flags to CPP
+global_cppflags :=
+
+global_cppflags += \
+ -DWTF_USE_ICU_UNICODE=1
+
+# Default compiler flags
+global_cflags := \
+ -Wall -W -Wcast-align -Wchar-subscripts -Wreturn-type \
+ -Wformat -Wformat-security -Wno-format-y2k -Wundef \
+ -Wmissing-format-attribute -Wpointer-arith -Wwrite-strings \
+ -Wno-unused-parameter -Wno-parentheses
+
+global_cxxflags := \
+ $(SYMBOL_VISIBILITY_INLINES)
+
+if !ENABLE_DEBUG
+global_cflags += \
+ -fno-exceptions \
+ $(SYMBOL_VISIBILITY)
+
+global_cxxflags += \
+ -fno-rtti
+endif
+
+# -no-undefined required for building DLLs on Windows
+# It breaks the build on other platforms, so we use it conditionally
+if OS_WIN32
+no_undefined = -no-undefined
+endif
+
+# Shared libraries
+lib_LTLIBRARIES = \
+ libwebkit-1.0.la
+
+# Convenience libraries
+noinst_LTLIBRARIES = \
+ libJavaScriptCore.la \
+ libWebCore.la
+
+#
+# JavaScriptCore
+javascriptcore_h_api :=
+javascriptcore_cppflags:=
+javascriptcore_sources :=
+javascriptcore_built_sources :=
+javascriptcore_built_nosources :=
+javascriptcore_dist :=
+
+javascriptcore_cppflags += \
+ -I$(srcdir)/JavaScriptCore \
+ -I$(srcdir)/JavaScriptCore/ForwardingHeaders \
+ -I$(srcdir)/JavaScriptCore/wtf \
+ -I$(srcdir)/JavaScriptCore/kjs \
+ -I$(top_builddir)/DerivedSources
+
+# The variables above are already included below so no need to touch
+# these variables unless you really have to
+nodist_EXTRA_libJavaScriptCore_la_SOURCES = \
+ $(javascriptcore_built_nosources)
+
+nodist_libJavaScriptCore_la_SOURCES = \
+ $(javascriptcore_built_sources)
+
+libJavaScriptCore_ladir = $(prefix)/include/webkit-1.0/JavaScriptCore
+libJavaScriptCore_la_HEADERS = $(javascriptcore_h_api)
+
+libJavaScriptCore_la_SOURCES = \
+ $(javascriptcore_sources)
+
+libJavaScriptCore_la_LIBADD = \
+ $(UNICODE_LIBS) \
+ $(GLOBALDEPS_LIBS) \
+ -lpthread
+
+libJavaScriptCore_la_CXXFLAGS = \
+ -fstrict-aliasing \
+ -O3 \
+ $(global_cxxflags) \
+ $(global_cflags) \
+ $(GLOBALDEPS_CFLAGS) \
+ $(UNICODE_CFLAGS)
+
+libJavaScriptCore_la_CFLAGS = \
+ -fstrict-aliasing \
+ -O3 \
+ $(global_cflags) \
+ $(GLOBALDEPS_CFLAGS) \
+ $(UNICODE_CFLAGS)
+
+libJavaScriptCore_la_CPPFLAGS = \
+ $(global_cppflags) \
+ $(javascriptcore_cppflags)
+
+#
+# WebCore
+webcore_cppflags :=
+webcore_sources :=
+webcore_libadd :=
+webcore_built_sources :=
+webcore_built_nosources :=
+webcore_dist :=
+webcoregtk_cppflags :=
+webcoregtk_sources :=
+
+nodist_libWebCore_la_SOURCES = \
+ $(webcore_built_sources)
+
+libWebCore_la_SOURCES = \
+ $(webcore_sources) \
+ $(webcoregtk_sources)
+
+libWebCore_la_CXXFLAGS = \
+ -fno-strict-aliasing \
+ -O2 \
+ $(global_cxxflags) \
+ $(global_cflags) \
+ $(GLOBALDEPS_CFLAGS) \
+ $(UNICODE_CFLAGS) \
+ $(WEBKITDEPS_CFLAGS) \
+ $(XT_CFLAGS) \
+ $(LIBCURL_CFLAGS) \
+ $(LIBSOUP_CFLAGS) \
+ $(FREETYPE_CFLAGS) \
+ $(SQLITE3_CFLAGS) \
+ $(GSTREAMER_CFLAGS) \
+ $(LIBXSLT_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ $(HILDON_CFLAGS)
+
+libWebCore_la_CFLAGS = \
+ -fno-strict-aliasing \
+ -O2 \
+ $(global_cflags) \
+ $(GLOBALDEPS_CFLAGS) \
+ $(UNICODE_CFLAGS) \
+ $(WEBKITDEPS_CFLAGS) \
+ $(XT_CFLAGS) \
+ $(LIBCURL_CFLAGS) \
+ $(LIBSOUP_CFLAGS) \
+ $(FREETYPE_CFLAGS) \
+ $(SQLITE3_CFLAGS) \
+ $(GSTREAMER_CFLAGS) \
+ $(LIBXSLT_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ $(HILDON_CFLAGS)
+
+libWebCore_la_CPPFLAGS = \
+ $(global_cppflags) \
+ $(webcore_cppflags) \
+ $(javascriptcore_cppflags) \
+ $(webcoregtk_cppflags) \
+ $(HILDON_CPPFLAGS)
+
+libWebCore_la_LIBADD = \
+ libJavaScriptCore.la \
+ $(webcore_libadd) \
+ $(GLOBALDEPS_LIBS) \
+ $(WEBKITDEPS_LIBS) \
+ $(XT_LIBS) \
+ $(LIBCURL_LIBS) \
+ $(LIBSOUP_LIBS) \
+ $(FREETYPE_LIBS) \
+ $(UNICODE_LIBS) \
+ $(SQLITE3_LIBS) \
+ $(GSTREAMER_LIBS) \
+ $(LIBXSLT_LIBS) \
+ $(HILDON_LIBS) \
+ $(JPEG_LIBS) \
+ -lpthread
+
+# WebKit
+webkitgtk_h_api :=
+webkitgtk_sources :=
+webkitgtk_cppflags :=
+webkitgtk_built_sources :=
+webkitgtk_built_nosources :=
+webkitgtk_cleanfiles :=
+
+nodist_libwebkit_1_0_la_SOURCES = \
+ $(webkitgtk_built_sources)
+
+libwebkit_1_0_ladir = $(prefix)/include/webkit-1.0/webkit
+libwebkit_1_0_la_HEADERS = \
+ $(webkitgtk_h_api) \
+ WebKit/gtk/webkit/webkitenumtypes.h
+
+libwebkit_1_0_la_SOURCES = \
+ $(webkitgtk_sources)
+
+libwebkit_1_0_la_CXXFLAGS = \
+ $(libWebCore_la_CXXFLAGS)
+
+libwebkit_1_0_la_CFLAGS = \
+ $(libWebCore_la_CFLAGS)
+
+libwebkit_1_0_la_CPPFLAGS = \
+ $(libWebCore_la_CPPFLAGS) \
+ $(webkitgtk_cppflags)
+
+libwebkit_1_0_la_LDFLAGS = \
+ $(COVERAGE_LDFLAGS) \
+ -version-info @LIBWEBKITGTK_VERSION@ \
+ -Wl,--version-script,$(srcdir)/symbols.filter \
+ $(no_undefined)
+
+libwebkit_1_0_la_LIBADD = \
+ libWebCore.la
+
+#
+# Extra checks and flags
+global_cppflags += \
+ -DBUILDING_CAIRO__=1 \
+ -DBUILDING_GTK__=1 \
+ -DWTF_CHANGES
+
+if !ENABLE_FAST_MALLOC
+global_cppflags += \
+ -DUSE_SYSTEM_MALLOC
+endif
+
+if TARGET_X11
+global_cppflags += -DXP_UNIX
+endif
+
+if !ENABLE_DEBUG
+global_cppflags += -DNDEBUG
+else
+webcoregtk_cppflags += \
+ -DG_DISABLE_DEPRECATED \
+ -DGDK_PIXBUF_DISABLE_DEPRECATED \
+ -DGDK_DISABLE_DEPRECATED \
+ -DGTK_DISABLE_DEPRECATED \
+ -DPANGO_DISABLE_DEPRECATED
+
+# Might be useful in the future
+# -DGDK_MULTIHEAD_SAFE \
+# -DGTK_MULTIHEAD_SAFE
+endif
+
+if !ENABLE_DATABASE
+global_cppflags += -DENABLE_DATABASE=0
+endif
+
+if !ENABLE_ICONDATABASE
+global_cppflags += -DENABLE_ICONDATABASE=0
+endif
+
+if ENABLE_COVERAGE
+global_cppflags += \
+ -DGCC_GENERATE_TEST_COVERAGE_FILES \
+ -DGCC_INSTRUMENT_PROGRAM_FLOW_ARCS
+endif
+
+if ENABLE_VIDEO
+webcore_libadd += -lgstinterfaces-0.10 -lgstvideo-0.10
+endif
+
+webkitgtk_h_api += \
+ WebKit/gtk/webkit/webkit.h \
+ WebKit/gtk/webkit/webkitdefines.h \
+ WebKit/gtk/webkit/webkitnetworkrequest.h \
+ WebKit/gtk/webkit/webkitversion.h \
+ WebKit/gtk/webkit/webkitwebbackforwardlist.h \
+ WebKit/gtk/webkit/webkitwebframe.h \
+ WebKit/gtk/webkit/webkitwebhistoryitem.h \
+ WebKit/gtk/webkit/webkitwebsettings.h \
+ WebKit/gtk/webkit/webkitwebview.h
+
+webkitgtk_built_sources += \
+ DerivedSources/webkitenumtypes.cpp \
+ DerivedSources/webkitmarshal.cpp \
+ DerivedSources/webkitmarshal.h \
+ WebKit/gtk/webkit/webkitenumtypes.h
+
+webkitgtk_sources += \
+ WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp \
+ WebKit/gtk/WebCoreSupport/ChromeClientGtk.h \
+ WebKit/gtk/WebCoreSupport/ContextMenuClientGtk.cpp \
+ WebKit/gtk/WebCoreSupport/ContextMenuClientGtk.h \
+ WebKit/gtk/WebCoreSupport/DragClientGtk.cpp \
+ WebKit/gtk/WebCoreSupport/DragClientGtk.h \
+ WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp \
+ WebKit/gtk/WebCoreSupport/EditorClientGtk.h \
+ WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp \
+ WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h \
+ WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp \
+ WebKit/gtk/WebCoreSupport/InspectorClientGtk.h \
+ WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp \
+ WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h \
+ WebKit/gtk/webkit/webkitnetworkrequest.cpp \
+ WebKit/gtk/webkit/webkitprivate.cpp \
+ WebKit/gtk/webkit/webkitprivate.h \
+ WebKit/gtk/webkit/webkitversion.cpp \
+ WebKit/gtk/webkit/webkitwebbackforwardlist.cpp \
+ WebKit/gtk/webkit/webkitwebframe.cpp \
+ WebKit/gtk/webkit/webkitwebhistoryitem.cpp \
+ WebKit/gtk/webkit/webkitwebsettings.cpp \
+ WebKit/gtk/webkit/webkitwebview.cpp
+
+webkitgtk_cppflags += \
+ -DBUILDING_WEBKIT \
+ -I$(srcdir)/WebKit/gtk \
+ -I$(srcdir)/WebKit/gtk/WebCoreSupport \
+ -I$(srcdir)/WebKit/gtk/webkit \
+ -I$(top_builddir)/WebKit/gtk/webkit
+
+webkitgtk_cleanfiles += \
+ $(top_builddir)/Programs/GtkLauncher \
+ $(top_builddir)/WebKit/gtk/webkit-1.0.pc
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = WebKit/gtk/webkit-1.0.pc
+
+stamp_files := \
+ stamp-webkitmarshal.cpp \
+ stamp-webkitmarshal.h \
+ stamp-webkitenumtypes.cpp \
+ stamp-webkitenumtypes.h
+
+WEBKIT_MARSHAL = $(GENSOURCES)/webkitmarshal
+WEBKIT_MARSHAL_LIST = $(WEBKIT_MARSHAL).list
+
+$(WEBKIT_MARSHAL_LIST): $(webkitgtk_sources) GNUmakefile.am
+ ( cd $(top_srcdir) && \
+ sed -n -e 's/.*webkit_marshal_\([[:upper:][:digit:]]*__[[:upper:][:digit:]_]*\).*/\1/p' \
+ $(webkitgtk_sources) ) \
+ | sed -e 's/__/:/' -e 'y/_/,/' | sort -u > $@.tmp
+ if cmp -s $@.tmp $@; then \
+ rm $@.tmp; \
+ else \
+ mv $@.tmp $@; \
+ fi
+
+$(WEBKIT_MARSHAL).cpp: stamp-webkitmarshal.cpp
+ @true
+
+$(WEBKIT_MARSHAL).h: stamp-webkitmarshal.h
+ @true
+
+stamp-webkitmarshal.cpp: $(WEBKIT_MARSHAL_LIST)
+ echo "extern \"C\" {" > $(WEBKIT_MARSHAL).cpp && \
+ $(GLIB_GENMARSHAL) --prefix=webkit_marshal $(WEBKIT_MARSHAL_LIST) --body >> $(WEBKIT_MARSHAL).cpp && echo '}' >> $(WEBKIT_MARSHAL).cpp && \
+ echo timestamp > $(@F)
+
+stamp-webkitmarshal.h: $(WEBKIT_MARSHAL_LIST)
+ $(GLIB_GENMARSHAL) --prefix=webkit_marshal $(WEBKIT_MARSHAL_LIST) --header > $(WEBKIT_MARSHAL).h && \
+ echo timestamp > $(@F)
+
+WebKit/gtk/webkit/webkitenumtypes.h: stamp-webkitenumtypes.h
+ @true
+stamp-webkitenumtypes.h: $(webkitgtk_h_api) GNUmakefile
+ (cd $(srcdir) \
+ && glib-mkenums \
+ --fhead "#ifndef WEBKIT_ENUM_TYPES_H\n" \
+ --fhead "#define WEBKIT_ENUM_TYPES_H\n\n" \
+ --fhead "#include <glib-object.h>\n\n" \
+ --fhead "#include <webkit/webkitdefines.h>\n\n" \
+ --fhead "G_BEGIN_DECLS\n\n" \
+ --ftail "G_END_DECLS\n\n" \
+ --ftail "#endif\n" \
+ --fprod "#include <@filename@>\n\n" \
+ --eprod "#define WEBKIT_TYPE_@ENUMSHORT@ @enum_name@_get_type()\n\n" \
+ --eprod "WEBKIT_API GType\n@enum_name@_get_type(void);\n\n" \
+ $(webkitgtk_h_api) | \
+ sed 's,WebKit/gtk/,,' | \
+ sed 's,web_kit,webkit,' | \
+ sed 's,WEBKIT_TYPE_KIT,WEBKIT_TYPE,' \
+ ) > xgen-gth \
+ && (cmp -s xgen-gth WebKit/gtk/webkit/webkitenumtypes.h || cp xgen-gth WebKit/gtk/webkit/webkitenumtypes.h) \
+ && rm -f xgen-gth \
+ && echo timestamp > $(@F)
+
+DerivedSources/webkitenumtypes.cpp: $(webkitgtk_h_api) GNUmakefile
+ (cd $(srcdir) \
+ && glib-mkenums \
+ --fhead "#include <config.h>\n" \
+ --fhead "#include <glib-object.h>\n" \
+ --fhead "#include \"$(top_builddir)/WebKit/gtk/webkit/webkitenumtypes.h\"\n\n" \
+ --fhead "extern \"C\" {\n\n" \
+ --fprod "\n/* enumerations from \"@filename@\" */" \
+ --vhead "static const G@Type@Value _@enum_name@_values[] = {" \
+ --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
+ --vtail " { 0, NULL, NULL }\n};\n\n" \
+ --vtail "GType @enum_name@_get_type(void)\n{\n" \
+ --vtail " static GType type = 0;\n\n" \
+ --vtail " if (!type)\n" \
+ --vtail " type = g_@type@_register_static(\"@EnumName@\", _@enum_name@_values);\n\n" \
+ --vtail " return type;\n}\n\n" \
+ --ftail "}\n" \
+ $(webkitgtk_h_api) | \
+ sed 's,web_kit,webkit,' \
+ ) > xgen-gtc \
+ && cp xgen-gtc $@ \
+ && rm -f xgen-gtc
+
+# END WEBKIT GTK+
+#
+# Files that will be distributed
+EXTRA_DIST = \
+ $(javascriptcore_dist) \
+ $(webcore_dist) \
+ symbols.filter
+
+# Files that will be cleaned
+MAINTAINERCLEANFILES := $(stamp_files) $(BUILT_SOURCES)
+DISTCLEANFILES := $(stamp_files) $(BUILT_SOURCES)
+CLEANFILES := $(stamp_files) $(BUILT_SOURCES)
+
+# Include module makefiles
+include JavaScriptCore/GNUmakefile.am
+include WebCore/GNUmakefile.am
+include WebKitTools/GNUmakefile.am
+
+# Autogenerated sources
+BUILT_SOURCES = \
+ $(javascriptcore_built_sources) \
+ $(javascriptcore_built_nosources) \
+ $(webcore_built_sources) \
+ $(webcore_built_nosources) \
+ $(webkitgtk_built_sources) \
+ $(webkitgtk_built_nosources)
+
+# Project-wide clean rules
+CLEANFILES += \
+ $(webkitgtk_cleanfiles)
+
+MAINTAINERCLEANFILES += \
+ $(srcdir)/aconfig.h.in \
+ configure \
+ config.* \
+ GNUmakefile.in \
+ INSTALL \
+ README
+
+# remove built sources and program directories
+clean-local:
+ -rm -rf $(GENSOURCES) $(GENPROGRAMS)
View
111 JavaScriptCore/API/APICast.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef APICast_h
+#define APICast_h
+
+#include "ustring.h"
+#include "ExecState.h"
+
+typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
+typedef const struct OpaqueJSContext* JSContextRef;
+typedef struct OpaqueJSContext* JSGlobalContextRef;
+typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
+typedef const struct OpaqueJSValue* JSValueRef;
+typedef struct OpaqueJSValue* JSObjectRef;
+
+/* Opaque typing convenience methods */
+
+inline JSC::ExecState* toJS(JSContextRef c)
+{
+ return reinterpret_cast<JSC::ExecState*>(const_cast<OpaqueJSContext*>(c));
+}
+
+inline JSC::ExecState* toJS(JSGlobalContextRef c)
+{
+ return reinterpret_cast<JSC::ExecState*>(c);
+}
+
+inline JSC::JSValue* toJS(JSValueRef v)
+{
+ return reinterpret_cast<JSC::JSValue*>(const_cast<OpaqueJSValue*>(v));
+}
+
+inline JSC::JSObject* toJS(JSObjectRef o)
+{
+ return reinterpret_cast<JSC::JSObject*>(o);
+}
+
+inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
+{
+ return reinterpret_cast<JSC::PropertyNameArray*>(a);
+}
+
+inline JSC::JSGlobalData* toJS(JSContextGroupRef g)
+{
+ return reinterpret_cast<JSC::JSGlobalData*>(const_cast<OpaqueJSContextGroup*>(g));
+}
+
+inline JSValueRef toRef(JSC::JSValue* v)
+{
+ return reinterpret_cast<JSValueRef>(v);
+}
+
+inline JSValueRef* toRef(JSC::JSValue** v)
+{
+ return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v));
+}
+
+inline JSObjectRef toRef(JSC::JSObject* o)
+{
+ return reinterpret_cast<JSObjectRef>(o);
+}
+
+inline JSObjectRef toRef(const JSC::JSObject* o)
+{
+ return reinterpret_cast<JSObjectRef>(const_cast<JSC::JSObject*>(o));
+}
+
+inline JSContextRef toRef(JSC::ExecState* e)
+{
+ return reinterpret_cast<JSContextRef>(e);
+}
+
+inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e)
+{
+ return reinterpret_cast<JSGlobalContextRef>(e);
+}
+
+inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)
+{
+ return reinterpret_cast<JSPropertyNameAccumulatorRef>(l);
+}
+
+inline JSContextGroupRef toRef(JSC::JSGlobalData* g)
+{
+ return reinterpret_cast<JSContextGroupRef>(g);
+}
+
+#endif // APICast_h
View
116 JavaScriptCore/API/JSBase.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSBase.h"
+#include "JSBasePrivate.h"
+
+#include "APICast.h"
+#include "completion.h"
+#include "OpaqueJSString.h"
+#include "SourceCode.h"
+#include <runtime/ExecState.h>
+#include <runtime/InitializeThreading.h>
+#include <kjs/interpreter.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <runtime/JSObject.h>
+
+using namespace JSC;
+
+JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ JSObject* jsThisObject = toJS(thisObject);
+
+ // Interpreter::evaluate sets "this" to the global object if it is NULL
+ JSGlobalObject* globalObject = exec->dynamicGlobalObject();
+ SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
+ Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
+
+ if (completion.complType() == Throw) {
+ if (exception)
+ *exception = toRef(completion.value());
+ return 0;
+ }
+
+ if (completion.value())
+ return toRef(completion.value());
+
+ // happens, for example, when the only statement is an empty (';') statement
+ return toRef(jsUndefined());
+}
+
+bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
+ Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), source);
+ if (completion.complType() == Throw) {
+ if (exception)
+ *exception = toRef(completion.value());
+ return false;
+ }
+
+ return true;
+}
+
+void JSGarbageCollect(JSContextRef ctx)
+{
+ // We used to recommend passing NULL as an argument here, which caused the only heap to be collected.
+ // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC
+ // will happen when the context group is destroyed).
+ // Because the function argument was originally ignored, some clients may pass their released context here,
+ // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
+ if (!ctx)
+ return;
+
+ ExecState* exec = toJS(ctx);
+ JSGlobalData& globalData = exec->globalData();
+
+ JSLock lock(globalData.isSharedInstance);
+
+ if (!globalData.heap.isBusy())
+ globalData.heap.collect();
+
+ // FIXME: Perhaps we should trigger a second mark and sweep
+ // once the garbage collector is done if this is called when
+ // the collector is busy.
+}
+
+void JSReportExtraMemoryCost(JSContextRef ctx, size_t size)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ exec->globalData().heap.reportExtraMemoryCost(size);
+}
View
130 JavaScriptCore/API/JSBase.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSBase_h
+#define JSBase_h
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+/* JavaScript engine interface */
+
+/*! @typedef JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. */
+typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
+
+/*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */
+typedef const struct OpaqueJSContext* JSContextRef;
+
+/*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */
+typedef struct OpaqueJSContext* JSGlobalContextRef;
+
+/*! @typedef JSStringRef A UTF16 character buffer. The fundamental string representation in JavaScript. */
+typedef struct OpaqueJSString* JSStringRef;
+
+/*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */
+typedef struct OpaqueJSClass* JSClassRef;
+
+/*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */
+typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef;
+
+/*! @typedef JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties. */
+typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
+
+
+/* JavaScript data types */
+
+/*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */
+typedef const struct OpaqueJSValue* JSValueRef;
+
+/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
+typedef struct OpaqueJSValue* JSObjectRef;
+
+/* JavaScript symbol exports */
+
+#undef JS_EXPORT
+#if defined(__GNUC__)
+ #define JS_EXPORT __attribute__((visibility("default")))
+#elif defined(WIN32) || defined(_WIN32)
+ /*
+ * TODO: Export symbols with JS_EXPORT when using MSVC.
+ * See http://bugs.webkit.org/show_bug.cgi?id=16227
+ */
+ #define JS_EXPORT
+#else
+ #define JS_EXPORT
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Script Evaluation */
+
+/*!
+@function JSEvaluateScript
+@abstract Evaluates a string of JavaScript.
+@param ctx The execution context to use.
+@param script A JSString containing the script to evaluate.
+@param thisObject The object to use as "this," or NULL to use the global object as "this."
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+@result The JSValue that results from evaluating script, or NULL if an exception is thrown.
+*/
+JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function JSCheckScriptSyntax
+@abstract Checks for syntax errors in a string of JavaScript.
+@param ctx The execution context to use.
+@param script A JSString containing the script to check for syntax errors.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
+@result true if the script is syntactically correct, otherwise false.
+*/
+JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function JSGarbageCollect
+@abstract Performs a JavaScript garbage collection.
+@param ctx The execution context to use.
+@discussion JavaScript values that are on the machine stack, in a register,
+ protected by JSValueProtect, set as the global object of an execution context,
+ or reachable from any such value will not be collected.
+
+ During JavaScript execution, you are not required to call this function; the
+ JavaScript engine will garbage collect as needed. JavaScript values created
+ within a context group are automatically destroyed when the last reference
+ to the context group is released.
+*/
+JS_EXPORT void JSGarbageCollect(JSContextRef ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSBase_h */
View
52 JavaScriptCore/API/JSBasePrivate.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSBasePrivate_h
+#define JSBasePrivate_h
+
+#include <JavaScriptCore/JSBase.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@function
+@abstract Reports an object's non-GC memory payload to the garbage collector.
+@param ctx The execution context to use.
+@param size The payload's size, in bytes.
+@discussion Use this function to notify the garbage collector that a GC object
+owns a large non-GC memory region. Calling this function will encourage the
+garbage collector to collect soon, hoping to reclaim that large non-GC memory
+region.
+*/
+JS_EXPORT void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSBasePrivate_h */
View
79 JavaScriptCore/API/JSCallbackConstructor.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSCallbackConstructor.h"
+
+#include "APICast.h"
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <runtime/ObjectPrototype.h>
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
+
+JSCallbackConstructor::JSCallbackConstructor(PassRefPtr<StructureID> structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
+ : JSObject(structure)
+ , m_class(jsClass)
+ , m_callback(callback)
+{
+ if (m_class)
+ JSClassRetain(jsClass);
+}
+
+JSCallbackConstructor::~JSCallbackConstructor()
+{
+ if (m_class)
+ JSClassRelease(m_class);
+}
+
+static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef constructorRef = toRef(constructor);
+
+ JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
+ if (callback) {
+ int argumentCount = static_cast<int>(args.size());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(args.at(exec, i));
+
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(callback(ctx, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ }
+
+ return toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0));
+}
+
+ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData)
+{
+ constructData.native.function = constructJSCallback;
+ return ConstructTypeHost;
+}
+
+} // namespace JSC
View
57 JavaScriptCore/API/JSCallbackConstructor.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSCallbackConstructor_h
+#define JSCallbackConstructor_h
+
+#include "JSObjectRef.h"
+#include <runtime/JSObject.h>
+
+namespace JSC {
+
+class JSCallbackConstructor : public JSObject {
+public:
+ JSCallbackConstructor(PassRefPtr<StructureID>, JSClassRef, JSObjectCallAsConstructorCallback);
+ virtual ~JSCallbackConstructor();
+ JSClassRef classRef() const { return m_class; }
+ JSObjectCallAsConstructorCallback callback() const { return m_callback; }
+ static const ClassInfo info;
+
+ static PassRefPtr<StructureID> createStructureID(JSValue* proto)
+ {
+ return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance | HasStandardGetOwnPropertySlot));
+ }
+
+private:
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ JSClassRef m_class;
+ JSObjectCallAsConstructorCallback m_callback;
+};
+
+} // namespace JSC
+
+#endif // JSCallbackConstructor_h
View
70 JavaScriptCore/API/JSCallbackFunction.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include <wtf/Platform.h>
+#include "JSCallbackFunction.h"
+
+#include "APICast.h"
+#include "JSFunction.h"
+#include "FunctionPrototype.h"
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackFunction);
+
+const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 };
+
+JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name)
+ : InternalFunction(&exec->globalData(), exec->lexicalGlobalObject()->callbackFunctionStructure(), name)
+ , m_callback(callback)
+{
+}
+
+JSValue* JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef functionRef = toRef(functionObject);
+ JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec));
+
+ int argumentCount = static_cast<int>(args.size());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(args.at(exec, i));
+
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(static_cast<JSCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+}
+
+CallType JSCallbackFunction::getCallData(CallData& callData)
+{
+ callData.native.function = call;
+ return CallTypeHost;
+}
+
+} // namespace JSC
View
58 JavaScriptCore/API/JSCallbackFunction.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSCallbackFunction_h
+#define JSCallbackFunction_h
+
+#include "InternalFunction.h"
+#include "JSObjectRef.h"
+
+namespace JSC {
+
+class JSCallbackFunction : public InternalFunction {
+public:
+ JSCallbackFunction(ExecState*, JSObjectCallAsFunctionCallback, const Identifier& name);
+
+ static const ClassInfo info;
+
+ // InternalFunction mish-mashes constructor and function behavior -- we should
+ // refactor the code so this override isn't necessary
+ static PassRefPtr<StructureID> createStructureID(JSValue* proto)
+ {
+ return StructureID::create(proto, TypeInfo(ObjectType, HasStandardGetOwnPropertySlot));
+ }
+
+private:
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ static JSValue* call(ExecState*, JSObject*, JSValue*, const ArgList&);
+
+ JSObjectCallAsFunctionCallback m_callback;
+};
+
+} // namespace JSC
+
+#endif // JSCallbackFunction_h
View
41 JavaScriptCore/API/JSCallbackObject.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSCallbackObject.h"
+
+#include "collector.h"
+
+namespace JSC {
+
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSObject>);
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSGlobalObject>);
+
+// Define the two types of JSCallbackObjects we support.
+template <> const ClassInfo JSCallbackObject<JSObject>::info = { "CallbackObject", 0, 0, 0 };
+template <> const ClassInfo JSCallbackObject<JSGlobalObject>::info = { "CallbackGlobalObject", 0, 0, 0 };
+
+} // namespace JSC
View
115 JavaScriptCore/API/JSCallbackObject.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSCallbackObject_h
+#define JSCallbackObject_h
+
+#include "JSObjectRef.h"
+#include "JSValueRef.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+template <class Base>
+class JSCallbackObject : public Base {
+public:
+ JSCallbackObject(ExecState*, PassRefPtr<StructureID>, JSClassRef, void* data);
+ JSCallbackObject(JSClassRef);
+ virtual ~JSCallbackObject();
+
+ void setPrivate(void* data);
+ void* getPrivate();
+
+ static const ClassInfo info;
+
+ JSClassRef classRef() const { return m_callbackObjectData->jsClass; }
+ bool inherits(JSClassRef) const;
+
+ static PassRefPtr<StructureID> createStructureID(JSValue* proto)
+ {
+ return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance | OverridesHasInstance));
+ }
+
+private:
+ virtual UString className() const;
+
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, unsigned, PropertySlot&);
+
+ virtual void put(ExecState*, const Identifier&, JSValue*, PutPropertySlot&);
+
+ virtual bool deleteProperty(ExecState*, const Identifier&);
+ virtual bool deleteProperty(ExecState*, unsigned);
+
+ virtual bool hasInstance(ExecState* exec, JSValue* value, JSValue* proto);
+
+ virtual void getPropertyNames(ExecState*, PropertyNameArray&);
+
+ virtual double toNumber(ExecState*) const;
+ virtual UString toString(ExecState*) const;
+
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ void init(ExecState*);
+
+ static JSCallbackObject* asCallbackObject(JSValue*);
+
+ static JSValue* call(ExecState*, JSObject* functionObject, JSValue* thisValue, const ArgList&);
+ static JSObject* construct(ExecState*, JSObject* constructor, const ArgList&);
+
+ static JSValue* cachedValueGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* staticValueGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* staticFunctionGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* callbackGetter(ExecState*, const Identifier&, const PropertySlot&);
+
+ struct JSCallbackObjectData {
+ JSCallbackObjectData(void* privateData, JSClassRef jsClass)
+ : privateData(privateData)
+ , jsClass(jsClass)
+ {
+ JSClassRetain(jsClass);
+ }
+
+ ~JSCallbackObjectData()
+ {
+ JSClassRelease(jsClass);
+ }
+
+ void* privateData;
+ JSClassRef jsClass;
+ };
+
+ OwnPtr<JSCallbackObjectData> m_callbackObjectData;
+};
+
+} // namespace JSC
+
+// include the actual template class implementation
+#include "JSCallbackObjectFunctions.h"
+
+#endif // JSCallbackObject_h
View
507 JavaScriptCore/API/JSCallbackObjectFunctions.h
@@ -0,0 +1,507 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "APICast.h"
+#include "Error.h"
+#include "JSCallbackFunction.h"
+#include "JSClassRef.h"
+#include "JSGlobalObject.h"
+#include "JSLock.h"
+#include "JSObjectRef.h"
+#include "JSString.h"
+#include "JSStringRef.h"
+#include "OpaqueJSString.h"
+#include "PropertyNameArray.h"
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+template <class Base>
+inline JSCallbackObject<Base>* JSCallbackObject<Base>::asCallbackObject(JSValue* value)
+{
+ ASSERT(asObject(value)->inherits(&info));
+ return static_cast<JSCallbackObject*>(asObject(value));
+}
+
+template <class Base>
+JSCallbackObject<Base>::JSCallbackObject(ExecState* exec, PassRefPtr<StructureID> structure, JSClassRef jsClass, void* data)
+ : Base(structure)
+ , m_callbackObjectData(new JSCallbackObjectData(data, jsClass))
+{
+ init(exec);
+}
+
+// Global object constructor.
+// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one.
+template <class Base>
+JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass)
+ : Base()
+ , m_callbackObjectData(new JSCallbackObjectData(0, jsClass))
+{
+ ASSERT(Base::isGlobalObject());
+ init(static_cast<JSGlobalObject*>(this)->globalExec());
+}
+
+template <class Base>
+void JSCallbackObject<Base>::init(ExecState* exec)
+{
+ ASSERT(exec);
+
+ Vector<JSObjectInitializeCallback, 16> initRoutines;
+ JSClassRef jsClass = classRef();
+ do {
+ if (JSObjectInitializeCallback initialize = jsClass->initialize)
+ initRoutines.append(initialize);
+ } while ((jsClass = jsClass->parentClass));
+
+ // initialize from base to derived
+ for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) {
+ JSLock::DropAllLocks dropAllLocks(exec);
+ JSObjectInitializeCallback initialize = initRoutines[i];
+ initialize(toRef(exec), toRef(this));
+ }
+}
+
+template <class Base>
+JSCallbackObject<Base>::~JSCallbackObject()
+{
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectFinalizeCallback finalize = jsClass->finalize)
+ finalize(thisRef);
+}
+
+template <class Base>
+UString JSCallbackObject<Base>::className() const
+{
+ UString thisClassName = classRef()->className();
+ if (!thisClassName.isNull())
+ return thisClassName;
+
+ return Base::className();
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ // optional optimization to bypass getProperty in cases when we only need to know if the property exists
+ if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
+ slot.setCustom(this, callbackGetter);
+ return true;
+ }
+ } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) {
+ // cache the value so we don't have to compute it again
+ // FIXME: This violates the PropertySlot design a little bit.
+ // We should either use this optimization everywhere, or nowhere.
+ slot.setCustom(asObject(toJS(value)), cachedValueGetter);
+ return true;
+ }
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (staticValues->contains(propertyName.ustring().rep())) {
+ slot.setCustom(this, staticValueGetter);
+ return true;
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (staticFunctions->contains(propertyName.ustring().rep())) {
+ slot.setCustom(this, staticFunctionGetter);
+ return true;
+ }
+ }
+ }
+
+ return Base::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
+{
+ return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
+}
+
+template <class Base>
+void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueJSString> propertyNameRef;
+ JSValueRef valueRef = toRef(value);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
+ return;
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kJSPropertyAttributeReadOnly)
+ return;
+ if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
+ return;
+ } else
+ throwError(exec, ReferenceError, "Attempt to set a property that is not settable.");
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kJSPropertyAttributeReadOnly)
+ return;
+ JSCallbackObject<Base>::putDirect(propertyName, value); // put as override property
+ return;
+ }
+ }
+ }
+
+ return Base::put(exec, propertyName, value, slot);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& propertyName)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (deleteProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
+ return true;
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kJSPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kJSPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
+ }
+ }
+
+ return Base::deleteProperty(exec, propertyName);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, unsigned propertyName)
+{
+ return deleteProperty(exec, Identifier::from(exec, propertyName));
+}
+
+template <class Base>
+ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructData)
+{
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsConstructor) {
+ constructData.native.function = construct;
+ return ConstructTypeHost;
+ }
+ }
+ return ConstructTypeNone;
+}
+
+template <class Base>
+JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef constructorRef = toRef(constructor);
+
+ for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
+ int argumentCount = static_cast<int>(args.size());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(args.at(exec, i));
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ }
+ }
+
+ ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
+ return 0;
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue* value, JSValue*)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
+ }
+ }
+ return false;
+}
+
+template <class Base>
+CallType JSCallbackObject<Base>::getCallData(CallData& callData)
+{
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsFunction) {
+ callData.native.function = call;
+ return CallTypeHost;
+ }
+ }
+ return CallTypeNone;
+}
+
+template <class Base>
+JSValue* JSCallbackObject<Base>::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef functionRef = toRef(functionObject);
+ JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec));
+
+ for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(functionObject)->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
+ int argumentCount = static_cast<int>(args.size());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(args.at(exec, i));
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ }
+ }
+
+ ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
+ return noValue();
+}
+
+template <class Base>
+void JSCallbackObject<Base>::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
+ JSLock::DropAllLocks dropAllLocks(exec);
+ getPropertyNames(execRef, thisRef, toRef(&propertyNames));
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ typedef OpaqueJSClassStaticValuesTable::const_iterator iterator;
+ iterator end = staticValues->end();
+ for (iterator it = staticValues->begin(); it != end; ++it) {
+ UString::Rep* name = it->first.get();
+ StaticValueEntry* entry = it->second;
+ if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum))
+ propertyNames.add(Identifier(exec, name));
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator;
+ iterator end = staticFunctions->end();
+ for (iterator it = staticFunctions->begin(); it != end; ++it) {
+ UString::Rep* name = it->first.get();
+ StaticFunctionEntry* entry = it->second;
+ if (!(entry->attributes & kJSPropertyAttributeDontEnum))
+ propertyNames.add(Identifier(exec, name));
+ }
+ }
+ }
+
+ Base::getPropertyNames(exec, propertyNames);
+}
+
+template <class Base>
+double JSCallbackObject<Base>::toNumber(ExecState* exec) const
+{
+ // We need this check to guard against the case where this object is rhs of
+ // a binary expression where lhs threw an exception in its conversion to
+ // primitive
+ if (exec->hadException())
+ return NaN;
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
+ return toJS(value)->getNumber();
+ }
+
+ return Base::toNumber(exec);
+}
+
+template <class Base>
+UString JSCallbackObject<Base>::toString(ExecState* exec) const
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
+ JSValueRef value;
+ {
+ JSLock::DropAllLocks dropAllLocks(exec);
+ value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot()));
+ }
+ if (value)
+ return toJS(value)->getString();
+ }
+
+ return Base::toString(exec);
+}
+
+template <class Base>
+void JSCallbackObject<Base>::setPrivate(void* data)
+{
+ m_callbackObjectData->privateData = data;
+}
+
+template <class Base>
+void* JSCallbackObject<Base>::getPrivate()
+{
+ return m_callbackObjectData->privateData;
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::inherits(JSClassRef c) const
+{
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (jsClass == c)
+ return true;
+
+ return false;
+}
+
+template <class Base>
+JSValue* JSCallbackObject<Base>::cachedValueGetter(ExecState*, const Identifier&, const PropertySlot& slot)
+{
+ JSValue* v = slot.slotBase();
+ ASSERT(v);
+ return v;
+}
+
+template <class Base>
+JSValue* JSCallbackObject<Base>::staticValueGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
+
+ JSObjectRef thisRef = toRef(thisObj);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
+ if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
+ if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
+ return toJS(value);
+ }
+
+ return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
+}
+
+template <class Base>
+JSValue* JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
+
+ // Check for cached or override property.
+ PropertySlot slot2(thisObj);
+ if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))
+ return slot2.getValue(exec, propertyName);
+
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
+ if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
+ JSObject* o = new (exec) JSCallbackFunction(exec, callAsFunction, propertyName);
+ thisObj->putDirect(propertyName, o, entry->attributes);
+ return o;
+ }
+ }
+ }
+ }
+
+ return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
+}
+
+template <class Base>
+JSValue* JSCallbackObject<Base>::callbackGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
+
+ JSObjectRef thisRef = toRef(thisObj);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
+ return toJS(value);
+ }
+
+ return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
+}
+
+} // namespace JSC
View
244 JavaScriptCore/API/JSClassRef.cpp
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSClassRef.h"
+
+#include "APICast.h"
+#include "JSCallbackObject.h"
+#include "JSObjectRef.h"
+#include <runtime/InitializeThreading.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/ObjectPrototype.h>
+#include <kjs/identifier.h>
+
+using namespace JSC;
+
+const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
+ : parentClass(definition->parentClass)
+ , prototypeClass(0)
+ , initialize(definition->initialize)
+ , finalize(definition->finalize)
+ , hasProperty(definition->hasProperty)
+ , getProperty(definition->getProperty)
+ , setProperty(definition->setProperty)
+ , deleteProperty(definition->deleteProperty)
+ , getPropertyNames(definition->getPropertyNames)
+ , callAsFunction(definition->callAsFunction)
+ , callAsConstructor(definition->callAsConstructor)
+ , hasInstance(definition->hasInstance)
+ , convertToType(definition->convertToType)
+ , m_className(UString::Rep::createFromUTF8(definition->className))
+ , m_staticValues(0)
+ , m_staticFunctions(0)
+{
+ initializeThreading();
+
+ if (const JSStaticValue* staticValue = definition->staticValues) {
+ m_staticValues = new OpaqueJSClassStaticValuesTable();
+ while (staticValue->name) {
+ m_staticValues->add(UString::Rep::createFromUTF8(staticValue->name),
+ new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
+ ++staticValue;
+ }
+ }
+
+ if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
+ m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();
+ while (staticFunction->name) {
+ m_staticFunctions->add(UString::Rep::createFromUTF8(staticFunction->name),
+ new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
+ ++staticFunction;
+ }
+ }
+
+ if (protoClass)
+ prototypeClass = JSClassRetain(protoClass);
+}
+
+OpaqueJSClass::~OpaqueJSClass()
+{
+ ASSERT(!m_className.rep()->identifierTable());
+
+ if (m_staticValues) {
+ OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end();
+ for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ delete it->second;
+ }
+ delete m_staticValues;
+ }
+
+ if (m_staticFunctions) {
+ OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end();
+ for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ delete it->second;
+ }
+ delete m_staticFunctions;
+ }
+
+ if (prototypeClass)
+ JSClassRelease(prototypeClass);
+}
+
+PassRefPtr<OpaqueJSClass> OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition)
+{
+ return adoptRef(new OpaqueJSClass(definition, 0));
+}
+
+void clearReferenceToPrototype(JSObjectRef prototype)
+{
+ OpaqueJSClassContextData* jsClassData = static_cast<OpaqueJSClassContextData*>(JSObjectGetPrivate(prototype));
+ ASSERT(jsClassData);
+ jsClassData->cachedPrototype = 0;
+}
+
+PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* definition)
+{
+ if (const JSStaticFunction* staticFunctions = definition->staticFunctions) {
+ // copy functions into a prototype class
+ JSClassDefinition protoDefinition = kJSClassDefinitionEmpty;
+ protoDefinition.staticFunctions = staticFunctions;
+ protoDefinition.finalize = clearReferenceToPrototype;
+
+ // We are supposed to use JSClassRetain/Release but since we know that we currently have
+ // the only reference to this class object we cheat and use a RefPtr instead.
+ RefPtr<OpaqueJSClass> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0));
+
+ // remove functions from the original class
+ JSClassDefinition objectDefinition = *definition;
+ objectDefinition.staticFunctions = 0;
+
+ return adoptRef(new OpaqueJSClass(&objectDefinition, protoClass.get()));
+ }
+
+ return adoptRef(new OpaqueJSClass(definition, 0));
+}
+
+OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass)
+ : m_class(jsClass)
+ , cachedPrototype(0)
+{
+ if (jsClass->m_staticValues) {
+ staticValues = new OpaqueJSClassStaticValuesTable;
+ OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
+ for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ staticValues->add(UString::Rep::createCopying(it->first->data(), it->first->size()),
+ new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes));
+ }
+
+ } else
+ staticValues = 0;
+
+
+ if (jsClass->m_staticFunctions) {
+ staticFunctions = new OpaqueJSClassStaticFunctionsTable;
+ OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end();
+ for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ staticFunctions->add(UString::Rep::createCopying(it->first->data(), it->first->size()),
+ new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes));
+ }
+
+ } else
+ staticFunctions = 0;
+}
+
+OpaqueJSClassContextData::~OpaqueJSClassContextData()
+{
+ if (staticValues) {
+ deleteAllValues(*staticValues);
+ delete staticValues;
+ }
+
+ if (staticFunctions) {
+ deleteAllValues(*staticFunctions);
+ delete staticFunctions;
+ }
+}
+
+OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
+{
+ OpaqueJSClassContextData*& contextData = exec->globalData().opaqueJSClassData.add(this, 0).first->second;
+ if (!contextData)
+ contextData = new OpaqueJSClassContextData(this);
+ return *contextData;
+}
+
+UString OpaqueJSClass::className()
+{
+ // Make a deep copy, so that the caller has no chance to put the original into IdentifierTable.
+ return UString(m_className.data(), m_className.size());
+}
+
+OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec)
+{
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+ return jsClassData.staticValues;
+}
+
+OpaqueJSClassStaticFunctionsTable* OpaqueJSClass::staticFunctions(JSC::ExecState* exec)
+{
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+ return jsClassData.staticFunctions;
+}
+
+/*!
+// Doc here in case we make this public. (Hopefully we won't.)
+@function
+ @abstract Returns the prototype that will be used when constructing an object with a given class.
+ @param ctx The execution context to use.
+ @param jsClass A JSClass whose prototype you want to get.
+ @result The JSObject prototype that was automatically generated for jsClass, or NULL if no prototype was automatically generated. This is the prototype that will be used when constructing an object using jsClass.
+*/
+JSObject* OpaqueJSClass::prototype(ExecState* exec)
+{
+ /* Class (C++) and prototype (JS) inheritance are parallel, so:
+ * (C++) | (JS)
+ * ParentClass | ParentClassPrototype
+ * ^ | ^
+ * | | |
+ * DerivedClass | DerivedClassPrototype
+ */
+
+ if (!prototypeClass)
+ return 0;
+
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+
+ if (!jsClassData.cachedPrototype) {
+ // Recursive, but should be good enough for our purposes
+ jsClassData.cachedPrototype = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData); // set jsClassData as the object's private data, so it can clear our reference on destruction
+ if (parentClass) {
+ if (JSObject* prototype = parentClass->prototype(exec))
+ jsClassData.cachedPrototype->setPrototype(prototype);
+ }
+ }
+ return jsClassData.cachedPrototype;
+}
View
122 JavaScriptCore/API/JSClassRef.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright