From 061cd28751cd7c3bf900ed9172f0739089473814 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 5 Jan 2012 09:38:07 +0100 Subject: [PATCH 1/1] Created QtJSBackend module. Imported src/v8, tools and tests from qtbase (1fdfc2abfe1fa26b86028934d4853432e25b4655) and added the necessary build system files to build it as a top-level Qt module. Change-Id: I0b784165157bfb031059f1528c1b3b2828284f6f --- .gitignore | 4 + qtjsbackend.pro | 14 ++ src/modules/qt_v8.pri | 16 ++ src/src.pro | 2 + src/tools/mkv8snapshot/mkv8snapshot.pro | 39 ++++ src/v8/v8.pri | 307 ++++++++++++++++++++++++++ src/v8/v8.pro | 41 ++++ src/v8/v8base.pri | 24 ++ sync.profile | 26 +++ tests/auto/auto.pro | 2 + tests/auto/v8/Makefile.nonqt | 16 ++ tests/auto/v8/README.txt | 13 ++ tests/auto/v8/tst_v8.cpp | 98 +++++++++ tests/auto/v8/v8.pro | 10 + tests/auto/v8/v8main.cpp | 66 ++++++ tests/auto/v8/v8test.cpp | 379 ++++++++++++++++++++++++++++++++ tests/auto/v8/v8test.h | 58 +++++ tests/tests.pro | 2 + 18 files changed, 1117 insertions(+) create mode 100644 .gitignore create mode 100644 qtjsbackend.pro create mode 100644 src/modules/qt_v8.pri create mode 100644 src/src.pro create mode 100644 src/tools/mkv8snapshot/mkv8snapshot.pro create mode 100644 src/v8/v8.pri create mode 100644 src/v8/v8.pro create mode 100644 src/v8/v8base.pri create mode 100644 sync.profile create mode 100644 tests/auto/auto.pro create mode 100644 tests/auto/v8/Makefile.nonqt create mode 100644 tests/auto/v8/README.txt create mode 100644 tests/auto/v8/tst_v8.cpp create mode 100644 tests/auto/v8/v8.pro create mode 100644 tests/auto/v8/v8main.cpp create mode 100644 tests/auto/v8/v8test.cpp create mode 100644 tests/auto/v8/v8test.h create mode 100644 tests/tests.pro diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..201a58f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# This file is used to ignore files which are generated in the Qt build system +# ---------------------------------------------------------------------------- +src/v8/qtv8version.h +src/v8/generated-debug/ diff --git a/qtjsbackend.pro b/qtjsbackend.pro new file mode 100644 index 0000000..b2c9a10 --- /dev/null +++ b/qtjsbackend.pro @@ -0,0 +1,14 @@ +TEMPLATE = subdirs + +module_qtjsbackend_src.subdir = src +module_qtjsbackend_src.target = module-qtjsbackend-src + +module_qtjsbackend_tests.subdir = tests +module_qtjsbackend_tests.target = module-qtjsbackend-tests +module_qtjsbackend_tests.depends = module_qtjsbackend_src +module_qtjsbackend_tests.CONFIG = no_default_install +!contains(QT_BUILD_PARTS,tests):module_qtjsbackend_tests.CONFIG += no_default_target + +SUBDIRS += module_qtjsbackend_src \ + module_qtjsbackend_tests + diff --git a/src/modules/qt_v8.pri b/src/modules/qt_v8.pri new file mode 100644 index 0000000..89d6c26 --- /dev/null +++ b/src/modules/qt_v8.pri @@ -0,0 +1,16 @@ +QT.v8.VERSION = 5.0.0 +QT.v8.MAJOR_VERSION = 5 +QT.v8.MINOR_VERSION = 0 +QT.v8.PATCH_VERSION = 0 + +QT.v8.name = QtV8 +QT.v8.bins = $$QT_MODULE_BIN_BASE +QT.v8.includes = $$QT_MODULE_INCLUDE_BASE/QtV8 +QT.v8.private_includes = $$QT_MODULE_INCLUDE_BASE/QtV8/$$QT.v8.VERSION +QT.v8.sources = $$QT_MODULE_BASE/src/v8 +QT.v8.libs = $$QT_MODULE_LIB_BASE +QT.v8.plugins = $$QT_MODULE_PLUGIN_BASE +QT.v8.imports = $$QT_MODULE_IMPORT_BASE +QT.v8.depends = +QT.v8.DEFINES = +!contains(QT_CONFIG, static): QT.v8.DEFINES += V8_SHARED USING_V8_SHARED diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..5d6dc20 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = v8 diff --git a/src/tools/mkv8snapshot/mkv8snapshot.pro b/src/tools/mkv8snapshot/mkv8snapshot.pro new file mode 100644 index 0000000..41fa5df --- /dev/null +++ b/src/tools/mkv8snapshot/mkv8snapshot.pro @@ -0,0 +1,39 @@ +TEMPLATE = app +TARGET = mkv8snapshot +QT = +CONFIG -= app_bundle +CONFIG -= qt +CONFIG += console +CONFIG += warn_off + +DESTDIR = ../../../bin +INCLUDEPATH += . +DEPENDPATH += . +LIBS = +OBJECTS_DIR = . + +contains(QT_CONFIG, build_all): CONFIG += build_all +win32|mac:!macx-xcode: CONFIG += debug_and_release + +TARGET = $$TARGET$$qtPlatformTargetSuffix() + +cross_compile { + equals(QT_ARCH, arm): V8_TARGET_ARCH = arm +} + +include(../../v8/v8.pri) + +cross_compile { + equals(V8_TARGET_ARCH, arm): SOURCES += $$V8SRC/arm/simulator-arm.cc +} + +SOURCES += \ + $$V8SRC/snapshot-empty.cc \ + $$V8SRC/mksnapshot.cc + +unix:LIBS += -lpthread + +# We don't need to install this tool, it's only used for building v8. +# However we do have to make sure that 'make install' builds it. +dummytarget.CONFIG = dummy_install +INSTALLS += dummytarget diff --git a/src/v8/v8.pri b/src/v8/v8.pri new file mode 100644 index 0000000..530b2a7 --- /dev/null +++ b/src/v8/v8.pri @@ -0,0 +1,307 @@ +isEmpty(QT_ARCH) { + # We're most likely being parsed in a fromfile() call, in which case the + # QMake environment isn't complete. Load qt_config in an attempt to set + # the variables we need (QT_ARCH and CONFIG, in particular). + load(qt_config) +} + +isEmpty(V8_TARGET_ARCH) { + # Detect target + equals(QT_ARCH, x86_64)|contains(CONFIG, x86_64):V8_TARGET_ARCH = x64 + else:equals(QT_ARCH, "i386"): V8_TARGET_ARCH = ia32 + else:equals(QT_ARCH, "mips"): V8_TARGET_ARCH = mips + else:equals(QT_ARCH, "arm"): V8_TARGET_ARCH = arm + else:equals(QMAKE_HOST.arch, armv7l): V8_TARGET_ARCH = arm + else:equals(QMAKE_HOST.arch, armv5tel): V8_TARGET_ARCH = arm + else:equals(QMAKE_HOST.arch, x86_64): V8_TARGET_ARCH = x64 + else:equals(QMAKE_HOST.arch, x86): V8_TARGET_ARCH = ia32 + else:equals(QMAKE_HOST.arch, i386): V8_TARGET_ARCH = ia32 + else:equals(QMAKE_HOST.arch, i686): V8_TARGET_ARCH = ia32 + else:error("Couldn't detect supported v8 architecture ($$QMAKE_HOST.arch/$$QT_ARCH). Currently supported architectures are: x64, x86 and arm") +} + +include($$PWD/v8base.pri) + +# In debug-and-release builds, generated sources must not go to the same +# directory, or they could clobber each other in highly parallelized builds +CONFIG(debug, debug|release):V8_GENERATED_SOURCES_DIR = generated-debug +else: V8_GENERATED_SOURCES_DIR = generated-release + +# this maybe removed in future +DEFINES += ENABLE_DEBUGGER_SUPPORT + +# this is needed by crankshaft ( http://code.google.com/p/v8/issues/detail?id=1271 ) +DEFINES += ENABLE_VMSTATE_TRACKING ENABLE_LOGGING_AND_PROFILING + +CONFIG(debug, debug|release) { + DEFINES += DEBUG V8_ENABLE_CHECKS OBJECT_PRINT ENABLE_DISASSEMBLER +} else { + DEFINES += NDEBUG +} + +V8SRC = $$V8DIR/src + +INCLUDEPATH += \ + $$V8SRC + +SOURCES += \ + $$V8SRC/accessors.cc \ + $$V8SRC/allocation.cc \ + $$V8SRC/api.cc \ + $$V8SRC/assembler.cc \ + $$V8SRC/ast.cc \ + $$V8SRC/atomicops_internals_x86_gcc.cc \ + $$V8SRC/bignum.cc \ + $$V8SRC/bignum-dtoa.cc \ + $$V8SRC/bootstrapper.cc \ + $$V8SRC/builtins.cc \ + $$V8SRC/cached-powers.cc \ + $$V8SRC/checks.cc \ + $$V8SRC/circular-queue.cc \ + $$V8SRC/code-stubs.cc \ + $$V8SRC/codegen.cc \ + $$V8SRC/compilation-cache.cc \ + $$V8SRC/compiler.cc \ + $$V8SRC/contexts.cc \ + $$V8SRC/conversions.cc \ + $$V8SRC/counters.cc \ + $$V8SRC/cpu-profiler.cc \ + $$V8SRC/data-flow.cc \ + $$V8SRC/dateparser.cc \ + $$V8SRC/debug-agent.cc \ + $$V8SRC/debug.cc \ + $$V8SRC/deoptimizer.cc \ + $$V8SRC/disassembler.cc \ + $$V8SRC/diy-fp.cc \ + $$V8SRC/dtoa.cc \ + $$V8SRC/elements.cc \ + $$V8SRC/execution.cc \ + $$V8SRC/factory.cc \ + $$V8SRC/flags.cc \ + $$V8SRC/frames.cc \ + $$V8SRC/full-codegen.cc \ + $$V8SRC/func-name-inferrer.cc \ + $$V8SRC/gdb-jit.cc \ + $$V8SRC/global-handles.cc \ + $$V8SRC/fast-dtoa.cc \ + $$V8SRC/fixed-dtoa.cc \ + $$V8SRC/handles.cc \ + $$V8SRC/hashmap.cc \ + $$V8SRC/heap-profiler.cc \ + $$V8SRC/heap.cc \ + $$V8SRC/hydrogen.cc \ + $$V8SRC/hydrogen-instructions.cc \ + $$V8SRC/ic.cc \ + $$V8SRC/incremental-marking.cc \ + $$V8SRC/inspector.cc \ + $$V8SRC/interpreter-irregexp.cc \ + $$V8SRC/isolate.cc \ + $$V8SRC/jsregexp.cc \ + $$V8SRC/lithium-allocator.cc \ + $$V8SRC/lithium.cc \ + $$V8SRC/liveedit.cc \ + $$V8SRC/liveobjectlist.cc \ + $$V8SRC/log-utils.cc \ + $$V8SRC/log.cc \ + $$V8SRC/mark-compact.cc \ + $$V8SRC/messages.cc \ + $$V8SRC/objects.cc \ + $$V8SRC/objects-printer.cc \ + $$V8SRC/objects-visiting.cc \ + $$V8SRC/parser.cc \ + $$V8SRC/preparser.cc \ + $$V8SRC/preparse-data.cc \ + $$V8SRC/profile-generator.cc \ + $$V8SRC/property.cc \ + $$V8SRC/regexp-macro-assembler-irregexp.cc \ + $$V8SRC/regexp-macro-assembler.cc \ + $$V8SRC/regexp-stack.cc \ + $$V8SRC/rewriter.cc \ + $$V8SRC/runtime.cc \ + $$V8SRC/runtime-profiler.cc \ + $$V8SRC/safepoint-table.cc \ + $$V8SRC/scanner.cc \ + $$V8SRC/scanner-character-streams.cc \ + $$V8SRC/scopeinfo.cc \ + $$V8SRC/scopes.cc \ + $$V8SRC/serialize.cc \ + $$V8SRC/snapshot-common.cc \ + $$V8SRC/spaces.cc \ + $$V8SRC/string-search.cc \ + $$V8SRC/string-stream.cc \ + $$V8SRC/strtod.cc \ + $$V8SRC/stub-cache.cc \ + $$V8SRC/token.cc \ + $$V8SRC/type-info.cc \ + $$V8SRC/unicode.cc \ + $$V8SRC/utils.cc \ + $$V8SRC/v8-counters.cc \ + $$V8SRC/v8.cc \ + $$V8SRC/v8conversions.cc \ + $$V8SRC/v8threads.cc \ + $$V8SRC/v8utils.cc \ + $$V8SRC/variables.cc \ + $$V8SRC/version.cc \ + $$V8SRC/store-buffer.cc \ + $$V8SRC/zone.cc \ + $$V8SRC/extensions/gc-extension.cc \ + $$V8SRC/extensions/externalize-string-extension.cc + +equals(V8_TARGET_ARCH, arm) { +DEFINES += V8_TARGET_ARCH_ARM +DEFINES += USE_EABI_HARDFLOAT=1 CAN_USE_VFP_INSTRUCTIONS +SOURCES += \ + $$V8SRC/arm/builtins-arm.cc \ + $$V8SRC/arm/code-stubs-arm.cc \ + $$V8SRC/arm/codegen-arm.cc \ + $$V8SRC/arm/constants-arm.cc \ + $$V8SRC/arm/cpu-arm.cc \ + $$V8SRC/arm/debug-arm.cc \ + $$V8SRC/arm/deoptimizer-arm.cc \ + $$V8SRC/arm/disasm-arm.cc \ + $$V8SRC/arm/frames-arm.cc \ + $$V8SRC/arm/full-codegen-arm.cc \ + $$V8SRC/arm/ic-arm.cc \ + $$V8SRC/arm/lithium-arm.cc \ + $$V8SRC/arm/lithium-codegen-arm.cc \ + $$V8SRC/arm/lithium-gap-resolver-arm.cc \ + $$V8SRC/arm/macro-assembler-arm.cc \ + $$V8SRC/arm/regexp-macro-assembler-arm.cc \ + $$V8SRC/arm/stub-cache-arm.cc \ + $$V8SRC/arm/assembler-arm.cc +} else:equals(V8_TARGET_ARCH, ia32) { +DEFINES += V8_TARGET_ARCH_IA32 +SOURCES += \ + $$V8SRC/ia32/assembler-ia32.cc \ + $$V8SRC/ia32/builtins-ia32.cc \ + $$V8SRC/ia32/code-stubs-ia32.cc \ + $$V8SRC/ia32/codegen-ia32.cc \ + $$V8SRC/ia32/cpu-ia32.cc \ + $$V8SRC/ia32/debug-ia32.cc \ + $$V8SRC/ia32/deoptimizer-ia32.cc \ + $$V8SRC/ia32/disasm-ia32.cc \ + $$V8SRC/ia32/frames-ia32.cc \ + $$V8SRC/ia32/full-codegen-ia32.cc \ + $$V8SRC/ia32/ic-ia32.cc \ + $$V8SRC/ia32/lithium-codegen-ia32.cc \ + $$V8SRC/ia32/lithium-gap-resolver-ia32.cc \ + $$V8SRC/ia32/lithium-ia32.cc \ + $$V8SRC/ia32/macro-assembler-ia32.cc \ + $$V8SRC/ia32/regexp-macro-assembler-ia32.cc \ + $$V8SRC/ia32/stub-cache-ia32.cc +} else:equals(V8_TARGET_ARCH, x64) { +# FIXME What about 32-bit Macs? +DEFINES += V8_TARGET_ARCH_X64 +SOURCES += \ + $$V8SRC/x64/assembler-x64.cc \ + $$V8SRC/x64/builtins-x64.cc \ + $$V8SRC/x64/code-stubs-x64.cc \ + $$V8SRC/x64/codegen-x64.cc \ + $$V8SRC/x64/cpu-x64.cc \ + $$V8SRC/x64/debug-x64.cc \ + $$V8SRC/x64/deoptimizer-x64.cc \ + $$V8SRC/x64/disasm-x64.cc \ + $$V8SRC/x64/frames-x64.cc \ + $$V8SRC/x64/full-codegen-x64.cc \ + $$V8SRC/x64/ic-x64.cc \ + $$V8SRC/x64/lithium-codegen-x64.cc \ + $$V8SRC/x64/lithium-gap-resolver-x64.cc \ + $$V8SRC/x64/lithium-x64.cc \ + $$V8SRC/x64/macro-assembler-x64.cc \ + $$V8SRC/x64/regexp-macro-assembler-x64.cc \ + $$V8SRC/x64/stub-cache-x64.cc +} else:equals(V8_TARGET_ARCH, mips) { +DEFINES += V8_TARGET_MIPS +SOURCES += \ + $$V8SRC/mips/assembler-mips.cc \ + $$V8SRC/mips/builtins-mips.cc \ + $$V8SRC/mips/codegen-mips.cc \ + $$V8SRC/mips/code-stubs-mips.cc \ + $$V8SRC/mips/constants-mips.cc \ + $$V8SRC/mips/cpu-mips.cc \ + $$V8SRC/mips/debug-mips.cc \ + $$V8SRC/mips/deoptimizer-mips.cc \ + $$V8SRC/mips/disasm-mips.cc \ + $$V8SRC/mips/frames-mips.cc \ + $$V8SRC/mips/full-codegen-mips.cc \ + $$V8SRC/mips/ic-mips.cc \ + $$V8SRC/mips/macro-assembler-mips.cc \ + $$V8SRC/mips/regexp-macro-assembler-mips.cc \ + $$V8SRC/mips/simulator-mips.cc \ + $$V8SRC/mips/stub-cache-mips.cc +} + +#os:macos +macx { +SOURCES += \ + $$V8SRC/platform-macos.cc \ + $$V8SRC/platform-posix.cc +} else:freebsd-* { +SOURCES += \ + $$V8SRC/platform-freebsd.cc \ + $$V8SRC/platform-posix.cc +LIBS += -lexecinfo +} else:unix:!symbian { +SOURCES += \ + $$V8SRC/platform-linux.cc \ + $$V8SRC/platform-posix.cc +} + +win32 { +SOURCES += \ + $$V8SRC/platform-win32.cc \ + $$V8SRC/win32-math.cc +LIBS += -lWs2_32 -lWinmm +win32-msvc*: QMAKE_CXXFLAGS += -wd4100 -wd 4291 -wd4351 -wd4355 -wd4800 +win32-msvc*:arch_i386: DEFINES += _USE_32BIT_TIME_T +} + +#mode:debug +CONFIG(debug) { + SOURCES += \ + $$V8SRC/objects-debug.cc \ + $$V8SRC/prettyprinter.cc \ + $$V8SRC/regexp-macro-assembler-tracer.cc +} + +V8_LIBRARY_FILES = \ + $$V8SRC/runtime.js \ + $$V8SRC/v8natives.js \ + $$V8SRC/array.js \ + $$V8SRC/string.js \ + $$V8SRC/uri.js \ + $$V8SRC/math.js \ + $$V8SRC/messages.js \ + $$V8SRC/apinatives.js \ + $$V8SRC/date.js \ + $$V8SRC/regexp.js \ + $$V8SRC/json.js \ + $$V8SRC/liveedit-debugger.js \ + $$V8SRC/mirror-debugger.js \ + $$V8SRC/debug-debugger.js + +V8_EXPERIMENTAL_LIBRARY_FILES = \ + $$V8SRC/proxy.js \ + +v8_js2c.commands = python $$V8DIR/tools/js2c.py $$V8_GENERATED_SOURCES_DIR/libraries.cpp CORE off +v8_js2c.commands += $$V8SRC/macros.py ${QMAKE_FILE_IN} +v8_js2c.output = $$V8_GENERATED_SOURCES_DIR/libraries.cpp +v8_js2c.input = V8_LIBRARY_FILES +v8_js2c.variable_out = SOURCES +v8_js2c.dependency_type = TYPE_C +v8_js2c.depends = $$V8DIR/tools/js2c.py $$V8SRC/macros.py +v8_js2c.CONFIG += combine +v8_js2c.name = generating[v8] ${QMAKE_FILE_IN} +silent:v8_js2c.commands = @echo generating[v8] ${QMAKE_FILE_IN} && $$v8_js2c.commands + +v8_js2c_experimental.commands = python $$V8DIR/tools/js2c.py $$V8_GENERATED_SOURCES_DIR/experimental-libraries.cpp EXPERIMENTAL off +v8_js2c_experimental.commands += $$V8SRC/macros.py ${QMAKE_FILE_IN} +v8_js2c_experimental.output = $$V8_GENERATED_SOURCES_DIR/experimental-libraries.cpp +v8_js2c_experimental.input = V8_EXPERIMENTAL_LIBRARY_FILES +v8_js2c_experimental.variable_out = SOURCES +v8_js2c_experimental.dependency_type = TYPE_C +v8_js2c_experimental.depends = $$V8DIR/tools/js2c.py $$V8SRC/macros.py +v8_js2c_experimental.CONFIG += combine +v8_js2c_experimental.name = generating[v8] ${QMAKE_FILE_IN} + +QMAKE_EXTRA_COMPILERS += v8_js2c v8_js2c_experimental diff --git a/src/v8/v8.pro b/src/v8/v8.pro new file mode 100644 index 0000000..c71d32b --- /dev/null +++ b/src/v8/v8.pro @@ -0,0 +1,41 @@ +load(qt_module) + +TARGET = QtV8 +QPRO_PWD = $$PWD +QT = + +CONFIG += module +MODULE_PRI = ../modules/qt_v8.pri + +win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 + +load(qt_module_config) +CONFIG += warn_off + +# Remove includepaths that were added by qt_module_config. +# These cause compilation of V8 to fail because they appear before +# 3rdparty/v8/src; 3rdparty/v8/src/v8.h will then be "shadowed" by +# the public v8.h API header (they are not the same!). +INCLUDEPATH -= $$MODULE_PRIVATE_INCLUDES +INCLUDEPATH -= $$MODULE_PRIVATE_INCLUDES/$$TARGET +INCLUDEPATH -= $$MODULE_INCLUDES $$MODULE_INCLUDES/.. + +HEADERS += qtv8version.h + +!contains(QT_CONFIG, static): DEFINES += V8_SHARED BUILDING_V8_SHARED + +include(v8.pri) + +contains(QT_CONFIG, v8snapshot) { + mkv8snapshot.commands = ../../bin/mkv8snapshot$$qtPlatformTargetSuffix() ${QMAKE_FILE_OUT} + DUMMY_FILE = v8.pro + mkv8snapshot.input = DUMMY_FILE + mkv8snapshot.output = $$V8_GENERATED_SOURCES_DIR/snapshot.cpp + mkv8snapshot.variable_out = SOURCES + mkv8snapshot.dependency_type = TYPE_C + mkv8snapshot.name = generating[v8] ${QMAKE_FILE_IN} + silent:mkv8snapshot.commands = @echo generating[v8] ${QMAKE_FILE_IN} && $$mkv8snapshot.commands + QMAKE_EXTRA_COMPILERS += mkv8snapshot +} else { + SOURCES += $$V8SRC/snapshot-empty.cc +} diff --git a/src/v8/v8base.pri b/src/v8/v8base.pri new file mode 100644 index 0000000..8a7d18c --- /dev/null +++ b/src/v8/v8base.pri @@ -0,0 +1,24 @@ +V8DIR = $$(V8DIR) +isEmpty(V8DIR) { + V8DIR = $$PWD/../3rdparty/v8 + !exists($$V8DIR/src):error("$$V8DIR/src does not exist! $$escape_expand(\\n)\ + If you are building from git, please ensure you have the v8 submodule available, e.g. $$escape_expand(\\n\\n)\ + git submodule update --init src/3rdparty/v8 $$escape_expand(\\n\\n)\ + Alternatively, Qt may be configured with -no-v8 to disable v8.\ + ") +} else { + message(using external V8 from $$V8DIR) +} + +*-g++*: { + QMAKE_CFLAGS_WARN_ON += -Wno-unused-parameter + QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter + + # mksnapshot hangs if gcc 4.5 is used + # for reference look at http://code.google.com/p/v8/issues/detail?id=884 + equals(QT_GCC_MAJOR_VERSION, 4): equals(QT_GCC_MINOR_VERSION, 5) { + message(because of a bug in gcc / v8 we need to add -fno-strict-aliasing) + QMAKE_CFLAGS += -fno-strict-aliasing + QMAKE_CXXFLAGS += -fno-strict-aliasing + } +} diff --git a/sync.profile b/sync.profile new file mode 100644 index 0000000..7a88ec1 --- /dev/null +++ b/sync.profile @@ -0,0 +1,26 @@ +%modules = ( # path to module name map + "QtV8" => "$basedir/src/v8", +); +%moduleheaders = ( # restrict the module headers to those found in relative path + "QtV8" => "../3rdparty/v8/include", +); +@allmoduleheadersprivate = ( + "QtV8" +); +%classnames = ( + "qtv8version.h" => "QtV8Version", +); +%mastercontent = (); +%modulepris = ( + "QtV8" => "$basedir/src/modules/qt_v8.pri", +); + +# Module dependencies. +# Every module that is required to build this module should have one entry. +# Each of the module version specifiers can take one of the following values: +# - A specific Git revision. +# - any git symbolic ref resolvable from the module's repository (e.g. "refs/heads/master" to track master branch) +# +%dependencies = ( + "qtbase" => "refs/heads/master", +); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..5d6dc20 --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = v8 diff --git a/tests/auto/v8/Makefile.nonqt b/tests/auto/v8/Makefile.nonqt new file mode 100644 index 0000000..ded1ba3 --- /dev/null +++ b/tests/auto/v8/Makefile.nonqt @@ -0,0 +1,16 @@ +V8PATH = ../../../src/3rdparty/v8 +V8LIBPATH = $(V8PATH) +V8INCPATH = $(V8PATH)/include +SOURCES = v8main.cpp v8test.cpp + +release-m32: + g++ -o v8test_release_m32 -m32 -O2 -I$(V8INCPATH) $(SOURCES) -lpthread -L$(V8LIBPATH) -lv8 + +debug-m32: + g++ -o v8test_debug_m32 -m32 -g -I$(V8INCPATH) $(SOURCES) -lpthread -L$(V8LIBPATH) -lv8_g + +release: + g++ -o v8test_release -O2 -I$(V8INCPATH) $(SOURCES) -lpthread -L$(V8LIBPATH) -lv8 + +debug: + g++ -o v8test_debug -g -I$(V8INCPATH) $(SOURCES) -lpthread -L$(V8LIBPATH) -lv8_g diff --git a/tests/auto/v8/README.txt b/tests/auto/v8/README.txt new file mode 100644 index 0000000..097c459 --- /dev/null +++ b/tests/auto/v8/README.txt @@ -0,0 +1,13 @@ +The v8 tests are actually implemented in v8test.[h|cpp]. There are also QtTest +(tst_v8.cpp) and non-Qt (v8main.cpp) stubs provided to run these tests. This +is done to allow the tests to be run both in the Qt CI system, and manually +without a build of Qt. The latter is necessary to run them against more exotic +build of V8, like the ARM simulator. + +To build the non-Qt version of the tests, first build a debug or release V8 +library under src/3rdparty/v8 using scons, and then use the Makefile.nonqt +makefile selecting one of the following targets: + release: Build the tests with -O2 and link against libv8 + debug: Build the tests with -g and link against libv8_g + release-m32: Build the tests with -O2 -m32 and link against libv8 + debug-m32: Build the tests with -g -m32 and link against libv8_g diff --git a/tests/auto/v8/tst_v8.cpp b/tests/auto/v8/tst_v8.cpp new file mode 100644 index 0000000..bb3184c --- /dev/null +++ b/tests/auto/v8/tst_v8.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include "v8test.h" + +using namespace v8; + +class tst_v8 : public QObject +{ + Q_OBJECT +public: + tst_v8() {} + +private slots: + void initTestCase() {} + void cleanupTestCase() {} + + void eval(); + void evalwithinwith(); + void userobjectcompare(); + void externalteardown(); + void globalcall(); +}; + +void tst_v8::eval() +{ + QVERIFY(v8test_eval()); +} + +void tst_v8::evalwithinwith() +{ + QVERIFY(v8test_evalwithinwith()); +} + +void tst_v8::userobjectcompare() +{ + QVERIFY(v8test_userobjectcompare()); +} + +void tst_v8::externalteardown() +{ + QVERIFY(v8test_externalteardown()); +} + +void tst_v8::globalcall() +{ + QVERIFY(v8test_globalcall()); +} + +int main(int argc, char *argv[]) +{ + V8::SetFlagsFromCommandLine(&argc, argv, true); + + QCoreApplication app(argc, argv); + tst_v8 tc; + return QTest::qExec(&tc, argc, argv); +} + +#include "tst_v8.moc" diff --git a/tests/auto/v8/v8.pro b/tests/auto/v8/v8.pro new file mode 100644 index 0000000..493ea8e --- /dev/null +++ b/tests/auto/v8/v8.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_v8 +macx:CONFIG -= app_bundle + +SOURCES += tst_v8.cpp v8test.cpp +HEADERS += v8test.h + +CONFIG += parallel_test + +QT = core v8-private testlib diff --git a/tests/auto/v8/v8main.cpp b/tests/auto/v8/v8main.cpp new file mode 100644 index 0000000..f8ffea0 --- /dev/null +++ b/tests/auto/v8/v8main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "v8test.h" +#include +#include + +#define RUN_TEST(testname) { \ + if (argc == 1 || 0 == ::strcmp(argv[1], # testname)) { \ + if (!v8test_ ## testname()) \ + printf ("Test %s FAILED\n", # testname); \ + else \ + printf ("Test %s PASS\n", # testname); \ + } \ +} + +int main(int argc, char *argv[]) +{ + v8::V8::SetFlagsFromCommandLine(&argc, argv, true); + + RUN_TEST(eval); + RUN_TEST(evalwithinwith); + RUN_TEST(userobjectcompare); + RUN_TEST(externalteardown); + RUN_TEST(globalcall); + + return -1; +} diff --git a/tests/auto/v8/v8test.cpp b/tests/auto/v8/v8test.cpp new file mode 100644 index 0000000..5576f47 --- /dev/null +++ b/tests/auto/v8/v8test.cpp @@ -0,0 +1,379 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "v8test.h" + +using namespace v8; + +#define BEGINTEST() bool _testPassed = true; +#define ENDTEST() return _testPassed; + +#define VERIFY(expr) { \ + if (!(expr)) { \ + fprintf(stderr, "FAIL: %s:%d %s\n", __FILE__, __LINE__, # expr); \ + _testPassed = false; \ + goto cleanup; \ + } \ +} + +struct MyStringResource : public String::ExternalAsciiStringResource +{ + static bool wasDestroyed; + virtual ~MyStringResource() { wasDestroyed = true; } + virtual const char* data() const { return "v8test"; } + virtual size_t length() const { return 6; } +}; +bool MyStringResource::wasDestroyed = false; + +struct MyResource : public Object::ExternalResource +{ + static bool wasDestroyed; + virtual ~MyResource() { wasDestroyed = true; } +}; +bool MyResource::wasDestroyed = false; + +bool v8test_externalteardown() +{ + BEGINTEST(); + + Isolate *isolate = v8::Isolate::New(); + isolate->Enter(); + + { + HandleScope handle_scope; + Persistent context = Context::New(); + Context::Scope context_scope(context); + + String::NewExternal(new MyStringResource); + + Local ft = FunctionTemplate::New(); + ft->InstanceTemplate()->SetHasExternalResource(true); + + Local obj = ft->GetFunction()->NewInstance(); + obj->SetExternalResource(new MyResource); + + context.Dispose(); + } + + // while (!v8::V8::IdleNotification()) ; + isolate->Exit(); + isolate->Dispose(); + + // ExternalString resources aren't guaranteed to be freed by v8 at this + // point. Uncommenting the IdleNotification() line above helps. +// VERIFY(MyStringResource::wasDestroyed); + + VERIFY(MyResource::wasDestroyed); + +cleanup: + + ENDTEST(); +} + +bool v8test_eval() +{ + BEGINTEST(); + + HandleScope handle_scope; + Persistent context = Context::New(); + Context::Scope context_scope(context); + + Local qmlglobal = Object::New(); + qmlglobal->Set(String::New("a"), Integer::New(1922)); + + Local