aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--examples/declarative/canvas/svgpath/tiger.js761
-rw-r--r--examples/declarative/canvas/svgpath/tiger.qml33
-rw-r--r--src/3rdparty/javascriptcore/COPYING.LIB488
-rw-r--r--src/3rdparty/javascriptcore/DateMath.cpp382
-rw-r--r--src/3rdparty/javascriptcore/DateMath.h190
-rw-r--r--src/3rdparty/javascriptcore/VERSION15
m---------src/3rdparty/v80
-rw-r--r--src/declarative/debugger/qdeclarativedebughelper.cpp5
-rw-r--r--src/declarative/debugger/qdeclarativedebughelper_p.h2
-rw-r--r--src/declarative/debugger/qjsdebuggeragent.cpp2
-rw-r--r--src/declarative/declarative.pro9
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp90
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h5
-rw-r--r--src/declarative/items/qsgcanvasitem.cpp27
-rw-r--r--src/declarative/items/qsgcanvasitem_p.h9
-rw-r--r--src/declarative/items/qsgcontext2d.cpp2180
-rw-r--r--src/declarative/items/qsgcontext2d_p.h15
-rw-r--r--src/declarative/items/qsgcontext2d_p_p.h13
-rw-r--r--src/declarative/items/qsgitem.cpp74
-rw-r--r--src/declarative/items/qsgitem.h4
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp178
-rw-r--r--src/declarative/qml/qdeclarativebinding_p.h8
-rw-r--r--src/declarative/qml/qdeclarativebinding_p_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeboundsignal.cpp1
-rw-r--r--src/declarative/qml/qdeclarativecompileddata.cpp3
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp192
-rw-r--r--src/declarative/qml/qdeclarativecompiler_p.h12
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp125
-rw-r--r--src/declarative/qml/qdeclarativecomponent.h4
-rw-r--r--src/declarative/qml/qdeclarativecomponent_p.h2
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp33
-rw-r--r--src/declarative/qml/qdeclarativecontext.h2
-rw-r--r--src/declarative/qml/qdeclarativecontext_p.h19
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass.cpp335
-rw-r--r--src/declarative/qml/qdeclarativedata_p.h19
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp1049
-rw-r--r--src/declarative/qml/qdeclarativeengine.h2
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h116
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp4
-rw-r--r--src/declarative/qml/qdeclarativeexpression.cpp466
-rw-r--r--src/declarative/qml/qdeclarativeexpression.h7
-rw-r--r--src/declarative/qml/qdeclarativeexpression_p.h242
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass.cpp147
-rw-r--r--src/declarative/qml/qdeclarativeinclude.cpp310
-rw-r--r--src/declarative/qml/qdeclarativeinstruction.cpp8
-rw-r--r--src/declarative/qml/qdeclarativeinstruction_p.h16
-rw-r--r--src/declarative/qml/qdeclarativeintegercache.cpp29
-rw-r--r--src/declarative/qml/qdeclarativeintegercache_p.h36
-rw-r--r--src/declarative/qml/qdeclarativelist.cpp2
-rw-r--r--src/declarative/qml/qdeclarativelistscriptclass.cpp149
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp9
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass.cpp1226
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass_p.h166
-rw-r--r--src/declarative/qml/qdeclarativeparser.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeparser_p.h13
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp153
-rw-r--r--src/declarative/qml/qdeclarativeproperty_p.h7
-rw-r--r--src/declarative/qml/qdeclarativepropertycache.cpp339
-rw-r--r--src/declarative/qml/qdeclarativepropertycache_p.h123
-rw-r--r--src/declarative/qml/qdeclarativerefcount_p.h67
-rw-r--r--src/declarative/qml/qdeclarativerewrite.cpp2
-rw-r--r--src/declarative/qml/qdeclarativescarceresourcescriptclass.cpp219
-rw-r--r--src/declarative/qml/qdeclarativescarceresourcescriptclass_p.h163
-rw-r--r--src/declarative/qml/qdeclarativescriptparser.cpp16
-rw-r--r--src/declarative/qml/qdeclarativesqldatabase.cpp585
-rw-r--r--src/declarative/qml/qdeclarativesqldatabase_p.h8
-rw-r--r--src/declarative/qml/qdeclarativetypeloader.cpp16
-rw-r--r--src/declarative/qml/qdeclarativetypeloader_p.h8
-rw-r--r--src/declarative/qml/qdeclarativetypenamecache.cpp29
-rw-r--r--src/declarative/qml/qdeclarativetypenamecache_p.h38
-rw-r--r--src/declarative/qml/qdeclarativetypenamescriptclass.cpp195
-rw-r--r--src/declarative/qml/qdeclarativevaluetypescriptclass.cpp242
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp141
-rw-r--r--src/declarative/qml/qdeclarativevme_p.h5
-rw-r--r--src/declarative/qml/qdeclarativevmemetaobject.cpp81
-rw-r--r--src/declarative/qml/qdeclarativevmemetaobject_p.h16
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript.cpp414
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript_p.h8
-rw-r--r--src/declarative/qml/qdeclarativexmlhttprequest.cpp1390
-rw-r--r--src/declarative/qml/qdeclarativexmlhttprequest_p.h6
-rw-r--r--src/declarative/qml/qintrusivelist_p.h7
-rw-r--r--src/declarative/qml/qml.pri17
-rw-r--r--src/declarative/qml/v4/qdeclarativev4bindings.cpp4
-rw-r--r--src/declarative/qml/v4/qdeclarativev4irbuilder.cpp17
-rw-r--r--src/declarative/qml/v8/notes.txt4
-rw-r--r--src/declarative/qml/v8/qhashedstring.cpp103
-rw-r--r--src/declarative/qml/v8/qhashedstring_p.h664
-rw-r--r--src/declarative/qml/v8/qv8_p.h1
-rw-r--r--src/declarative/qml/v8/qv8bindings.cpp243
-rw-r--r--src/declarative/qml/v8/qv8bindings_p.h94
-rw-r--r--src/declarative/qml/v8/qv8contextwrapper.cpp453
-rw-r--r--src/declarative/qml/v8/qv8contextwrapper_p.h120
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp1634
-rw-r--r--src/declarative/qml/v8/qv8engine_p.h464
-rw-r--r--src/declarative/qml/v8/qv8include.cpp244
-rw-r--r--src/declarative/qml/v8/qv8include_p.h (renamed from src/declarative/qml/qdeclarativeinclude_p.h)48
-rw-r--r--src/declarative/qml/v8/qv8listwrapper.cpp178
-rw-r--r--src/declarative/qml/v8/qv8listwrapper_p.h96
-rw-r--r--src/declarative/qml/v8/qv8qobjectwrapper.cpp1989
-rw-r--r--src/declarative/qml/v8/qv8qobjectwrapper_p.h157
-rw-r--r--src/declarative/qml/v8/qv8stringwrapper.cpp94
-rw-r--r--src/declarative/qml/v8/qv8stringwrapper_p.h76
-rw-r--r--src/declarative/qml/v8/qv8typewrapper.cpp217
-rw-r--r--src/declarative/qml/v8/qv8typewrapper_p.h (renamed from src/declarative/qml/qdeclarativetypenamescriptclass_p.h)47
-rw-r--r--src/declarative/qml/v8/qv8valuetypewrapper.cpp289
-rw-r--r--src/declarative/qml/v8/qv8valuetypewrapper_p.h (renamed from src/declarative/qml/qdeclarativevaluetypescriptclass_p.h)46
-rw-r--r--src/declarative/qml/v8/qv8variantwrapper.cpp220
-rw-r--r--src/declarative/qml/v8/qv8variantwrapper_p.h (renamed from src/declarative/qml/qdeclarativecontextscriptclass_p.h)77
-rw-r--r--src/declarative/qml/v8/qv8worker.cpp352
-rw-r--r--src/declarative/qml/v8/qv8worker_p.h75
-rw-r--r--src/declarative/qml/v8/v8.pri34
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp424
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p.h16
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p_p.h80
-rw-r--r--src/declarative/util/qdeclarativelistmodelworkeragent.cpp19
-rw-r--r--src/declarative/util/qdeclarativelistmodelworkeragent_p.h20
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp18
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel_p.h4
-rw-r--r--src/imports/testlib/SignalSpy.qml2
-rw-r--r--src/imports/testlib/TestCase.qml31
-rw-r--r--src/imports/testlib/main.cpp98
-rw-r--r--src/imports/testlib/testlib.pro2
-rw-r--r--src/qmltest/quicktest.cpp18
-rw-r--r--src/src.pro2
-rw-r--r--src/v8/0001-Add-hashing-and-comparison-methods-to-v8-String.patch338
-rw-r--r--src/v8/0002-Add-a-bit-field-3-to-Map.patch118
-rw-r--r--src/v8/0003-Add-a-fallback-mode-for-named-property-interceptors.patch364
-rw-r--r--src/v8/0004-Generalize-external-object-resources.patch894
-rw-r--r--src/v8/0005-Introduce-a-QML-compilation-mode.patch1777
-rw-r--r--src/v8/0006-Allow-access-to-the-calling-script-data.patch48
-rw-r--r--src/v8/0007-Fix-warnings.patch46
-rw-r--r--src/v8/0008-Add-custom-object-compare-callback.patch489
-rw-r--r--src/v8/README1
-rw-r--r--src/v8/v8.pro263
-rw-r--r--src/v8/v8base.pri18
-rwxr-xr-xsrc/v8/wrapcc.pl48
-rw-r--r--tests/auto/declarative/declarative.pro203
-rw-r--r--tests/auto/declarative/nodes/nodes.pro (renamed from tests/auto/declarative/node/nodes.pro)0
-rw-r--r--tests/auto/declarative/nodes/tst_nodestest.cpp (renamed from tests/auto/declarative/node/tst_nodestest.cpp)2
-rw-r--r--tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp16
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml1
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp314
-rw-r--r--tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp6
-rw-r--r--tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml4
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/data/model.qml4
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp252
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp117
-rw-r--r--tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js6
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp28
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml12
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml61
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp37
-rw-r--r--tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp6
-rw-r--r--tests/auto/declarative/v8/Makefile.nonqt11
-rw-r--r--tests/auto/declarative/v8/README.txt13
-rw-r--r--tests/auto/declarative/v8/tst_v8.cpp (renamed from src/declarative/qml/qdeclarativelistscriptclass_p.h)66
-rw-r--r--tests/auto/declarative/v8/v8.pro15
-rw-r--r--tests/auto/declarative/v8/v8main.cpp17
-rw-r--r--tests/auto/declarative/v8/v8test.cpp254
-rw-r--r--tests/auto/declarative/v8/v8test.h (renamed from src/declarative/qml/qdeclarativeglobalscriptclass_p.h)49
169 files changed, 19955 insertions, 8307 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000000..183f5b46cc
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "src/3rdparty/v8"]
+ path = src/3rdparty/v8
+ url = git://github.com/aaronkennedy/v8.git
diff --git a/examples/declarative/canvas/svgpath/tiger.js b/examples/declarative/canvas/svgpath/tiger.js
new file mode 100644
index 0000000000..2695cd52fe
--- /dev/null
+++ b/examples/declarative/canvas/svgpath/tiger.js
@@ -0,0 +1,761 @@
+var tiger = [
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-122.304 84.285C-122.304 84.285 -122.203 86.179 -123.027 86.16C-123.851 86.141 -140.305 38.066 -160.833 40.309C-160.833 40.309 -143.05 32.956 -122.304 84.285z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-118.774 81.262C-118.774 81.262 -119.323 83.078 -120.092 82.779C-120.86 82.481 -119.977 31.675 -140.043 26.801C-140.043 26.801 -120.82 25.937 -118.774 81.262z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-91.284 123.59C-91.284 123.59 -89.648 124.55 -90.118 125.227C-90.589 125.904 -139.763 113.102 -149.218 131.459C-149.218 131.459 -145.539 112.572 -91.284 123.59z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-94.093 133.801C-94.093 133.801 -92.237 134.197 -92.471 134.988C-92.704 135.779 -143.407 139.121 -146.597 159.522C-146.597 159.522 -149.055 140.437 -94.093 133.801z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-98.304 128.276C-98.304 128.276 -96.526 128.939 -96.872 129.687C-97.218 130.435 -147.866 126.346 -153.998 146.064C-153.998 146.064 -153.646 126.825 -98.304 128.276z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-109.009 110.072C-109.009 110.072 -107.701 111.446 -108.34 111.967C-108.979 112.488 -152.722 86.634 -166.869 101.676C-166.869 101.676 -158.128 84.533 -109.009 110.072z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-116.554 114.263C-116.554 114.263 -115.098 115.48 -115.674 116.071C-116.25 116.661 -162.638 95.922 -174.992 112.469C-174.992 112.469 -168.247 94.447 -116.554 114.263z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-119.154 118.335C-119.154 118.335 -117.546 119.343 -118.036 120.006C-118.526 120.669 -167.308 106.446 -177.291 124.522C-177.291 124.522 -173.066 105.749 -119.154 118.335z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-108.42 118.949C-108.42 118.949 -107.298 120.48 -107.999 120.915C-108.7 121.35 -148.769 90.102 -164.727 103.207C-164.727 103.207 -153.862 87.326 -108.42 118.949z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-128.2 90C-128.2 90 -127.6 91.8 -128.4 92C-129.2 92.2 -157.8 50.2 -177.001 57.8C-177.001 57.8 -161.8 46 -128.2 90z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-127.505 96.979C-127.505 96.979 -126.53 98.608 -127.269 98.975C-128.007 99.343 -164.992 64.499 -182.101 76.061C-182.101 76.061 -169.804 61.261 -127.505 96.979z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.172,
+ "path":"M-127.62 101.349C-127.62 101.349 -126.498 102.88 -127.199 103.315C-127.9 103.749 -167.969 72.502 -183.927 85.607C-183.927 85.607 -173.062 69.726 -127.62 101.349z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000",
+ "path":"M-129.83 103.065C-129.327 109.113 -128.339 115.682 -126.6 118.801C-126.6 118.801 -130.2 131.201 -121.4 144.401C-121.4 144.401 -121.8 151.601 -120.2 154.801C-120.2 154.801 -116.2 163.201 -111.4 164.001C-107.516 164.648 -98.793 167.717 -88.932 169.121C-88.932 169.121 -71.8 183.201 -75 196.001C-75 196.001 -75.4 212.401 -79 214.001C-79 214.001 -67.4 202.801 -77 219.601L-81.4 238.401C-81.4 238.401 -55.8 216.801 -71.4 235.201L-81.4 261.201C-81.4 261.201 -61.8 242.801 -69 251.201L-72.2 260.001C-72.2 260.001 -29 232.801 -59.8 262.401C-59.8 262.401 -51.8 258.801 -47.4 261.601C-47.4 261.601 -40.6 260.401 -41.4 262.001C-41.4 262.001 -62.2 272.401 -65.8 290.801C-65.8 290.801 -57.4 280.801 -60.6 291.601L-60.2 303.201C-60.2 303.201 -56.2 281.601 -56.6 319.201C-56.6 319.201 -37.4 301.201 -49 322.001L-49 338.801C-49 338.801 -33.8 322.401 -40.2 335.201C-40.2 335.201 -30.2 326.401 -34.2 341.601C-34.2 341.601 -35 352.001 -30.6 340.801C-30.6 340.801 -14.6 310.201 -20.6 336.401C-20.6 336.401 -21.4 355.601 -16.6 340.801C-16.6 340.801 -16.2 351.201 -7 358.401C-7 358.401 -8.2 307.601 4.6 343.601L8.6 360.001C8.6 360.001 11.4 350.801 11 345.601C11 345.601 25.8 329.201 19 353.601C19 353.601 34.2 330.801 31 344.001C31 344.001 23.4 360.001 25 364.801C25 364.801 41.8 330.001 43 328.401C43 328.401 41 370.802 51.8 334.801C51.8 334.801 57.4 346.801 54.6 351.201C54.6 351.201 62.6 343.201 61.8 340.001C61.8 340.001 66.4 331.801 69.2 345.401C69.2 345.401 71 354.801 72.6 351.601C72.6 351.601 76.6 375.602 77.8 352.801C77.8 352.801 79.4 339.201 72.2 327.601C72.2 327.601 73 324.401 70.2 320.401C70.2 320.401 83.8 342.001 76.6 313.201C76.6 313.201 87.801 321.201 89.001 321.201C89.001 321.201 75.4 298.001 84.2 302.801C84.2 302.801 79 292.401 97.001 304.401C97.001 304.401 81 288.401 98.601 298.001C98.601 298.001 106.601 304.401 99.001 294.401C99.001 294.401 84.6 278.401 106.601 296.401C106.601 296.401 118.201 312.801 119.001 315.601C119.001 315.601 109.001 286.401 104.601 283.601C104.601 283.601 113.001 247.201 154.201 262.801C154.201 262.801 161.001 280.001 165.401 261.601C165.401 261.601 178.201 255.201 189.401 282.801C189.401 282.801 193.401 269.201 192.601 266.401C192.601 266.401 199.401 267.601 198.601 266.401C198.601 266.401 211.801 270.801 213.001 270.001C213.001 270.001 219.801 276.801 220.201 273.201C220.201 273.201 229.401 276.001 227.401 272.401C227.401 272.401 236.201 288.001 236.601 291.601L239.001 277.601L241.001 280.401C241.001 280.401 242.601 272.801 241.801 271.601C241.001 270.401 261.801 278.401 266.601 299.201L268.601 307.601C268.601 307.601 274.601 292.801 273.001 288.801C273.001 288.801 278.201 289.601 278.601 294.001C278.601 294.001 282.601 270.801 277.801 264.801C277.801 264.801 282.201 264.001 283.401 267.601L283.401 260.401C283.401 260.401 290.601 261.201 290.601 258.801C290.601 258.801 295.001 254.801 297.001 259.601C297.001 259.601 284.601 224.401 303.001 243.601C303.001 243.601 310.201 254.401 306.601 235.601C303.001 216.801 299.001 215.201 303.801 214.801C303.801 214.801 304.601 211.201 302.601 209.601C300.601 208.001 303.801 209.601 303.801 209.601C303.801 209.601 308.601 213.601 303.401 191.601C303.401 191.601 309.801 193.201 297.801 164.001C297.801 164.001 300.601 161.601 296.601 153.201C296.601 153.201 304.601 157.601 307.401 156.001C307.401 156.001 307.001 154.401 303.801 150.401C303.801 150.401 282.201 95.6 302.601 117.601C302.601 117.601 314.451 131.151 308.051 108.351C308.051 108.351 298.94 84.341 299.717 80.045L-129.83 103.065z"}
+ ,
+ {"fill": "#cc7226", "stroke":"#000000",
+ "path":"M299.717 80.245C300.345 80.426 302.551 81.55 303.801 83.2C303.801 83.2 310.601 94 305.401 75.6C305.401 75.6 296.201 46.8 305.001 58C305.001 58 311.001 65.2 307.801 51.6C303.936 35.173 301.401 28.8 301.401 28.8C301.401 28.8 313.001 33.6 286.201 -6L295.001 -2.4C295.001 -2.4 275.401 -42 253.801 -47.2L245.801 -53.2C245.801 -53.2 284.201 -91.2 271.401 -128C271.401 -128 264.601 -133.2 255.001 -124C255.001 -124 248.601 -119.2 242.601 -120.8C242.601 -120.8 211.801 -119.6 209.801 -119.6C207.801 -119.6 173.001 -156.8 107.401 -139.2C107.401 -139.2 102.201 -137.2 97.801 -138.4C97.801 -138.4 79.4 -154.4 30.6 -131.6C30.6 -131.6 20.6 -129.6 19 -129.6C17.4 -129.6 14.6 -129.6 6.6 -123.2C-1.4 -116.8 -1.8 -116 -3.8 -114.4C-3.8 -114.4 -20.2 -103.2 -25 -102.4C-25 -102.4 -36.6 -96 -41 -86L-44.6 -84.8C-44.6 -84.8 -46.2 -77.6 -46.6 -76.4C-46.6 -76.4 -51.4 -72.8 -52.2 -67.2C-52.2 -67.2 -61 -61.2 -60.6 -56.8C-60.6 -56.8 -62.2 -51.6 -63 -46.8C-63 -46.8 -70.2 -42 -69.4 -39.2C-69.4 -39.2 -77 -25.2 -75.8 -18.4C-75.8 -18.4 -82.2 -18.8 -85 -16.4C-85 -16.4 -85.8 -11.6 -87.4 -11.2C-87.4 -11.2 -90.2 -10 -87.8 -6C-87.8 -6 -89.4 -3.2 -89.8 -1.6C-89.8 -1.6 -89 1.2 -93.4 6.8C-93.4 6.8 -99.8 25.6 -97.8 30.8C-97.8 30.8 -97.4 35.6 -100.2 37.2C-100.2 37.2 -103.8 36.8 -95.4 48.8C-95.4 48.8 -94.6 50 -97.8 52.4C-97.8 52.4 -115 56 -117.4 72.4C-117.4 72.4 -131 87.2 -131 92.4C-131 94.705 -130.729 97.852 -130.03 102.465C-130.03 102.465 -130.6 110.801 -103 111.601C-75.4 112.401 299.717 80.245 299.717 80.245z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M-115.6 102.6C-140.6 63.2 -126.2 119.601 -126.2 119.601C-117.4 154.001 12.2 116.401 12.2 116.401C12.2 116.401 181.001 86 192.201 82C203.401 78 298.601 84.4 298.601 84.4L293.001 67.6C228.201 21.2 209.001 44.4 195.401 40.4C181.801 36.4 184.201 46 181.001 46.8C177.801 47.6 138.601 22.8 132.201 23.6C125.801 24.4 100.459 0.649 115.401 32.4C131.401 66.4 57 71.6 40.2 60.4C23.4 49.2 47.4 78.8 47.4 78.8C65.8 98.8 31.4 82 31.4 82C-3 69.2 -27 94.8 -30.2 95.6C-33.4 96.4 -38.2 99.6 -39 93.2C-39.8 86.8 -47.31 70.099 -79 96.4C-99 113.001 -112.8 91 -112.8 91L-115.6 102.6z"}
+ ,
+ {"fill": "#e87f3a",
+ "path":"M133.51 25.346C127.11 26.146 101.743 2.407 116.71 34.146C133.31 69.346 58.31 73.346 41.51 62.146C24.709 50.946 48.71 80.546 48.71 80.546C67.11 100.546 32.709 83.746 32.709 83.746C-1.691 70.946 -25.691 96.546 -28.891 97.346C-32.091 98.146 -36.891 101.346 -37.691 94.946C-38.491 88.546 -45.87 72.012 -77.691 98.146C-98.927 115.492 -112.418 94.037 -112.418 94.037L-115.618 104.146C-140.618 64.346 -125.546 122.655 -125.546 122.655C-116.745 157.056 13.509 118.146 13.509 118.146C13.509 118.146 182.31 87.746 193.51 83.746C204.71 79.746 299.038 86.073 299.038 86.073L293.51 68.764C228.71 22.364 210.31 46.146 196.71 42.146C183.11 38.146 185.51 47.746 182.31 48.546C179.11 49.346 139.91 24.546 133.51 25.346z"}
+ ,
+ {"fill": "#ea8c4d",
+ "path":"M134.819 27.091C128.419 27.891 103.685 3.862 118.019 35.891C134.219 72.092 59.619 75.092 42.819 63.892C26.019 52.692 50.019 82.292 50.019 82.292C68.419 102.292 34.019 85.492 34.019 85.492C-0.381 72.692 -24.382 98.292 -27.582 99.092C-30.782 99.892 -35.582 103.092 -36.382 96.692C-37.182 90.292 -44.43 73.925 -76.382 99.892C-98.855 117.983 -112.036 97.074 -112.036 97.074L-115.636 105.692C-139.436 66.692 -124.891 125.71 -124.891 125.71C-116.091 160.11 14.819 119.892 14.819 119.892C14.819 119.892 183.619 89.492 194.819 85.492C206.019 81.492 299.474 87.746 299.474 87.746L294.02 69.928C229.219 23.528 211.619 47.891 198.019 43.891C184.419 39.891 186.819 49.491 183.619 50.292C180.419 51.092 141.219 26.291 134.819 27.091z"}
+ ,
+ {"fill": "#ec9961",
+ "path":"M136.128 28.837C129.728 29.637 104.999 5.605 119.328 37.637C136.128 75.193 60.394 76.482 44.128 65.637C27.328 54.437 51.328 84.037 51.328 84.037C69.728 104.037 35.328 87.237 35.328 87.237C0.928 74.437 -23.072 100.037 -26.272 100.837C-29.472 101.637 -34.272 104.837 -35.072 98.437C-35.872 92.037 -42.989 75.839 -75.073 101.637C-98.782 120.474 -111.655 100.11 -111.655 100.11L-115.655 107.237C-137.455 70.437 -124.236 128.765 -124.236 128.765C-115.436 163.165 16.128 121.637 16.128 121.637C16.128 121.637 184.928 91.237 196.129 87.237C207.329 83.237 299.911 89.419 299.911 89.419L294.529 71.092C229.729 24.691 212.929 49.637 199.329 45.637C185.728 41.637 188.128 51.237 184.928 52.037C181.728 52.837 142.528 28.037 136.128 28.837z"}
+ ,
+ {"fill": "#eea575",
+ "path":"M137.438 30.583C131.037 31.383 106.814 7.129 120.637 39.383C137.438 78.583 62.237 78.583 45.437 67.383C28.637 56.183 52.637 85.783 52.637 85.783C71.037 105.783 36.637 88.983 36.637 88.983C2.237 76.183 -21.763 101.783 -24.963 102.583C-28.163 103.383 -32.963 106.583 -33.763 100.183C-34.563 93.783 -41.548 77.752 -73.763 103.383C-98.709 122.965 -111.273 103.146 -111.273 103.146L-115.673 108.783C-135.473 73.982 -123.582 131.819 -123.582 131.819C-114.782 166.22 17.437 123.383 17.437 123.383C17.437 123.383 186.238 92.983 197.438 88.983C208.638 84.983 300.347 91.092 300.347 91.092L295.038 72.255C230.238 25.855 214.238 51.383 200.638 47.383C187.038 43.383 189.438 52.983 186.238 53.783C183.038 54.583 143.838 29.783 137.438 30.583z"}
+ ,
+ {"fill": "#f1b288",
+ "path":"M138.747 32.328C132.347 33.128 106.383 9.677 121.947 41.128C141.147 79.928 63.546 80.328 46.746 69.128C29.946 57.928 53.946 87.528 53.946 87.528C72.346 107.528 37.946 90.728 37.946 90.728C3.546 77.928 -20.454 103.528 -23.654 104.328C-26.854 105.128 -31.654 108.328 -32.454 101.928C-33.254 95.528 -40.108 79.665 -72.454 105.128C-98.636 125.456 -110.891 106.183 -110.891 106.183L-115.691 110.328C-133.691 77.128 -122.927 134.874 -122.927 134.874C-114.127 169.274 18.746 125.128 18.746 125.128C18.746 125.128 187.547 94.728 198.747 90.728C209.947 86.728 300.783 92.764 300.783 92.764L295.547 73.419C230.747 27.019 215.547 53.128 201.947 49.128C188.347 45.128 190.747 54.728 187.547 55.528C184.347 56.328 145.147 31.528 138.747 32.328z"}
+ ,
+ {"fill": "#f3bf9c",
+ "path":"M140.056 34.073C133.655 34.873 107.313 11.613 123.255 42.873C143.656 82.874 64.855 82.074 48.055 70.874C31.255 59.674 55.255 89.274 55.255 89.274C73.655 109.274 39.255 92.474 39.255 92.474C4.855 79.674 -19.145 105.274 -22.345 106.074C-25.545 106.874 -30.345 110.074 -31.145 103.674C-31.945 97.274 -38.668 81.578 -71.145 106.874C-98.564 127.947 -110.509 109.219 -110.509 109.219L-115.709 111.874C-131.709 81.674 -122.273 137.929 -122.273 137.929C-113.473 172.329 20.055 126.874 20.055 126.874C20.055 126.874 188.856 96.474 200.056 92.474C211.256 88.474 301.22 94.437 301.22 94.437L296.056 74.583C231.256 28.183 216.856 54.874 203.256 50.874C189.656 46.873 192.056 56.474 188.856 57.274C185.656 58.074 146.456 33.273 140.056 34.073z"}
+ ,
+ {"fill": "#f5ccb0",
+ "path":"M141.365 35.819C134.965 36.619 107.523 13.944 124.565 44.619C146.565 84.219 66.164 83.819 49.364 72.619C32.564 61.419 56.564 91.019 56.564 91.019C74.964 111.019 40.564 94.219 40.564 94.219C6.164 81.419 -17.836 107.019 -21.036 107.819C-24.236 108.619 -29.036 111.819 -29.836 105.419C-30.636 99.019 -37.227 83.492 -69.836 108.619C-98.491 130.438 -110.127 112.256 -110.127 112.256L-115.727 113.419C-130.128 85.019 -121.618 140.983 -121.618 140.983C-112.818 175.384 21.364 128.619 21.364 128.619C21.364 128.619 190.165 98.219 201.365 94.219C212.565 90.219 301.656 96.11 301.656 96.11L296.565 75.746C231.765 29.346 218.165 56.619 204.565 52.619C190.965 48.619 193.365 58.219 190.165 59.019C186.965 59.819 147.765 35.019 141.365 35.819z"}
+ ,
+ {"fill": "#f8d8c4",
+ "path":"M142.674 37.565C136.274 38.365 108.832 15.689 125.874 46.365C147.874 85.965 67.474 85.565 50.674 74.365C33.874 63.165 57.874 92.765 57.874 92.765C76.274 112.765 41.874 95.965 41.874 95.965C7.473 83.165 -16.527 108.765 -19.727 109.565C-22.927 110.365 -27.727 113.565 -28.527 107.165C-29.327 100.765 -35.786 85.405 -68.527 110.365C-98.418 132.929 -109.745 115.293 -109.745 115.293L-115.745 114.965C-129.346 88.564 -120.963 144.038 -120.963 144.038C-112.163 178.438 22.673 130.365 22.673 130.365C22.673 130.365 191.474 99.965 202.674 95.965C213.874 91.965 302.093 97.783 302.093 97.783L297.075 76.91C232.274 30.51 219.474 58.365 205.874 54.365C192.274 50.365 194.674 59.965 191.474 60.765C188.274 61.565 149.074 36.765 142.674 37.565z"}
+ ,
+ {"fill": "#fae5d7",
+ "path":"M143.983 39.31C137.583 40.11 110.529 17.223 127.183 48.11C149.183 88.91 68.783 87.31 51.983 76.11C35.183 64.91 59.183 94.51 59.183 94.51C77.583 114.51 43.183 97.71 43.183 97.71C8.783 84.91 -15.217 110.51 -18.417 111.31C-21.618 112.11 -26.418 115.31 -27.218 108.91C-28.018 102.51 -34.346 87.318 -67.218 112.11C-98.345 135.42 -109.363 118.329 -109.363 118.329L-115.764 116.51C-128.764 92.51 -120.309 147.093 -120.309 147.093C-111.509 181.493 23.983 132.11 23.983 132.11C23.983 132.11 192.783 101.71 203.983 97.71C215.183 93.71 302.529 99.456 302.529 99.456L297.583 78.074C232.783 31.673 220.783 60.11 207.183 56.11C193.583 52.11 195.983 61.71 192.783 62.51C189.583 63.31 150.383 38.51 143.983 39.31z"}
+ ,
+ {"fill": "#fcf2eb",
+ "path":"M145.292 41.055C138.892 41.855 112.917 18.411 128.492 49.855C149.692 92.656 70.092 89.056 53.292 77.856C36.492 66.656 60.492 96.256 60.492 96.256C78.892 116.256 44.492 99.456 44.492 99.456C10.092 86.656 -13.908 112.256 -17.108 113.056C-20.308 113.856 -25.108 117.056 -25.908 110.656C-26.708 104.256 -32.905 89.232 -65.908 113.856C-98.273 137.911 -108.982 121.365 -108.982 121.365L-115.782 118.056C-128.582 94.856 -119.654 150.147 -119.654 150.147C-110.854 184.547 25.292 133.856 25.292 133.856C25.292 133.856 194.093 103.456 205.293 99.456C216.493 95.456 302.965 101.128 302.965 101.128L298.093 79.237C233.292 32.837 222.093 61.856 208.493 57.856C194.893 53.855 197.293 63.456 194.093 64.256C190.892 65.056 151.692 40.255 145.292 41.055z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M-115.8 119.601C-128.6 97.6 -119 153.201 -119 153.201C-110.2 187.601 26.6 135.601 26.6 135.601C26.6 135.601 195.401 105.2 206.601 101.2C217.801 97.2 303.401 102.8 303.401 102.8L298.601 80.4C233.801 34 223.401 63.6 209.801 59.6C196.201 55.6 198.601 65.2 195.401 66C192.201 66.8 153.001 42 146.601 42.8C140.201 43.6 114.981 19.793 129.801 51.6C152.028 99.307 69.041 89.227 54.6 79.6C37.8 68.4 61.8 98 61.8 98C80.2 118.001 45.8 101.2 45.8 101.2C11.4 88.4 -12.6 114.001 -15.8 114.801C-19 115.601 -23.8 118.801 -24.6 112.401C-25.4 106 -31.465 91.144 -64.6 115.601C-98.2 140.401 -108.6 124.401 -108.6 124.401L-115.8 119.601z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-74.2 149.601C-74.2 149.601 -81.4 161.201 -60.6 174.401C-60.6 174.401 -59.2 175.801 -77.2 171.601C-77.2 171.601 -83.4 169.601 -85 159.201C-85 159.201 -89.8 154.801 -94.6 149.201C-99.4 143.601 -74.2 149.601 -74.2 149.601z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M65.8 102C65.8 102 83.498 128.821 82.9 133.601C81.6 144.001 81.4 153.601 84.6 157.601C87.801 161.601 96.601 194.801 96.601 194.801C96.601 194.801 96.201 196.001 108.601 158.001C108.601 158.001 120.201 142.001 100.201 123.601C100.201 123.601 65 94.8 65.8 102z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-54.2 176.401C-54.2 176.401 -43 183.601 -57.4 214.801L-51 212.401C-51 212.401 -51.8 223.601 -55 226.001L-47.8 222.801C-47.8 222.801 -43 230.801 -47 235.601C-47 235.601 -30.2 243.601 -31 250.001C-31 250.001 -24.6 242.001 -28.6 235.601C-32.6 229.201 -39.8 233.201 -39 214.801L-47.8 218.001C-47.8 218.001 -42.2 209.201 -42.2 202.801L-50.2 205.201C-50.2 205.201 -34.731 178.623 -45.4 177.201C-51.4 176.401 -54.2 176.401 -54.2 176.401z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-21.8 193.201C-21.8 193.201 -19 188.801 -21.8 189.601C-24.6 190.401 -55.8 205.201 -61.8 214.801C-61.8 214.801 -27.4 190.401 -21.8 193.201z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-11.4 201.201C-11.4 201.201 -8.6 196.801 -11.4 197.601C-14.2 198.401 -45.4 213.201 -51.4 222.801C-51.4 222.801 -17 198.401 -11.4 201.201z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M1.8 186.001C1.8 186.001 4.6 181.601 1.8 182.401C-1 183.201 -32.2 198.001 -38.2 207.601C-38.2 207.601 -3.8 183.201 1.8 186.001z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-21.4 229.601C-21.4 229.601 -21.4 223.601 -24.2 224.401C-27 225.201 -63 242.801 -69 252.401C-69 252.401 -27 226.801 -21.4 229.601z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-20.2 218.801C-20.2 218.801 -19 214.001 -21.8 214.801C-23.8 214.801 -50.2 226.401 -56.2 236.001C-56.2 236.001 -26.6 214.401 -20.2 218.801z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-34.6 266.401L-44.6 274.001C-44.6 274.001 -34.2 266.401 -30.6 267.601C-30.6 267.601 -37.4 278.801 -38.2 284.001C-38.2 284.001 -27.8 271.201 -22.2 271.601C-22.2 271.601 -14.6 272.001 -14.6 282.801C-14.6 282.801 -9 272.401 -5.8 272.801C-5.8 272.801 -4.6 279.201 -5.8 286.001C-5.8 286.001 -1.8 278.401 2.2 280.001C2.2 280.001 8.6 278.001 7.8 289.601C7.8 289.601 7.8 300.001 7 302.801C7 302.801 12.6 276.401 15 276.001C15 276.001 23 274.801 27.8 283.601C27.8 283.601 23.8 276.001 28.6 278.001C28.6 278.001 39.4 279.601 42.6 286.401C42.6 286.401 35.8 274.401 41.4 277.601C41.4 277.601 48.2 277.601 49.4 284.001C49.4 284.001 57.8 305.201 59.8 306.801C59.8 306.801 52.2 285.201 53.8 285.201C53.8 285.201 51.8 273.201 57 288.001C57 288.001 53.8 274.001 59.4 274.801C65 275.601 69.4 285.601 77.8 283.201C77.8 283.201 87.401 288.801 89.401 219.601L-34.6 266.401z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-29.8 173.601C-29.8 173.601 -15 167.601 25 173.601C25 173.601 32.2 174.001 39 165.201C45.8 156.401 72.6 149.201 79 151.201L88.601 157.601L89.401 158.801C89.401 158.801 101.801 169.201 102.201 176.801C102.601 184.401 87.801 232.401 78.2 248.401C68.6 264.401 59 276.801 39.8 274.401C39.8 274.401 19 270.401 -6.6 274.401C-6.6 274.401 -35.8 272.801 -38.6 264.801C-41.4 256.801 -27.4 241.601 -27.4 241.601C-27.4 241.601 -23 233.201 -24.2 218.801C-25.4 204.401 -25 176.401 -29.8 173.601z"}
+ ,
+ {"fill": "#e5668c",
+ "path":"M-7.8 175.601C0.6 194.001 -29 259.201 -29 259.201C-31 260.801 -16.34 266.846 -6.2 264.401C4.746 261.763 45 266.001 45 266.001C68.6 250.401 81.4 206.001 81.4 206.001C81.4 206.001 91.801 182.001 74.2 178.801C56.6 175.601 -7.8 175.601 -7.8 175.601z"}
+ ,
+ {"fill": "#b23259",
+ "path":"M-9.831 206.497C-6.505 193.707 -4.921 181.906 -7.8 175.601C-7.8 175.601 54.6 182.001 65.8 161.201C70.041 153.326 84.801 184.001 84.4 193.601C84.4 193.601 21.4 208.001 6.6 196.801L-9.831 206.497z"}
+ ,
+ {"fill": "#a5264c",
+ "path":"M-5.4 222.801C-5.4 222.801 -3.4 230.001 -5.8 234.001C-5.8 234.001 -7.4 234.801 -8.6 235.201C-8.6 235.201 -7.4 238.801 -1.4 240.401C-1.4 240.401 0.6 244.801 3 245.201C5.4 245.601 10.2 251.201 14.2 250.001C18.2 248.801 29.4 244.801 29.4 244.801C29.4 244.801 35 241.601 43.8 245.201C43.8 245.201 46.175 244.399 46.6 240.401C47.1 235.701 50.2 232.001 52.2 230.001C54.2 228.001 63.8 215.201 62.6 214.801C61.4 214.401 -5.4 222.801 -5.4 222.801z"}
+ ,
+ {"fill": "#ff727f", "stroke":"#000000",
+ "path":"M-9.8 174.401C-9.8 174.401 -12.6 196.801 -9.4 205.201C-6.2 213.601 -7 215.601 -7.8 219.601C-8.6 223.601 -4.2 233.601 1.4 239.601L13.4 241.201C13.4 241.201 28.6 237.601 37.8 240.401C37.8 240.401 46.794 241.744 50.2 226.801C50.2 226.801 55 220.401 62.2 217.601C69.4 214.801 76.6 173.201 72.6 165.201C68.6 157.201 54.2 152.801 38.2 168.401C22.2 184.001 20.2 167.201 -9.8 174.401z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-8.2 249.201C-8.2 249.201 -9 247.201 -13.4 246.801C-13.4 246.801 -35.8 243.201 -44.2 230.801C-44.2 230.801 -51 225.201 -46.6 236.801C-46.6 236.801 -36.2 257.201 -29.4 260.001C-29.4 260.001 -13 264.001 -8.2 249.201z"}
+ ,
+ {"fill": "#cc3f4c",
+ "path":"M71.742 185.229C72.401 177.323 74.354 168.709 72.6 165.201C66.154 152.307 49.181 157.695 38.2 168.401C22.2 184.001 20.2 167.201 -9.8 174.401C-9.8 174.401 -11.545 188.364 -10.705 198.376C-10.705 198.376 26.6 186.801 27.4 192.401C27.4 192.401 29 189.201 38.2 189.201C47.4 189.201 70.142 188.029 71.742 185.229z"}
+ ,
+ {"stroke":"#a51926", "width":2,
+ "path":"M28.6 175.201C28.6 175.201 33.4 180.001 29.8 189.601C29.8 189.601 15.4 205.601 17.4 219.601"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-19.4 260.001C-19.4 260.001 -23.8 247.201 -15 254.001C-15 254.001 -10.2 256.001 -11.4 257.601C-12.6 259.201 -18.2 263.201 -19.4 260.001z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-14.36 261.201C-14.36 261.201 -17.88 250.961 -10.84 256.401C-10.84 256.401 -6.419 258.849 -7.96 259.281C-12.52 260.561 -7.96 263.121 -14.36 261.201z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-9.56 261.201C-9.56 261.201 -13.08 250.961 -6.04 256.401C-6.04 256.401 -1.665 258.711 -3.16 259.281C-6.52 260.561 -3.16 263.121 -9.56 261.201z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-2.96 261.401C-2.96 261.401 -6.48 251.161 0.56 256.601C0.56 256.601 4.943 258.933 3.441 259.481C0.48 260.561 3.441 263.321 -2.96 261.401z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M3.52 261.321C3.52 261.321 0 251.081 7.041 256.521C7.041 256.521 10.881 258.121 9.921 259.401C8.961 260.681 9.921 263.241 3.52 261.321z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M10.2 262.001C10.2 262.001 5.4 249.601 14.6 256.001C14.6 256.001 19.4 258.001 18.2 259.601C17 261.201 18.2 264.401 10.2 262.001z"}
+ ,
+ {"stroke":"#a5264c", "width":2,
+ "path":"M-18.2 244.801C-18.2 244.801 -5 242.001 1 245.201C1 245.201 7 246.401 8.2 246.001C9.4 245.601 12.6 245.201 12.6 245.201"}
+ ,
+ {"stroke":"#a5264c", "width":2,
+ "path":"M15.8 253.601C15.8 253.601 27.8 240.001 39.8 244.401C46.816 246.974 45.8 243.601 46.6 240.801C47.4 238.001 47.6 233.801 52.6 230.801"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M33 237.601C33 237.601 29 226.801 26.2 239.601C23.4 252.401 20.2 256.001 18.6 258.801C18.6 258.801 18.6 264.001 27 263.601C27 263.601 37.8 263.201 38.2 260.401C38.6 257.601 37 246.001 33 237.601z"}
+ ,
+ {"stroke":"#a5264c", "width":2,
+ "path":"M47 244.801C47 244.801 50.6 242.401 53 243.601"}
+ ,
+ {"stroke":"#a5264c", "width":2,
+ "path":"M53.5 228.401C53.5 228.401 56.4 223.501 61.2 222.701"}
+ ,
+ {"fill": "#b2b2b2",
+ "path":"M-25.8 265.201C-25.8 265.201 -7.8 268.401 -3.4 266.801C-3.4 266.801 5.4 266.801 -3 268.801C-3 268.801 -15.8 268.801 -23.8 267.601C-23.8 267.601 -35.4 262.001 -25.8 265.201z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-11.8 172.001C-11.8 172.001 5.8 172.001 7.8 172.801C7.8 172.801 15 203.601 11.4 211.201C11.4 211.201 10.2 214.001 7.4 208.401C7.4 208.401 -11 175.601 -14.2 173.601C-17.4 171.601 -13 172.001 -11.8 172.001z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-88.9 169.301C-88.9 169.301 -80 171.001 -67.4 173.601C-67.4 173.601 -62.6 196.001 -59.4 200.801C-56.2 205.601 -59.8 205.601 -63.4 202.801C-67 200.001 -81.8 186.001 -83.8 181.601C-85.8 177.201 -88.9 169.301 -88.9 169.301z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-67.039 173.818C-67.039 173.818 -61.239 175.366 -60.23 177.581C-59.222 179.795 -61.432 183.092 -61.432 183.092C-61.432 183.092 -62.432 186.397 -63.634 184.235C-64.836 182.072 -67.708 174.412 -67.039 173.818z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-67 173.601C-67 173.601 -63.4 178.801 -59.8 178.801C-56.2 178.801 -55.818 178.388 -53 179.001C-48.4 180.001 -48.8 178.001 -42.2 179.201C-39.56 179.681 -37 178.801 -34.2 180.001C-31.4 181.201 -28.2 180.401 -27 178.401C-25.8 176.401 -21 172.201 -21 172.201C-21 172.201 -33.8 174.001 -36.6 174.801C-36.6 174.801 -59 176.001 -67 173.601z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-22.4 173.801C-22.4 173.801 -28.85 177.301 -29.25 179.701C-29.65 182.101 -24 185.801 -24 185.801C-24 185.801 -21.25 190.401 -20.65 188.001C-20.05 185.601 -21.6 174.201 -22.4 173.801z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-59.885 179.265C-59.885 179.265 -52.878 190.453 -52.661 179.242C-52.661 179.242 -52.104 177.984 -53.864 177.962C-59.939 177.886 -58.418 173.784 -59.885 179.265z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-52.707 179.514C-52.707 179.514 -44.786 190.701 -45.422 179.421C-45.422 179.421 -45.415 179.089 -47.168 178.936C-51.915 178.522 -51.57 174.004 -52.707 179.514z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-45.494 179.522C-45.494 179.522 -37.534 190.15 -38.203 180.484C-38.203 180.484 -38.084 179.251 -39.738 178.95C-43.63 178.244 -43.841 174.995 -45.494 179.522z"}
+ ,
+ {"fill": "#ffffcc", "stroke":"#000000", "width":0.5,
+ "path":"M-38.618 179.602C-38.618 179.602 -30.718 191.163 -30.37 181.382C-30.37 181.382 -28.726 180.004 -30.472 179.782C-36.29 179.042 -35.492 174.588 -38.618 179.602z"}
+ ,
+ {"fill": "#e5e5b2",
+ "path":"M-74.792 183.132L-82.45 181.601C-85.05 176.601 -87.15 170.451 -87.15 170.451C-87.15 170.451 -80.8 171.451 -68.3 174.251C-68.3 174.251 -67.424 177.569 -65.952 183.364L-74.792 183.132z"}
+ ,
+ {"fill": "#e5e5b2",
+ "path":"M-9.724 178.47C-11.39 175.964 -12.707 174.206 -13.357 173.8C-16.37 171.917 -12.227 172.294 -11.098 172.294C-11.098 172.294 5.473 172.294 7.356 173.047C7.356 173.047 7.88 175.289 8.564 178.68C8.564 178.68 -1.524 176.67 -9.724 178.47z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M43.88 40.321C71.601 44.281 97.121 8.641 98.881 -1.04C100.641 -10.72 90.521 -22.6 90.521 -22.6C91.841 -25.68 87.001 -39.76 81.721 -49C76.441 -58.24 60.54 -57.266 43 -58.24C27.16 -59.12 8.68 -35.8 7.36 -34.04C6.04 -32.28 12.2 6.001 13.52 11.721C14.84 17.441 12.2 43.841 12.2 43.841C46.44 34.741 16.16 36.361 43.88 40.321z"}
+ ,
+ {"fill": "#ea8e51",
+ "path":"M8.088 -33.392C6.792 -31.664 12.84 5.921 14.136 11.537C15.432 17.153 12.84 43.073 12.84 43.073C45.512 34.193 16.728 35.729 43.944 39.617C71.161 43.505 96.217 8.513 97.945 -0.992C99.673 -10.496 89.737 -22.16 89.737 -22.16C91.033 -25.184 86.281 -39.008 81.097 -48.08C75.913 -57.152 60.302 -56.195 43.08 -57.152C27.528 -58.016 9.384 -35.12 8.088 -33.392z"}
+ ,
+ {"fill": "#efaa7c",
+ "path":"M8.816 -32.744C7.544 -31.048 13.48 5.841 14.752 11.353C16.024 16.865 13.48 42.305 13.48 42.305C44.884 33.145 17.296 35.097 44.008 38.913C70.721 42.729 95.313 8.385 97.009 -0.944C98.705 -10.272 88.953 -21.72 88.953 -21.72C90.225 -24.688 85.561 -38.256 80.473 -47.16C75.385 -56.064 60.063 -55.125 43.16 -56.064C27.896 -56.912 10.088 -34.44 8.816 -32.744z"}
+ ,
+ {"fill": "#f4c6a8",
+ "path":"M9.544 -32.096C8.296 -30.432 14.12 5.761 15.368 11.169C16.616 16.577 14.12 41.537 14.12 41.537C43.556 32.497 17.864 34.465 44.072 38.209C70.281 41.953 94.409 8.257 96.073 -0.895C97.737 -10.048 88.169 -21.28 88.169 -21.28C89.417 -24.192 84.841 -37.504 79.849 -46.24C74.857 -54.976 59.824 -54.055 43.24 -54.976C28.264 -55.808 10.792 -33.76 9.544 -32.096z"}
+ ,
+ {"fill": "#f9e2d3",
+ "path":"M10.272 -31.448C9.048 -29.816 14.76 5.681 15.984 10.985C17.208 16.289 14.76 40.769 14.76 40.769C42.628 31.849 18.432 33.833 44.136 37.505C69.841 41.177 93.505 8.129 95.137 -0.848C96.769 -9.824 87.385 -20.84 87.385 -20.84C88.609 -23.696 84.121 -36.752 79.225 -45.32C74.329 -53.888 59.585 -52.985 43.32 -53.888C28.632 -54.704 11.496 -33.08 10.272 -31.448z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M44.2 36.8C69.4 40.4 92.601 8 94.201 -0.8C95.801 -9.6 86.601 -20.4 86.601 -20.4C87.801 -23.2 83.4 -36 78.6 -44.4C73.8 -52.8 59.346 -51.914 43.4 -52.8C29 -53.6 12.2 -32.4 11 -30.8C9.8 -29.2 15.4 5.6 16.6 10.8C17.8 16 15.4 40 15.4 40C40.9 31.4 19 33.2 44.2 36.8z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M90.601 2.8C90.601 2.8 62.8 10.4 51.2 8.8C51.2 8.8 35.4 2.2 26.6 24C26.6 24 23 31.2 21 33.2C19 35.2 90.601 2.8 90.601 2.8z"}
+ ,
+ {"fill": "#000000",
+ "path":"M94.401 0.6C94.401 0.6 65.4 12.8 55.4 12.4C55.4 12.4 39 7.8 30.6 22.4C30.6 22.4 22.2 31.6 19 33.2C19 33.2 18.6 34.8 25 30.8L35.4 36C35.4 36 50.2 45.6 59.8 29.6C59.8 29.6 63.8 18.4 63.8 16.4C63.8 14.4 85 8.8 86.601 8.4C88.201 8 94.801 3.8 94.401 0.6z"}
+ ,
+ {"fill": "#99cc32",
+ "path":"M47 36.514C40.128 36.514 31.755 32.649 31.755 26.4C31.755 20.152 40.128 13.887 47 13.887C53.874 13.887 59.446 18.952 59.446 25.2C59.446 31.449 53.874 36.514 47 36.514z"}
+ ,
+ {"fill": "#659900",
+ "path":"M43.377 19.83C38.531 20.552 33.442 22.055 33.514 21.839C35.054 17.22 41.415 13.887 47 13.887C51.296 13.887 55.084 15.865 57.32 18.875C57.32 18.875 52.004 18.545 43.377 19.83z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M55.4 19.6C55.4 19.6 51 16.4 51 18.6C51 18.6 54.6 23 55.4 19.6z"}
+ ,
+ {"fill": "#000000",
+ "path":"M45.4 27.726C42.901 27.726 40.875 25.7 40.875 23.2C40.875 20.701 42.901 18.675 45.4 18.675C47.9 18.675 49.926 20.701 49.926 23.2C49.926 25.7 47.9 27.726 45.4 27.726z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M-58.6 14.4C-58.6 14.4 -61.8 -6.8 -59.4 -11.2C-59.4 -11.2 -48.6 -21.2 -49 -24.8C-49 -24.8 -49.4 -42.8 -50.6 -43.6C-51.8 -44.4 -59.4 -50.4 -65.4 -44C-65.4 -44 -75.8 -26 -75 -19.6L-75 -17.6C-75 -17.6 -82.6 -18 -84.2 -16C-84.2 -16 -85.4 -10.8 -86.6 -10.4C-86.6 -10.4 -89.4 -8 -87.4 -5.2C-87.4 -5.2 -89.4 -2.8 -89 1.2L-81.4 5.2C-81.4 5.2 -79.4 19.6 -68.6 24.8C-63.764 27.129 -60.6 20.4 -58.6 14.4z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M-59.6 12.56C-59.6 12.56 -62.48 -6.52 -60.32 -10.48C-60.32 -10.48 -50.6 -19.48 -50.96 -22.72C-50.96 -22.72 -51.32 -38.92 -52.4 -39.64C-53.48 -40.36 -60.32 -45.76 -65.72 -40C-65.72 -40 -75.08 -23.8 -74.36 -18.04L-74.36 -16.24C-74.36 -16.24 -81.2 -16.6 -82.64 -14.8C-82.64 -14.8 -83.72 -10.12 -84.8 -9.76C-84.8 -9.76 -87.32 -7.6 -85.52 -5.08C-85.52 -5.08 -87.32 -2.92 -86.96 0.68L-80.12 4.28C-80.12 4.28 -78.32 17.24 -68.6 21.92C-64.248 24.015 -61.4 17.96 -59.6 12.56z"}
+ ,
+ {"fill": "#eb955c",
+ "path":"M-51.05 -42.61C-52.14 -43.47 -59.63 -49.24 -65.48 -43C-65.48 -43 -75.62 -25.45 -74.84 -19.21L-74.84 -17.26C-74.84 -17.26 -82.25 -17.65 -83.81 -15.7C-83.81 -15.7 -84.98 -10.63 -86.15 -10.24C-86.15 -10.24 -88.88 -7.9 -86.93 -5.17C-86.93 -5.17 -88.88 -2.83 -88.49 1.07L-81.08 4.97C-81.08 4.97 -79.13 19.01 -68.6 24.08C-63.886 26.35 -60.8 19.79 -58.85 13.94C-58.85 13.94 -61.97 -6.73 -59.63 -11.02C-59.63 -11.02 -49.1 -20.77 -49.49 -24.28C-49.49 -24.28 -49.88 -41.83 -51.05 -42.61z"}
+ ,
+ {"fill": "#f2b892",
+ "path":"M-51.5 -41.62C-52.48 -42.54 -59.86 -48.08 -65.56 -42C-65.56 -42 -75.44 -24.9 -74.68 -18.82L-74.68 -16.92C-74.68 -16.92 -81.9 -17.3 -83.42 -15.4C-83.42 -15.4 -84.56 -10.46 -85.7 -10.08C-85.7 -10.08 -88.36 -7.8 -86.46 -5.14C-86.46 -5.14 -88.36 -2.86 -87.98 0.94L-80.76 4.74C-80.76 4.74 -78.86 18.42 -68.6 23.36C-64.006 25.572 -61 19.18 -59.1 13.48C-59.1 13.48 -62.14 -6.66 -59.86 -10.84C-59.86 -10.84 -49.6 -20.34 -49.98 -23.76C-49.98 -23.76 -50.36 -40.86 -51.5 -41.62z"}
+ ,
+ {"fill": "#f8dcc8",
+ "path":"M-51.95 -40.63C-52.82 -41.61 -60.09 -46.92 -65.64 -41C-65.64 -41 -75.26 -24.35 -74.52 -18.43L-74.52 -16.58C-74.52 -16.58 -81.55 -16.95 -83.03 -15.1C-83.03 -15.1 -84.14 -10.29 -85.25 -9.92C-85.25 -9.92 -87.84 -7.7 -85.99 -5.11C-85.99 -5.11 -87.84 -2.89 -87.47 0.81L-80.44 4.51C-80.44 4.51 -78.59 17.83 -68.6 22.64C-64.127 24.794 -61.2 18.57 -59.35 13.02C-59.35 13.02 -62.31 -6.59 -60.09 -10.66C-60.09 -10.66 -50.1 -19.91 -50.47 -23.24C-50.47 -23.24 -50.84 -39.89 -51.95 -40.63z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M-59.6 12.46C-59.6 12.46 -62.48 -6.52 -60.32 -10.48C-60.32 -10.48 -50.6 -19.48 -50.96 -22.72C-50.96 -22.72 -51.32 -38.92 -52.4 -39.64C-53.16 -40.68 -60.32 -45.76 -65.72 -40C-65.72 -40 -75.08 -23.8 -74.36 -18.04L-74.36 -16.24C-74.36 -16.24 -81.2 -16.6 -82.64 -14.8C-82.64 -14.8 -83.72 -10.12 -84.8 -9.76C-84.8 -9.76 -87.32 -7.6 -85.52 -5.08C-85.52 -5.08 -87.32 -2.92 -86.96 0.68L-80.12 4.28C-80.12 4.28 -78.32 17.24 -68.6 21.92C-64.248 24.015 -61.4 17.86 -59.6 12.46z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-62.7 6.2C-62.7 6.2 -84.3 -4 -85.2 -4.8C-85.2 -4.8 -76.1 3.4 -75.3 3.4C-74.5 3.4 -62.7 6.2 -62.7 6.2z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-79.8 0C-79.8 0 -61.4 3.6 -61.4 8C-61.4 10.912 -61.643 24.331 -67 22.8C-75.4 20.4 -71.8 6 -79.8 0z"}
+ ,
+ {"fill": "#99cc32",
+ "path":"M-71.4 3.8C-71.4 3.8 -62.422 5.274 -61.4 8C-60.8 9.6 -60.137 17.908 -65.6 19C-70.152 19.911 -72.382 9.69 -71.4 3.8z"}
+ ,
+ {"fill": "#000000",
+ "path":"M14.595 46.349C14.098 44.607 15.409 44.738 17.2 44.2C19.2 43.6 31.4 39.8 32.2 37.2C33 34.6 46.2 39 46.2 39C48 39.8 52.4 42.4 52.4 42.4C57.2 43.6 63.8 44 63.8 44C66.2 45 69.6 47.8 69.6 47.8C84.2 58 96.601 50.8 96.601 50.8C116.601 44.2 110.601 27 110.601 27C107.601 18 110.801 14.6 110.801 14.6C111.001 10.8 118.201 17.2 118.201 17.2C120.801 21.4 121.601 26.4 121.601 26.4C129.601 37.6 126.201 19.8 126.201 19.8C126.401 18.8 123.601 15.2 123.601 14C123.601 12.8 121.801 9.4 121.801 9.4C118.801 6 121.201 -1 121.201 -1C123.001 -14.8 120.801 -13 120.801 -13C119.601 -14.8 110.401 -4.8 110.401 -4.8C108.201 -1.4 102.201 0.2 102.201 0.2C99.401 2 96.001 0.6 96.001 0.6C93.401 0.2 87.801 7.2 87.801 7.2C90.601 7 93.001 11.4 95.401 11.6C97.801 11.8 99.601 9.2 101.201 8.6C102.801 8 105.601 13.8 105.601 13.8C106.001 16.4 100.401 21.2 100.401 21.2C100.001 25.8 98.401 24.2 98.401 24.2C95.401 23.6 94.201 27.4 93.201 32C92.201 36.6 88.001 37 88.001 37C86.401 44.4 85.2 41.4 85.2 41.4C85 35.8 79 41.6 79 41.6C77.8 43.6 73.2 41.4 73.2 41.4C66.4 39.4 68.8 37.4 68.8 37.4C70.6 35.2 81.8 37.4 81.8 37.4C84 35.8 76 31.8 76 31.8C75.4 30 76.4 25.6 76.4 25.6C77.6 22.4 84.4 16.8 84.4 16.8C93.801 15.6 91.001 14 91.001 14C84.801 8.8 79 16.4 79 16.4C76.8 22.6 59.4 37.6 59.4 37.6C54.6 41 57.2 34.2 53.2 37.6C49.2 41 28.6 32 28.6 32C17.038 30.807 14.306 46.549 10.777 43.429C10.777 43.429 16.195 51.949 14.595 46.349z"}
+ ,
+ {"fill": "#000000",
+ "path":"M209.401 -120C209.401 -120 183.801 -112 181.001 -93.2C181.001 -93.2 178.601 -70.4 199.001 -52.8C199.001 -52.8 199.401 -46.4 201.401 -43.2C201.401 -43.2 199.801 -38.4 218.601 -46L245.801 -54.4C245.801 -54.4 252.201 -56.8 257.401 -65.6C262.601 -74.4 277.801 -93.2 274.201 -118.4C274.201 -118.4 275.401 -129.6 269.401 -130C269.401 -130 261.001 -131.6 253.801 -124C253.801 -124 247.001 -120.8 244.601 -121.2L209.401 -120z"}
+ ,
+ {"fill": "#000000",
+ "path":"M264.022 -120.99C264.022 -120.99 266.122 -129.92 261.282 -125.08C261.282 -125.08 254.242 -119.36 246.761 -119.36C246.761 -119.36 232.241 -117.16 227.841 -103.96C227.841 -103.96 223.881 -77.12 231.801 -71.4C231.801 -71.4 236.641 -63.92 243.681 -70.52C250.722 -77.12 266.222 -107.35 264.022 -120.99z"}
+ ,
+ {"fill": "#323232",
+ "path":"M263.648 -120.632C263.648 -120.632 265.738 -129.376 260.986 -124.624C260.986 -124.624 254.074 -119.008 246.729 -119.008C246.729 -119.008 232.473 -116.848 228.153 -103.888C228.153 -103.888 224.265 -77.536 232.041 -71.92C232.041 -71.92 236.793 -64.576 243.705 -71.056C250.618 -77.536 265.808 -107.24 263.648 -120.632z"}
+ ,
+ {"fill": "#666666",
+ "path":"M263.274 -120.274C263.274 -120.274 265.354 -128.832 260.69 -124.168C260.69 -124.168 253.906 -118.656 246.697 -118.656C246.697 -118.656 232.705 -116.536 228.465 -103.816C228.465 -103.816 224.649 -77.952 232.281 -72.44C232.281 -72.44 236.945 -65.232 243.729 -71.592C250.514 -77.952 265.394 -107.13 263.274 -120.274z"}
+ ,
+ {"fill": "#999999",
+ "path":"M262.9 -119.916C262.9 -119.916 264.97 -128.288 260.394 -123.712C260.394 -123.712 253.738 -118.304 246.665 -118.304C246.665 -118.304 232.937 -116.224 228.777 -103.744C228.777 -103.744 225.033 -78.368 232.521 -72.96C232.521 -72.96 237.097 -65.888 243.753 -72.128C250.41 -78.368 264.98 -107.02 262.9 -119.916z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M262.526 -119.558C262.526 -119.558 264.586 -127.744 260.098 -123.256C260.098 -123.256 253.569 -117.952 246.633 -117.952C246.633 -117.952 233.169 -115.912 229.089 -103.672C229.089 -103.672 225.417 -78.784 232.761 -73.48C232.761 -73.48 237.249 -66.544 243.777 -72.664C250.305 -78.784 264.566 -106.91 262.526 -119.558z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M262.151 -119.2C262.151 -119.2 264.201 -127.2 259.801 -122.8C259.801 -122.8 253.401 -117.6 246.601 -117.6C246.601 -117.6 233.401 -115.6 229.401 -103.6C229.401 -103.6 225.801 -79.2 233.001 -74C233.001 -74 237.401 -67.2 243.801 -73.2C250.201 -79.2 264.151 -106.8 262.151 -119.2z"}
+ ,
+ {"fill": "#992600",
+ "path":"M50.6 84C50.6 84 30.2 64.8 22.2 64C22.2 64 -12.2 60 -27 78C-27 78 -9.4 57.6 18.2 63.2C18.2 63.2 -3.4 58.8 -15.8 62C-15.8 62 -32.6 62 -42.2 76L-45 80.8C-45 80.8 -41 66 -22.6 60C-22.6 60 0.2 55.2 11 60C11 60 -10.6 53.2 -20.6 55.2C-20.6 55.2 -51 52.8 -63.8 79.2C-63.8 79.2 -59.8 64.8 -45 57.6C-45 57.6 -31.4 48.8 -11 51.6C-11 51.6 3.4 54.8 8.6 57.2C13.8 59.6 12.6 56.8 4.2 52C4.2 52 -1.4 42 -15.4 42.4C-15.4 42.4 -58.2 46 -68.6 58C-68.6 58 -55 46.8 -44.6 44C-44.6 44 -22.2 36 -13.8 36.8C-13.8 36.8 11 37.8 18.6 33.8C18.6 33.8 7.4 38.8 10.6 42C13.8 45.2 20.6 52.8 20.6 54C20.6 55.2 44.8 77.3 48.4 81.7L50.6 84z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M189 278C189 278 173.5 241.5 161 232C161 232 187 248 190.5 266C190.5 266 190.5 276 189 278z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M236 285.5C236 285.5 209.5 230.5 191 206.5C191 206.5 234.5 244 239.5 270.5L240 276L237 273.5C237 273.5 236.5 282.5 236 285.5z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M292.5 237C292.5 237 230 177.5 228.5 175C228.5 175 289 241 292 248.5C292 248.5 290 239.5 292.5 237z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M104 280.5C104 280.5 123.5 228.5 142.5 251C142.5 251 157.5 261 157 264C157 264 153 257.5 135 258C135 258 116 255 104 280.5z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M294.5 153C294.5 153 249.5 124.5 242 123C230.193 120.639 291.5 152 296.5 162.5C296.5 162.5 298.5 160 294.5 153z"}
+ ,
+ {"fill": "#000000",
+ "path":"M143.801 259.601C143.801 259.601 164.201 257.601 171.001 250.801L175.401 254.401L193.001 216.001L196.601 221.201C196.601 221.201 211.001 206.401 210.201 198.401C209.401 190.401 223.001 204.401 223.001 204.401C223.001 204.401 222.201 192.801 229.401 199.601C229.401 199.601 227.001 184.001 235.401 192.001C235.401 192.001 224.864 161.844 247.401 187.601C253.001 194.001 248.601 187.201 248.601 187.201C248.601 187.201 222.601 139.201 244.201 153.601C244.201 153.601 246.201 130.801 245.001 126.401C243.801 122.001 241.801 99.6 237.001 94.4C232.201 89.2 237.401 87.6 243.001 92.8C243.001 92.8 231.801 68.8 245.001 80.8C245.001 80.8 241.401 65.6 237.001 62.8C237.001 62.8 231.401 45.6 246.601 56.4C246.601 56.4 242.201 44 239.001 40.8C239.001 40.8 227.401 13.2 234.601 18L239.001 21.6C239.001 21.6 232.201 7.6 238.601 12C245.001 16.4 245.001 16 245.001 16C245.001 16 223.801 -17.2 244.201 0.4C244.201 0.4 236.042 -13.518 232.601 -20.4C232.601 -20.4 213.801 -40.8 228.201 -34.4L233.001 -32.8C233.001 -32.8 224.201 -42.8 216.201 -44.4C208.201 -46 218.601 -52.4 225.001 -50.4C231.401 -48.4 247.001 -40.8 247.001 -40.8C247.001 -40.8 259.801 -22 263.801 -21.6C263.801 -21.6 243.801 -29.2 249.801 -21.2C249.801 -21.2 264.201 -7.2 257.001 -7.6C257.001 -7.6 251.001 -0.4 255.801 8.4C255.801 8.4 237.342 -9.991 252.201 15.6L259.001 32C259.001 32 234.601 7.2 245.801 29.2C245.801 29.2 263.001 52.8 265.001 53.2C267.001 53.6 271.401 62.4 271.401 62.4L267.001 60.4L272.201 69.2C272.201 69.2 261.001 57.2 267.001 70.4L272.601 84.8C272.601 84.8 252.201 62.8 265.801 92.4C265.801 92.4 249.401 87.2 258.201 104.4C258.201 104.4 256.601 120.401 257.001 125.601C257.401 130.801 258.601 159.201 254.201 167.201C249.801 175.201 260.201 194.401 262.201 198.401C264.201 202.401 267.801 213.201 259.001 204.001C250.201 194.801 254.601 200.401 256.601 209.201C258.601 218.001 264.601 233.601 263.801 239.201C263.801 239.201 262.601 240.401 259.401 236.801C259.401 236.801 244.601 214.001 246.201 228.401C246.201 228.401 245.001 236.401 241.801 245.201C241.801 245.201 238.601 256.001 238.601 247.201C238.601 247.201 235.401 230.401 232.601 238.001C229.801 245.601 226.201 251.601 223.401 254.001C220.601 256.401 215.401 233.601 214.201 244.001C214.201 244.001 202.201 231.601 197.401 248.001L185.801 264.401C185.801 264.401 185.401 252.001 184.201 258.001C184.201 258.001 154.201 264.001 143.801 259.601z"}
+ ,
+ {"fill": "#000000",
+ "path":"M109.401 -97.2C109.401 -97.2 97.801 -105.2 93.801 -104.8C89.801 -104.4 121.401 -113.6 162.601 -86C162.601 -86 167.401 -83.2 171.001 -83.6C171.001 -83.6 174.201 -81.2 171.401 -77.6C171.401 -77.6 162.601 -68 173.801 -56.8C173.801 -56.8 192.201 -50 186.601 -58.8C186.601 -58.8 197.401 -54.8 199.801 -50.8C202.201 -46.8 201.001 -50.8 201.001 -50.8C201.001 -50.8 194.601 -58 188.601 -63.2C188.601 -63.2 183.401 -65.2 180.601 -73.6C177.801 -82 175.401 -92 179.801 -95.2C179.801 -95.2 175.801 -90.8 176.601 -94.8C177.401 -98.8 181.001 -102.4 182.601 -102.8C184.201 -103.2 200.601 -119 207.401 -119.4C207.401 -119.4 198.201 -118 195.201 -119C192.201 -120 165.601 -131.4 159.601 -132.6C159.601 -132.6 142.801 -139.2 154.801 -137.2C154.801 -137.2 190.601 -133.4 208.801 -120.2C208.801 -120.2 201.601 -128.6 183.201 -135.6C183.201 -135.6 161.001 -148.2 125.801 -143.2C125.801 -143.2 108.001 -140 100.201 -138.2C100.201 -138.2 97.601 -138.8 97.001 -139.2C96.401 -139.6 84.6 -148.6 57 -141.6C57 -141.6 40 -137 31.4 -132.2C31.4 -132.2 16.2 -131 12.6 -127.8C12.6 -127.8 -6 -113.2 -8 -112.4C-10 -111.6 -21.4 -104 -22.2 -103.6C-22.2 -103.6 2.4 -110.2 4.8 -112.6C7.2 -115 24.6 -117.6 27 -116.2C29.4 -114.8 37.8 -115.4 28.2 -114.8C28.2 -114.8 103.801 -100 104.601 -98C105.401 -96 109.401 -97.2 109.401 -97.2z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M180.801 -106.4C180.801 -106.4 170.601 -113.8 168.601 -113.8C166.601 -113.8 154.201 -124 150.001 -123.6C145.801 -123.2 133.601 -133.2 106.201 -125C106.201 -125 105.601 -127 109.201 -127.8C109.201 -127.8 115.601 -130 116.001 -130.6C116.001 -130.6 136.201 -134.8 143.401 -131.2C143.401 -131.2 152.601 -128.6 158.801 -122.4C158.801 -122.4 170.001 -119.2 173.201 -120.2C173.201 -120.2 182.001 -118 182.401 -116.2C182.401 -116.2 188.201 -113.2 186.401 -110.6C186.401 -110.6 186.801 -109 180.801 -106.4z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M168.33 -108.509C169.137 -107.877 170.156 -107.779 170.761 -106.97C170.995 -106.656 170.706 -106.33 170.391 -106.233C169.348 -105.916 168.292 -106.486 167.15 -105.898C166.748 -105.691 166.106 -105.873 165.553 -106.022C163.921 -106.463 162.092 -106.488 160.401 -105.8C158.416 -106.929 156.056 -106.345 153.975 -107.346C153.917 -107.373 153.695 -107.027 153.621 -107.054C150.575 -108.199 146.832 -107.916 144.401 -110.2C141.973 -110.612 139.616 -111.074 137.188 -111.754C135.37 -112.263 133.961 -113.252 132.341 -114.084C130.964 -114.792 129.507 -115.314 127.973 -115.686C126.11 -116.138 124.279 -116.026 122.386 -116.546C122.293 -116.571 122.101 -116.227 122.019 -116.254C121.695 -116.362 121.405 -116.945 121.234 -116.892C119.553 -116.37 118.065 -117.342 116.401 -117C115.223 -118.224 113.495 -117.979 111.949 -118.421C108.985 -119.269 105.831 -117.999 102.801 -119C106.914 -120.842 111.601 -119.61 115.663 -121.679C117.991 -122.865 120.653 -121.763 123.223 -122.523C123.71 -122.667 124.401 -122.869 124.801 -122.2C124.935 -122.335 125.117 -122.574 125.175 -122.546C127.625 -121.389 129.94 -120.115 132.422 -119.049C132.763 -118.903 133.295 -119.135 133.547 -118.933C135.067 -117.717 137.01 -117.82 138.401 -116.6C140.099 -117.102 141.892 -116.722 143.621 -117.346C143.698 -117.373 143.932 -117.032 143.965 -117.054C145.095 -117.802 146.25 -117.531 147.142 -117.227C147.48 -117.112 148.143 -116.865 148.448 -116.791C149.574 -116.515 150.43 -116.035 151.609 -115.852C151.723 -115.834 151.908 -116.174 151.98 -116.146C153.103 -115.708 154.145 -115.764 154.801 -114.6C154.936 -114.735 155.101 -114.973 155.183 -114.946C156.21 -114.608 156.859 -113.853 157.96 -113.612C158.445 -113.506 159.057 -112.88 159.633 -112.704C162.025 -111.973 163.868 -110.444 166.062 -109.549C166.821 -109.239 167.697 -109.005 168.33 -108.509z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M91.696 -122.739C89.178 -124.464 86.81 -125.57 84.368 -127.356C84.187 -127.489 83.827 -127.319 83.625 -127.441C82.618 -128.05 81.73 -128.631 80.748 -129.327C80.209 -129.709 79.388 -129.698 78.88 -129.956C76.336 -131.248 73.707 -131.806 71.2 -133C71.882 -133.638 73.004 -133.394 73.6 -134.2C73.795 -133.92 74.033 -133.636 74.386 -133.827C76.064 -134.731 77.914 -134.884 79.59 -134.794C81.294 -134.702 83.014 -134.397 84.789 -134.125C85.096 -134.078 85.295 -133.555 85.618 -133.458C87.846 -132.795 90.235 -133.32 92.354 -132.482C93.945 -131.853 95.515 -131.03 96.754 -129.755C97.006 -129.495 96.681 -129.194 96.401 -129C96.789 -129.109 97.062 -128.903 97.173 -128.59C97.257 -128.351 97.257 -128.049 97.173 -127.81C97.061 -127.498 96.782 -127.397 96.408 -127.346C95.001 -127.156 96.773 -128.536 96.073 -128.088C94.8 -127.274 95.546 -125.868 94.801 -124.6C94.521 -124.794 94.291 -125.012 94.401 -125.4C94.635 -124.878 94.033 -124.588 93.865 -124.272C93.48 -123.547 92.581 -122.132 91.696 -122.739z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M59.198 -115.391C56.044 -116.185 52.994 -116.07 49.978 -117.346C49.911 -117.374 49.688 -117.027 49.624 -117.054C48.258 -117.648 47.34 -118.614 46.264 -119.66C45.351 -120.548 43.693 -120.161 42.419 -120.648C42.095 -120.772 41.892 -121.284 41.591 -121.323C40.372 -121.48 39.445 -122.429 38.4 -123C40.736 -123.795 43.147 -123.764 45.609 -124.148C45.722 -124.166 45.867 -123.845 46 -123.845C46.136 -123.845 46.266 -124.066 46.4 -124.2C46.595 -123.92 46.897 -123.594 47.154 -123.848C47.702 -124.388 48.258 -124.198 48.798 -124.158C48.942 -124.148 49.067 -123.845 49.2 -123.845C49.336 -123.845 49.467 -124.156 49.6 -124.156C49.736 -124.155 49.867 -123.845 50 -123.845C50.136 -123.845 50.266 -124.066 50.4 -124.2C51.092 -123.418 51.977 -123.972 52.799 -123.793C53.837 -123.566 54.104 -122.418 55.178 -122.12C59.893 -120.816 64.03 -118.671 68.393 -116.584C68.7 -116.437 68.91 -116.189 68.8 -115.8C69.067 -115.8 69.38 -115.888 69.57 -115.756C70.628 -115.024 71.669 -114.476 72.366 -113.378C72.582 -113.039 72.253 -112.632 72.02 -112.684C67.591 -113.679 63.585 -114.287 59.198 -115.391z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M45.338 -71.179C43.746 -72.398 43.162 -74.429 42.034 -76.221C41.82 -76.561 42.094 -76.875 42.411 -76.964C42.971 -77.123 43.514 -76.645 43.923 -76.443C45.668 -75.581 47.203 -74.339 49.2 -74.2C51.19 -71.966 55.45 -71.581 55.457 -68.2C55.458 -67.341 54.03 -68.259 53.6 -67.4C51.149 -68.403 48.76 -68.3 46.38 -69.767C45.763 -70.148 46.093 -70.601 45.338 -71.179z"}
+ ,
+ {"fill": "#cc7226",
+ "path":"M17.8 -123.756C17.935 -123.755 24.966 -123.522 24.949 -123.408C24.904 -123.099 17.174 -122.05 16.81 -122.22C16.646 -122.296 9.134 -119.866 9 -120C9.268 -120.135 17.534 -123.756 17.8 -123.756z"}
+ ,
+ {"fill": "#000000",
+ "path":"M33.2 -114C33.2 -114 18.4 -112.2 14 -111C9.6 -109.8 -9 -102.2 -12 -100.2C-12 -100.2 -25.4 -94.8 -42.4 -74.8C-42.4 -74.8 -34.8 -78.2 -32.6 -81C-32.6 -81 -19 -93.6 -19.2 -91C-19.2 -91 -7 -99.6 -7.6 -97.4C-7.6 -97.4 16.8 -108.6 14.8 -105.4C14.8 -105.4 36.4 -110 35.4 -108C35.4 -108 54.2 -103.6 51.4 -103.4C51.4 -103.4 45.6 -102.2 52 -98.6C52 -98.6 48.6 -94.2 43.2 -98.2C37.8 -102.2 40.8 -100 35.8 -99C35.8 -99 33.2 -98.2 28.6 -102.2C28.6 -102.2 23 -106.8 14.2 -103.2C14.2 -103.2 -16.4 -90.6 -18.4 -90C-18.4 -90 -22 -87.2 -24.4 -83.6C-24.4 -83.6 -30.2 -79.2 -33.2 -77.8C-33.2 -77.8 -46 -66.2 -47.2 -64.8C-47.2 -64.8 -50.6 -59.6 -51.4 -59.2C-51.4 -59.2 -45 -63 -43 -65C-43 -65 -29 -75 -23.6 -75.8C-23.6 -75.8 -19.2 -78.8 -18.4 -80.2C-18.4 -80.2 -4 -89.4 0.2 -89.4C0.2 -89.4 9.4 -84.2 11.8 -91.2C11.8 -91.2 17.6 -93 23.2 -91.8C23.2 -91.8 26.4 -94.4 25.6 -96.6C25.6 -96.6 27.2 -98.4 28.2 -94.6C28.2 -94.6 31.6 -91 36.4 -93C36.4 -93 40.4 -93.2 38.4 -90.8C38.4 -90.8 34 -87 22.2 -86.8C22.2 -86.8 9.8 -86.2 -6.6 -78.6C-6.6 -78.6 -36.4 -68.2 -45.6 -57.8C-45.6 -57.8 -52 -49 -57.4 -47.8C-57.4 -47.8 -63.2 -47 -69.2 -39.6C-69.2 -39.6 -59.4 -45.4 -50.4 -45.4C-50.4 -45.4 -46.4 -47.8 -50.2 -44.2C-50.2 -44.2 -53.8 -36.6 -52.2 -31.2C-52.2 -31.2 -52.8 -26 -53.6 -24.4C-53.6 -24.4 -61.4 -11.6 -61.4 -9.2C-61.4 -6.8 -60.2 3 -59.8 3.6C-59.4 4.2 -60.8 2 -57 4.4C-53.2 6.8 -50.4 8.4 -49.6 11.2C-48.8 14 -51.6 5.8 -51.8 4C-52 2.2 -56.2 -5 -55.4 -7.4C-55.4 -7.4 -54.4 -6.4 -53.6 -5C-53.6 -5 -54.2 -5.6 -53.6 -9.2C-53.6 -9.2 -52.8 -14.4 -51.4 -17.6C-50 -20.8 -48 -24.6 -47.6 -25.4C-47.2 -26.2 -47.2 -32 -45.8 -29.4L-42.4 -26.8C-42.4 -26.8 -45.2 -29.4 -43 -31.6C-43 -31.6 -44 -37.2 -42.2 -39.8C-42.2 -39.8 -35.2 -48.2 -33.6 -49.2C-32 -50.2 -33.4 -49.8 -33.4 -49.8C-33.4 -49.8 -27.4 -54 -33.2 -52.4C-33.2 -52.4 -37.2 -50.8 -40.2 -50.8C-40.2 -50.8 -47.8 -48.8 -43.8 -53C-39.8 -57.2 -29.8 -62.6 -26 -62.4L-25.2 -60.8L-14 -63.2L-15.2 -62.4C-15.2 -62.4 -15.4 -62.6 -11.2 -63C-7 -63.4 -1.2 -62 0.2 -63.8C1.6 -65.6 5 -66.6 4.6 -65.2C4.2 -63.8 4 -61.8 4 -61.8C4 -61.8 9 -67.6 8.4 -65.4C7.8 -63.2 -0.4 -58 -1.8 -51.8L8.6 -60L12.2 -63C12.2 -63 15.8 -60.8 16 -62.4C16.2 -64 20.8 -69.8 22 -69.6C23.2 -69.4 25.2 -72.2 25 -69.6C24.8 -67 32.4 -61.6 32.4 -61.6C32.4 -61.6 35.6 -63.4 37 -62C38.4 -60.6 42.6 -81.8 42.6 -81.8L67.6 -92.4L111.201 -95.8L94.201 -102.6L33.2 -114z"}
+ ,
+ {"stroke":"#4c0000", "width":2,
+ "path":"M51.4 85C51.4 85 36.4 68.2 28 65.6C28 65.6 14.6 58.8 -10 66.6"}
+ ,
+ {"stroke":"#4c0000", "width":2,
+ "path":"M24.8 64.2C24.8 64.2 -0.4 56.2 -15.8 60.4C-15.8 60.4 -34.2 62.4 -42.6 76.2"}
+ ,
+ {"stroke":"#4c0000", "width":2,
+ "path":"M21.2 63C21.2 63 4.2 55.8 -10.6 53.6C-10.6 53.6 -27.2 51 -43.8 58.2C-43.8 58.2 -56 64.2 -61.4 74.4"}
+ ,
+ {"stroke":"#4c0000", "width":2,
+ "path":"M22.2 63.4C22.2 63.4 6.8 52.4 5.8 51C5.8 51 -1.2 40 -14.2 39.6C-14.2 39.6 -35.6 40.4 -52.8 48.4"}
+ ,
+ {"fill": "#000000",
+ "path":"M20.895 54.407C22.437 55.87 49.4 84.8 49.4 84.8C84.6 121.401 56.6 87.2 56.6 87.2C49 82.4 39.8 63.6 39.8 63.6C38.6 60.8 53.8 70.8 53.8 70.8C57.8 71.6 71.4 90.8 71.4 90.8C64.6 88.4 69.4 95.6 69.4 95.6C72.2 97.6 92.601 113.201 92.601 113.201C96.201 117.201 100.201 118.801 100.201 118.801C114.201 113.601 107.801 126.801 107.801 126.801C110.201 133.601 115.801 122.001 115.801 122.001C127.001 105.2 110.601 107.601 110.601 107.601C80.6 110.401 73.8 94.4 73.8 94.4C71.4 92 80.2 94.4 80.2 94.4C88.601 96.4 73 82 73 82C75.4 82 84.6 88.8 84.6 88.8C95.001 98 97.001 96 97.001 96C115.001 87.2 125.401 94.8 125.401 94.8C127.401 96.4 121.801 103.2 123.401 108.401C125.001 113.601 129.801 126.001 129.801 126.001C127.401 127.601 127.801 138.401 127.801 138.401C144.601 161.601 135.001 159.601 135.001 159.601C119.401 159.201 134.201 166.801 134.201 166.801C137.401 168.801 146.201 176.001 146.201 176.001C143.401 174.801 141.801 180.001 141.801 180.001C146.601 184.001 143.801 188.801 143.801 188.801C137.801 190.001 136.601 194.001 136.601 194.001C143.401 202.001 133.401 202.401 133.401 202.401C137.001 206.801 132.201 218.801 132.201 218.801C127.401 218.801 121.001 224.401 121.001 224.401C123.401 229.201 113.001 234.801 113.001 234.801C104.601 236.401 107.401 243.201 107.401 243.201C99.401 249.201 97.001 265.201 97.001 265.201C96.201 275.601 93.801 278.801 99.001 276.801C104.201 274.801 103.401 262.401 103.401 262.401C98.601 246.801 141.401 230.801 141.401 230.801C145.401 229.201 146.201 224.001 146.201 224.001C148.201 224.401 157.001 232.001 157.001 232.001C164.601 243.201 165.001 234.001 165.001 234.001C166.201 230.401 164.601 224.401 164.601 224.401C170.601 202.801 156.601 196.401 156.601 196.401C146.601 162.801 160.601 171.201 160.601 171.201C163.401 176.801 174.201 182.001 174.201 182.001L177.801 179.601C176.201 174.801 184.601 168.801 184.601 168.801C187.401 175.201 193.401 167.201 193.401 167.201C197.001 142.801 209.401 157.201 209.401 157.201C213.401 158.401 214.601 151.601 214.601 151.601C218.201 141.201 214.601 127.601 214.601 127.601C218.201 127.201 227.801 133.201 227.801 133.201C230.601 129.601 221.401 112.801 225.401 115.201C229.401 117.601 233.801 119.201 233.801 119.201C234.601 117.201 224.601 104.801 224.601 104.801C220.201 102 215.001 81.6 215.001 81.6C222.201 85.2 212.201 70 212.201 70C212.201 66.8 218.201 55.6 218.201 55.6C217.401 48.8 218.201 49.2 218.201 49.2C221.001 50.4 229.001 52 222.201 45.6C215.401 39.2 223.001 34.4 223.001 34.4C227.401 31.6 213.801 32 213.801 32C208.601 27.6 209.001 23.6 209.001 23.6C217.001 25.6 202.601 11.2 200.201 7.6C197.801 4 207.401 -1.2 207.401 -1.2C220.601 -4.8 209.001 -8 209.001 -8C189.401 -7.6 200.201 -18.4 200.201 -18.4C206.201 -18 204.601 -20.4 204.601 -20.4C199.401 -21.6 189.801 -28 189.801 -28C185.801 -31.6 189.401 -30.8 189.401 -30.8C206.201 -29.6 177.401 -40.8 177.401 -40.8C185.401 -40.8 167.401 -51.2 167.401 -51.2C165.401 -52.8 162.201 -60.4 162.201 -60.4C156.201 -65.6 151.401 -72.4 151.401 -72.4C151.001 -76.8 146.201 -81.6 146.201 -81.6C134.601 -95.2 129.001 -94.8 129.001 -94.8C114.201 -98.4 109.001 -97.6 109.001 -97.6L56.2 -93.2C29.8 -80.4 37.6 -59.4 37.6 -59.4C44 -51 53.2 -54.8 53.2 -54.8C57.8 -61 69.4 -58.8 69.4 -58.8C89.801 -55.6 87.201 -59.2 87.201 -59.2C84.801 -63.8 68.6 -70 68.4 -70.6C68.2 -71.2 59.4 -74.6 59.4 -74.6C56.4 -75.8 52 -85 52 -85C48.8 -88.4 64.6 -82.6 64.6 -82.6C63.4 -81.6 70.8 -77.6 70.8 -77.6C88.201 -78.6 98.801 -67.8 98.801 -67.8C109.601 -51.2 109.801 -59.4 109.801 -59.4C112.601 -68.8 100.801 -90 100.801 -90C101.201 -92 109.401 -85.4 109.401 -85.4C110.801 -87.4 111.601 -81.6 111.601 -81.6C111.801 -79.2 115.601 -71.2 115.601 -71.2C118.401 -58.2 122.001 -65.6 122.001 -65.6L126.601 -56.2C128.001 -53.6 122.001 -46 122.001 -46C121.801 -43.2 122.601 -43.4 117.001 -35.8C111.401 -28.2 114.801 -23.8 114.801 -23.8C113.401 -17.2 122.201 -17.6 122.201 -17.6C124.801 -15.4 128.201 -15.4 128.201 -15.4C130.001 -13.4 132.401 -14 132.401 -14C134.001 -17.8 140.201 -15.8 140.201 -15.8C141.601 -18.2 149.801 -18.6 149.801 -18.6C150.801 -21.2 151.201 -22.8 154.601 -23.4C158.001 -24 133.401 -67 133.401 -67C139.801 -67.8 131.601 -80.2 131.601 -80.2C129.401 -86.8 140.801 -72.2 143.001 -70.8C145.201 -69.4 146.201 -67.2 144.601 -67.4C143.001 -67.6 141.201 -65.4 142.601 -65.2C144.001 -65 157.001 -50 160.401 -39.8C163.801 -29.6 169.801 -25.6 176.001 -19.6C182.201 -13.6 181.401 10.6 181.401 10.6C181.001 19.4 187.001 30 187.001 30C189.001 33.8 184.801 52 184.801 52C182.801 54.2 184.201 55 184.201 55C185.201 56.2 192.001 69.4 192.001 69.4C190.201 69.2 193.801 72.8 193.801 72.8C199.001 78.8 192.601 75.8 192.601 75.8C186.601 74.2 193.601 84 193.601 84C194.801 85.8 185.801 81.2 185.801 81.2C176.601 80.6 188.201 87.8 188.201 87.8C196.801 95 185.401 90.6 185.401 90.6C180.801 88.8 184.001 95.6 184.001 95.6C187.201 97.2 204.401 104.2 204.401 104.2C204.801 108.001 201.801 113.001 201.801 113.001C202.201 117.001 200.001 120.401 200.001 120.401C198.801 128.601 198.201 129.401 198.201 129.401C194.001 129.601 186.601 143.401 186.601 143.401C184.801 146.001 174.601 158.001 174.601 158.001C172.601 165.001 154.601 157.801 154.601 157.801C148.001 161.201 150.001 157.801 150.001 157.801C149.601 155.601 154.401 149.601 154.401 149.601C161.401 147.001 158.801 136.201 158.801 136.201C162.801 134.801 151.601 132.001 151.801 130.801C152.001 129.601 157.801 128.201 157.801 128.201C165.801 126.201 161.401 123.801 161.401 123.801C160.801 119.801 163.801 114.201 163.801 114.201C175.401 113.401 163.801 97.2 163.801 97.2C153.001 89.6 152.001 83.8 152.001 83.8C164.601 75.6 156.401 63.2 156.601 59.6C156.801 56 158.001 34.4 158.001 34.4C156.001 28.2 153.001 14.6 153.001 14.6C155.201 9.4 162.601 -3.2 162.601 -3.2C165.401 -7.4 174.201 -12.2 172.001 -15.2C169.801 -18.2 162.001 -16.4 162.001 -16.4C154.201 -17.8 154.801 -12.6 154.801 -12.6C153.201 -11.6 152.401 -6.6 152.401 -6.6C151.68 1.333 142.801 7.6 142.801 7.6C131.601 13.8 140.801 17.8 140.801 17.8C146.801 24.4 137.001 24.6 137.001 24.6C126.001 22.8 134.201 33 134.201 33C145.001 45.8 142.001 48.6 142.001 48.6C131.801 49.6 144.401 58.8 144.401 58.8C144.401 58.8 143.601 56.8 143.801 58.6C144.001 60.4 147.001 64.6 147.801 66.6C148.601 68.6 144.601 68.8 144.601 68.8C145.201 78.4 129.801 74.2 129.801 74.2C129.801 74.2 129.801 74.2 128.201 74.4C126.601 74.6 115.401 73.8 109.601 71.6C103.801 69.4 97.001 69.4 97.001 69.4C97.001 69.4 93.001 71.2 85.4 71C77.8 70.8 69.8 73.6 69.8 73.6C65.4 73.2 74 68.8 74.2 69C74.4 69.2 80 63.6 72 64.2C50.203 65.835 39.4 55.6 39.4 55.6C37.4 54.2 34.8 51.4 34.8 51.4C24.8 49.4 36.2 63.8 36.2 63.8C37.4 65.2 36 66.2 36 66.2C35.2 64.6 27.4 59.2 27.4 59.2C24.589 58.227 23.226 56.893 20.895 54.407z"}
+ ,
+ {"fill": "#4c0000",
+ "path":"M-3 42.8C-3 42.8 8.6 48.4 11.2 51.2C13.8 54 27.8 65.4 27.8 65.4C27.8 65.4 22.4 63.4 19.8 61.6C17.2 59.8 6.4 51.6 6.4 51.6C6.4 51.6 2.6 45.6 -3 42.8z"}
+ ,
+ {"fill": "#99cc32",
+ "path":"M-61.009 11.603C-60.672 11.455 -61.196 8.743 -61.4 8.2C-62.422 5.474 -71.4 4 -71.4 4C-71.627 5.365 -71.682 6.961 -71.576 8.599C-71.576 8.599 -66.708 14.118 -61.009 11.603z"}
+ ,
+ {"fill": "#659900",
+ "path":"M-61.009 11.403C-61.458 11.561 -61.024 8.669 -61.2 8.2C-62.222 5.474 -71.4 3.9 -71.4 3.9C-71.627 5.265 -71.682 6.861 -71.576 8.499C-71.576 8.499 -67.308 13.618 -61.009 11.403z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-65.4 11.546C-66.025 11.546 -66.531 10.406 -66.531 9C-66.531 7.595 -66.025 6.455 -65.4 6.455C-64.775 6.455 -64.268 7.595 -64.268 9C-64.268 10.406 -64.775 11.546 -65.4 11.546z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-65.4 9z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-111 109.601C-111 109.601 -116.6 119.601 -91.8 113.601C-91.8 113.601 -77.8 112.401 -75.4 110.001C-74.2 110.801 -65.834 113.734 -63 114.401C-56.2 116.001 -47.8 106 -47.8 106C-47.8 106 -43.2 95.5 -40.4 95.5C-37.6 95.5 -40.8 97.1 -40.8 97.1C-40.8 97.1 -47.4 107.201 -47 108.801C-47 108.801 -52.2 128.801 -68.2 129.601C-68.2 129.601 -84.35 130.551 -83 136.401C-83 136.401 -74.2 134.001 -71.8 136.401C-71.8 136.401 -61 136.001 -69 142.401L-75.8 154.001C-75.8 154.001 -75.66 157.919 -85.8 154.401C-95.6 151.001 -105.9 138.101 -105.9 138.101C-105.9 138.101 -121.85 123.551 -111 109.601z"}
+ ,
+ {"fill": "#e59999",
+ "path":"M-112.2 113.601C-112.2 113.601 -114.2 123.201 -77.4 112.801C-77.4 112.801 -73 112.801 -70.6 113.601C-68.2 114.401 -56.2 117.201 -54.2 116.001C-54.2 116.001 -61.4 129.601 -73 128.001C-73 128.001 -86.2 129.601 -85.8 134.401C-85.8 134.401 -81.8 141.601 -77 144.001C-77 144.001 -74.2 146.401 -74.6 149.601C-75 152.801 -77.8 154.401 -79.8 155.201C-81.8 156.001 -85 152.801 -86.6 152.801C-88.2 152.801 -96.6 146.401 -101 141.601C-105.4 136.801 -113.8 124.801 -113.4 122.001C-113 119.201 -112.2 113.601 -112.2 113.601z"}
+ ,
+ {"fill": "#b26565",
+ "path":"M-109 131.051C-106.4 135.001 -103.2 139.201 -101 141.601C-96.6 146.401 -88.2 152.801 -86.6 152.801C-85 152.801 -81.8 156.001 -79.8 155.201C-77.8 154.401 -75 152.801 -74.6 149.601C-74.2 146.401 -77 144.001 -77 144.001C-80.066 142.468 -82.806 138.976 -84.385 136.653C-84.385 136.653 -84.2 139.201 -89.4 138.401C-94.6 137.601 -99.8 134.801 -101.4 131.601C-103 128.401 -105.4 126.001 -103.8 129.601C-102.2 133.201 -99.8 136.801 -98.2 137.201C-96.6 137.601 -97 138.801 -99.4 138.401C-101.8 138.001 -104.6 137.601 -109 132.401z"}
+ ,
+ {"fill": "#992600",
+ "path":"M-111.6 110.001C-111.6 110.001 -109.8 96.4 -108.6 92.4C-108.6 92.4 -109.4 85.6 -107 81.4C-104.6 77.2 -102.6 71 -99.6 65.6C-96.6 60.2 -96.4 56.2 -92.4 54.6C-88.4 53 -82.4 44.4 -79.6 43.4C-76.8 42.4 -77 43.2 -77 43.2C-77 43.2 -70.2 28.4 -56.6 32.4C-56.6 32.4 -72.8 29.6 -57 20.2C-57 20.2 -61.8 21.3 -58.5 14.3C-56.299 9.632 -56.8 16.4 -67.8 28.2C-67.8 28.2 -72.8 36.8 -78 39.8C-83.2 42.8 -95.2 49.8 -96.4 53.6C-97.6 57.4 -100.8 63.2 -102.8 64.8C-104.8 66.4 -107.6 70.6 -108 74C-108 74 -109.2 78 -110.6 79.2C-112 80.4 -112.2 83.6 -112.2 85.6C-112.2 87.6 -114.2 90.4 -114 92.8C-114 92.8 -113.2 111.801 -113.6 113.801L-111.6 110.001z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M-120.2 114.601C-120.2 114.601 -122.2 113.201 -126.6 119.201C-126.6 119.201 -119.3 152.201 -119.3 153.601C-119.3 153.601 -118.2 151.501 -119.5 144.301C-120.8 137.101 -121.7 124.401 -121.7 124.401L-120.2 114.601z"}
+ ,
+ {"fill": "#992600",
+ "path":"M-98.6 54C-98.6 54 -116.2 57.2 -115.8 86.4L-116.6 111.201C-116.6 111.201 -117.8 85.6 -119 84C-120.2 82.4 -116.2 71.2 -119.4 77.2C-119.4 77.2 -133.4 91.2 -125.4 112.401C-125.4 112.401 -123.9 115.701 -126.9 111.101C-126.9 111.101 -131.5 98.5 -130.4 92.1C-130.4 92.1 -130.2 89.9 -128.3 87.1C-128.3 87.1 -119.7 75.4 -117 73.1C-117 73.1 -115.2 58.7 -99.8 53.5C-99.8 53.5 -94.1 51.2 -98.6 54z"}
+ ,
+ {"fill": "#000000",
+ "path":"M40.8 -12.2C41.46 -12.554 41.451 -13.524 42.031 -13.697C43.18 -14.041 43.344 -15.108 43.862 -15.892C44.735 -17.211 44.928 -18.744 45.51 -20.235C45.782 -20.935 45.809 -21.89 45.496 -22.55C44.322 -25.031 43.62 -27.48 42.178 -29.906C41.91 -30.356 41.648 -31.15 41.447 -31.748C40.984 -33.132 39.727 -34.123 38.867 -35.443C38.579 -35.884 39.104 -36.809 38.388 -36.893C37.491 -36.998 36.042 -37.578 35.809 -36.552C35.221 -33.965 36.232 -31.442 37.2 -29C36.418 -28.308 36.752 -27.387 36.904 -26.62C37.614 -23.014 36.416 -19.662 35.655 -16.188C35.632 -16.084 35.974 -15.886 35.946 -15.824C34.724 -13.138 33.272 -10.693 31.453 -8.312C30.695 -7.32 29.823 -6.404 29.326 -5.341C28.958 -4.554 28.55 -3.588 28.8 -2.6C25.365 0.18 23.115 4.025 20.504 7.871C20.042 8.551 20.333 9.76 20.884 10.029C21.697 10.427 22.653 9.403 23.123 8.557C23.512 7.859 23.865 7.209 24.356 6.566C24.489 6.391 24.31 5.972 24.445 5.851C27.078 3.504 28.747 0.568 31.2 -1.8C33.15 -2.129 34.687 -3.127 36.435 -4.14C36.743 -4.319 37.267 -4.07 37.557 -4.265C39.31 -5.442 39.308 -7.478 39.414 -9.388C39.464 -10.272 39.66 -11.589 40.8 -12.2z"}
+ ,
+ {"fill": "#000000",
+ "path":"M31.959 -16.666C32.083 -16.743 31.928 -17.166 32.037 -17.382C32.199 -17.706 32.602 -17.894 32.764 -18.218C32.873 -18.434 32.71 -18.814 32.846 -18.956C35.179 -21.403 35.436 -24.427 34.4 -27.4C35.424 -28.02 35.485 -29.282 35.06 -30.129C34.207 -31.829 34.014 -33.755 33.039 -35.298C32.237 -36.567 30.659 -37.811 29.288 -36.508C28.867 -36.108 28.546 -35.321 28.824 -34.609C28.888 -34.446 29.173 -34.3 29.146 -34.218C29.039 -33.894 28.493 -33.67 28.487 -33.398C28.457 -31.902 27.503 -30.391 28.133 -29.062C28.905 -27.433 29.724 -25.576 30.4 -23.8C29.166 -21.684 30.199 -19.235 28.446 -17.358C28.31 -17.212 28.319 -16.826 28.441 -16.624C28.733 -16.138 29.139 -15.732 29.625 -15.44C29.827 -15.319 30.175 -15.317 30.375 -15.441C30.953 -15.803 31.351 -16.29 31.959 -16.666z"}
+ ,
+ {"fill": "#000000",
+ "path":"M94.771 -26.977C96.16 -25.185 96.45 -22.39 94.401 -21C94.951 -17.691 98.302 -19.67 100.401 -20.2C100.292 -20.588 100.519 -20.932 100.802 -20.937C101.859 -20.952 102.539 -21.984 103.601 -21.8C104.035 -23.357 105.673 -24.059 106.317 -25.439C108.043 -29.134 107.452 -33.407 104.868 -36.653C104.666 -36.907 104.883 -37.424 104.759 -37.786C104.003 -39.997 101.935 -40.312 100.001 -41C98.824 -44.875 98.163 -48.906 96.401 -52.6C94.787 -52.85 94.089 -54.589 92.752 -55.309C91.419 -56.028 90.851 -54.449 90.892 -53.403C90.899 -53.198 91.351 -52.974 91.181 -52.609C91.105 -52.445 90.845 -52.334 90.845 -52.2C90.846 -52.065 91.067 -51.934 91.201 -51.8C90.283 -50.98 88.86 -50.503 88.565 -49.358C87.611 -45.648 90.184 -42.523 91.852 -39.322C92.443 -38.187 91.707 -36.916 90.947 -35.708C90.509 -35.013 90.617 -33.886 90.893 -33.03C91.645 -30.699 93.236 -28.96 94.771 -26.977z"}
+ ,
+ {"fill": "#000000",
+ "path":"M57.611 -8.591C56.124 -6.74 52.712 -4.171 55.629 -2.243C55.823 -2.114 56.193 -2.11 56.366 -2.244C58.387 -3.809 60.39 -4.712 62.826 -5.294C62.95 -5.323 63.224 -4.856 63.593 -5.017C65.206 -5.72 67.216 -5.662 68.4 -7C72.167 -6.776 75.732 -7.892 79.123 -9.2C80.284 -9.648 81.554 -10.207 82.755 -10.709C84.131 -11.285 85.335 -12.213 86.447 -13.354C86.58 -13.49 86.934 -13.4 87.201 -13.4C87.161 -14.263 88.123 -14.39 88.37 -15.012C88.462 -15.244 88.312 -15.64 88.445 -15.742C90.583 -17.372 91.503 -19.39 90.334 -21.767C90.049 -22.345 89.8 -22.963 89.234 -23.439C88.149 -24.35 87.047 -23.496 86 -23.8C85.841 -23.172 85.112 -23.344 84.726 -23.146C83.867 -22.707 82.534 -23.292 81.675 -22.854C80.313 -22.159 79.072 -21.99 77.65 -21.613C77.338 -21.531 76.56 -21.627 76.4 -21C76.266 -21.134 76.118 -21.368 76.012 -21.346C74.104 -20.95 72.844 -20.736 71.543 -19.044C71.44 -18.911 70.998 -19.09 70.839 -18.955C69.882 -18.147 69.477 -16.913 68.376 -16.241C68.175 -16.118 67.823 -16.286 67.629 -16.157C66.983 -15.726 66.616 -15.085 65.974 -14.638C65.645 -14.409 65.245 -14.734 65.277 -14.99C65.522 -16.937 66.175 -18.724 65.6 -20.6C67.677 -23.12 70.194 -25.069 72 -27.8C72.015 -29.966 72.707 -32.112 72.594 -34.189C72.584 -34.382 72.296 -35.115 72.17 -35.462C71.858 -36.316 72.764 -37.382 71.92 -38.106C70.516 -39.309 69.224 -38.433 68.4 -37C66.562 -36.61 64.496 -35.917 62.918 -37.151C61.911 -37.938 61.333 -38.844 60.534 -39.9C59.549 -41.202 59.884 -42.638 59.954 -44.202C59.96 -44.33 59.645 -44.466 59.645 -44.6C59.646 -44.735 59.866 -44.866 60 -45C59.294 -45.626 59.019 -46.684 58 -47C58.305 -48.092 57.629 -48.976 56.758 -49.278C54.763 -49.969 53.086 -48.057 51.194 -47.984C50.68 -47.965 50.213 -49.003 49.564 -49.328C49.132 -49.544 48.428 -49.577 48.066 -49.311C47.378 -48.807 46.789 -48.693 46.031 -48.488C44.414 -48.052 43.136 -46.958 41.656 -46.103C40.171 -45.246 39.216 -43.809 38.136 -42.489C37.195 -41.337 37.059 -38.923 38.479 -38.423C40.322 -37.773 41.626 -40.476 43.592 -40.15C43.904 -40.099 44.11 -39.788 44 -39.4C44.389 -39.291 44.607 -39.52 44.8 -39.8C45.658 -38.781 46.822 -38.444 47.76 -37.571C48.73 -36.667 50.476 -37.085 51.491 -36.088C53.02 -34.586 52.461 -31.905 54.4 -30.6C53.814 -29.287 53.207 -28.01 52.872 -26.583C52.59 -25.377 53.584 -24.18 54.795 -24.271C56.053 -24.365 56.315 -25.124 56.8 -26.2C57.067 -25.933 57.536 -25.636 57.495 -25.42C57.038 -23.033 56.011 -21.04 55.553 -18.609C55.494 -18.292 55.189 -18.09 54.8 -18.2C54.332 -14.051 50.28 -11.657 47.735 -8.492C47.332 -7.99 47.328 -6.741 47.737 -6.338C49.14 -4.951 51.1 -6.497 52.8 -7C53.013 -8.206 53.872 -9.148 55.204 -9.092C55.46 -9.082 55.695 -9.624 56.019 -9.754C56.367 -9.892 56.869 -9.668 57.155 -9.866C58.884 -11.061 60.292 -12.167 62.03 -13.356C62.222 -13.487 62.566 -13.328 62.782 -13.436C63.107 -13.598 63.294 -13.985 63.617 -14.17C63.965 -14.37 64.207 -14.08 64.4 -13.8C63.754 -13.451 63.75 -12.494 63.168 -12.292C62.393 -12.024 61.832 -11.511 61.158 -11.064C60.866 -10.871 60.207 -11.119 60.103 -10.94C59.505 -9.912 58.321 -9.474 57.611 -8.591z"}
+ ,
+ {"fill": "#000000",
+ "path":"M2.2 -58C2.2 -58 -7.038 -60.872 -18.2 -35.2C-18.2 -35.2 -20.6 -30 -23 -28C-25.4 -26 -36.6 -22.4 -38.6 -18.4L-49 -2.4C-49 -2.4 -34.2 -18.4 -31 -20.8C-31 -20.8 -23 -29.2 -26.2 -22.4C-26.2 -22.4 -40.2 -11.6 -39 -2.4C-39 -2.4 -44.6 12 -45.4 14C-45.4 14 -29.4 -18 -27 -19.2C-24.6 -20.4 -23.4 -20.4 -24.6 -16.8C-25.8 -13.2 -26.2 3.2 -29 5.2C-29 5.2 -21 -15.2 -21.8 -18.4C-21.8 -18.4 -18.6 -22 -16.2 -16.8L-17.4 -0.8L-13 11.2C-13 11.2 -15.4 0 -13.8 -15.6C-13.8 -15.6 -15.8 -26 -11.8 -20.4C-7.8 -14.8 1.8 -8.8 1.8 -4C1.8 -4 -3.4 -21.6 -12.6 -26.4L-16.6 -20.4L-17.8 -22.4C-17.8 -22.4 -21.4 -23.2 -17 -30C-12.6 -36.8 -13 -37.6 -13 -37.6C-13 -37.6 -6.6 -30.4 -5 -30.4C-5 -30.4 8.2 -38 9.4 -13.6C9.4 -13.6 16.2 -28 7 -34.8C7 -34.8 -7.8 -36.8 -6.6 -42L0.6 -54.4C4.2 -59.6 2.6 -56.8 2.6 -56.8z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-17.8 -41.6C-17.8 -41.6 -30.6 -41.6 -33.8 -36.4L-41 -26.8C-41 -26.8 -23.8 -36.8 -19.8 -38C-15.8 -39.2 -17.8 -41.6 -17.8 -41.6z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-57.8 -35.2C-57.8 -35.2 -59.8 -34 -60.2 -31.2C-60.6 -28.4 -63 -28 -62.2 -25.2C-61.4 -22.4 -59.4 -20 -59.4 -24C-59.4 -28 -57.8 -30 -57 -31.2C-56.2 -32.4 -54.6 -36.8 -57.8 -35.2z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-66.6 26C-66.6 26 -75 22 -78.2 18.4C-81.4 14.8 -80.948 19.966 -85.8 19.6C-91.647 19.159 -90.6 3.2 -90.6 3.2L-94.6 10.8C-94.6 10.8 -95.8 25.2 -87.8 22.8C-83.893 21.628 -82.6 23.2 -84.2 24C-85.8 24.8 -78.6 25.2 -81.4 26.8C-84.2 28.4 -69.8 23.2 -72.2 33.6L-66.6 26z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-79.2 40.4C-79.2 40.4 -94.6 44.8 -98.2 35.2C-98.2 35.2 -103 37.6 -100.8 40.6C-98.6 43.6 -97.4 44 -97.4 44C-97.4 44 -92 45.2 -92.6 46C-93.2 46.8 -95.6 50.2 -95.6 50.2C-95.6 50.2 -85.4 44.2 -79.2 40.4z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M149.201 118.601C148.774 120.735 147.103 121.536 145.201 122.201C143.284 121.243 140.686 118.137 138.801 120.201C138.327 119.721 137.548 119.661 137.204 118.999C136.739 118.101 137.011 117.055 136.669 116.257C136.124 114.985 135.415 113.619 135.601 112.201C137.407 111.489 138.002 109.583 137.528 107.82C137.459 107.563 137.03 107.366 137.23 107.017C137.416 106.694 137.734 106.467 138.001 106.2C137.866 106.335 137.721 106.568 137.61 106.548C137 106.442 137.124 105.805 137.254 105.418C137.839 103.672 139.853 103.408 141.201 104.6C141.457 104.035 141.966 104.229 142.401 104.2C142.351 103.621 142.759 103.094 142.957 102.674C143.475 101.576 145.104 102.682 145.901 102.07C146.977 101.245 148.04 100.546 149.118 101.149C150.927 102.162 152.636 103.374 153.835 105.115C154.41 105.949 154.65 107.23 154.592 108.188C154.554 108.835 153.173 108.483 152.83 109.412C152.185 111.16 154.016 111.679 154.772 113.017C154.97 113.366 154.706 113.67 154.391 113.768C153.98 113.896 153.196 113.707 153.334 114.16C154.306 117.353 151.55 118.031 149.201 118.601z"}
+ ,
+ {"fill": "#ffffff",
+ "path":"M139.6 138.201C139.593 136.463 137.992 134.707 139.201 133.001C139.336 133.135 139.467 133.356 139.601 133.356C139.736 133.356 139.867 133.135 140.001 133.001C141.496 135.217 145.148 136.145 145.006 138.991C144.984 139.438 143.897 140.356 144.801 141.001C142.988 142.349 142.933 144.719 142.001 146.601C140.763 146.315 139.551 145.952 138.401 145.401C138.753 143.915 138.636 142.231 139.456 140.911C139.89 140.213 139.603 139.134 139.6 138.201z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-26.6 129.201C-26.6 129.201 -43.458 139.337 -29.4 124.001C-20.6 114.401 -10.6 108.801 -10.6 108.801C-10.6 108.801 -0.2 104.4 3.4 103.2C7 102 22.2 96.8 25.4 96.4C28.6 96 38.2 92 45 96C51.8 100 59.8 104.4 59.8 104.4C59.8 104.4 43.4 96 39.8 98.4C36.2 100.8 29 100.4 23 103.6C23 103.6 8.2 108.001 5 110.001C1.8 112.001 -8.6 123.601 -10.2 122.801C-11.8 122.001 -9.8 121.601 -8.6 118.801C-7.4 116.001 -9.4 114.401 -17.4 120.801C-25.4 127.201 -26.6 129.201 -26.6 129.201z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-19.195 123.234C-19.195 123.234 -17.785 110.194 -9.307 111.859C-9.307 111.859 -1.081 107.689 1.641 105.721C1.641 105.721 9.78 104.019 11.09 103.402C29.569 94.702 44.288 99.221 44.835 98.101C45.381 96.982 65.006 104.099 68.615 108.185C69.006 108.628 58.384 102.588 48.686 100.697C40.413 99.083 18.811 100.944 7.905 106.48C4.932 107.989 -4.013 113.773 -6.544 113.662C-9.075 113.55 -19.195 123.234 -19.195 123.234z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-23 148.801C-23 148.801 -38.2 146.401 -21.4 144.801C-21.4 144.801 -3.4 142.801 0.6 137.601C0.6 137.601 14.2 128.401 17 128.001C19.8 127.601 49.8 120.401 50.2 118.001C50.6 115.601 56.2 115.601 57.8 116.401C59.4 117.201 58.6 118.401 55.8 119.201C53 120.001 21.8 136.401 15.4 137.601C9 138.801 -2.6 146.401 -7.4 147.601C-12.2 148.801 -23 148.801 -23 148.801z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-3.48 141.403C-3.48 141.403 -12.062 140.574 -3.461 139.755C-3.461 139.755 5.355 136.331 7.403 133.668C7.403 133.668 14.367 128.957 15.8 128.753C17.234 128.548 31.194 124.861 31.399 123.633C31.604 122.404 65.67 109.823 70.09 113.013C73.001 115.114 63.1 113.437 53.466 117.847C52.111 118.467 18.258 133.054 14.981 133.668C11.704 134.283 5.765 138.174 3.307 138.788C0.85 139.403 -3.48 141.403 -3.48 141.403z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-11.4 143.601C-11.4 143.601 -6.2 143.201 -7.4 144.801C-8.6 146.401 -11 145.601 -11 145.601L-11.4 143.601z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-18.6 145.201C-18.6 145.201 -13.4 144.801 -14.6 146.401C-15.8 148.001 -18.2 147.201 -18.2 147.201L-18.6 145.201z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-29 146.801C-29 146.801 -23.8 146.401 -25 148.001C-26.2 149.601 -28.6 148.801 -28.6 148.801L-29 146.801z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-36.6 147.601C-36.6 147.601 -31.4 147.201 -32.6 148.801C-33.8 150.401 -36.2 149.601 -36.2 149.601L-36.6 147.601z"}
+ ,
+ {"fill": "#000000",
+ "path":"M1.8 108.001C1.8 108.001 6.2 108.001 5 109.601C3.8 111.201 0.6 110.801 0.6 110.801L1.8 108.001z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-8.2 113.601C-8.2 113.601 -1.694 111.46 -4.2 114.801C-5.4 116.401 -7.8 115.601 -7.8 115.601L-8.2 113.601z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-19.4 118.401C-19.4 118.401 -14.2 118.001 -15.4 119.601C-16.6 121.201 -19 120.401 -19 120.401L-19.4 118.401z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-27 124.401C-27 124.401 -21.8 124.001 -23 125.601C-24.2 127.201 -26.6 126.401 -26.6 126.401L-27 124.401z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-33.8 129.201C-33.8 129.201 -28.6 128.801 -29.8 130.401C-31 132.001 -33.4 131.201 -33.4 131.201L-33.8 129.201z"}
+ ,
+ {"fill": "#000000",
+ "path":"M5.282 135.598C5.282 135.598 12.203 135.066 10.606 137.195C9.009 139.325 5.814 138.26 5.814 138.26L5.282 135.598z"}
+ ,
+ {"fill": "#000000",
+ "path":"M15.682 130.798C15.682 130.798 22.603 130.266 21.006 132.395C19.409 134.525 16.214 133.46 16.214 133.46L15.682 130.798z"}
+ ,
+ {"fill": "#000000",
+ "path":"M26.482 126.398C26.482 126.398 33.403 125.866 31.806 127.995C30.209 130.125 27.014 129.06 27.014 129.06L26.482 126.398z"}
+ ,
+ {"fill": "#000000",
+ "path":"M36.882 121.598C36.882 121.598 43.803 121.066 42.206 123.195C40.609 125.325 37.414 124.26 37.414 124.26L36.882 121.598z"}
+ ,
+ {"fill": "#000000",
+ "path":"M9.282 103.598C9.282 103.598 16.203 103.066 14.606 105.195C13.009 107.325 9.014 107.06 9.014 107.06L9.282 103.598z"}
+ ,
+ {"fill": "#000000",
+ "path":"M19.282 100.398C19.282 100.398 26.203 99.866 24.606 101.995C23.009 104.125 18.614 103.86 18.614 103.86L19.282 100.398z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-3.4 140.401C-3.4 140.401 1.8 140.001 0.6 141.601C-0.6 143.201 -3 142.401 -3 142.401L-3.4 140.401z"}
+ ,
+ {"fill": "#992600",
+ "path":"M-76.6 41.2C-76.6 41.2 -81 50 -81.4 53.2C-81.4 53.2 -80.6 44.4 -79.4 42.4C-78.2 40.4 -76.6 41.2 -76.6 41.2z"}
+ ,
+ {"fill": "#992600",
+ "path":"M-95 55.2C-95 55.2 -98.2 69.6 -97.8 72.4C-97.8 72.4 -99 60.8 -98.6 59.6C-98.2 58.4 -95 55.2 -95 55.2z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-74.2 -19.4L-74.4 -16.2L-76.6 -16C-76.6 -16 -62.4 -3.4 -61.8 4.2C-61.8 4.2 -61 -4 -74.2 -19.4z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-70.216 -18.135C-70.647 -18.551 -70.428 -19.296 -70.836 -19.556C-71.645 -20.072 -69.538 -20.129 -69.766 -20.845C-70.149 -22.051 -69.962 -22.072 -70.084 -23.348C-70.141 -23.946 -69.553 -25.486 -69.168 -25.926C-67.722 -27.578 -69.046 -30.51 -67.406 -32.061C-67.102 -32.35 -66.726 -32.902 -66.441 -33.32C-65.782 -34.283 -64.598 -34.771 -63.648 -35.599C-63.33 -35.875 -63.531 -36.702 -62.962 -36.61C-62.248 -36.495 -61.007 -36.625 -61.052 -35.784C-61.165 -33.664 -62.494 -31.944 -63.774 -30.276C-63.323 -29.572 -63.781 -28.937 -64.065 -28.38C-65.4 -25.76 -65.211 -22.919 -65.385 -20.079C-65.39 -19.994 -65.697 -19.916 -65.689 -19.863C-65.336 -17.528 -64.752 -15.329 -63.873 -13.1C-63.507 -12.17 -63.036 -11.275 -62.886 -10.348C-62.775 -9.662 -62.672 -8.829 -63.08 -8.124C-61.045 -5.234 -62.354 -2.583 -61.185 0.948C-60.978 1.573 -59.286 3.487 -59.749 3.326C-62.262 2.455 -62.374 2.057 -62.551 1.304C-62.697 0.681 -63.027 -0.696 -63.264 -1.298C-63.328 -1.462 -63.499 -3.346 -63.577 -3.468C-65.09 -5.85 -63.732 -5.674 -65.102 -8.032C-66.53 -8.712 -67.496 -9.816 -68.619 -10.978C-68.817 -11.182 -67.674 -11.906 -67.855 -12.119C-68.947 -13.408 -70.1 -14.175 -69.764 -15.668C-69.609 -16.358 -69.472 -17.415 -70.216 -18.135z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-73.8 -16.4C-73.8 -16.4 -73.4 -9.6 -71 -8C-68.6 -6.4 -69.8 -7.2 -73 -8.4C-76.2 -9.6 -75 -10.4 -75 -10.4C-75 -10.4 -77.8 -10 -75.4 -8C-73 -6 -69.4 -3.6 -71 -3.6C-72.6 -3.6 -80.2 -7.6 -80.2 -10.4C-80.2 -13.2 -81.2 -17.3 -81.2 -17.3C-81.2 -17.3 -80.1 -18.1 -75.3 -18C-75.3 -18 -73.9 -17.3 -73.8 -16.4z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-74.6 2.2C-74.6 2.2 -83.12 -0.591 -101.6 2.8C-101.6 2.8 -92.569 0.722 -73.8 3C-63.5 4.25 -74.6 2.2 -74.6 2.2z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-72.502 2.129C-72.502 2.129 -80.748 -1.389 -99.453 0.392C-99.453 0.392 -90.275 -0.897 -71.774 2.995C-61.62 5.131 -72.502 2.129 -72.502 2.129z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-70.714 2.222C-70.714 2.222 -78.676 -1.899 -97.461 -1.514C-97.461 -1.514 -88.213 -2.118 -70.052 3.14C-60.086 6.025 -70.714 2.222 -70.714 2.222z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-69.444 2.445C-69.444 2.445 -76.268 -1.862 -93.142 -2.96C-93.142 -2.96 -84.803 -2.79 -68.922 3.319C-60.206 6.672 -69.444 2.445 -69.444 2.445z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M45.84 12.961C45.84 12.961 44.91 13.605 45.124 12.424C45.339 11.243 73.547 -1.927 77.161 -1.677C77.161 -1.677 46.913 11.529 45.84 12.961z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M42.446 13.6C42.446 13.6 41.57 14.315 41.691 13.121C41.812 11.927 68.899 -3.418 72.521 -3.452C72.521 -3.452 43.404 12.089 42.446 13.6z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M39.16 14.975C39.16 14.975 38.332 15.747 38.374 14.547C38.416 13.348 58.233 -2.149 68.045 -4.023C68.045 -4.023 50.015 4.104 39.16 14.975z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M36.284 16.838C36.284 16.838 35.539 17.532 35.577 16.453C35.615 15.373 53.449 1.426 62.28 -0.26C62.28 -0.26 46.054 7.054 36.284 16.838z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M4.6 164.801C4.6 164.801 -10.6 162.401 6.2 160.801C6.2 160.801 24.2 158.801 28.2 153.601C28.2 153.601 41.8 144.401 44.6 144.001C47.4 143.601 63.8 140.001 64.2 137.601C64.6 135.201 70.6 132.801 72.2 133.601C73.8 134.401 73.8 143.601 71 144.401C68.2 145.201 49.4 152.401 43 153.601C36.6 154.801 25 162.401 20.2 163.601C15.4 164.801 4.6 164.801 4.6 164.801z"}
+ ,
+ {"fill": "#000000",
+ "path":"M77.6 127.401C77.6 127.401 74.6 129.001 73.4 131.601C73.4 131.601 67 142.201 52.8 145.401C52.8 145.401 29.8 154.401 22 156.401C22 156.401 8.6 161.401 1.2 160.601C1.2 160.601 -5.8 160.801 0.4 162.401C0.4 162.401 20.6 160.401 24 158.601C24 158.601 39.6 153.401 42.6 150.801C45.6 148.201 63.8 143.201 66 141.201C68.2 139.201 78 130.801 77.6 127.401z"}
+ ,
+ {"fill": "#000000",
+ "path":"M18.882 158.911C18.882 158.911 24.111 158.685 22.958 160.234C21.805 161.784 19.357 160.91 19.357 160.91L18.882 158.911z"}
+ ,
+ {"fill": "#000000",
+ "path":"M11.68 160.263C11.68 160.263 16.908 160.037 15.756 161.586C14.603 163.136 12.155 162.263 12.155 162.263L11.68 160.263z"}
+ ,
+ {"fill": "#000000",
+ "path":"M1.251 161.511C1.251 161.511 6.48 161.284 5.327 162.834C4.174 164.383 1.726 163.51 1.726 163.51L1.251 161.511z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-6.383 162.055C-6.383 162.055 -1.154 161.829 -2.307 163.378C-3.46 164.928 -5.908 164.054 -5.908 164.054L-6.383 162.055z"}
+ ,
+ {"fill": "#000000",
+ "path":"M35.415 151.513C35.415 151.513 42.375 151.212 40.84 153.274C39.306 155.336 36.047 154.174 36.047 154.174L35.415 151.513z"}
+ ,
+ {"fill": "#000000",
+ "path":"M45.73 147.088C45.73 147.088 51.689 143.787 51.155 148.849C50.885 151.405 46.362 149.749 46.362 149.749L45.73 147.088z"}
+ ,
+ {"fill": "#000000",
+ "path":"M54.862 144.274C54.862 144.274 62.021 140.573 60.287 146.035C59.509 148.485 55.493 146.935 55.493 146.935L54.862 144.274z"}
+ ,
+ {"fill": "#000000",
+ "path":"M64.376 139.449C64.376 139.449 68.735 134.548 69.801 141.21C70.207 143.748 65.008 142.11 65.008 142.11L64.376 139.449z"}
+ ,
+ {"fill": "#000000",
+ "path":"M26.834 155.997C26.834 155.997 32.062 155.77 30.91 157.32C29.757 158.869 27.308 157.996 27.308 157.996L26.834 155.997z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M62.434 34.603C62.434 34.603 61.708 35.268 61.707 34.197C61.707 33.127 79.191 19.863 88.034 18.479C88.034 18.479 71.935 25.208 62.434 34.603z"}
+ ,
+ {"fill": "#000000",
+ "path":"M65.4 98.4C65.4 98.4 87.401 120.801 96.601 124.401C96.601 124.401 105.801 135.601 101.801 161.601C101.801 161.601 98.601 169.201 95.401 148.401C95.401 148.401 98.601 123.201 87.401 139.201C87.401 139.201 79 129.301 85.4 129.601C85.4 129.601 88.601 131.601 89.001 130.001C89.401 128.401 81.4 114.801 64.2 100.4C47 86 65.4 98.4 65.4 98.4z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M7 137.201C7 137.201 6.8 135.401 8.6 136.201C10.4 137.001 104.601 143.201 136.201 167.201C136.201 167.201 91.001 144.001 7 137.201z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M17.4 132.801C17.4 132.801 17.2 131.001 19 131.801C20.8 132.601 157.401 131.601 181.001 164.001C181.001 164.001 159.001 138.801 17.4 132.801z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M29 128.801C29 128.801 28.8 127.001 30.6 127.801C32.4 128.601 205.801 115.601 229.401 148.001C229.401 148.001 219.801 122.401 29 128.801z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M39 124.001C39 124.001 38.8 122.201 40.6 123.001C42.4 123.801 164.601 85.2 188.201 117.601C188.201 117.601 174.801 93 39 124.001z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-19 146.801C-19 146.801 -19.2 145.001 -17.4 145.801C-15.6 146.601 2.2 148.801 4.2 187.601C4.2 187.601 -3 145.601 -19 146.801z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-27.8 148.401C-27.8 148.401 -28 146.601 -26.2 147.401C-24.4 148.201 -10.2 143.601 -13 182.401C-13 182.401 -11.8 147.201 -27.8 148.401z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-35.8 148.801C-35.8 148.801 -36 147.001 -34.2 147.801C-32.4 148.601 -17 149.201 -29.4 171.601C-29.4 171.601 -19.8 147.601 -35.8 148.801z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M11.526 104.465C11.526 104.465 11.082 106.464 12.631 105.247C28.699 92.622 61.141 33.72 116.826 28.086C116.826 28.086 78.518 15.976 11.526 104.465z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M22.726 102.665C22.726 102.665 21.363 101.472 23.231 100.847C25.099 100.222 137.541 27.72 176.826 35.686C176.826 35.686 149.719 28.176 22.726 102.665z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M1.885 108.767C1.885 108.767 1.376 110.366 3.087 109.39C12.062 104.27 15.677 47.059 59.254 45.804C59.254 45.804 26.843 31.09 1.885 108.767z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-18.038 119.793C-18.038 119.793 -19.115 121.079 -17.162 120.825C-6.916 119.493 14.489 78.222 58.928 83.301C58.928 83.301 26.962 68.955 -18.038 119.793z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-6.8 113.667C-6.8 113.667 -7.611 115.136 -5.742 114.511C4.057 111.237 17.141 66.625 61.729 63.078C61.729 63.078 27.603 55.135 -6.8 113.667z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-25.078 124.912C-25.078 124.912 -25.951 125.954 -24.369 125.748C-16.07 124.669 1.268 91.24 37.264 95.354C37.264 95.354 11.371 83.734 -25.078 124.912z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-32.677 130.821C-32.677 130.821 -33.682 131.866 -32.091 131.748C-27.923 131.439 2.715 98.36 21.183 113.862C21.183 113.862 9.168 95.139 -32.677 130.821z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M36.855 98.898C36.855 98.898 35.654 97.543 37.586 97.158C39.518 96.774 160.221 39.061 198.184 51.927C198.184 51.927 172.243 41.053 36.855 98.898z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M3.4 163.201C3.4 163.201 3.2 161.401 5 162.201C6.8 163.001 22.2 163.601 9.8 186.001C9.8 186.001 19.4 162.001 3.4 163.201z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M13.8 161.601C13.8 161.601 13.6 159.801 15.4 160.601C17.2 161.401 35 163.601 37 202.401C37 202.401 29.8 160.401 13.8 161.601z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M20.6 160.001C20.6 160.001 20.4 158.201 22.2 159.001C24 159.801 48.6 163.201 72.2 195.601C72.2 195.601 36.6 158.801 20.6 160.001z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M28.225 157.972C28.225 157.972 27.788 156.214 29.678 156.768C31.568 157.322 52.002 155.423 90.099 189.599C90.099 189.599 43.924 154.656 28.225 157.972z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M38.625 153.572C38.625 153.572 38.188 151.814 40.078 152.368C41.968 152.922 76.802 157.423 128.499 192.399C128.499 192.399 54.324 150.256 38.625 153.572z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-1.8 142.001C-1.8 142.001 -2 140.201 -0.2 141.001C1.6 141.801 55 144.401 85.4 171.201C85.4 171.201 50.499 146.426 -1.8 142.001z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M-11.8 146.001C-11.8 146.001 -12 144.201 -10.2 145.001C-8.4 145.801 16.2 149.201 39.8 181.601C39.8 181.601 4.2 144.801 -11.8 146.001z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M49.503 148.962C49.503 148.962 48.938 147.241 50.864 147.655C52.79 148.068 87.86 150.004 141.981 181.098C141.981 181.098 64.317 146.704 49.503 148.962z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M57.903 146.562C57.903 146.562 57.338 144.841 59.264 145.255C61.19 145.668 96.26 147.604 150.381 178.698C150.381 178.698 73.317 143.904 57.903 146.562z"}
+ ,
+ {"fill": "#ffffff", "stroke":"#000000", "width":0.1,
+ "path":"M67.503 141.562C67.503 141.562 66.938 139.841 68.864 140.255C70.79 140.668 113.86 145.004 203.582 179.298C203.582 179.298 82.917 138.904 67.503 141.562z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-43.8 148.401C-43.8 148.401 -38.6 148.001 -39.8 149.601C-41 151.201 -43.4 150.401 -43.4 150.401L-43.8 148.401z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-13 162.401C-13 162.401 -7.8 162.001 -9 163.601C-10.2 165.201 -12.6 164.401 -12.6 164.401L-13 162.401z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-21.8 162.001C-21.8 162.001 -16.6 161.601 -17.8 163.201C-19 164.801 -21.4 164.001 -21.4 164.001L-21.8 162.001z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-117.169 150.182C-117.169 150.182 -112.124 151.505 -113.782 152.624C-115.439 153.744 -117.446 152.202 -117.446 152.202L-117.169 150.182z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-115.169 140.582C-115.169 140.582 -110.124 141.905 -111.782 143.024C-113.439 144.144 -115.446 142.602 -115.446 142.602L-115.169 140.582z"}
+ ,
+ {"fill": "#000000",
+ "path":"M-122.369 136.182C-122.369 136.182 -117.324 137.505 -118.982 138.624C-120.639 139.744 -122.646 138.202 -122.646 138.202L-122.369 136.182z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-42.6 211.201C-42.6 211.201 -44.2 211.201 -48.2 213.201C-50.2 213.201 -61.4 216.801 -67 226.801C-67 226.801 -54.6 217.201 -42.6 211.201z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M45.116 303.847C45.257 304.105 45.312 304.525 45.604 304.542C46.262 304.582 47.495 304.883 47.37 304.247C46.522 299.941 45.648 295.004 41.515 293.197C40.876 292.918 39.434 293.331 39.36 294.215C39.233 295.739 39.116 297.088 39.425 298.554C39.725 299.975 41.883 299.985 42.8 298.601C43.736 300.273 44.168 302.116 45.116 303.847z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M34.038 308.581C34.786 309.994 34.659 311.853 36.074 312.416C36.814 312.71 38.664 311.735 38.246 310.661C37.444 308.6 37.056 306.361 35.667 304.55C35.467 304.288 35.707 303.755 35.547 303.427C34.953 302.207 33.808 301.472 32.4 301.801C31.285 304.004 32.433 306.133 33.955 307.842C34.091 307.994 33.925 308.37 34.038 308.581z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-5.564 303.391C-5.672 303.014 -5.71 302.551 -5.545 302.23C-5.014 301.197 -4.221 300.075 -4.558 299.053C-4.906 297.997 -6.022 298.179 -6.672 298.748C-7.807 299.742 -7.856 301.568 -8.547 302.927C-8.743 303.313 -8.692 303.886 -9.133 304.277C-9.607 304.698 -10.047 306.222 -9.951 306.793C-9.898 307.106 -10.081 317.014 -9.859 316.751C-9.24 316.018 -6.19 306.284 -6.121 305.392C-6.064 304.661 -5.332 304.196 -5.564 303.391z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-31.202 296.599C-28.568 294.1 -25.778 291.139 -26.22 287.427C-26.336 286.451 -28.111 286.978 -28.298 287.824C-29.1 291.449 -31.139 294.11 -33.707 296.502C-35.903 298.549 -37.765 304.893 -38 305.401C-34.303 300.145 -32.046 297.399 -31.202 296.599z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-44.776 290.635C-44.253 290.265 -44.555 289.774 -44.338 289.442C-43.385 287.984 -42.084 286.738 -42.066 285C-42.063 284.723 -42.441 284.414 -42.776 284.638C-43.053 284.822 -43.395 284.952 -43.503 285.082C-45.533 287.531 -46.933 290.202 -48.376 293.014C-48.559 293.371 -49.703 297.862 -49.39 297.973C-49.151 298.058 -47.431 293.877 -47.221 293.763C-45.958 293.077 -45.946 291.462 -44.776 290.635z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-28.043 310.179C-27.599 309.31 -26.023 308.108 -26.136 307.219C-26.254 306.291 -25.786 304.848 -26.698 305.536C-27.955 306.484 -31.404 307.833 -31.674 313.641C-31.7 314.212 -28.726 311.519 -28.043 310.179z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-13.6 293.001C-13.2 292.333 -12.492 292.806 -12.033 292.543C-11.385 292.171 -10.774 291.613 -10.482 290.964C-9.512 288.815 -7.743 286.995 -7.6 284.601C-9.091 283.196 -9.77 285.236 -10.4 286.201C-11.723 284.554 -12.722 286.428 -14.022 286.947C-14.092 286.975 -14.305 286.628 -14.38 286.655C-15.557 287.095 -16.237 288.176 -17.235 288.957C-17.406 289.091 -17.811 288.911 -17.958 289.047C-18.61 289.65 -19.583 289.975 -19.863 290.657C-20.973 293.364 -24.113 295.459 -26 303.001C-25.619 303.91 -21.488 296.359 -21.001 295.661C-20.165 294.465 -20.047 297.322 -18.771 296.656C-18.72 296.629 -18.534 296.867 -18.4 297.001C-18.206 296.721 -17.988 296.492 -17.6 296.601C-17.6 296.201 -17.734 295.645 -17.533 295.486C-16.296 294.509 -16.38 293.441 -15.6 292.201C-15.142 292.99 -14.081 292.271 -13.6 293.001z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M46.2 347.401C46.2 347.401 53.6 327.001 49.2 315.801C49.2 315.801 60.6 337.401 56 348.601C56 348.601 55.6 338.201 51.6 333.201C51.6 333.201 47.6 346.001 46.2 347.401z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M31.4 344.801C31.4 344.801 36.8 336.001 28.8 317.601C28.8 317.601 28 338.001 21.2 349.001C21.2 349.001 35.4 328.801 31.4 344.801z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M21.4 342.801C21.4 342.801 21.2 322.801 21.6 319.801C21.6 319.801 17.8 336.401 7.6 346.001C7.6 346.001 22 334.001 21.4 342.801z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M11.8 310.801C11.8 310.801 17.8 324.401 7.8 342.801C7.8 342.801 14.2 330.601 9.4 323.601C9.4 323.601 12 320.201 11.8 310.801z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-7.4 342.401C-7.4 342.401 -8.4 326.801 -6.6 324.601C-6.6 324.601 -6.4 318.201 -6.8 317.201C-6.8 317.201 -2.8 311.001 -2.6 318.401C-2.6 318.401 -1.2 326.201 1.6 330.801C1.6 330.801 5.2 336.201 5 342.601C5 342.601 -5 312.401 -7.4 342.401z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-11 314.801C-11 314.801 -17.6 325.601 -19.4 344.601C-19.4 344.601 -20.8 338.401 -17 324.001C-17 324.001 -12.8 308.601 -11 314.801z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-32.8 334.601C-32.8 334.601 -27.8 329.201 -26.4 324.201C-26.4 324.201 -22.8 308.401 -29.2 317.001C-29.2 317.001 -29 325.001 -37.2 332.401C-37.2 332.401 -32.4 330.001 -32.8 334.601z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-38.6 329.601C-38.6 329.601 -35.2 312.201 -34.4 311.401C-34.4 311.401 -32.6 308.001 -35.4 311.201C-35.4 311.201 -44.2 330.401 -48.2 337.001C-48.2 337.001 -40.2 327.801 -38.6 329.601z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-44.4 313.001C-44.4 313.001 -32.8 290.601 -54.6 316.401C-54.6 316.401 -43.6 306.601 -44.4 313.001z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M-59.8 298.401C-59.8 298.401 -55 279.601 -52.4 279.801C-52.4 279.801 -44.2 270.801 -50.8 281.401C-50.8 281.401 -56.8 291.001 -56.2 300.801C-56.2 300.801 -56.8 291.201 -59.8 298.401z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M270.5 287C270.5 287 258.5 277 256 273.5C256 273.5 269.5 292 269.5 299C269.5 299 272 291.5 270.5 287z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M276 265C276 265 255 250 251.5 242.5C251.5 242.5 278 272 278 276.5C278 276.5 278.5 267.5 276 265z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M293 111C293 111 281 103 279.5 105C279.5 105 290 111.5 292.5 120C292.5 120 291 111 293 111z"}
+ ,
+ {"fill": "#cccccc",
+ "path":"M301.5 191.5L284 179.5C284 179.5 303 196.5 303.5 200.5L301.5 191.5z"}
+ ,
+ {"stroke":"#000000",
+ "path":"M-89.25 169L-67.25 173.75"}
+ ,
+ {"stroke":"#000000",
+ "path":"M-39 331C-39 331 -39.5 327.5 -48.5 338"}
+ ,
+ {"stroke":"#000000",
+ "path":"M-33.5 336C-33.5 336 -31.5 329.5 -38 334"}
+ ,
+ {"stroke":"#000000",
+ "path":"M20.5 344.5C20.5 344.5 22 333.5 10.5 346.5"}
+];
+
+
+
+function draw(ctx, frame)
+{
+ var totalPaths = tiger.length;
+
+ if (frame > totalPaths)
+ return;
+ ctx.reset();
+ ctx.globalCompositeOperation = "source-over";
+ ctx.fillStyle = "rgba(0,0,0,0)";
+ //ctx.fillRect(0, 0, 600, 600);
+ ctx.fillRect(0, 0, 1900, 1200);
+
+ ctx.strokeColor = Qt.rgba(133, 133, 133,1);
+ ctx.lineWidth = 1;
+ //ctx.translate(200, 200);
+ ctx.translate(750, 350);
+ ctx.scale(2,2);
+ for (var i = 0; i < frame; i++) {
+ if (tiger[i].width != undefined)
+ ctx.lineWidth = tiger[i].width;
+
+ if (tiger[i].path != undefined)
+ ctx.setPathString(tiger[i].path);
+
+ if (tiger[i].fill != undefined) {
+ ctx.fillStyle = tiger[i].fill;
+ ctx.fill();
+ }
+
+ if (tiger[i].stroke != undefined) {
+ ctx.strokeStyle = tiger[i].stroke;
+ ctx.stroke();
+ }
+ }
+}
+
+
diff --git a/examples/declarative/canvas/svgpath/tiger.qml b/examples/declarative/canvas/svgpath/tiger.qml
new file mode 100644
index 0000000000..96d19d3dba
--- /dev/null
+++ b/examples/declarative/canvas/svgpath/tiger.qml
@@ -0,0 +1,33 @@
+import QtQuick 2.0
+import "tiger.js" as Tiger
+
+Canvas {
+ id:canvas
+ width:1900
+ height:1100
+ property int frame:0
+
+ Timer {
+ repeat:true
+ interval:100
+ running:true
+ onTriggered: {
+ canvas.frame++;
+ if (canvas.frame > Tiger.tiger.length) {
+ canvas.frame = 0;
+ } else {
+ Tiger.draw(canvas.getContext(), canvas.frame);
+ }
+ }
+ }
+/*
+ onDrawRegion:{
+ Tiger.draw(context, canvas.frame);
+ }
+Text {
+ anchors.top : parent.top
+ font.pixelSize : 30
+ text: "drawing path:" + canvas.frame + "/" + Tiger.tiger.length;
+}
+*/
+}
diff --git a/src/3rdparty/javascriptcore/COPYING.LIB b/src/3rdparty/javascriptcore/COPYING.LIB
new file mode 100644
index 0000000000..87c4a33dd8
--- /dev/null
+++ b/src/3rdparty/javascriptcore/COPYING.LIB
@@ -0,0 +1,488 @@
+
+
+NOTE! The LGPL below is copyrighted by the Free Software Foundation, but
+the instance of code that it refers to (the kde libraries) are copyrighted
+by the authors who actually wrote it.
+
+---------------------------------------------------------------------------
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor
+ Boston, MA 02110-1301, USA.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL. It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it. You can use it for
+your libraries, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library. If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software. To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+ Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs. This
+license, the GNU Library General Public License, applies to certain
+designated libraries. This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+ The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it. Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program. However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+ Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries. We
+concluded that weaker conditions might promote sharing better.
+
+ However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves. This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them. (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.) The hope is that this
+will lead to faster development of free libraries.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+ Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License"). Each licensee is
+addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ c) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ d) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/src/3rdparty/javascriptcore/DateMath.cpp b/src/3rdparty/javascriptcore/DateMath.cpp
new file mode 100644
index 0000000000..11c224aebb
--- /dev/null
+++ b/src/3rdparty/javascriptcore/DateMath.cpp
@@ -0,0 +1,382 @@
+/*
+ * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2007-2009 Torch Mobile, Inc.
+ *
+ * The Original Code is Mozilla Communicator client code, released
+ * March 31, 1998.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Alternatively, the contents of this file may be used under the terms
+ * of either the Mozilla Public License Version 1.1, found at
+ * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
+ * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
+ * (the "GPL"), in which case the provisions of the MPL or the GPL are
+ * applicable instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of one of those two
+ * licenses (the MPL or the GPL) and not to allow others to use your
+ * version of this file under the LGPL, indicate your decision by
+ * deletingthe provisions above and replace them with the notice and
+ * other provisions required by the MPL or the GPL, as the case may be.
+ * If you do not delete the provisions above, a recipient may use your
+ * version of this file under any of the LGPL, the MPL or the GPL.
+
+ * Copyright 2006-2008 the V8 project authors. All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 "DateMath.h"
+
+#include <algorithm>
+#include <limits.h>
+#include <limits>
+#include <stdint.h>
+#include <time.h>
+
+//#if HAVE(SYS_TIME_H)
+#if defined(EXISTS_SYS_TIME)
+#include <sys/time.h>
+#endif
+
+//#if HAVE(SYS_TIMEB_H)
+#if defined(EXISTS_SYS_TIMEB)
+#include <sys/timeb.h>
+#endif
+
+#define NaN std::numeric_limits<double>::quiet_NaN()
+
+using namespace QV8DateConverter::WTF;
+
+namespace QV8DateConverter {
+
+namespace WTF {
+
+/* Constants */
+
+static const double minutesPerDay = 24.0 * 60.0;
+static const double secondsPerDay = 24.0 * 60.0 * 60.0;
+static const double secondsPerYear = 24.0 * 60.0 * 60.0 * 365.0;
+
+static const double usecPerSec = 1000000.0;
+
+static const double maxUnixTime = 2145859200.0; // 12/31/2037
+// ECMAScript asks not to support for a date of which total
+// millisecond value is larger than the following value.
+// See 15.9.1.14 of ECMA-262 5th edition.
+static const double maxECMAScriptTime = 8.64E15;
+
+// Day of year for the first day of each month, where index 0 is January, and day 0 is January 1.
+// First for non-leap years, then for leap years.
+static const int firstDayOfMonth[2][12] = {
+ {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
+ {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
+};
+
+static inline bool isLeapYear(int year)
+{
+ if (year % 4 != 0)
+ return false;
+ if (year % 400 == 0)
+ return true;
+ if (year % 100 == 0)
+ return false;
+ return true;
+}
+
+static inline int daysInYear(int year)
+{
+ return 365 + isLeapYear(year);
+}
+
+static inline double daysFrom1970ToYear(int year)
+{
+ // The Gregorian Calendar rules for leap years:
+ // Every fourth year is a leap year. 2004, 2008, and 2012 are leap years.
+ // However, every hundredth year is not a leap year. 1900 and 2100 are not leap years.
+ // Every four hundred years, there's a leap year after all. 2000 and 2400 are leap years.
+
+ static const int leapDaysBefore1971By4Rule = 1970 / 4;
+ static const int excludedLeapDaysBefore1971By100Rule = 1970 / 100;
+ static const int leapDaysBefore1971By400Rule = 1970 / 400;
+
+ const double yearMinusOne = year - 1;
+ const double yearsToAddBy4Rule = floor(yearMinusOne / 4.0) - leapDaysBefore1971By4Rule;
+ const double yearsToExcludeBy100Rule = floor(yearMinusOne / 100.0) - excludedLeapDaysBefore1971By100Rule;
+ const double yearsToAddBy400Rule = floor(yearMinusOne / 400.0) - leapDaysBefore1971By400Rule;
+
+ return 365.0 * (year - 1970) + yearsToAddBy4Rule - yearsToExcludeBy100Rule + yearsToAddBy400Rule;
+}
+
+static inline double msToDays(double ms)
+{
+ return floor(ms / msPerDay);
+}
+
+int msToYear(double ms)
+{
+ int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970);
+ double msFromApproxYearTo1970 = msPerDay * daysFrom1970ToYear(approxYear);
+ if (msFromApproxYearTo1970 > ms)
+ return approxYear - 1;
+ if (msFromApproxYearTo1970 + msPerDay * daysInYear(approxYear) <= ms)
+ return approxYear + 1;
+ return approxYear;
+}
+
+int dayInYear(double ms, int year)
+{
+ return static_cast<int>(msToDays(ms) - daysFrom1970ToYear(year));
+}
+
+static inline double msToMilliseconds(double ms)
+{
+ double result = fmod(ms, msPerDay);
+ if (result < 0)
+ result += msPerDay;
+ return result;
+}
+
+// 0: Sunday, 1: Monday, etc.
+static inline int msToWeekDay(double ms)
+{
+ int wd = (static_cast<int>(msToDays(ms)) + 4) % 7;
+ if (wd < 0)
+ wd += 7;
+ return wd;
+}
+
+static inline int msToSeconds(double ms)
+{
+ double result = fmod(floor(ms / msPerSecond), secondsPerMinute);
+ if (result < 0)
+ result += secondsPerMinute;
+ return static_cast<int>(result);
+}
+
+static inline int msToMinutes(double ms)
+{
+ double result = fmod(floor(ms / msPerMinute), minutesPerHour);
+ if (result < 0)
+ result += minutesPerHour;
+ return static_cast<int>(result);
+}
+
+static inline int msToHours(double ms)
+{
+ double result = fmod(floor(ms/msPerHour), hoursPerDay);
+ if (result < 0)
+ result += hoursPerDay;
+ return static_cast<int>(result);
+}
+
+int monthFromDayInYear(int dayInYear, bool leapYear)
+{
+ const int d = dayInYear;
+ int step;
+
+ if (d < (step = 31))
+ return 0;
+ step += (leapYear ? 29 : 28);
+ if (d < step)
+ return 1;
+ if (d < (step += 31))
+ return 2;
+ if (d < (step += 30))
+ return 3;
+ if (d < (step += 31))
+ return 4;
+ if (d < (step += 30))
+ return 5;
+ if (d < (step += 31))
+ return 6;
+ if (d < (step += 31))
+ return 7;
+ if (d < (step += 30))
+ return 8;
+ if (d < (step += 31))
+ return 9;
+ if (d < (step += 30))
+ return 10;
+ return 11;
+}
+
+static inline bool checkMonth(int dayInYear, int& startDayOfThisMonth, int& startDayOfNextMonth, int daysInThisMonth)
+{
+ startDayOfThisMonth = startDayOfNextMonth;
+ startDayOfNextMonth += daysInThisMonth;
+ return (dayInYear <= startDayOfNextMonth);
+}
+
+int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
+{
+ const int d = dayInYear;
+ int step;
+ int next = 30;
+
+ if (d <= next)
+ return d + 1;
+ const int daysInFeb = (leapYear ? 29 : 28);
+ if (checkMonth(d, step, next, daysInFeb))
+ return d - step;
+ if (checkMonth(d, step, next, 31))
+ return d - step;
+ if (checkMonth(d, step, next, 30))
+ return d - step;
+ if (checkMonth(d, step, next, 31))
+ return d - step;
+ if (checkMonth(d, step, next, 30))
+ return d - step;
+ if (checkMonth(d, step, next, 31))
+ return d - step;
+ if (checkMonth(d, step, next, 31))
+ return d - step;
+ if (checkMonth(d, step, next, 30))
+ return d - step;
+ if (checkMonth(d, step, next, 31))
+ return d - step;
+ if (checkMonth(d, step, next, 30))
+ return d - step;
+ step = next;
+ return d - step;
+}
+
+static inline int monthToDayInYear(int month, bool isLeapYear)
+{
+ return firstDayOfMonth[isLeapYear][month];
+}
+
+static inline double timeToMS(double hour, double min, double sec, double ms)
+{
+ return (((hour * minutesPerHour + min) * secondsPerMinute + sec) * msPerSecond + ms);
+}
+
+double dateToDaysFrom1970(int year, int month, int day)
+{
+ year += month / 12;
+
+ month %= 12;
+ if (month < 0) {
+ month += 12;
+ --year;
+ }
+
+ double yearday = floor(daysFrom1970ToYear(year));
+ int monthday = monthToDayInYear(month, isLeapYear(year));
+
+ return yearday + monthday + day - 1;
+}
+
+static inline double ymdhmsToSeconds(long year, int mon, int day, int hour, int minute, int second)
+{
+ double days = (day - 32075)
+ + floor(1461 * (year + 4800.0 + (mon - 14) / 12) / 4)
+ + 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12
+ - floor(3 * ((year + 4900.0 + (mon - 14) / 12) / 100) / 4)
+ - 2440588;
+ return ((days * hoursPerDay + hour) * minutesPerHour + minute) * secondsPerMinute + second;
+}
+
+// We follow the recommendation of RFC 2822 to consider all
+// obsolete time zones not listed here equivalent to "-0000".
+static const struct KnownZone {
+ const
+ char tzName[4];
+ int tzOffset;
+} known_zones[] = {
+ { "UT", 0 },
+ { "GMT", 0 },
+ { "EST", -300 },
+ { "EDT", -240 },
+ { "CST", -360 },
+ { "CDT", -300 },
+ { "MST", -420 },
+ { "MDT", -360 },
+ { "PST", -480 },
+ { "PDT", -420 }
+};
+
+double timeClip(double t)
+{
+ if (!isfinite(t))
+ return NaN;
+ if (fabs(t) > maxECMAScriptTime)
+ return NaN;
+ return trunc(t);
+}
+} // namespace WTF
+
+namespace JSC {
+
+double gregorianDateTimeToMS(const GregorianDateTime& t, double milliSeconds)
+{
+ double day = dateToDaysFrom1970(t.year + 1900, t.month, t.monthDay);
+ double ms = timeToMS(t.hour, t.minute, t.second, milliSeconds);
+ double result = (day * WTF::msPerDay) + ms;
+
+ return result;
+}
+
+// input is UTC
+void msToGregorianDateTime(double ms, GregorianDateTime& tm)
+{
+ const int year = msToYear(ms);
+ tm.second = msToSeconds(ms);
+ tm.minute = msToMinutes(ms);
+ tm.hour = msToHours(ms);
+ tm.weekDay = msToWeekDay(ms);
+ tm.yearDay = dayInYear(ms, year);
+ tm.monthDay = dayInMonthFromDayInYear(tm.yearDay, isLeapYear(year));
+ tm.month = monthFromDayInYear(tm.yearDay, isLeapYear(year));
+ tm.year = year - 1900;
+ tm.isDST = false;
+ tm.utcOffset = static_cast<long>(0); // no ExecState :. cannot calculate offset. Assume UTC output.
+ tm.timeZone = NULL;
+}
+
+} // namespace JSC
+
+} // namespace QV8DateConverter
+
diff --git a/src/3rdparty/javascriptcore/DateMath.h b/src/3rdparty/javascriptcore/DateMath.h
new file mode 100644
index 0000000000..5adb0d358c
--- /dev/null
+++ b/src/3rdparty/javascriptcore/DateMath.h
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code, released
+ * March 31, 1998.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ */
+
+#ifndef DateMath_h
+#define DateMath_h
+
+#include <math.h>
+#include <string.h>
+#include <time.h>
+
+namespace QV8DateConverter {
+
+namespace WTF {
+
+double timeClip(double);
+
+const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
+const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
+const double hoursPerDay = 24.0;
+const double minutesPerHour = 60.0;
+const double secondsPerHour = 60.0 * 60.0;
+const double secondsPerMinute = 60.0;
+const double msPerSecond = 1000.0;
+const double msPerMinute = 60.0 * 1000.0;
+const double msPerHour = 60.0 * 60.0 * 1000.0;
+const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
+const double msPerMonth = 2592000000.0;
+
+// Returns the number of days from 1970-01-01 to the specified date.
+double dateToDaysFrom1970(int year, int month, int day);
+int msToYear(double ms);
+int dayInYear(double ms, int year);
+int monthFromDayInYear(int dayInYear, bool leapYear);
+int dayInMonthFromDayInYear(int dayInYear, bool leapYear);
+
+} // namespace WTF
+
+using WTF::dateToDaysFrom1970;
+using WTF::dayInMonthFromDayInYear;
+using WTF::dayInYear;
+using WTF::minutesPerHour;
+using WTF::monthFromDayInYear;
+using WTF::msPerDay;
+using WTF::msPerSecond;
+using WTF::msToYear;
+using WTF::secondsPerMinute;
+
+namespace JSC {
+struct GregorianDateTime;
+
+void msToGregorianDateTime(double, GregorianDateTime&);
+double gregorianDateTimeToMS(const GregorianDateTime&, double);
+
+// Intentionally overridding the default tm of the system.
+// The members of tm differ on various operating systems.
+struct GregorianDateTime {
+ GregorianDateTime()
+ : second(0)
+ , minute(0)
+ , hour(0)
+ , weekDay(0)
+ , monthDay(0)
+ , yearDay(0)
+ , month(0)
+ , year(0)
+ , isDST(0)
+ , utcOffset(0)
+ , timeZone(0)
+ {
+ }
+
+ ~GregorianDateTime()
+ {
+ delete [] timeZone;
+ }
+
+ GregorianDateTime(const tm& inTm)
+ : second(inTm.tm_sec)
+ , minute(inTm.tm_min)
+ , hour(inTm.tm_hour)
+ , weekDay(inTm.tm_wday)
+ , monthDay(inTm.tm_mday)
+ , yearDay(inTm.tm_yday)
+ , month(inTm.tm_mon)
+ , year(inTm.tm_year)
+ , isDST(inTm.tm_isdst)
+ {
+ utcOffset = static_cast<int>(0);
+ timeZone = 0;
+ }
+
+ operator tm() const
+ {
+ tm ret;
+ memset(&ret, 0, sizeof(ret));
+
+ ret.tm_sec = second;
+ ret.tm_min = minute;
+ ret.tm_hour = hour;
+ ret.tm_wday = weekDay;
+ ret.tm_mday = monthDay;
+ ret.tm_yday = yearDay;
+ ret.tm_mon = month;
+ ret.tm_year = year;
+ ret.tm_isdst = isDST;
+ return ret;
+ }
+
+ void copyFrom(const GregorianDateTime& rhs)
+ {
+ second = rhs.second;
+ minute = rhs.minute;
+ hour = rhs.hour;
+ weekDay = rhs.weekDay;
+ monthDay = rhs.monthDay;
+ yearDay = rhs.yearDay;
+ month = rhs.month;
+ year = rhs.year;
+ isDST = rhs.isDST;
+ utcOffset = rhs.utcOffset;
+ if (rhs.timeZone) {
+ int inZoneSize = strlen(rhs.timeZone) + 1;
+ timeZone = new char[inZoneSize];
+ strncpy(timeZone, rhs.timeZone, inZoneSize);
+ } else
+ timeZone = 0;
+ }
+
+ int second;
+ int minute;
+ int hour;
+ int weekDay;
+ int monthDay;
+ int yearDay;
+ int month;
+ int year;
+ int isDST;
+ int utcOffset;
+ char* timeZone;
+};
+
+static inline int gmtoffset(const GregorianDateTime& t)
+{
+ return t.utcOffset;
+}
+
+} // namespace JSC
+
+} // namespace QV8DateConverter
+
+#endif // DateMath_h
diff --git a/src/3rdparty/javascriptcore/VERSION b/src/3rdparty/javascriptcore/VERSION
new file mode 100644
index 0000000000..af6229afcb
--- /dev/null
+++ b/src/3rdparty/javascriptcore/VERSION
@@ -0,0 +1,15 @@
+This is a snapshot of the files: DateMath.h and DateMath.cpp
+from a snapshot of JavaScriptCore from
+
+ git://gitorious.org/qtwebkit/qtwebkit.git
+
+The commit imported was from the
+
+ javascriptcore-snapshot-27012011 branch/tag
+
+and has the sha1 checksum
+
+ 3ab0f621048fbeb480b687a28ed31d92d8506150
+
+The two files were then modified slightly so that unneeded
+functionality was removed (mostly regarding timezone offset).
diff --git a/src/3rdparty/v8 b/src/3rdparty/v8
new file mode 160000
+Subproject eb2dadf516823ec342e6d75a3a78b2af7b1dea8
diff --git a/src/declarative/debugger/qdeclarativedebughelper.cpp b/src/declarative/debugger/qdeclarativedebughelper.cpp
index 6f5df7690a..6eea82c948 100644
--- a/src/declarative/debugger/qdeclarativedebughelper.cpp
+++ b/src/declarative/debugger/qdeclarativedebughelper.cpp
@@ -52,11 +52,6 @@
QT_BEGIN_NAMESPACE
-QScriptEngine *QDeclarativeDebugHelper::getScriptEngine(QDeclarativeEngine *engine)
-{
- return QDeclarativeEnginePrivate::getScriptEngine(engine);
-}
-
void QDeclarativeDebugHelper::setAnimationSlowDownFactor(qreal factor)
{
QUnifiedTimer *timer = QUnifiedTimer::instance();
diff --git a/src/declarative/debugger/qdeclarativedebughelper_p.h b/src/declarative/debugger/qdeclarativedebughelper_p.h
index db4d5dc26b..60187112bf 100644
--- a/src/declarative/debugger/qdeclarativedebughelper_p.h
+++ b/src/declarative/debugger/qdeclarativedebughelper_p.h
@@ -50,7 +50,6 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-class QScriptEngine;
class QDeclarativeEngine;
// Helper methods to access private API through a stable interface
@@ -58,7 +57,6 @@ class QDeclarativeEngine;
class Q_DECLARATIVE_EXPORT QDeclarativeDebugHelper
{
public:
- static QScriptEngine *getScriptEngine(QDeclarativeEngine *engine);
static void setAnimationSlowDownFactor(qreal factor);
// Enables remote debugging functionality
diff --git a/src/declarative/debugger/qjsdebuggeragent.cpp b/src/declarative/debugger/qjsdebuggeragent.cpp
index dff637b7da..3169f91b59 100644
--- a/src/declarative/debugger/qjsdebuggeragent.cpp
+++ b/src/declarative/debugger/qjsdebuggeragent.cpp
@@ -238,7 +238,7 @@ QJSDebuggerAgent::QJSDebuggerAgent(QScriptEngine *engine, QObject *parent)
QJSDebuggerAgent::QJSDebuggerAgent(QDeclarativeEngine *engine, QObject *parent)
: QObject(parent)
- , QScriptEngineAgent(QDeclarativeDebugHelper::getScriptEngine(engine))
+ , QScriptEngineAgent(0)
, d(new QJSDebuggerAgentPrivate(this))
{
QJSDebuggerAgent::engine()->setAgent(this);
diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro
index 1f79a9a017..5cb1d9570c 100644
--- a/src/declarative/declarative.pro
+++ b/src/declarative/declarative.pro
@@ -52,3 +52,12 @@ linux-g++-maemo:DEFINES += QDECLARATIVEVIEW_NOBACKGROUND
DEFINES += QT_NO_OPENTYPE
INCLUDEPATH += $$QT_SOURCE_TREE/src/3rdparty/harfbuzz/src
+
+macx:CONFIG(debug, debug|release) {
+ LIBS += -L../v8/ -lv8_debug
+} else {
+ LIBS += -L../v8/ -lv8
+}
+
+# Prevent qmake adding v8 as a dependency
+CONFIG -= explicitlib
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 15cd728561..87e058037f 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -63,6 +63,8 @@
#include <QtGui/qgraphicstransform.h>
#include <qlistmodelinterface_p.h>
+#include <private/qv8engine_p.h>
+
#include <float.h>
QT_BEGIN_NAMESPACE
@@ -2653,31 +2655,33 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep)
If \a item is a \c null value, this maps the point from the coordinate
system of the root QML view.
*/
+void QDeclarativeItem::mapFromItem(QDeclarativeV8Function *args) const
+{
+ if (args->Length() != 0) {
+ v8::Local<v8::Value> item = (*args)[0];
+ QV8Engine *engine = args->engine();
-/*!
- Maps the point (\a x, \a y), which is in \a item's coordinate system, to
- this item's coordinate system, and returns a script value with \c x and \c y
- properties matching the mapped cooordinate.
+ QDeclarativeItem *itemObj = 0;
+ if (!item->IsNull())
+ itemObj = qobject_cast<QDeclarativeItem*>(engine->toQObject(item));
- If \a item is a \c null value, this maps the point from the coordinate
- system of the root QML view.
+ if (!itemObj && !item->IsNull()) {
+ qmlInfo(this) << "mapFromItem() given argument \"" << engine->toString(item->ToString())
+ << "\" which is neither null nor an Item";
+ return;
+ }
- \sa Item::mapFromItem()
-*/
-QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qreal y) const
-{
- QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
- QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
- if (!itemObj && !item.isNull()) {
- qmlInfo(this) << "mapFromItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
- return 0;
- }
+ v8::Local<v8::Object> rv = v8::Object::New();
+ args->returnValue(rv);
+
+ qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
+ qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
- // If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
- QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y);
- sv.setProperty(QLatin1String("x"), p.x());
- sv.setProperty(QLatin1String("y"), p.y());
- return sv;
+ QPointF p = QGraphicsItem::mapFromItem(itemObj, x, y);
+
+ rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
+ rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
+ }
}
/*!
@@ -2690,31 +2694,33 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qr
If \a item is a \c null value, this maps \a x and \a y to the coordinate
system of the root QML view.
*/
+void QDeclarativeItem::mapToItem(QDeclarativeV8Function *args) const
+{
+ if (args->Length() != 0) {
+ v8::Local<v8::Value> item = (*args)[0];
+ QV8Engine *engine = args->engine();
-/*!
- Maps the point (\a x, \a y), which is in this item's coordinate system, to
- \a item's coordinate system, and returns a script value with \c x and \c y
- properties matching the mapped cooordinate.
+ QDeclarativeItem *itemObj = 0;
+ if (!item->IsNull())
+ itemObj = qobject_cast<QDeclarativeItem*>(engine->toQObject(item));
- If \a item is a \c null value, this maps \a x and \a y to the coordinate
- system of the root QML view.
+ if (!itemObj && !item->IsNull()) {
+ qmlInfo(this) << "mapToItem() given argument \"" << engine->toString(item->ToString())
+ << "\" which is neither null nor an Item";
+ return;
+ }
- \sa Item::mapToItem()
-*/
-QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qreal y) const
-{
- QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
- QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
- if (!itemObj && !item.isNull()) {
- qmlInfo(this) << "mapToItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
- return 0;
- }
+ v8::Local<v8::Object> rv = v8::Object::New();
+ args->returnValue(rv);
- // If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene()
- QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y);
- sv.setProperty(QLatin1String("x"), p.x());
- sv.setProperty(QLatin1String("y"), p.y());
- return sv;
+ qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
+ qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
+
+ QPointF p = QGraphicsItem::mapToItem(itemObj, x, y);
+
+ rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
+ rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
+ }
}
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index 947eaee8a4..1bb9b3de42 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -64,6 +64,7 @@ class QDeclarativeTransition;
class QDeclarativeKeyEvent;
class QDeclarativeAnchors;
class QDeclarativeItemPrivate;
+class QDeclarativeV8Function;
class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDeclarativeParserStatus
{
Q_OBJECT
@@ -149,8 +150,8 @@ public:
bool keepMouseGrab() const;
void setKeepMouseGrab(bool);
- Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
- Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
+ Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
+ Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
Q_INVOKABLE void forceActiveFocus();
Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const;
diff --git a/src/declarative/items/qsgcanvasitem.cpp b/src/declarative/items/qsgcanvasitem.cpp
index 9f6e9db56b..f346db4c66 100644
--- a/src/declarative/items/qsgcanvasitem.cpp
+++ b/src/declarative/items/qsgcanvasitem.cpp
@@ -94,25 +94,40 @@ void QSGCanvasItem::paint(QPainter *painter)
Q_D(QSGCanvasItem);
if (d->context) {
+ emit drawRegion(getContext(), QRect(0, 0, width(), height()));
d->context->paint(painter);
emit canvasUpdated();
}
}
-QScriptValue QSGCanvasItem::getContext(const QString &contextId)
+void QSGCanvasItem::componentComplete()
+{
+ const QMetaObject *metaObject = this->metaObject();
+ int propertyCount = metaObject->propertyCount();
+ int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
+ for (int ii = QSGCanvasItem::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
+ QMetaProperty p = metaObject->property(ii);
+ if (p.hasNotifySignal())
+ QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
+ }
+ QSGPaintedItem::componentComplete();
+}
+
+
+QDeclarativeV8Handle QSGCanvasItem::getContext(const QString &contextId)
{
Q_D(QSGCanvasItem);
- QScriptEngine* e = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
+
if (contextId == QLatin1String("2d")) {
if (!d->context) {
+ QV8Engine *e = QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this));
d->context = new QSGContext2D(this);
- d->context->setScriptEngine(e);
+ d->context->setV8Engine(e);
connect(d->context, SIGNAL(changed()), this, SLOT(requestPaint()));
}
- return d->context->scriptValue();
+ return QDeclarativeV8Handle::fromHandle(d->context->v8value());
}
- qDebug("Canvas:requesting unsupported context");
- return e->undefinedValue();
+ return QDeclarativeV8Handle::fromHandle(v8::Undefined());
}
void QSGCanvasItem::requestPaint()
diff --git a/src/declarative/items/qsgcanvasitem_p.h b/src/declarative/items/qsgcanvasitem_p.h
index 8f3130c340..71358c4d9e 100644
--- a/src/declarative/items/qsgcanvasitem_p.h
+++ b/src/declarative/items/qsgcanvasitem_p.h
@@ -43,6 +43,7 @@
#define QSGCANVASITEM_P_H
#include "qsgpainteditem.h"
+#include <private/qv8engine_p.h>
#define QSGCANVASITEM_DEBUG //enable this for just DEBUG purpose!
@@ -55,7 +56,6 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QScriptValue;
class QSGContext2D;
class QSGCanvasItemPrivate;
class QSGCanvasItem : public QSGPaintedItem
@@ -65,11 +65,13 @@ public:
QSGCanvasItem(QSGItem *parent = 0);
~QSGCanvasItem();
-signals:
+Q_SIGNALS:
void canvasUpdated();
+ void drawRegion(QDeclarativeV8Handle context, const QRect &region);
+
public Q_SLOTS:
QString toDataURL(const QString& type = QLatin1String("image/png")) const;
- QScriptValue getContext(const QString & = QLatin1String("2d"));
+ QDeclarativeV8Handle getContext(const QString & = QLatin1String("2d"));
void requestPaint();
// Save current canvas to disk
@@ -77,6 +79,7 @@ public Q_SLOTS:
protected:
void paint(QPainter *painter);
+ virtual void componentComplete();
private:
Q_DECLARE_PRIVATE(QSGCanvasItem)
friend class QSGContext2D;
diff --git a/src/declarative/items/qsgcontext2d.cpp b/src/declarative/items/qsgcontext2d.cpp
index db23e5bc7b..f3371ed982 100644
--- a/src/declarative/items/qsgcontext2d.cpp
+++ b/src/declarative/items/qsgcontext2d.cpp
@@ -53,7 +53,9 @@
#include <qdeclarativeinfo.h>
#include <QtCore/qmath.h>
#include "qdeclarativepixmapcache_p.h"
-#include <QtScript/QScriptEngine>
+
+#include <private/qv8engine_p.h>
+#include "qvarlengtharray.h"
QT_BEGIN_NAMESPACE
@@ -366,547 +368,882 @@ static QString compositeOperatorToString(QPainter::CompositionMode op)
return QString();
}
+class QV8Context2DResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(Context2DType)
+public:
+ QV8Context2DResource(QV8Engine *e) : QV8ObjectResource(e) {}
+ QDeclarativeGuard<QSGContext2D> context;
+};
- #include <QScriptEngine>
-
-//static QtScript functions
-static QScriptValue ctx2d_sync(QScriptContext *c, QScriptEngine* e)
+//static script functions
+static v8::Handle<v8::Value> ctx2d_sync(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->sync();
- return e->nullValue();
-}
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->sync();
+ return v8::Undefined();
+}
// back-reference to the canvas, getter
-static QScriptValue ctx2d_canvas(QScriptContext *c, QScriptEngine* e)
+static v8::Handle<v8::Value> ctx2d_canvas(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- return e->newQObject(ctx2d->canvas());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->newQObject(r->context->canvas());
}
// state
-static QScriptValue ctx2d_restore(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_restore(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->restore();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->restore();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_save(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_reset(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->save();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->reset();
+
+ return v8::Undefined();
+}
+
+static v8::Handle<v8::Value> ctx2d_save(const v8::Arguments &args)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->save();
+
+ return v8::Undefined();
}
// transformations
-static QScriptValue ctx2d_rotate(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_rotate(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {
- ctx2d->rotate(c->argument(0).toNumber());
- }
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 1)
+ r->context->rotate(args[0]->NumberValue());
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_scale(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_scale(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 2) {
- ctx2d->scale(c->argument(0).toNumber(), c->argument(1).toNumber());
- }
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 2)
+ r->context->scale(args[0]->NumberValue(), args[1]->NumberValue());
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_setTransform(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_setTransform(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 6) {
- ctx2d->setTransform(c->argument(0).toNumber()
- , c->argument(1).toNumber()
- , c->argument(2).toNumber()
- , c->argument(3).toNumber()
- , c->argument(4).toNumber()
- , c->argument(5).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 6) {
+ r->context->setTransform(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue(),
+ args[5]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_transform(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_transform(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 6) {
- ctx2d->transform(c->argument(0).toNumber()
- , c->argument(1).toNumber()
- , c->argument(2).toNumber()
- , c->argument(3).toNumber()
- , c->argument(4).toNumber()
- , c->argument(5).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 6) {
+ r->context->transform(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue(),
+ args[5]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_translate(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_translate(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 2) {
- ctx2d->translate(c->argument(0).toNumber()
- , c->argument(1).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 2) {
+ r->context->translate(args[0]->NumberValue(),
+ args[1]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
// compositing
// float getter/setter default 1.0
-static QScriptValue ctx2d_globalAlpha(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_globalAlpha(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setGlobalAlpha(c->argument(0).toNumber());
- }
- return e->toScriptValue(ctx2d->globalAlpha());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Number::New(r->context->globalAlpha());
+}
+
+static void ctx2d_globalAlpha_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ r->context->setGlobalAlpha(value->NumberValue());
}
// string getter/setter default "source-over"
-static QScriptValue ctx2d_globalCompositeOperation(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_globalCompositeOperation(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (ctx2d) {
- if (c->argumentCount() == 1) {//setter
- ctx2d->setGlobalCompositeOperation(c->argument(0).toString());
- }
- return e->toScriptValue(ctx2d->globalCompositeOperation());
- }
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->toString(r->context->globalCompositeOperation());
+}
+
+static void ctx2d_globalCompositeOperation_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setGlobalCompositeOperation(engine->toString(value));
}
// colors and styles
// getter/setter
-static QScriptValue ctx2d_fillStyle(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_fillStyle(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setFillStyle(c->argument(0).toVariant());
- }
- return e->toScriptValue(ctx2d->fillStyle());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->fromVariant(r->context->fillStyle());
+}
+
+static void ctx2d_fillStyle_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setFillStyle(engine->toVariant(value, -1));
}
// colors and styles
// getter/setter
-static QScriptValue ctx2d_fillColor(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_fillColor(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setFillColor(c->argument(0).toVariant().value<QColor>());
- }
- return e->toScriptValue(ctx2d->fillColor());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->fromVariant(r->context->fillColor());
}
+static void ctx2d_fillColor_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setFillColor(engine->toVariant(value, -1).value<QColor>());
+}
//getter/setter
-static QScriptValue ctx2d_strokeStyle(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_strokeStyle(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setStrokeStyle(c->argument(0).toVariant());
- }
- return e->toScriptValue(ctx2d->strokeStyle());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->fromVariant(r->context->strokeStyle());
+}
+
+static void ctx2d_strokeStyle_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setStrokeStyle(engine->toVariant(value, -1));
}
// colors and styles
// getter/setter
-static QScriptValue ctx2d_strokeColor(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_strokeColor(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setStrokeColor(c->argument(0).toVariant().value<QColor>());
- }
- return e->toScriptValue(ctx2d->strokeColor());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->fromVariant(r->context->strokeColor());
+}
+
+static void ctx2d_strokeColor_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setStrokeColor(engine->toVariant(value, -1).value<QColor>());
}
-static QScriptValue ctx2d_createLinearGradient(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_createLinearGradient(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 4) {
- QObject* gradient = ctx2d->createLinearGradient( c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber());
- return e->toScriptValue(gradient);
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (args.Length() == 4) {
+ QObject* gradient = r->context->createLinearGradient(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
+ return engine->newQObject(gradient);
}
- return e->nullValue();
+
+ return v8::Null();
}
-static QScriptValue ctx2d_createRadialGradient(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_createRadialGradient(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 6) {
- QObject* gradient = ctx2d->createRadialGradient( c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber()
- ,c->argument(4).toNumber()
- ,c->argument(5).toNumber());
- return e->toScriptValue(gradient);
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (args.Length() == 6) {
+ QObject* gradient = r->context->createRadialGradient(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue(),
+ args[5]->NumberValue());
+ return engine->newQObject(gradient);
}
- return e->nullValue();
+
+ return v8::Null();
}
-static QScriptValue ctx2d_createPattern(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_createPattern(const v8::Arguments &args)
{
//TODO
- return e->nullValue();
+ return v8::Null();
}
// line styles
// string getter/setter
-static QScriptValue ctx2d_lineCap(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_lineCap(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setLineCap(c->argument(0).toString());
- }
- return e->toScriptValue(ctx2d->lineCap());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->toString(r->context->lineCap());
+}
+
+static void ctx2d_lineCap_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setLineCap(engine->toString(value));
}
// string getter/setter
-static QScriptValue ctx2d_lineJoin(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_lineJoin(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setLineJoin(c->argument(0).toString());
- }
- return e->toScriptValue(ctx2d->lineJoin());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->toString(r->context->lineJoin());
}
+
+static void ctx2d_lineJoin_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setLineJoin(engine->toString(value));
+}
+
// float getter/setter
-static QScriptValue ctx2d_lineWidth(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_lineWidth(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setLineWidth(c->argument(0).toNumber());
- }
- return e->toScriptValue(ctx2d->lineWidth());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Number::New(r->context->lineWidth());
}
+
+static void ctx2d_lineWidth_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ r->context->setLineWidth(value->NumberValue());
+}
+
// float getter/setter
-static QScriptValue ctx2d_miterLimit(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_miterLimit(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setMiterLimit(c->argument(0).toNumber());
- }
- return e->toScriptValue(ctx2d->miterLimit());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Number::New(r->context->miterLimit());
+}
+
+static void ctx2d_miterLimit_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ r->context->setMiterLimit(value->NumberValue());
}
// shadows
// float getter/setter
-static QScriptValue ctx2d_shadowBlur(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_shadowBlur(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setShadowBlur(c->argument(0).toNumber());
- }
- return e->toScriptValue(ctx2d->shadowBlur());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Number::New(r->context->shadowBlur());
}
-static QScriptValue ctx2d_shadowColor(QScriptContext *c, QScriptEngine *e)
+
+static void ctx2d_shadowBlur_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setShadowColor(c->argument(0).toString());
- }
- return e->toScriptValue(ctx2d->shadowColor());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ r->context->setShadowBlur(value->NumberValue());
+}
+
+v8::Handle<v8::Value> ctx2d_shadowColor(v8::Local<v8::String>, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ return engine->toString(r->context->shadowColor());
}
-static QScriptValue ctx2d_shadowOffsetX(QScriptContext *c, QScriptEngine *e)
+
+static void ctx2d_shadowColor_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setShadowOffsetX(c->argument(0).toNumber());
- }
- return e->toScriptValue(ctx2d->shadowOffsetX());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE_ACCESSOR();
+
+ r->context->setShadowColor(engine->toString(value));
}
-static QScriptValue ctx2d_shadowOffsetY(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_shadowOffsetX(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 1) {//setter
- ctx2d->setShadowOffsetY(c->argument(0).toNumber());
- }
- return e->toScriptValue(ctx2d->shadowOffsetY());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Number::New(r->context->shadowOffsetX());
+}
+
+static void ctx2d_shadowOffsetX_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ r->context->setShadowOffsetX(value->NumberValue());
+}
+
+v8::Handle<v8::Value> ctx2d_shadowOffsetY(v8::Local<v8::String>, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Number::New(r->context->shadowOffsetY());
+}
+
+static void ctx2d_shadowOffsetY_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ r->context->setShadowOffsetY(value->NumberValue());
}
//rects
-static QScriptValue ctx2d_clearRect(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_clearRect(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 4) {
- ctx2d->clearRect(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 4) {
+ r->context->clearRect(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_fillRect(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_fillRect(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 4) {
- ctx2d->fillRect(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 4) {
+ r->context->fillRect(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_strokeRect(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_strokeRect(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 4) {
- ctx2d->strokeRect(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 4) {
+ r->context->strokeRect(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
// Complex shapes (paths) API
-static QScriptValue ctx2d_arc(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_arc(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 6) {
- ctx2d->arc(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber()
- ,c->argument(4).toNumber()
- ,c->argument(5).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 6) {
+ r->context->arc(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue(),
+ args[5]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_arcTo(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_arcTo(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 5) {
- ctx2d->arcTo(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber()
- ,c->argument(4).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 5) {
+ r->context->arcTo(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_beginPath(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_beginPath(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->beginPath();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->beginPath();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_bezierCurveTo(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_bezierCurveTo(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 5) {
- ctx2d->bezierCurveTo(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber()
- ,c->argument(4).toNumber()
- ,c->argument(5).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 5) {
+ r->context->bezierCurveTo(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue(),
+ args[5]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_clip(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_clip(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->clip();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->clip();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_closePath(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_closePath(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->closePath();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->closePath();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_fill(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_fill(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->fill();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->fill();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_lineTo(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_lineTo(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 2) {
- ctx2d->lineTo(c->argument(0).toNumber()
- ,c->argument(1).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 2) {
+ r->context->lineTo(args[0]->NumberValue(),
+ args[1]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_moveTo(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_moveTo(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 2) {
- ctx2d->moveTo(c->argument(0).toNumber()
- ,c->argument(1).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 2) {
+ r->context->moveTo(args[0]->NumberValue(),
+ args[1]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_quadraticCurveTo(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_quadraticCurveTo(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 4) {
- ctx2d->quadraticCurveTo(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 4) {
+ r->context->quadraticCurveTo(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_rect(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_rect(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 4) {
- ctx2d->rect(c->argument(0).toNumber()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ if (args.Length() == 4) {
+ r->context->rect(args[0]->NumberValue(),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue());
}
- return e->nullValue();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_stroke(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_stroke(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- ctx2d->stroke();
- return e->nullValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ r->context->stroke();
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_isPointInPath(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_isPointInPath(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
bool pointInPath = false;
- if (c->argumentCount() == 2) {
- pointInPath = ctx2d->isPointInPath(c->argument(0).toNumber()
- ,c->argument(1).toNumber());
+ if (args.Length() == 2) {
+ pointInPath = r->context->isPointInPath(args[0]->NumberValue(),
+ args[1]->NumberValue());
}
- return e->toScriptValue(pointInPath);
-}
-// text
-static QScriptValue ctx2d_font(QScriptContext *c, QScriptEngine *e)
-{
- return QScriptValue();
-}
-static QScriptValue ctx2d_textAlign(QScriptContext *c, QScriptEngine *e)
-{
- return QScriptValue();
+ return v8::Boolean::New(pointInPath);
}
-static QScriptValue ctx2d_textBaseline(QScriptContext *c, QScriptEngine *e)
-{
- return QScriptValue();
-}
-static QScriptValue ctx2d_fillText(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_setPathString(const v8::Arguments &args)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 3) {
- ctx2d->fillText(c->argument(0).toString()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber());
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE();
+ if (args.Length() == 1) {
+ r->context->setPathString(engine->toString(args[0]));
}
- return e->nullValue();
+ return v8::Undefined();
}
-static QScriptValue ctx2d_strokeText(QScriptContext *c, QScriptEngine *e)
+
+// text
+v8::Handle<v8::Value> ctx2d_font(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 3) {
- ctx2d->strokeText(c->argument(0).toString()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber());
- }
- return e->nullValue();
-}
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
-// drawing images
-static QScriptValue ctx2d_drawImage(QScriptContext *c, QScriptEngine *e)
-{
- QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
- if (c->argumentCount() == 3) {
- ctx2d->drawImage(c->argument(0).toString()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber());
- } else if (c->argumentCount() == 5) {
- ctx2d->drawImage(c->argument(0).toString()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber()
- ,c->argument(4).toNumber());
- } else if (c->argumentCount() == 9) {
- ctx2d->drawImage(c->argument(0).toString()
- ,c->argument(1).toNumber()
- ,c->argument(2).toNumber()
- ,c->argument(3).toNumber()
- ,c->argument(4).toNumber()
- ,c->argument(5).toNumber()
- ,c->argument(6).toNumber()
- ,c->argument(7).toNumber()
- ,c->argument(8).toNumber());
- }
- return e->nullValue();
+ return v8::Undefined();
}
-// pixel manipulation
-static QScriptValue ctx2d_createImageData(QScriptContext *c, QScriptEngine *e)
+static void ctx2d_font_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ Q_UNUSED(value);
}
-static QScriptValue ctx2d_getImageData(QScriptContext *c, QScriptEngine *e)
+
+v8::Handle<v8::Value> ctx2d_textAlign(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_putImageData(QScriptContext *c, QScriptEngine *e)
+
+static void ctx2d_textAlign_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ Q_UNUSED(value);
}
-//Image Data Interface
-static QScriptValue ctx2d_imageData_data(QScriptContext *c, QScriptEngine *e)
+v8::Handle<v8::Value> ctx2d_textBaseline(v8::Local<v8::String>, const v8::AccessorInfo &info)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ return v8::Undefined();
}
-static QScriptValue ctx2d_imageData_height(QScriptContext *c, QScriptEngine *e)
+
+static void ctx2d_textBaseline_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This());
+ if (!r || !r->context)
+ V8THROW_ERROR_SETTER("Not a Context2D object");
+
+ Q_UNUSED(value);
}
-static QScriptValue ctx2d_imageData_width(QScriptContext *c, QScriptEngine *e)
+
+static v8::Handle<v8::Value> ctx2d_fillText(const v8::Arguments &args)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (args.Length() == 3) {
+ r->context->fillText(engine->toString(args[0]),
+ args[1]->NumberValue(),
+ args[2]->NumberValue());
+ }
+
+ return v8::Undefined();
}
-//CanvasPixelArray interface
-static QScriptValue ctx2d_pixelArray_length(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_strokeText(const v8::Arguments &args)
{
- //#TODO
- return QScriptValue();
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (args.Length() == 3) {
+ r->context->strokeText(engine->toString(args[0]),
+ args[1]->NumberValue(),
+ args[2]->NumberValue());
+ }
+
+ return v8::Undefined();
}
-//getter/setter by index how to?
-static QScriptValue ctx2d_pixelArray(QScriptContext *c, QScriptEngine *e)
+
+// drawing images
+static v8::Handle<v8::Value> ctx2d_drawImage(const v8::Arguments &args)
+{
+ QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This());
+ if (!r || !r->context)
+ V8THROW_ERROR("Not a Context2D object");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (args.Length() == 3) {
+ r->context->drawImage(engine->toString(args[0]),
+ args[1]->NumberValue(),
+ args[2]->NumberValue());
+ } else if (args.Length() == 5) {
+ r->context->drawImage(engine->toString(args[0]),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue());
+ } else if (args.Length() == 9) {
+ r->context->drawImage(engine->toString(args[0]),
+ args[1]->NumberValue(),
+ args[2]->NumberValue(),
+ args[3]->NumberValue(),
+ args[4]->NumberValue(),
+ args[5]->NumberValue(),
+ args[6]->NumberValue(),
+ args[7]->NumberValue(),
+ args[8]->NumberValue());
+ }
+
+ return v8::Undefined();
+}
+
+// pixel manipulation
+static v8::Handle<v8::Value> ctx2d_createImageData(const v8::Arguments &args)
{
//#TODO
- return QScriptValue();
+ return v8::Undefined();
}
-//CanvasGradient interface
-static QScriptValue ctx2d_gradient_addColorStop(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_getImageData(const v8::Arguments &args)
{
//#TODO
- return QScriptValue();
+ return v8::Undefined();
}
-//TextMetrics
-static QScriptValue ctx2d_textMetrics_width(QScriptContext *c, QScriptEngine *e)
+static v8::Handle<v8::Value> ctx2d_putImageData(const v8::Arguments &args)
{
//#TODO
- return QScriptValue();
+ return v8::Undefined();
}
-
bool QSGContext2DPrivate::hasShadow() const
{
return state.shadowColor.isValid()
@@ -2132,6 +2469,593 @@ bool QSGContext2D::isPointInPath(qreal x, qreal y) const
return d->path.contains(QPointF(x, y));
}
+//copied from QtSvg (qsvghandler.cpp).
+Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
+// '0' is 0x30 and '9' is 0x39
+static inline bool isDigit(ushort ch)
+{
+ static quint16 magic = 0x3ff;
+ return ((ch >> 4) == 3) && (magic >> (ch & 15));
+}
+
+static qreal toDouble(const QChar *&str)
+{
+ const int maxLen = 255;//technically doubles can go til 308+ but whatever
+ char temp[maxLen+1];
+ int pos = 0;
+
+ if (*str == QLatin1Char('-')) {
+ temp[pos++] = '-';
+ ++str;
+ } else if (*str == QLatin1Char('+')) {
+ ++str;
+ }
+ while (isDigit(str->unicode()) && pos < maxLen) {
+ temp[pos++] = str->toLatin1();
+ ++str;
+ }
+ if (*str == QLatin1Char('.') && pos < maxLen) {
+ temp[pos++] = '.';
+ ++str;
+ }
+ while (isDigit(str->unicode()) && pos < maxLen) {
+ temp[pos++] = str->toLatin1();
+ ++str;
+ }
+ bool exponent = false;
+ if ((*str == QLatin1Char('e') || *str == QLatin1Char('E')) && pos < maxLen) {
+ exponent = true;
+ temp[pos++] = 'e';
+ ++str;
+ if ((*str == QLatin1Char('-') || *str == QLatin1Char('+')) && pos < maxLen) {
+ temp[pos++] = str->toLatin1();
+ ++str;
+ }
+ while (isDigit(str->unicode()) && pos < maxLen) {
+ temp[pos++] = str->toLatin1();
+ ++str;
+ }
+ }
+
+ temp[pos] = '\0';
+
+ qreal val;
+ if (!exponent && pos < 10) {
+ int ival = 0;
+ const char *t = temp;
+ bool neg = false;
+ if(*t == '-') {
+ neg = true;
+ ++t;
+ }
+ while(*t && *t != '.') {
+ ival *= 10;
+ ival += (*t) - '0';
+ ++t;
+ }
+ if(*t == '.') {
+ ++t;
+ int div = 1;
+ while(*t) {
+ ival *= 10;
+ ival += (*t) - '0';
+ div *= 10;
+ ++t;
+ }
+ val = ((qreal)ival)/((qreal)div);
+ } else {
+ val = ival;
+ }
+ if (neg)
+ val = -val;
+ } else {
+#if defined(Q_WS_QWS) && !defined(Q_OS_VXWORKS)
+ if(sizeof(qreal) == sizeof(float))
+ val = strtof(temp, 0);
+ else
+#endif
+ {
+ bool ok = false;
+ val = qstrtod(temp, 0, &ok);
+ }
+ }
+ return val;
+
+}
+static qreal toDouble(const QString &str, bool *ok = NULL)
+{
+ const QChar *c = str.constData();
+ qreal res = toDouble(c);
+ if (ok) {
+ *ok = ((*c) == QLatin1Char('\0'));
+ }
+ return res;
+}
+
+static qreal toDouble(const QStringRef &str, bool *ok = NULL)
+{
+ const QChar *c = str.constData();
+ qreal res = toDouble(c);
+ if (ok) {
+ *ok = (c == (str.constData() + str.length()));
+ }
+ return res;
+}
+static inline void parseNumbersArray(const QChar *&str, QVarLengthArray<qreal, 8> &points)
+{
+ while (str->isSpace())
+ ++str;
+ while (isDigit(str->unicode()) ||
+ *str == QLatin1Char('-') || *str == QLatin1Char('+') ||
+ *str == QLatin1Char('.')) {
+
+ points.append(toDouble(str));
+
+ while (str->isSpace())
+ ++str;
+ if (*str == QLatin1Char(','))
+ ++str;
+
+ //eat the rest of space
+ while (str->isSpace())
+ ++str;
+ }
+}
+
+static void pathArcSegment(QPainterPath &path,
+ qreal xc, qreal yc,
+ qreal th0, qreal th1,
+ qreal rx, qreal ry, qreal xAxisRotation)
+{
+ qreal sinTh, cosTh;
+ qreal a00, a01, a10, a11;
+ qreal x1, y1, x2, y2, x3, y3;
+ qreal t;
+ qreal thHalf;
+
+ sinTh = qSin(xAxisRotation * (Q_PI / 180.0));
+ cosTh = qCos(xAxisRotation * (Q_PI / 180.0));
+
+ a00 = cosTh * rx;
+ a01 = -sinTh * ry;
+ a10 = sinTh * rx;
+ a11 = cosTh * ry;
+
+ thHalf = 0.5 * (th1 - th0);
+ t = (8.0 / 3.0) * qSin(thHalf * 0.5) * qSin(thHalf * 0.5) / qSin(thHalf);
+ x1 = xc + qCos(th0) - t * qSin(th0);
+ y1 = yc + qSin(th0) + t * qCos(th0);
+ x3 = xc + qCos(th1);
+ y3 = yc + qSin(th1);
+ x2 = x3 + t * qSin(th1);
+ y2 = y3 - t * qCos(th1);
+
+ path.cubicTo(a00 * x1 + a01 * y1, a10 * x1 + a11 * y1,
+ a00 * x2 + a01 * y2, a10 * x2 + a11 * y2,
+ a00 * x3 + a01 * y3, a10 * x3 + a11 * y3);
+}
+
+static void pathArc(QPainterPath &path,
+ qreal rx,
+ qreal ry,
+ qreal x_axis_rotation,
+ int large_arc_flag,
+ int sweep_flag,
+ qreal x,
+ qreal y,
+ qreal curx, qreal cury)
+{
+ qreal sin_th, cos_th;
+ qreal a00, a01, a10, a11;
+ qreal x0, y0, x1, y1, xc, yc;
+ qreal d, sfactor, sfactor_sq;
+ qreal th0, th1, th_arc;
+ int i, n_segs;
+ qreal dx, dy, dx1, dy1, Pr1, Pr2, Px, Py, check;
+
+ rx = qAbs(rx);
+ ry = qAbs(ry);
+
+ sin_th = qSin(x_axis_rotation * (Q_PI / 180.0));
+ cos_th = qCos(x_axis_rotation * (Q_PI / 180.0));
+
+ dx = (curx - x) / 2.0;
+ dy = (cury - y) / 2.0;
+ dx1 = cos_th * dx + sin_th * dy;
+ dy1 = -sin_th * dx + cos_th * dy;
+ Pr1 = rx * rx;
+ Pr2 = ry * ry;
+ Px = dx1 * dx1;
+ Py = dy1 * dy1;
+ /* Spec : check if radii are large enough */
+ check = Px / Pr1 + Py / Pr2;
+ if (check > 1) {
+ rx = rx * qSqrt(check);
+ ry = ry * qSqrt(check);
+ }
+
+ a00 = cos_th / rx;
+ a01 = sin_th / rx;
+ a10 = -sin_th / ry;
+ a11 = cos_th / ry;
+ x0 = a00 * curx + a01 * cury;
+ y0 = a10 * curx + a11 * cury;
+ x1 = a00 * x + a01 * y;
+ y1 = a10 * x + a11 * y;
+ /* (x0, y0) is current point in transformed coordinate space.
+ (x1, y1) is new point in transformed coordinate space.
+
+ The arc fits a unit-radius circle in this space.
+ */
+ d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
+ sfactor_sq = 1.0 / d - 0.25;
+ if (sfactor_sq < 0) sfactor_sq = 0;
+ sfactor = qSqrt(sfactor_sq);
+ if (sweep_flag == large_arc_flag) sfactor = -sfactor;
+ xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0);
+ yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0);
+ /* (xc, yc) is center of the circle. */
+
+ th0 = qAtan2(y0 - yc, x0 - xc);
+ th1 = qAtan2(y1 - yc, x1 - xc);
+
+ th_arc = th1 - th0;
+ if (th_arc < 0 && sweep_flag)
+ th_arc += 2 * Q_PI;
+ else if (th_arc > 0 && !sweep_flag)
+ th_arc -= 2 * Q_PI;
+
+ n_segs = qCeil(qAbs(th_arc / (Q_PI * 0.5 + 0.001)));
+
+ for (i = 0; i < n_segs; i++) {
+ pathArcSegment(path, xc, yc,
+ th0 + i * th_arc / n_segs,
+ th0 + (i + 1) * th_arc / n_segs,
+ rx, ry, x_axis_rotation);
+ }
+}
+
+
+static bool parsePathDataFast(const QString &dataStr, QPainterPath &path)
+{
+ qreal x0 = 0, y0 = 0; // starting point
+ qreal x = 0, y = 0; // current point
+ char lastMode = 0;
+ QPointF ctrlPt;
+ const QChar *str = dataStr.constData();
+ const QChar *end = str + dataStr.size();
+
+ while (str != end) {
+ while (str->isSpace())
+ ++str;
+ QChar pathElem = *str;
+ ++str;
+ QChar endc = *end;
+ *const_cast<QChar *>(end) = 0; // parseNumbersArray requires 0-termination that QStringRef cannot guarantee
+ QVarLengthArray<qreal, 8> arg;
+ parseNumbersArray(str, arg);
+ *const_cast<QChar *>(end) = endc;
+ if (pathElem == QLatin1Char('z') || pathElem == QLatin1Char('Z'))
+ arg.append(0);//dummy
+ const qreal *num = arg.constData();
+ int count = arg.count();
+ while (count > 0) {
+ qreal offsetX = x; // correction offsets
+ qreal offsetY = y; // for relative commands
+ switch (pathElem.unicode()) {
+ case 'm': {
+ if (count < 2) {
+ num++;
+ count--;
+ break;
+ }
+ x = x0 = num[0] + offsetX;
+ y = y0 = num[1] + offsetY;
+ num += 2;
+ count -= 2;
+ path.moveTo(x0, y0);
+
+ // As per 1.2 spec 8.3.2 The "moveto" commands
+ // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands,
+ // the subsequent pairs shall be treated as implicit 'lineto' commands.
+ pathElem = QLatin1Char('l');
+ }
+ break;
+ case 'M': {
+ if (count < 2) {
+ num++;
+ count--;
+ break;
+ }
+ x = x0 = num[0];
+ y = y0 = num[1];
+ num += 2;
+ count -= 2;
+ path.moveTo(x0, y0);
+
+ // As per 1.2 spec 8.3.2 The "moveto" commands
+ // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands,
+ // the subsequent pairs shall be treated as implicit 'lineto' commands.
+ pathElem = QLatin1Char('L');
+ }
+ break;
+ case 'z':
+ case 'Z': {
+ x = x0;
+ y = y0;
+ count--; // skip dummy
+ num++;
+ path.closeSubpath();
+ }
+ break;
+ case 'l': {
+ if (count < 2) {
+ num++;
+ count--;
+ break;
+ }
+ x = num[0] + offsetX;
+ y = num[1] + offsetY;
+ num += 2;
+ count -= 2;
+ path.lineTo(x, y);
+
+ }
+ break;
+ case 'L': {
+ if (count < 2) {
+ num++;
+ count--;
+ break;
+ }
+ x = num[0];
+ y = num[1];
+ num += 2;
+ count -= 2;
+ path.lineTo(x, y);
+ }
+ break;
+ case 'h': {
+ x = num[0] + offsetX;
+ num++;
+ count--;
+ path.lineTo(x, y);
+ }
+ break;
+ case 'H': {
+ x = num[0];
+ num++;
+ count--;
+ path.lineTo(x, y);
+ }
+ break;
+ case 'v': {
+ y = num[0] + offsetY;
+ num++;
+ count--;
+ path.lineTo(x, y);
+ }
+ break;
+ case 'V': {
+ y = num[0];
+ num++;
+ count--;
+ path.lineTo(x, y);
+ }
+ break;
+ case 'c': {
+ if (count < 6) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF c1(num[0] + offsetX, num[1] + offsetY);
+ QPointF c2(num[2] + offsetX, num[3] + offsetY);
+ QPointF e(num[4] + offsetX, num[5] + offsetY);
+ num += 6;
+ count -= 6;
+ path.cubicTo(c1, c2, e);
+ ctrlPt = c2;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 'C': {
+ if (count < 6) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF c1(num[0], num[1]);
+ QPointF c2(num[2], num[3]);
+ QPointF e(num[4], num[5]);
+ num += 6;
+ count -= 6;
+ path.cubicTo(c1, c2, e);
+ ctrlPt = c2;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 's': {
+ if (count < 4) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF c1;
+ if (lastMode == 'c' || lastMode == 'C' ||
+ lastMode == 's' || lastMode == 'S')
+ c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
+ else
+ c1 = QPointF(x, y);
+ QPointF c2(num[0] + offsetX, num[1] + offsetY);
+ QPointF e(num[2] + offsetX, num[3] + offsetY);
+ num += 4;
+ count -= 4;
+ path.cubicTo(c1, c2, e);
+ ctrlPt = c2;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 'S': {
+ if (count < 4) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF c1;
+ if (lastMode == 'c' || lastMode == 'C' ||
+ lastMode == 's' || lastMode == 'S')
+ c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
+ else
+ c1 = QPointF(x, y);
+ QPointF c2(num[0], num[1]);
+ QPointF e(num[2], num[3]);
+ num += 4;
+ count -= 4;
+ path.cubicTo(c1, c2, e);
+ ctrlPt = c2;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 'q': {
+ if (count < 4) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF c(num[0] + offsetX, num[1] + offsetY);
+ QPointF e(num[2] + offsetX, num[3] + offsetY);
+ num += 4;
+ count -= 4;
+ path.quadTo(c, e);
+ ctrlPt = c;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 'Q': {
+ if (count < 4) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF c(num[0], num[1]);
+ QPointF e(num[2], num[3]);
+ num += 4;
+ count -= 4;
+ path.quadTo(c, e);
+ ctrlPt = c;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 't': {
+ if (count < 2) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF e(num[0] + offsetX, num[1] + offsetY);
+ num += 2;
+ count -= 2;
+ QPointF c;
+ if (lastMode == 'q' || lastMode == 'Q' ||
+ lastMode == 't' || lastMode == 'T')
+ c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
+ else
+ c = QPointF(x, y);
+ path.quadTo(c, e);
+ ctrlPt = c;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 'T': {
+ if (count < 2) {
+ num += count;
+ count = 0;
+ break;
+ }
+ QPointF e(num[0], num[1]);
+ num += 2;
+ count -= 2;
+ QPointF c;
+ if (lastMode == 'q' || lastMode == 'Q' ||
+ lastMode == 't' || lastMode == 'T')
+ c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
+ else
+ c = QPointF(x, y);
+ path.quadTo(c, e);
+ ctrlPt = c;
+ x = e.x();
+ y = e.y();
+ break;
+ }
+ case 'a': {
+ if (count < 7) {
+ num += count;
+ count = 0;
+ break;
+ }
+ qreal rx = (*num++);
+ qreal ry = (*num++);
+ qreal xAxisRotation = (*num++);
+ qreal largeArcFlag = (*num++);
+ qreal sweepFlag = (*num++);
+ qreal ex = (*num++) + offsetX;
+ qreal ey = (*num++) + offsetY;
+ count -= 7;
+ qreal curx = x;
+ qreal cury = y;
+ pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag),
+ int(sweepFlag), ex, ey, curx, cury);
+
+ x = ex;
+ y = ey;
+ }
+ break;
+ case 'A': {
+ if (count < 7) {
+ num += count;
+ count = 0;
+ break;
+ }
+ qreal rx = (*num++);
+ qreal ry = (*num++);
+ qreal xAxisRotation = (*num++);
+ qreal largeArcFlag = (*num++);
+ qreal sweepFlag = (*num++);
+ qreal ex = (*num++);
+ qreal ey = (*num++);
+ count -= 7;
+ qreal curx = x;
+ qreal cury = y;
+ pathArc(path, rx, ry, xAxisRotation, int(largeArcFlag),
+ int(sweepFlag), ex, ey, curx, cury);
+
+ x = ex;
+ y = ey;
+ }
+ break;
+ default:
+ return false;
+ }
+ lastMode = pathElem.toLatin1();
+ }
+ }
+ return true;
+}
+
+void QSGContext2D::setPathString(const QString& path)
+{
+ Q_D(QSGContext2D);
+ d->path = QPainterPath();
+ parsePathDataFast(path, d->path);
+}
QList<int> QSGContext2D::getImageData(qreal sx, qreal sy, qreal sw, qreal sh)
{
@@ -2184,78 +3108,110 @@ bool QSGContext2D::isDirty() const
return !d->commands.isEmpty();
}
-QScriptValue QSGContext2D::scriptValue() const
+v8::Handle<v8::Object> QSGContext2D::v8value() const
{
Q_D(const QSGContext2D);
- return d->scriptValue;
-}
-
-void QSGContext2D::setScriptEngine(QScriptEngine *eng)
+ return d->v8value;
+}
+
+class QSGContext2DEngineData : public QV8Engine::Deletable
+{
+public:
+ QSGContext2DEngineData(QV8Engine *engine);
+ ~QSGContext2DEngineData();
+
+ v8::Persistent<v8::Function> constructor;
+};
+
+QSGContext2DEngineData::QSGContext2DEngineData(QV8Engine *engine)
+{
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(engine->context());
+
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->PrototypeTemplate()->Set(v8::String::New("sync"), V8FUNCTION(ctx2d_sync, engine));
+ ft->PrototypeTemplate()->SetAccessor(v8::String::New("canvas"), ctx2d_canvas, 0, v8::External::Wrap(engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("restore"), V8FUNCTION(ctx2d_restore, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("reset"), V8FUNCTION(ctx2d_reset, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("save"), V8FUNCTION(ctx2d_save, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("rotate"), V8FUNCTION(ctx2d_rotate, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("scale"), V8FUNCTION(ctx2d_scale, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("setTransform"), V8FUNCTION(ctx2d_setTransform, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("transform"), V8FUNCTION(ctx2d_transform, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("translate"), V8FUNCTION(ctx2d_translate, engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("globalAlpha"), ctx2d_globalAlpha, ctx2d_globalAlpha_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("globalCompositeOperation"), ctx2d_globalCompositeOperation, ctx2d_globalCompositeOperation_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("fillStyle"), ctx2d_fillStyle, ctx2d_fillStyle_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("strokeStyle"), ctx2d_strokeStyle, ctx2d_strokeStyle_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("fillColor"), ctx2d_fillColor, ctx2d_fillColor_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("strokeColor"), ctx2d_strokeColor, ctx2d_strokeColor_set, v8::External::Wrap(engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("createLinearGradient"), V8FUNCTION(ctx2d_createLinearGradient, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("createRadialGradient"), V8FUNCTION(ctx2d_createRadialGradient, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("createPattern"), V8FUNCTION(ctx2d_createPattern, engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("lineCap"), ctx2d_lineCap, ctx2d_lineCap_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("lineJoin"), ctx2d_lineJoin, ctx2d_lineJoin_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("lineWidth"), ctx2d_lineWidth, ctx2d_lineWidth_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("miterLimit"), ctx2d_miterLimit, ctx2d_miterLimit_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowBlur"), ctx2d_shadowBlur, ctx2d_shadowBlur_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowColor"), ctx2d_shadowColor, ctx2d_shadowColor_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowOffsetX"), ctx2d_shadowOffsetX, ctx2d_shadowOffsetX_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowOffsetY"), ctx2d_shadowOffsetY, ctx2d_shadowOffsetY_set, v8::External::Wrap(engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("clearRect"), V8FUNCTION(ctx2d_clearRect, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("fillRect"), V8FUNCTION(ctx2d_fillRect, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("strokeRect"), V8FUNCTION(ctx2d_strokeRect, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("arc"), V8FUNCTION(ctx2d_arc, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("arcTo"), V8FUNCTION(ctx2d_arcTo, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("beginPath"), V8FUNCTION(ctx2d_beginPath, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("bezierCurveTo"), V8FUNCTION(ctx2d_bezierCurveTo, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("clip"), V8FUNCTION(ctx2d_clip, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("closePath"), V8FUNCTION(ctx2d_closePath, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("fill"), V8FUNCTION(ctx2d_fill, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("lineTo"), V8FUNCTION(ctx2d_lineTo, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("moveTo"), V8FUNCTION(ctx2d_moveTo, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("quadraticCurveTo"), V8FUNCTION(ctx2d_quadraticCurveTo, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("rect"), V8FUNCTION(ctx2d_rect, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("stroke"), V8FUNCTION(ctx2d_stroke, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("isPointInPath"), V8FUNCTION(ctx2d_isPointInPath, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("setPathString"), V8FUNCTION(ctx2d_setPathString, engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("font"), ctx2d_font, ctx2d_font_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("textAlign"), ctx2d_textAlign, ctx2d_textAlign_set, v8::External::Wrap(engine));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("textBaseline"), ctx2d_textBaseline, ctx2d_textBaseline_set, v8::External::Wrap(engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("fillText"), V8FUNCTION(ctx2d_fillText, engine));
+ // ft->PrototypeTemplate()->Set(v8::String::New("measureText"), V8FUNCTION(ctx2d_measureText, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("strokeText"), V8FUNCTION(ctx2d_strokeText, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("drawImage"), V8FUNCTION(ctx2d_drawImage, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("createImageData"), V8FUNCTION(ctx2d_createImageData, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("getImageData"), V8FUNCTION(ctx2d_getImageData, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("putImageData"), V8FUNCTION(ctx2d_putImageData, engine));
+
+ constructor = qPersistentNew(ft->GetFunction());
+}
+
+QSGContext2DEngineData::~QSGContext2DEngineData()
+{
+ qPersistentDispose(constructor);
+}
+
+V8_DEFINE_EXTENSION(QSGContext2DEngineData, engineData);
+
+void QSGContext2D::setV8Engine(QV8Engine *engine)
{
Q_D(QSGContext2D);
- if (d->scriptEngine != eng) {
- d->scriptEngine = eng;
- d->scriptValue = eng->newObject();
- d->scriptValue.setData(eng->toScriptValue(this));
- d->scriptValue.setProperty(QLatin1String("sync"), eng->newFunction(ctx2d_sync));
- d->scriptValue.setProperty(QLatin1String("canvas"), eng->newFunction(ctx2d_canvas),QScriptValue::PropertyGetter);
- d->scriptValue.setProperty(QLatin1String("restore"), eng->newFunction(ctx2d_restore));
- d->scriptValue.setProperty(QLatin1String("save"), eng->newFunction(ctx2d_save));
- d->scriptValue.setProperty(QLatin1String("rotate"), eng->newFunction(ctx2d_rotate, 1));
- d->scriptValue.setProperty(QLatin1String("scale"), eng->newFunction(ctx2d_scale, 2));
- d->scriptValue.setProperty(QLatin1String("setTransform"), eng->newFunction(ctx2d_setTransform, 6));
- d->scriptValue.setProperty(QLatin1String("transform"), eng->newFunction(ctx2d_transform, 6));
- d->scriptValue.setProperty(QLatin1String("translate"), eng->newFunction(ctx2d_translate, 2));
- d->scriptValue.setProperty(QLatin1String("globalAlpha"), eng->newFunction(ctx2d_globalAlpha), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("globalCompositeOperation"), eng->newFunction(ctx2d_globalCompositeOperation), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("fillStyle"), eng->newFunction(ctx2d_fillStyle), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("strokeStyle"), eng->newFunction(ctx2d_strokeStyle), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("fillColor"), eng->newFunction(ctx2d_fillColor), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("strokeColor"), eng->newFunction(ctx2d_strokeColor), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("createLinearGradient"), eng->newFunction(ctx2d_createLinearGradient, 4));
- d->scriptValue.setProperty(QLatin1String("createRadialGradient"), eng->newFunction(ctx2d_createRadialGradient, 6));
- d->scriptValue.setProperty(QLatin1String("createPattern"), eng->newFunction(ctx2d_createPattern, 2));
- d->scriptValue.setProperty(QLatin1String("lineCap"), eng->newFunction(ctx2d_lineCap), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("lineJoin"), eng->newFunction(ctx2d_lineJoin), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("lineWidth"), eng->newFunction(ctx2d_lineWidth), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("miterLimit"), eng->newFunction(ctx2d_miterLimit), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("shadowBlur"), eng->newFunction(ctx2d_shadowBlur), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("shadowColor"), eng->newFunction(ctx2d_shadowColor), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("shadowOffsetX"), eng->newFunction(ctx2d_shadowOffsetX), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("shadowOffsetY"), eng->newFunction(ctx2d_shadowOffsetY), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("clearRect"), eng->newFunction(ctx2d_clearRect, 4));
- d->scriptValue.setProperty(QLatin1String("fillRect"), eng->newFunction(ctx2d_fillRect, 4));
- d->scriptValue.setProperty(QLatin1String("strokeRect"), eng->newFunction(ctx2d_strokeRect, 4));
- d->scriptValue.setProperty(QLatin1String("arc"), eng->newFunction(ctx2d_arc, 6));
- d->scriptValue.setProperty(QLatin1String("arcTo"), eng->newFunction(ctx2d_arcTo, 5));
- d->scriptValue.setProperty(QLatin1String("beginPath"), eng->newFunction(ctx2d_beginPath));
- d->scriptValue.setProperty(QLatin1String("bezierCurveTo"), eng->newFunction(ctx2d_bezierCurveTo, 6));
- d->scriptValue.setProperty(QLatin1String("clip"), eng->newFunction(ctx2d_clip));
- d->scriptValue.setProperty(QLatin1String("closePath"), eng->newFunction(ctx2d_closePath));
- d->scriptValue.setProperty(QLatin1String("fill"), eng->newFunction(ctx2d_fill));
- d->scriptValue.setProperty(QLatin1String("lineTo"), eng->newFunction(ctx2d_lineTo, 2));
- d->scriptValue.setProperty(QLatin1String("moveTo"), eng->newFunction(ctx2d_moveTo, 2));
- d->scriptValue.setProperty(QLatin1String("quadraticCurveTo"), eng->newFunction(ctx2d_quadraticCurveTo, 4));
- d->scriptValue.setProperty(QLatin1String("rect"), eng->newFunction(ctx2d_rect, 4));
- d->scriptValue.setProperty(QLatin1String("stroke"), eng->newFunction(ctx2d_stroke));
- d->scriptValue.setProperty(QLatin1String("isPointInPath"), eng->newFunction(ctx2d_isPointInPath, 2));
- d->scriptValue.setProperty(QLatin1String("font"), eng->newFunction(ctx2d_font), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("textAlign"), eng->newFunction(ctx2d_textAlign), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("textBaseline"), eng->newFunction(ctx2d_textBaseline), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- d->scriptValue.setProperty(QLatin1String("fillText"), eng->newFunction(ctx2d_fillText, 4));
- //d->scriptValue.setProperty(QLatin1String("measureText"), eng->newFunction(ctx2d_measureText, 1));
- d->scriptValue.setProperty(QLatin1String("strokeText"), eng->newFunction(ctx2d_strokeText, 4));
- d->scriptValue.setProperty(QLatin1String("drawImage"), eng->newFunction(ctx2d_drawImage, 9));
- d->scriptValue.setProperty(QLatin1String("createImageData"), eng->newFunction(ctx2d_createImageData, 2));
- d->scriptValue.setProperty(QLatin1String("getImageData"), eng->newFunction(ctx2d_getImageData, 4));
- d->scriptValue.setProperty(QLatin1String("putImageData"), eng->newFunction(ctx2d_putImageData, 7));
- }
-}
-
-QScriptEngine *QSGContext2D::scriptEngine() const
-{
- Q_D(const QSGContext2D);
- return d->scriptEngine;
+ if (d->v8engine != engine) {
+ d->v8engine = engine;
+
+ qPersistentDispose(d->v8value);
+
+ if (d->v8engine == 0)
+ return;
+
+ QSGContext2DEngineData *ed = engineData(engine);
+ d->v8value = qPersistentNew(ed->constructor->NewInstance());
+ QV8Context2DResource *r = new QV8Context2DResource(engine);
+ r->context = this;
+ d->v8value->SetExternalResource(r);
+ }
}
void QSGContext2D::addref()
@@ -2274,353 +3230,6 @@ void QSGContext2D::release()
}
}
-
-bool QSGContext2D::inWorkerThread() const
-{
- Q_D(const QSGContext2D);
- return d->agentData != 0;
-}
-const QString& QSGContext2D::agentScript() const
-{
- static QString script;
- if (script.isEmpty()) {
- script = QString::fromLatin1(
- "function CanvasImageData(w, h, d) {"
- " this.width = w;"
- " this.height = h;"
- " this.data = d;"
- "}"
- "function Context2DAgent(_ctx2d) {"
- " this._ctx = _ctx2d;"
- " this._fillColor = '#000000';"
- " this._fillStyle = '#000000';"
- " this._strokeColor = '#000000';"
- " this._strokeStyle = '#000000';"
- " this._globalCompositeOperation = \"source-over\";"
- " this._commands = [];"
- " this.createImageData = function() {"
- " var d = null;"
- " if (arguments.length == 1 && arguments[0] instanceof CanvasImageData) {"
- " d = new CanvasImageData(arguments[0].width,"
- " arguments[0].height,"
- " new Array(arguments[0].width * arguments[0].height * 4));"
- " } else if (arguments.length == 2) {"
- " d = new CanvasImageData(arguments[0], arguments[1], new Array(arguments[0] * arguments[1] * 4));"
- " }"
- " if (d)"
- " for (var i=0; i<d.data.length; i++)"
- " d.data[i] = 255;"
- " return d;"
- " };"
- " this.getImageData = function(sx, sy, sw, sh) {"
- " var imageData = new CanvasImageData(sw, sh, this._ctx.getImageData(sx, sy, sw, sh));"
- " return imageData;"
- " };"
- " this.sync = function() {"
- " this._ctx.processCommands(this._commands);"
- " this._commands.length = 0;"
- " };");
-
- script.append(QString::fromLatin1(
- "this.save = function() {"
- " this._commands.push([%1]);"
- "};").arg(Save));
-
- script.append(QString::fromLatin1(
- "this.restore = function() {"
- " this._commands.push([%1]);"
- "};").arg(Restore));
-
- script.append(QString::fromLatin1(
- "this.scale = function(x, y) {"
- " this._commands.push([%1, x, y]);"
- "};").arg(Scale));
-
- script.append(QString::fromLatin1(
- "this.createImage = function(url) {"
- " return this._ctx.createImage(url);"
- "};"));
-
- script.append(QString::fromLatin1(
- "this.rotate = function(x) {"
- " this._commands.push([%1, x]);"
- "};").arg(Rotate));
-
- script.append(QString::fromLatin1(
- "this.translate = function(x, y) {"
- " this._commands.push([%1, x, y]);"
- "};").arg(Translate));
-
- script.append(QString::fromLatin1(
- "this.transform = function(a1, a2, a3, a4, a5, a6) {"
- " this._commands.push([%1, a1, a2, a3, a4, a5, a6]);"
- "};").arg(Transform));
-
- script.append(QString::fromLatin1(
- "this.setTransform = function(a1, a2, a3, a4, a5, a6) {"
- " this._commands.push([%1, a1, a2, a3, a4, a5, a6]);"
- "};").arg(SetTransform));
-
- script.append(QString::fromLatin1(
- "this.clearRect = function(x, y, w, h) {"
- " this._commands.push([%1, x, y, w, h]);"
- "};").arg(ClearRect));
-
- script.append(QString::fromLatin1(
- "this.fillRect = function(x, y, w, h) {"
- " this._commands.push([%1, x, y, w, h]);"
- "};").arg(FillRect));
-
- script.append(QString::fromLatin1(
- "this.strokeRect = function(x, y, w, h) {"
- " this._commands.push([%1, x, y, w, h]);"
- "};").arg(StrokeRect));
-
- script.append(QString::fromLatin1(
- "this.beginPath = function() {"
- " this._commands.push([%1]);"
- "};").arg(BeginPath));
-
- script.append(QString::fromLatin1(
- "this.closePath = function() {"
- " this._commands.push([%1]);"
- "};").arg(ClosePath));
-
- script.append(QString::fromLatin1(
- "this.moveTo = function(x, y) {"
- " this._commands.push([%1, x, y]);"
- "};").arg(MoveTo));
-
- script.append(QString::fromLatin1(
- "this.lineTo = function(x, y) {"
- " this._commands.push([%1, x, y]);"
- "};").arg(LineTo));
-
- script.append(QString::fromLatin1(
- "this.quadraticCurveTo = function(a1, a2, a3, a4) {"
- " this._commands.push([%1, a1, a2, a3, a4]);"
- "};").arg(QuadraticCurveTo));
-
- script.append(QString::fromLatin1(
- "this.bezierCurveTo = function(a1, a2, a3, a4, a5, a6) {"
- " this._commands.push([%1, a1, a2, a3, a4, a5, a6]);"
- "};").arg(BezierCurveTo));
-
- script.append(QString::fromLatin1(
- "this.arcTo = function(x1, y1, x2, y2, radius) {"
- " this._commands.push([%1, x1, y1, x2, y2, radius]);"
- "};").arg(ArcTo));
-
- script.append(QString::fromLatin1(
- "this.rect = function(x, y, w, h) {"
- " this._commands.push([%1, x, y, w, h]);"
- "};").arg(Rect));
-
- script.append(QString::fromLatin1(
- "this.rect = function(x, y, radius, startAngle, endAngle, anticlockwise) {"
- " this._commands.push([%1, x, y, radius, startAngle, endAngle, anticlockwise]);"
- "};").arg(Arc));
-
- script.append(QString::fromLatin1(
- "this.fill = function() {"
- " this._commands.push([%1]);"
- "};").arg(Fill));
-
- script.append(QString::fromLatin1(
- "this.stroke = function() {"
- " this._commands.push([%1]);"
- "};").arg(Stroke));
-
- script.append(QString::fromLatin1(
- "this.clip = function() {"
- " this._commands.push([%1]);"
- "};").arg(Clip));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"globalAlpha\", function() {"
- " return this._globalAlpha;"
- " });"
- " this.__defineSetter__(\"globalAlpha\", function(v) {"
- " this._globalAlpha = v;"
- " this._commands.push([%1, v]);"
- " });").arg(GlobalAlpha));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"globalCompositeOperation\", function() {"
- " return this._globalCompositeOperation;"
- " });"
- " this.__defineSetter__(\"globalCompositeOperation\", function(v) {"
- " this._globalCompositeOperation = v;"
- " this._commands.push([%1, v]);"
- " });").arg(GlobalCompositeOperation));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"strokeStyle\", function() {return this._strokeStyle; });"
- " this.__defineSetter__(\"strokeStyle\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._strokeStyle = v;"
- " });").arg(StrokeStyle));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"fillStyle\", function() {return this._fillStyle; });"
- " this.__defineSetter__(\"fillStyle\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._fillStyle = v;"
- " });").arg(FillStyle));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"strokeColor\", function() {return this._strokeColor; });"
- " this.__defineSetter__(\"strokeColor\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._strokeColor = v;"
- " });").arg(StrokeColor));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"fillColor\", function() {return this._fillColor; });"
- " this.__defineSetter__(\"fillColor\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._fillColor = v;"
- " });").arg(FillColor));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"lineWidth\", function() {return this._lineWidth; });"
- " this.__defineSetter__(\"lineWidth\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._lineWidth = v;"
- " });").arg(LineWidth));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"lineCap\", function() {return this._lineCap; });"
- " this.__defineSetter__(\"lineCap\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._lineCap = v;"
- " });").arg(LineCap));
-
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"lineJoin\", function() {return this._lineJoin; });"
- " this.__defineSetter__(\"lineJoin\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._lineJoin = v;"
- " });").arg(LineJoin));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"miterLimit\", function() {return this._miterLimit; });"
- " this.__defineSetter__(\"miterLimit\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._miterLimit = v;"
- " });").arg(MiterLimit));
-
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"shadowOffsetX\", function() {return this._shadowOffsetX; });"
- " this.__defineSetter__(\"shadowOffsetX\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._shadowOffsetX = v;"
- " });").arg(ShadowOffsetX));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"shadowOffsetY\", function() {return this._shadowOffsetY; });"
- " this.__defineSetter__(\"shadowOffsetY\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._shadowOffsetY = v;"
- " });").arg(ShadowOffsetY));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"shadowBlur\", function() {return this._shadowBlur; });"
- " this.__defineSetter__(\"shadowBlur\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._shadowBlur = v;"
- " });").arg(ShadowBlur));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"shadowColor\", function() {return this._shadowColor; });"
- " this.__defineSetter__(\"shadowColor\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._shadowColor = v;"
- " });").arg(ShadowColor));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"font\", function() {return this._font; });"
- " this.__defineSetter__(\"font\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._font = v;"
- " });").arg(Font));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"textBaseline\", function() {return this._textBaseline; });"
- " this.__defineSetter__(\"textBaseline\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._textBaseline = v;"
- " });").arg(TextBaseline));
-
- script.append(QString::fromLatin1(
- " this.__defineGetter__(\"textAlign\", function() {return this._textAlign; });"
- " this.__defineSetter__(\"textAlign\", function(v) {"
- " this._commands.push([%1, v]);"
- " this._textAlign = v;"
- " });").arg(TextAlign));
-
- script.append(QString::fromLatin1(
- "this.fillText = function(text, x, y) {"
- " this._commands.push([%1, text, x, y]);"
- "};").arg(FillText));
-
- script.append(QString::fromLatin1(
- "this.strokeText = function(text, x, y) {"
- " this._commands.push([%1, text, x, y]);"
- "};").arg(StrokeText));
-
- script.append(QString::fromLatin1(
- "this.drawImage = function() {"
- " if (arguments.length == 3) {"
- " this._commands.push([%1, arguments[0], arguments[1], arguments[2]]);"
- " } else if (arguments.length == 5) {"
- " this._commands.push([%2, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]]);"
- " } else if (arguments.length == 9) {"
- " this._commands.push([%3, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8]]);}"
- "};").arg(DrawImage1).arg(DrawImage2).arg(DrawImage3));
-
- script.append(QString::fromLatin1(
- "this.putImageData = function() {"
- " var dx = arguments[1];"
- " var dy = arguments[2];"
- " if (arguments.length == 3) {"
- " this._commands.push([%1, arguments[0].data, dx, dy, arguments[0].width, arguments[0].height]);"
- " } else if (arguments.length == 7) {"
- " var dirtyX = arguments[3];"
- " var dirtyY = arguments[4];"
- " var dirtyWidth = arguments[5];"
- " var dirtyHeight = arguments[6];"
- " var width = arguments[0].width;"
- " var height = arguments[0].heigh;"
- " var filteredData = arguments[0].data.filter(function(element, index, array){"
- " var x=index/width;"
- " var y=index%width-1;"
- " return x >= dirtyX && x < dirtyX+dirtyWidth"
- " && y >= dirtyY && y < dirtyY+dirtyHeight;"
- " });"
- " this._commands.push([%2, filteredData, dx, dy, dirtyWidth, dirtyHeight]);"
- " }"
- "};").arg(PutImageData).arg(PutImageData));
- script.append(QString::fromLatin1("}"));
- }
- return script;
-}
-
-QSGContext2D *QSGContext2D::agent()
-{
- Q_D(QSGContext2D);
-
- if (d->agent)
- return d->agent;
-
- d->agent = new QSGContext2D(this, new QSGContext2DWorkerAgent);
- connect(this, SIGNAL(painted()), d->agent, SIGNAL(painted()));
- d->agent->setSize(size());
- return d->agent;
-
-}
void QSGContext2D::processCommands(const QScriptValue& commands)
{
#ifdef QSGCANVASITEM_DEBUG
@@ -2941,10 +3550,8 @@ void QSGContext2D::paint(QPainter* p)
switch (cmd) {
case UpdateMatrix:
{
-// qDebug() << "update matrix from " << d->state.matrix << " to " << d->matrixes[matrix_idx];
- //p->setWorldTransform(transform * QTransform(d->matrixes[matrix_idx++]), false);
- //p->setMatrix(d->matrixes[matrix_idx++]);
d->state.matrix = d->matrixes[matrix_idx++];
+ p->setMatrix(d->state.matrix);
break;
}
case ClearRect:
@@ -2962,7 +3569,6 @@ void QSGContext2D::paint(QPainter* p)
qreal y = d->reals[real_idx++];
qreal w = d->reals[real_idx++];
qreal h = d->reals[real_idx++];
-// qDebug() << "fillRect(" << x << y << w << h << ")";
if (d->hasShadow())
d->fillRectShadow(p, QRectF(x, y, w, h));
else
@@ -2996,6 +3602,7 @@ void QSGContext2D::paint(QPainter* p)
case Fill:
{
QPainterPath path = d->pathes[path_idx++];
+ //qDebug() << "fill path:" << path.elementCount();
if (d->hasShadow())
d->fillShadowPath(p,path);
else
@@ -3004,8 +3611,10 @@ void QSGContext2D::paint(QPainter* p)
}
case Stroke:
{
- p->setMatrix(d->state.matrix);
- QPainterPath path = d->state.matrix.inverted().map(d->pathes[path_idx++]);
+ //p->setMatrix(d->state.matrix);
+ //QPainterPath path = d->state.matrix.inverted().map(d->pathes[path_idx++]);
+ //qDebug() << "stroke path:" << path.elementCount();
+ QPainterPath path = d->pathes[path_idx++];
if (d->hasShadow())
d->strokeShadowPath(p,path);
else
@@ -3229,9 +3838,6 @@ void QSGContext2D::setCachedImage(const QImage& image)
d->waitingForPainting = false;
}
#endif
- if (inWorkerThread()) {
- d->agent->setCachedImage(image);
- }
}
void QSGContext2D::clear()
diff --git a/src/declarative/items/qsgcontext2d_p.h b/src/declarative/items/qsgcontext2d_p.h
index 30af1f1cd6..924c4bf780 100644
--- a/src/declarative/items/qsgcontext2d_p.h
+++ b/src/declarative/items/qsgcontext2d_p.h
@@ -56,6 +56,7 @@
#include <QtCore/qcoreevent.h>
#include <QtCore/qvariant.h>
#include <QtScript/qscriptvalue.h>
+#include <private/qv8engine_p.h>
#include <QMutex>
#include <QWaitCondition>
#include "qsgimage_p.h"
@@ -290,6 +291,10 @@ public slots:
void clip();
bool isPointInPath(qreal x, qreal y) const;
+ //path string parser
+ //implement the W3C SVG path spec:
+ //http://www.w3.org/TR/SVG/paths.html
+ void setPathString(const QString& path);
QSGImage *createImage(const QString &url);
@@ -309,9 +314,8 @@ signals:
void painted();
public:
bool isDirty() const;
- QScriptValue scriptValue() const;
- void setScriptEngine(QScriptEngine *eng);
- QScriptEngine *scriptEngine() const;
+ v8::Handle<v8::Object> v8value() const;
+ void setV8Engine(QV8Engine *eng);
void addref();
void release();
@@ -335,11 +339,6 @@ public:
Sync() : QEvent(QEvent::User) {}
QSGContext2DWorkerAgent *data;
};
- inline bool inWorkerThread() const;
- QSGContext2D *agent();
- const QString& agentScript() const;
-
-
struct State {
QMatrix matrix;
QPainterPath clipPath;
diff --git a/src/declarative/items/qsgcontext2d_p_p.h b/src/declarative/items/qsgcontext2d_p_p.h
index a412e6638a..4fcf40406e 100644
--- a/src/declarative/items/qsgcontext2d_p_p.h
+++ b/src/declarative/items/qsgcontext2d_p_p.h
@@ -78,12 +78,17 @@ public:
QSGContext2DPrivate()
: agent(0)
, agentData(0)
- , scriptEngine(0)
+ , v8engine(0)
, cachedImage(1,1, QImage::Format_ARGB32)
, canvas(0)
, waitingForPainting(false)
{
}
+ ~QSGContext2DPrivate()
+ {
+ qPersistentDispose(v8value);
+ }
+
void updateMatrix(const QMatrix& m);
void setSize(const QSize &s)
@@ -215,8 +220,10 @@ public:
//workerscript agent
QSGContext2D* agent;
QSGContext2DWorkerAgent* agentData;
- QScriptEngine* scriptEngine;
- QScriptValue scriptValue;
+
+ QV8Engine *v8engine;
+ v8::Persistent<v8::Object> v8value;
+
QImage cachedImage;
QSGCanvasItem* canvas;
bool waitingForPainting;
diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp
index 5926274dba..2b6f5573aa 100644
--- a/src/declarative/items/qsgitem.cpp
+++ b/src/declarative/items/qsgitem.cpp
@@ -1837,20 +1837,33 @@ void QSGItem::polish()
}
}
-QScriptValue QSGItem::mapFromItem(const QScriptValue &item, qreal x, qreal y) const
+void QSGItem::mapFromItem(QDeclarativeV8Function *args) const
{
- QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
- QSGItem *itemObj = qobject_cast<QSGItem*>(item.toQObject());
- if (!itemObj && !item.isNull()) {
- qmlInfo(this) << "mapFromItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
- return 0;
- }
+ if (args->Length() != 0) {
+ v8::Local<v8::Value> item = (*args)[0];
+ QV8Engine *engine = args->engine();
+
+ QSGItem *itemObj = 0;
+ if (!item->IsNull())
+ itemObj = qobject_cast<QSGItem*>(engine->toQObject(item));
+
+ if (!itemObj && !item->IsNull()) {
+ qmlInfo(this) << "mapFromItem() given argument \"" << engine->toString(item->ToString())
+ << "\" which is neither null nor an Item";
+ return;
+ }
+
+ v8::Local<v8::Object> rv = v8::Object::New();
+ args->returnValue(rv);
+
+ qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
+ qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
- // If QSGItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
- QPointF p = mapFromItem(itemObj, QPointF(x, y));
- sv.setProperty(QLatin1String("x"), p.x());
- sv.setProperty(QLatin1String("y"), p.y());
- return sv;
+ QPointF p = mapFromItem(itemObj, QPointF(x, y));
+
+ rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
+ rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
+ }
}
QTransform QSGItem::itemTransform(QSGItem *other, bool *ok) const
@@ -1867,20 +1880,33 @@ QTransform QSGItem::itemTransform(QSGItem *other, bool *ok) const
return t;
}
-QScriptValue QSGItem::mapToItem(const QScriptValue &item, qreal x, qreal y) const
+void QSGItem::mapToItem(QDeclarativeV8Function *args) const
{
- QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
- QSGItem *itemObj = qobject_cast<QSGItem*>(item.toQObject());
- if (!itemObj && !item.isNull()) {
- qmlInfo(this) << "mapToItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
- return 0;
- }
+ if (args->Length() != 0) {
+ v8::Local<v8::Value> item = (*args)[0];
+ QV8Engine *engine = args->engine();
+
+ QSGItem *itemObj = 0;
+ if (!item->IsNull())
+ itemObj = qobject_cast<QSGItem*>(engine->toQObject(item));
+
+ if (!itemObj && !item->IsNull()) {
+ qmlInfo(this) << "mapToItem() given argument \"" << engine->toString(item->ToString())
+ << "\" which is neither null nor an Item";
+ return;
+ }
+
+ v8::Local<v8::Object> rv = v8::Object::New();
+ args->returnValue(rv);
+
+ qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
+ qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
- // If QSGItem::mapToItem() is called with 0, behaves the same as mapToScene()
- QPointF p = mapToItem(itemObj, QPointF(x, y));
- sv.setProperty(QLatin1String("x"), p.x());
- sv.setProperty(QLatin1String("y"), p.y());
- return sv;
+ QPointF p = mapToItem(itemObj, QPointF(x, y));
+
+ rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
+ rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
+ }
}
void QSGItem::forceActiveFocus()
diff --git a/src/declarative/items/qsgitem.h b/src/declarative/items/qsgitem.h
index 425e5bc35c..e7d9d0aa0a 100644
--- a/src/declarative/items/qsgitem.h
+++ b/src/declarative/items/qsgitem.h
@@ -288,8 +288,8 @@ public:
void polish();
- Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
- Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
+ Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
+ Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
Q_INVOKABLE void forceActiveFocus();
Q_INVOKABLE QSGItem *childAt(qreal x, qreal y) const;
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index 6c46de69e4..684726d346 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -218,22 +218,12 @@ void QDeclarativeBindingPrivate::refresh()
}
QDeclarativeBindingPrivate::QDeclarativeBindingPrivate()
-: updating(false), enabled(false), deleted(0)
+: updating(false), enabled(false)
{
}
QDeclarativeBindingPrivate::~QDeclarativeBindingPrivate()
{
- if (deleted) *deleted = true;
-}
-
-QDeclarativeBinding::QDeclarativeBinding(void *data, QDeclarativeRefCount *rc, QObject *obj,
- QDeclarativeContextData *ctxt, const QString &url, int lineNumber,
- QObject *parent)
-: QDeclarativeExpression(ctxt, data, rc, obj, url, lineNumber, *new QDeclarativeBindingPrivate)
-{
- setParent(parent);
- setNotifyOnValueChanged(true);
}
QDeclarativeBinding *
@@ -252,7 +242,7 @@ QDeclarativeBinding::createBinding(Identifier id, QObject *obj, QDeclarativeCont
typeData = engine->typeLoader.get(ctxtdata->url);
cdata = typeData->compiledData();
}
- QDeclarativeBinding *rv = cdata ? new QDeclarativeBinding((void*)cdata->datas.at(id).constData(), cdata, obj, ctxtdata, url, lineNumber, parent) : 0;
+ QDeclarativeBinding *rv = cdata ? new QDeclarativeBinding(cdata->primitives.at(id), true, obj, ctxtdata, url, lineNumber, parent) : 0;
if (typeData)
typeData->release();
return rv;
@@ -274,8 +264,26 @@ QDeclarativeBinding::QDeclarativeBinding(const QString &str, QObject *obj, QDecl
setNotifyOnValueChanged(true);
}
-QDeclarativeBinding::QDeclarativeBinding(const QScriptValue &func, QObject *obj, QDeclarativeContextData *ctxt, QObject *parent)
-: QDeclarativeExpression(ctxt, obj, func, *new QDeclarativeBindingPrivate)
+QDeclarativeBinding::QDeclarativeBinding(const QString &str, bool isRewritten, QObject *obj,
+ QDeclarativeContextData *ctxt,
+ const QString &url, int lineNumber, QObject *parent)
+: QDeclarativeExpression(ctxt, obj, str, isRewritten, url, lineNumber, *new QDeclarativeBindingPrivate)
+{
+ setParent(parent);
+ setNotifyOnValueChanged(true);
+}
+
+/*!
+ \internal
+
+ To avoid exposing v8 in the public API, functionPtr must be a pointer to a v8::Handle<v8::Function>.
+ For example:
+ v8::Handle<v8::Function> function;
+ new QDeclarativeBInding(&function, scope, ctxt);
+ */
+QDeclarativeBinding::QDeclarativeBinding(void *functionPtr, QObject *obj, QDeclarativeContextData *ctxt,
+ QObject *parent)
+: QDeclarativeExpression(ctxt, obj, functionPtr, *new QDeclarativeBindingPrivate)
{
setParent(parent);
setNotifyOnValueChanged(true);
@@ -302,13 +310,13 @@ QDeclarativeProperty QDeclarativeBinding::property() const
void QDeclarativeBinding::setEvaluateFlags(EvaluateFlags flags)
{
Q_D(QDeclarativeBinding);
- d->setEvaluateFlags(QDeclarativeQtScriptExpression::EvaluateFlags(static_cast<int>(flags)));
+ d->setRequiresThisObject(flags & RequiresThisObject);
}
QDeclarativeBinding::EvaluateFlags QDeclarativeBinding::evaluateFlags() const
{
Q_D(const QDeclarativeBinding);
- return QDeclarativeBinding::EvaluateFlags(static_cast<int>(d->evaluateFlags()));
+ return d->requiresThisObject()?RequiresThisObject:None;
}
@@ -337,8 +345,8 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
if (!d->updating) {
QDeclarativeBindingProfiler prof(this);
d->updating = true;
- bool wasDeleted = false;
- d->deleted = &wasDeleted;
+
+ QDeclarativeDeleteWatcher watcher(d);
if (d->property.propertyType() == qMetaTypeId<QDeclarativeBinding *>()) {
@@ -352,124 +360,56 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
QMetaObject::WriteProperty,
idx, a);
- if (wasDeleted)
- return;
-
} else {
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context()->engine);
- ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation.
+ ep->referenceScarceResources();
bool isUndefined = false;
- QVariant value;
- QScriptValue scriptValue = d->scriptValue(0, &isUndefined);
-
- if (wasDeleted) {
- ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
- return;
- }
-
- if (d->property.propertyTypeCategory() == QDeclarativeProperty::List) {
- value = ep->scriptValueToVariant(scriptValue, qMetaTypeId<QList<QObject *> >());
- } else if (scriptValue.isNull() &&
- d->property.propertyTypeCategory() == QDeclarativeProperty::Object) {
- value = QVariant::fromValue((QObject *)0);
- } else {
- value = ep->scriptValueToVariant(scriptValue, d->property.propertyType());
- if (value.userType() == QMetaType::QObjectStar && !qvariant_cast<QObject*>(value)) {
- // If the object is null, we extract the predicted type. While this isn't
- // 100% reliable, in many cases it gives us better error messages if we
- // assign this null-object to an incompatible property
- int type = ep->objectClass->objectType(scriptValue);
- QObject *o = 0;
- value = QVariant(type, (void *)&o);
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(ep->v8engine.context());
+ v8::Local<v8::Value> result = d->v8value(0, &isUndefined);
+
+ bool needsErrorData = false;
+ if (!watcher.wasDeleted() && !d->error.isValid())
+ needsErrorData = !QDeclarativePropertyPrivate::writeBinding(d->property, d, result,
+ isUndefined, flags);
+
+ if (!watcher.wasDeleted()) {
+
+ if (needsErrorData) {
+ QUrl url = QUrl(d->url);
+ int line = d->line;
+ if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
+
+ d->error.setUrl(url);
+ d->error.setLine(line);
+ d->error.setColumn(-1);
}
- }
-
- if (d->error.isValid()) {
-
- } else if (isUndefined && d->property.isResettable()) {
-
- d->property.reset();
-
- } else if (isUndefined && d->property.propertyType() == qMetaTypeId<QVariant>()) {
-
- QDeclarativePropertyPrivate::write(d->property, QVariant(), flags);
-
- } else if (isUndefined) {
-
- QUrl url = QUrl(d->url);
- int line = d->line;
- if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
-
- d->error.setUrl(url);
- d->error.setLine(line);
- d->error.setColumn(-1);
- d->error.setDescription(QLatin1String("Unable to assign [undefined] to ") +
- QLatin1String(QMetaType::typeName(d->property.propertyType())) +
- QLatin1String(" ") + d->property.name());
-
- } else if (!scriptValue.isRegExp() && scriptValue.isFunction()) {
-
- QUrl url = QUrl(d->url);
- int line = d->line;
- if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
-
- d->error.setUrl(url);
- d->error.setLine(line);
- d->error.setColumn(-1);
- d->error.setDescription(QLatin1String("Unable to assign a function to a property."));
-
- } else if (d->property.object() &&
- !QDeclarativePropertyPrivate::write(d->property, value, flags)) {
-
- if (wasDeleted) {
- ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
- return;
+ if (d->error.isValid()) {
+ if (!d->addError(ep)) ep->warning(this->error());
+ } else {
+ d->removeError();
}
- QUrl url = QUrl(d->url);
- int line = d->line;
- if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
-
- const char *valueType = 0;
- if (value.userType() == QVariant::Invalid) valueType = "null";
- else valueType = QMetaType::typeName(value.userType());
-
- d->error.setUrl(url);
- d->error.setLine(line);
- d->error.setColumn(-1);
- d->error.setDescription(QLatin1String("Unable to assign ") +
- QLatin1String(valueType) +
- QLatin1String(" to ") +
- QLatin1String(QMetaType::typeName(d->property.propertyType())));
}
- if (wasDeleted) {
- ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
- return;
- }
-
- if (d->error.isValid()) {
- if (!d->addError(ep)) ep->warning(this->error());
- } else {
- d->removeError();
- }
-
- // at this point, the binding has been evaluated. If any scarce
- // resources were copied during the evaluation of the binding,
- // we need to release those copies.
- ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
+ ep->dereferenceScarceResources();
}
- d->updating = false;
- d->deleted = 0;
+ if (!watcher.wasDeleted())
+ d->updating = false;
} else {
- qmlInfo(d->property.object()) << tr("Binding loop detected for property \"%1\"").arg(d->property.name());
+ QDeclarativeBindingPrivate::printBindingLoopError(d->property);
}
}
+void QDeclarativeBindingPrivate::printBindingLoopError(QDeclarativeProperty &prop)
+{
+ qmlInfo(prop.object()) << QDeclarativeBinding::tr("Binding loop detected for property \"%1\"").arg(prop.name());
+}
+
void QDeclarativeBindingPrivate::emitValueChanged()
{
Q_Q(QDeclarativeBinding);
diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h
index 62aeca2a6c..fedd63634b 100644
--- a/src/declarative/qml/qdeclarativebinding_p.h
+++ b/src/declarative/qml/qdeclarativebinding_p.h
@@ -147,14 +147,14 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeBinding : public QDeclarativeExpr
{
Q_OBJECT
public:
- enum EvaluateFlag { RequiresThisObject = 0x01 };
+ enum EvaluateFlag { None = 0x00, RequiresThisObject = 0x01 };
Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
QDeclarativeBinding(const QString &, QObject *, QDeclarativeContext *, QObject *parent=0);
QDeclarativeBinding(const QString &, QObject *, QDeclarativeContextData *, QObject *parent=0);
- QDeclarativeBinding(void *, QDeclarativeRefCount *, QObject *, QDeclarativeContextData *,
- const QString &, int, QObject *parent);
- QDeclarativeBinding(const QScriptValue &, QObject *, QDeclarativeContextData *, QObject *parent=0);
+ QDeclarativeBinding(const QString &, bool isRewritten, QObject *, QDeclarativeContextData *,
+ const QString &url, int lineNumber, QObject *parent=0);
+ QDeclarativeBinding(void *, QObject *, QDeclarativeContextData *, QObject *parent=0);
void setTarget(const QDeclarativeProperty &);
QDeclarativeProperty property() const;
diff --git a/src/declarative/qml/qdeclarativebinding_p_p.h b/src/declarative/qml/qdeclarativebinding_p_p.h
index 9e6f75bdb3..dc7ec074c8 100644
--- a/src/declarative/qml/qdeclarativebinding_p_p.h
+++ b/src/declarative/qml/qdeclarativebinding_p_p.h
@@ -69,6 +69,8 @@ public:
virtual void emitValueChanged();
+ static void printBindingLoopError(QDeclarativeProperty &prop);
+
protected:
virtual void refresh();
@@ -76,8 +78,6 @@ private:
bool updating:1;
bool enabled:1;
QDeclarativeProperty property;
-
- bool *deleted;
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp
index 3e036176a5..5accc003f5 100644
--- a/src/declarative/qml/qdeclarativeboundsignal.cpp
+++ b/src/declarative/qml/qdeclarativeboundsignal.cpp
@@ -227,7 +227,6 @@ QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(const QMeta
} else {
QByteArray propType = type;
if (t >= QVariant::UserType || t == QVariant::Invalid) {
- //copy of QDeclarativeObjectScriptClass::enumType()
QByteArray scope;
QByteArray name;
int scopeIdx = propType.lastIndexOf("::");
diff --git a/src/declarative/qml/qdeclarativecompileddata.cpp b/src/declarative/qml/qdeclarativecompileddata.cpp
index 2ea41d857f..d08a808d77 100644
--- a/src/declarative/qml/qdeclarativecompileddata.cpp
+++ b/src/declarative/qml/qdeclarativecompileddata.cpp
@@ -128,6 +128,9 @@ QDeclarativeCompiledData::~QDeclarativeCompiledData()
qDeleteAll(cachedPrograms);
qDeleteAll(cachedClosures);
+
+ for (int ii = 0; ii < v8bindings.count(); ++ii)
+ qPersistentDispose(v8bindings[ii]);
}
void QDeclarativeCompiledData::clear()
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 43bb58c88a..7571704f19 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -64,7 +64,6 @@
#include "private/qdeclarativescriptparser_p.h"
#include "private/qdeclarativebinding_p.h"
#include "private/qdeclarativev4compiler_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
#include <QColor>
#include <QDebug>
@@ -709,6 +708,15 @@ void QDeclarativeCompiler::compileTree(QDeclarativeParser::Object *tree)
init.init.compiledBinding = output->indexForByteArray(compileState.compiledBindingData);
output->addInstruction(init);
+ if (!compileState.v8BindingProgram.isEmpty()) {
+ QDeclarativeInstruction bindings;
+ bindings.setType(QDeclarativeInstruction::InitV8Bindings);
+ bindings.initV8Bindings.program = output->indexForString(compileState.v8BindingProgram);
+ bindings.initV8Bindings.programIndex = compileState.v8BindingProgramIndex;
+ bindings.initV8Bindings.line = compileState.v8BindingProgramLine;
+ output->addInstruction(bindings);
+ }
+
genObject(tree);
QDeclarativeInstruction def;
@@ -747,8 +755,6 @@ bool QDeclarativeCompiler::buildObject(QDeclarativeParser::Object *obj, const Bi
output->types.at(obj->type);
obj->metatype = tr.metaObject();
- if (tr.component)
- obj->url = tr.component->url;
if (tr.type)
obj->typeName = tr.type->qmlTypeName();
obj->className = tr.className;
@@ -811,7 +817,6 @@ bool QDeclarativeCompiler::buildObject(QDeclarativeParser::Object *obj, const Bi
defaultProperty->isDefault = true;
defaultProperty->location = obj->defaultProperty->location;
defaultProperty->listValueRange = obj->defaultProperty->listValueRange;
- defaultProperty->listCommaPositions = obj->defaultProperty->listCommaPositions;
defaultProperty->values = obj->defaultProperty->values;
defaultProperty->values += explicitProperty->values;
@@ -973,7 +978,8 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj)
reinterpret_cast<const QDeclarativeVMEMetaData *>(obj->synthdata.constData());
for (int ii = 0; ii < vmeMetaData->aliasCount; ++ii) {
int index = obj->metaObject()->propertyOffset() + vmeMetaData->propertyCount + ii;
- propertyCache->property(index)->flags |= QDeclarativePropertyCache::Data::IsAlias;
+ QDeclarativePropertyCache::Data *data = propertyCache->property(index);
+ data->setFlags(data->getFlags() | QDeclarativePropertyCache::Data::IsAlias);
}
}
@@ -1209,6 +1215,15 @@ void QDeclarativeCompiler::genComponent(QDeclarativeParser::Object *obj)
init.init.compiledBinding = output->indexForByteArray(compileState.compiledBindingData);
output->addInstruction(init);
+ if (!compileState.v8BindingProgram.isEmpty()) {
+ QDeclarativeInstruction bindings;
+ bindings.setType(QDeclarativeInstruction::InitV8Bindings);
+ bindings.initV8Bindings.program = output->indexForString(compileState.v8BindingProgram);
+ bindings.initV8Bindings.programIndex = compileState.v8BindingProgramIndex;
+ bindings.initV8Bindings.line = compileState.v8BindingProgramLine;
+ output->addInstruction(bindings);
+ }
+
genObject(root);
QDeclarativeInstruction def;
@@ -1529,8 +1544,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
output->types.at(prop->parent->type).component) {
QDeclarativePropertyCache *cache = output->types.at(prop->parent->type).component->rootPropertyCache;
- if (cache && cache->property(prop->index) &&
- cache->property(prop->index)->flags & QDeclarativePropertyCache::Data::IsAlias)
+ if (cache && cache->property(prop->index) && cache->property(prop->index)->isAlias())
prop->isAlias = true;
}
@@ -2261,7 +2275,7 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop
}
} else {
// Otherwise we have to search the whole type
- // This matches the logic in QDeclarativeTypeNameScriptClass
+ // This matches the logic in QV8TypeWrapper
QByteArray enumName = enumValue.toUtf8();
const QMetaObject *metaObject = type->baseMetaObject();
for (int ii = metaObject->enumeratorCount() - 1; value == -1 && ii >= 0; --ii) {
@@ -2312,33 +2326,15 @@ const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) con
}
// similar to logic of completeComponentBuild, but also sticks data
-// into datas at the end
+// into primitives at the end
int QDeclarativeCompiler::rewriteBinding(const QString& expression, const QByteArray& name)
{
QDeclarativeRewrite::RewriteBinding rewriteBinding;
rewriteBinding.setName('$' + name.mid(name.lastIndexOf('.') + 1));
- bool isSharable = false;
- QString rewrite = rewriteBinding(expression, 0, &isSharable);
-
- quint32 length = rewrite.length();
- quint32 pc;
-
- if (isSharable) {
- pc = output->cachedClosures.count();
- pc |= 0x80000000;
- output->cachedClosures.append(0);
- } else {
- pc = output->cachedPrograms.length();
- output->cachedPrograms.append(0);
- }
- QByteArray compiledData =
- QByteArray((const char *)&pc, sizeof(quint32)) +
- QByteArray((const char *)&length, sizeof(quint32)) +
- QByteArray((const char *)rewrite.constData(),
- rewrite.length() * sizeof(QChar));
+ QString rewrite = rewriteBinding(expression, 0, 0);
- return output->indexForByteArray(compiledData);
+ return output->indexForString(rewrite);
}
// Ensures that the dynamic meta specification on obj is valid
@@ -2366,7 +2362,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
if (propName.at(0).isUpper())
COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter"));
- if (enginePrivate->globalClass->illegalNames().contains(propName))
+ if (enginePrivate->v8engine.illegalNames().contains(propName))
COMPILE_EXCEPTION(&prop, tr("Illegal property name"));
propNames.insert(prop.name);
@@ -2379,7 +2375,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
QString nameStr = QString::fromUtf8(name);
if (nameStr.at(0).isUpper())
COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter"));
- if (enginePrivate->globalClass->illegalNames().contains(nameStr))
+ if (enginePrivate->v8engine.illegalNames().contains(nameStr))
COMPILE_EXCEPTION(obj, tr("Illegal signal name"));
methodNames.insert(name);
}
@@ -2390,7 +2386,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
QString nameStr = QString::fromUtf8(name);
if (nameStr.at(0).isUpper())
COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter"));
- if (enginePrivate->globalClass->illegalNames().contains(nameStr))
+ if (enginePrivate->v8engine.illegalNames().contains(nameStr))
COMPILE_EXCEPTION(obj, tr("Illegal method name"));
methodNames.insert(name);
}
@@ -2684,7 +2680,7 @@ bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QStr
}
- if (enginePrivate->globalClass->illegalNames().contains(val))
+ if (enginePrivate->v8engine.illegalNames().contains(val))
COMPILE_EXCEPTION(v, tr( "ID illegally masks global JavaScript property"));
return true;
@@ -2842,9 +2838,9 @@ void QDeclarativeCompiler::genBindingAssignment(QDeclarativeParser::Value *bindi
Q_ASSERT(compileState.bindings.contains(binding));
const BindingReference &ref = compileState.bindings.value(binding);
- if (ref.dataType == BindingReference::Experimental) {
+ if (ref.dataType == BindingReference::V4) {
QDeclarativeInstruction store;
- store.setType(QDeclarativeInstruction::StoreCompiledBinding);
+ store.setType(QDeclarativeInstruction::StoreV4Binding);
store.assignBinding.value = ref.compiledIndex;
store.assignBinding.context = ref.bindingContext.stack;
store.assignBinding.owner = ref.bindingContext.owner;
@@ -2856,28 +2852,43 @@ void QDeclarativeCompiler::genBindingAssignment(QDeclarativeParser::Value *bindi
store.assignBinding.property = prop->index;
store.assignBinding.line = binding->location.start.line;
output->addInstruction(store);
- return;
- }
+ } else if (ref.dataType == BindingReference::V8) {
+ QDeclarativeInstruction store;
+ store.setType(QDeclarativeInstruction::StoreV8Binding);
+ store.assignBinding.value = ref.compiledIndex;
+ store.assignBinding.context = ref.bindingContext.stack;
+ store.assignBinding.owner = ref.bindingContext.owner;
+ store.assignBinding.line = binding->location.start.line;
- QDeclarativeInstruction store;
- if (!prop->isAlias)
- store.setType(QDeclarativeInstruction::StoreBinding);
- else
- store.setType(QDeclarativeInstruction::StoreBindingOnAlias);
- store.assignBinding.value = output->indexForByteArray(ref.compiledData);
- store.assignBinding.context = ref.bindingContext.stack;
- store.assignBinding.owner = ref.bindingContext.owner;
- store.assignBinding.line = binding->location.start.line;
-
- Q_ASSERT(ref.bindingContext.owner == 0 ||
- (ref.bindingContext.owner != 0 && valueTypeProperty));
- if (ref.bindingContext.owner) {
- store.assignBinding.property = genValueTypeData(prop, valueTypeProperty);
+ Q_ASSERT(ref.bindingContext.owner == 0 ||
+ (ref.bindingContext.owner != 0 && valueTypeProperty));
+ if (ref.bindingContext.owner) {
+ store.assignBinding.property = genValueTypeData(prop, valueTypeProperty);
+ } else {
+ store.assignBinding.property = genPropertyData(prop);
+ }
+
+ output->addInstruction(store);
} else {
- store.assignBinding.property = genPropertyData(prop);
- }
+ QDeclarativeInstruction store;
+ if (!prop->isAlias)
+ store.setType(QDeclarativeInstruction::StoreBinding);
+ else
+ store.setType(QDeclarativeInstruction::StoreBindingOnAlias);
+ store.assignBinding.value = output->indexForString(ref.rewrittenExpression);
+ store.assignBinding.context = ref.bindingContext.stack;
+ store.assignBinding.owner = ref.bindingContext.owner;
+ store.assignBinding.line = binding->location.start.line;
- output->addInstruction(store);
+ Q_ASSERT(ref.bindingContext.owner == 0 ||
+ (ref.bindingContext.owner != 0 && valueTypeProperty));
+ if (ref.bindingContext.owner) {
+ store.assignBinding.property = genValueTypeData(prop, valueTypeProperty);
+ } else {
+ store.assignBinding.property = genPropertyData(prop);
+ }
+ output->addInstruction(store);
+ }
}
int QDeclarativeCompiler::genContextCache()
@@ -2885,7 +2896,7 @@ int QDeclarativeCompiler::genContextCache()
if (compileState.ids.count() == 0)
return -1;
- QDeclarativeIntegerCache *cache = new QDeclarativeIntegerCache(engine);
+ QDeclarativeIntegerCache *cache = new QDeclarativeIntegerCache();
for (QHash<QString, QDeclarativeParser::Object *>::ConstIterator iter = compileState.ids.begin();
iter != compileState.ids.end();
@@ -2930,6 +2941,8 @@ bool QDeclarativeCompiler::completeComponentBuild()
QDeclarativeV4Compiler bindingCompiler;
+ QList<BindingReference*> sharedBindings;
+
for (QHash<QDeclarativeParser::Value*,BindingReference>::Iterator iter = compileState.bindings.begin();
iter != compileState.bindings.end(); ++iter) {
@@ -2944,44 +2957,69 @@ bool QDeclarativeCompiler::completeComponentBuild()
int index = bindingCompiler.compile(expr, enginePrivate);
if (index != -1) {
- binding.dataType = BindingReference::Experimental;
+ binding.dataType = BindingReference::V4;
binding.compiledIndex = index;
componentStat.optimizedBindings.append(iter.key()->location);
continue;
}
}
- binding.dataType = BindingReference::QtScript;
-
// Pre-rewrite the expression
QString expression = binding.expression.asScript();
QDeclarativeRewrite::RewriteBinding rewriteBinding;
rewriteBinding.setName('$'+binding.property->name);
bool isSharable = false;
- expression = rewriteBinding(binding.expression.asAST(), expression, &isSharable);
-
- quint32 length = expression.length();
- quint32 pc;
-
- if (isSharable) {
- pc = output->cachedClosures.count();
- pc |= 0x80000000;
- output->cachedClosures.append(0);
+ binding.rewrittenExpression = rewriteBinding(binding.expression.asAST(), expression, &isSharable);
+
+ if (isSharable && !binding.property->isAlias /* See above re alias */ &&
+ binding.property->type != qMetaTypeId<QDeclarativeBinding*>()) {
+ binding.dataType = BindingReference::V8;
+ sharedBindings.append(&iter.value());
} else {
- pc = output->cachedPrograms.length();
- output->cachedPrograms.append(0);
+ binding.dataType = BindingReference::QtScript;
}
- binding.compiledData =
- QByteArray((const char *)&pc, sizeof(quint32)) +
- QByteArray((const char *)&length, sizeof(quint32)) +
- QByteArray((const char *)expression.constData(),
- expression.length() * sizeof(QChar));
-
componentStat.scriptBindings.append(iter.key()->location);
}
+ if (!sharedBindings.isEmpty()) {
+ struct Sort {
+ static bool lt(const BindingReference *lhs, const BindingReference *rhs)
+ {
+ return lhs->value->location.start.line < rhs->value->location.start.line;
+ }
+ };
+
+ qSort(sharedBindings.begin(), sharedBindings.end(), Sort::lt);
+
+ int startLineNumber = sharedBindings.at(0)->value->location.start.line;
+ int lineNumber = startLineNumber;
+
+ QString functionArray(QLatin1String("["));
+ for (int ii = 0; ii < sharedBindings.count(); ++ii) {
+ BindingReference *reference = sharedBindings.at(ii);
+ QDeclarativeParser::Value *value = reference->value;
+ const QString &expression = reference->rewrittenExpression;
+
+ if (ii != 0) functionArray += QLatin1String(",");
+
+ while (lineNumber < value->location.start.line) {
+ lineNumber++;
+ functionArray += QLatin1String("\n");
+ }
+
+ functionArray += expression;
+ reference->compiledIndex = ii;
+ }
+ functionArray += QLatin1String("]");
+
+ compileState.v8BindingProgram = functionArray;
+ compileState.v8BindingProgramLine = startLineNumber;
+ compileState.v8BindingProgramIndex = output->v8bindings.count();
+ output->v8bindings.append(v8::Persistent<v8::Array>());
+ }
+
if (bindingCompiler.isValid())
compileState.compiledBindingData = bindingCompiler.program();
@@ -3097,7 +3135,7 @@ int QDeclarativeCompiler::indexOfSignal(QDeclarativeParser::Object *object, cons
QDeclarativePropertyCache::Data *d = cache->property(strName);
if (notInRevision) *notInRevision = false;
- while (d && !(d->flags & QDeclarativePropertyCache::Data::IsFunction))
+ while (d && !(d->isFunction()))
d = cache->overrideData(d);
if (d && !cache->isAllowedInRevision(d)) {
@@ -3137,7 +3175,7 @@ int QDeclarativeCompiler::indexOfProperty(QDeclarativeParser::Object *object, co
QDeclarativePropertyCache::Data *d = cache->property(strName);
// Find the first property
- while (d && d->flags & QDeclarativePropertyCache::Data::IsFunction)
+ while (d && d->isFunction())
d = cache->overrideData(d);
if (d && !cache->isAllowedInRevision(d)) {
diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h
index e4b9240a93..a1dfabbd46 100644
--- a/src/declarative/qml/qdeclarativecompiler_p.h
+++ b/src/declarative/qml/qdeclarativecompiler_p.h
@@ -55,6 +55,7 @@
#include "qdeclarative.h"
#include "qdeclarativeerror.h"
+#include "private/qv8_p.h"
#include "private/qdeclarativeinstruction_p.h"
#include "private/qdeclarativeparser_p.h"
#include "private/qdeclarativeengine_p.h"
@@ -103,6 +104,8 @@ public:
};
QList<TypeReference> types;
+ QList<v8::Persistent<v8::Array> > v8bindings;
+
const QMetaObject *root;
QAbstractDynamicMetaObject rootData;
QDeclarativePropertyCache *rootPropertyCache;
@@ -283,12 +286,12 @@ private:
QDeclarativeParser::Property *property;
QDeclarativeParser::Value *value;
- enum DataType { QtScript, Experimental };
+ enum DataType { QtScript, V4, V8 };
DataType dataType;
int compiledIndex;
- QByteArray compiledData;
+ QString rewrittenExpression;
BindingContext bindingContext;
};
void addBindingReference(const BindingReference &);
@@ -296,7 +299,7 @@ private:
struct ComponentCompileState
{
ComponentCompileState()
- : parserStatusCount(0), pushedProperties(0), nested(false), root(0) {}
+ : parserStatusCount(0), pushedProperties(0), nested(false), v8BindingProgramLine(-1), root(0) {}
QHash<QString, QDeclarativeParser::Object *> ids;
QHash<int, QDeclarativeParser::Object *> idIndexes;
int parserStatusCount;
@@ -304,6 +307,9 @@ private:
bool nested;
QByteArray compiledBindingData;
+ QString v8BindingProgram;
+ int v8BindingProgramLine;
+ int v8BindingProgramIndex;
QHash<QDeclarativeParser::Value *, BindingReference> bindings;
QHash<QDeclarativeParser::Value *, BindingContext> signalExpressions;
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index 01e2434f76..e99928d862 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -660,49 +660,50 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q
Sets graphics object parent because forgetting to do this is a frequent
and serious problem.
*/
-QScriptValue QDeclarativeComponent::createObject(QObject* parent)
+void QDeclarativeComponent::createObject(QDeclarativeV8Function *args)
{
- Q_D(QDeclarativeComponent);
- return d->createObject(parent, QScriptValue(QScriptValue::NullValue));
-}
+ Q_ASSERT(args);
+
+#define RETURN(result) { args->returnValue((result)); return; }
-/*!
- \internal
- Overloadable method allows properties to be set during creation
-*/
-QScriptValue QDeclarativeComponent::createObject(QObject* parent, const QScriptValue& valuemap)
-{
Q_D(QDeclarativeComponent);
- if (!valuemap.isObject() || valuemap.isArray()) {
- qmlInfo(this) << tr("createObject: value is not an object");
- return QScriptValue(QScriptValue::NullValue);
+ Q_ASSERT(d->engine);
+
+ QDeclarativeEngine *engine = d->engine;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+ QV8Engine *v8engine = &ep->v8engine;
+
+ QDeclarativeContext *ctxt = creationContext();
+ if (!ctxt) ctxt = engine->rootContext();
+
+ v8::Local<v8::Object> valuemap;
+ if (args->Length() >= 2) {
+ v8::Local<v8::Value> v = (*args)[1];
+ if (!v->IsObject() || v->IsArray()) {
+ qmlInfo(this) << tr("createObject: value is not an object");
+ RETURN(v8::Null());
+ }
+ valuemap = v8::Local<v8::Object>::Cast(v);
}
- return d->createObject(parent, valuemap);
-}
-QScriptValue QDeclarativeComponentPrivate::createObject(QObject *publicParent, const QScriptValue valuemap)
-{
- Q_Q(QDeclarativeComponent);
- QDeclarativeContext* ctxt = q->creationContext();
- if(!ctxt && engine)
- ctxt = engine->rootContext();
- if (!ctxt)
- return QScriptValue(QScriptValue::NullValue);
- QObject* ret = q->beginCreate(ctxt);
+ QObject *parent = args->Length()?v8engine->toQObject((*args)[0]):0;
+
+ QObject *ret = beginCreate(ctxt);
if (!ret) {
- q->completeCreate();
- return QScriptValue(QScriptValue::NullValue);
+ completeCreate();
+ RETURN(v8::Null());
}
- if (publicParent) {
- ret->setParent(publicParent);
+ if (parent) {
+ ret->setParent(parent);
+
QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();
bool needParent = false;
for (int ii = 0; ii < functions.count(); ++ii) {
- QDeclarativePrivate::AutoParentResult res = functions.at(ii)(ret, publicParent);
+ QDeclarativePrivate::AutoParentResult res = functions.at(ii)(ret, parent);
if (res == QDeclarativePrivate::Parented) {
needParent = false;
break;
@@ -715,37 +716,41 @@ QScriptValue QDeclarativeComponentPrivate::createObject(QObject *publicParent, c
qWarning("QDeclarativeComponent: Created graphical object was not placed in the graphics scene.");
}
- QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(engine);
- QDeclarativeData::get(ret, true)->setImplicitDestructible();
- QScriptValue newObject = priv->objectClass->newQObject(ret, QMetaType::QObjectStar);
-
- if (valuemap.isObject() && !valuemap.isArray()) {
- //Iterate through and assign properties
- QScriptValueIterator it(valuemap);
- while (it.hasNext()) {
- it.next();
- QScriptValue prop = newObject;
- QString propName = it.name();
- int index = propName.indexOf(QLatin1Char('.'));
- if (index > 0) {
- QString subProp = propName;
- int lastIndex = 0;
- while (index > 0) {
- subProp = propName.mid(lastIndex, index - lastIndex);
- prop = prop.property(subProp);
- lastIndex = index + 1;
- index = propName.indexOf(QLatin1Char('.'), index + 1);
- }
- prop.setProperty(propName.mid(propName.lastIndexOf(QLatin1Char('.')) + 1), it.value());
- } else {
- newObject.setProperty(propName, it.value());
- }
- }
+ v8::Handle<v8::Value> ov = v8engine->newQObject(ret);
+ Q_ASSERT(ov->IsObject());
+ v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(ov);
+
+ if (!valuemap.IsEmpty()) {
+
+#define SET_ARGS_SOURCE \
+ "(function(object, values) {"\
+ "try {"\
+ "for(var property in values) {"\
+ "try {"\
+ "var properties = property.split(\".\");"\
+ "var o = object;"\
+ "for (var ii = 0; ii < properties.length - 1; ++ii) {"\
+ "o = o[properties[ii]];"\
+ "}"\
+ "o[properties[properties.length - 1]] = values[property];"\
+ "} catch(e) {}"\
+ "}"\
+ "} catch(e) {}"\
+ "})"
+
+ v8::Local<v8::Script> script = v8engine->qmlModeCompile(SET_ARGS_SOURCE);
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(script->Run(args->qmlGlobal()));
+
+ // Try catch isn't needed as the function itself is loaded with try/catch
+ v8::Handle<v8::Value> args[] = { object, valuemap };
+ function->Call(v8engine->global(), 2, args);
}
- q->completeCreate();
+ completeCreate();
+
+ RETURN(object);
- return newObject;
+#undef RETURN
}
/*!
@@ -884,8 +889,11 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *parentCon
ctxt->imports = component->importCache;
// Nested global imports
- if (componentCreationContext && start != -1)
+ if (componentCreationContext && start != -1) {
ctxt->importedScripts = componentCreationContext->importedScripts;
+ for (int ii = 0; ii < ctxt->importedScripts.count(); ++ii)
+ ctxt->importedScripts[ii] = qPersistentNew<v8::Object>(ctxt->importedScripts[ii]);
+ }
component->importCache->addref();
ctxt->setParent(parentContext);
@@ -974,7 +982,6 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri
state->bindValues.at(ii);
for (int jj = 0; jj < bv.count; ++jj) {
if(bv.at(jj)) {
- // XXX akennedy
bv.at(jj)->m_mePtr = 0;
bv.at(jj)->setEnabled(true, QDeclarativePropertyPrivate::BypassInterceptor |
QDeclarativePropertyPrivate::DontRemoveBinding);
diff --git a/src/declarative/qml/qdeclarativecomponent.h b/src/declarative/qml/qdeclarativecomponent.h
index 15004a6cb1..bb4d886914 100644
--- a/src/declarative/qml/qdeclarativecomponent.h
+++ b/src/declarative/qml/qdeclarativecomponent.h
@@ -60,6 +60,7 @@ class QByteArray;
class QDeclarativeComponentPrivate;
class QDeclarativeEngine;
class QDeclarativeComponentAttached;
+class QDeclarativeV8Function;
class Q_DECLARATIVE_EXPORT QDeclarativeComponent : public QObject
{
Q_OBJECT
@@ -110,8 +111,7 @@ Q_SIGNALS:
protected:
QDeclarativeComponent(QDeclarativeComponentPrivate &dd, QObject* parent);
- Q_INVOKABLE QScriptValue createObject(QObject* parent);
- Q_INVOKABLE Q_REVISION(1) QScriptValue createObject(QObject* parent, const QScriptValue& valuemap); //XXX Versioning
+ Q_INVOKABLE void createObject(QDeclarativeV8Function *);
private:
QDeclarativeComponent(QDeclarativeEngine *, QDeclarativeCompiledData *, int, QObject *parent);
diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h
index ef04a5e137..7677f305e2 100644
--- a/src/declarative/qml/qdeclarativecomponent_p.h
+++ b/src/declarative/qml/qdeclarativecomponent_p.h
@@ -115,8 +115,6 @@ public:
ConstructionState *state);
static void complete(QDeclarativeEnginePrivate *enginePriv, ConstructionState *state);
- QScriptValue createObject(QObject *publicParent, const QScriptValue valuemap);
-
QDeclarativeEngine *engine;
QDeclarativeGuardedContextData creationContext;
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index c48f2ed3d4..caa3b0c7d8 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -47,8 +47,8 @@
#include "private/qdeclarativeengine_p.h"
#include "qdeclarativeengine.h"
#include "qdeclarativeinfo.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
#include "private/qdeclarativev4bindings_p.h"
+#include "private/qv8bindings_p.h"
#include <qscriptengine.h>
#include <QtCore/qvarlengtharray.h>
@@ -313,7 +313,7 @@ void QDeclarativeContext::setContextProperty(const QString &name, const QVariant
}
}
- if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine);
+ if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache();
int idx = data->propertyNames->value(name);
if (idx == -1) {
@@ -350,7 +350,7 @@ void QDeclarativeContext::setContextProperty(const QString &name, QObject *value
return;
}
- if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine);
+ if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache();
int idx = data->propertyNames->value(name);
if (idx == -1) {
@@ -498,18 +498,18 @@ QObject *QDeclarativeContextPrivate::context_at(QDeclarativeListProperty<QObject
QDeclarativeContextData::QDeclarativeContextData()
-: parent(0), engine(0), isInternal(false), ownedByParent(false), publicContext(0), propertyNames(0), contextObject(0),
- imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0),
- contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0),
- componentAttached(0)
+: parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), isPragmaLibraryContext(false),
+ publicContext(0), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+ expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0),
+ componentAttached(0), v4bindings(0), v8bindings(0)
{
}
QDeclarativeContextData::QDeclarativeContextData(QDeclarativeContext *ctxt)
-: parent(0), engine(0), isInternal(false), ownedByParent(false), publicContext(ctxt), propertyNames(0), contextObject(0),
- imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0),
- contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0),
- componentAttached(0)
+: parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), isPragmaLibraryContext(false),
+ publicContext(ctxt), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+ expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0),
+ componentAttached(0), v4bindings(0), v8bindings(0)
{
}
@@ -608,8 +608,15 @@ void QDeclarativeContextData::destroy()
if (imports)
imports->release();
- if (optimizedBindings)
- optimizedBindings->release();
+ if (v4bindings)
+ v4bindings->release();
+
+ if (v8bindings)
+ v8bindings->release();
+
+ for (int ii = 0; ii < importedScripts.count(); ++ii) {
+ qPersistentDispose(importedScripts[ii]);
+ }
delete [] idValues;
diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h
index d1d6d9193c..fd33ccdabe 100644
--- a/src/declarative/qml/qdeclarativecontext.h
+++ b/src/declarative/qml/qdeclarativecontext.h
@@ -94,8 +94,6 @@ private:
friend class QDeclarativeEnginePrivate;
friend class QDeclarativeExpression;
friend class QDeclarativeExpressionPrivate;
- friend class QDeclarativeContextScriptClass;
- friend class QDeclarativeObjectScriptClass;
friend class QDeclarativeComponent;
friend class QDeclarativeComponentPrivate;
friend class QDeclarativeScriptPrivate;
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h
index d7486b9653..59d886c366 100644
--- a/src/declarative/qml/qdeclarativecontext_p.h
+++ b/src/declarative/qml/qdeclarativecontext_p.h
@@ -69,8 +69,11 @@
#include <private/qobject_p.h>
#include "private/qdeclarativeguard_p.h"
+#include <private/qv8_p.h>
+
QT_BEGIN_NAMESPACE
+class QV8Bindings;
class QDeclarativeContext;
class QDeclarativeExpression;
class QDeclarativeEngine;
@@ -137,7 +140,9 @@ public:
QDeclarativeContextPrivate *asQDeclarativeContextPrivate();
quint32 isInternal:1;
quint32 ownedByParent:1; // unrelated to isInternal; parent context deletes children if true.
- quint32 dummy:30;
+ quint32 isJSContext:1;
+ quint32 isPragmaLibraryContext:1;
+ quint32 dummy:28;
QDeclarativeContext *publicContext;
// Property name cache
@@ -147,7 +152,7 @@ public:
QObject *contextObject;
// Any script blocks that exist on this context
- QList<QScriptValue> importedScripts;
+ QList<v8::Persistent<v8::Object> > importedScripts;
// Context base url
QUrl url;
@@ -188,9 +193,6 @@ public:
void setIdProperty(int, QObject *);
void setIdPropertyData(QDeclarativeIntegerCache *);
- // Optimized binding pointer
- QDeclarativeV4Bindings *optimizedBindings;
-
// Linked contexts. this owns linkedContext.
QDeclarativeContextData *linkedContext;
@@ -198,6 +200,10 @@ public:
// context
QDeclarativeComponentAttached *componentAttached;
+ // Optimized binding objects. Needed for deferred properties.
+ QDeclarativeV4Bindings *v4bindings;
+ QV8Bindings *v8bindings;
+
// Return the outermost id for obj, if any.
QString findObjectId(const QObject *obj) const;
@@ -216,9 +222,10 @@ public:
inline QDeclarativeGuardedContextData(QDeclarativeContextData *);
inline ~QDeclarativeGuardedContextData();
+ inline QDeclarativeContextData *contextData();
inline void setContextData(QDeclarativeContextData *);
- inline QDeclarativeContextData *contextData();
+ inline bool isNull() const { return !m_contextData; }
inline operator QDeclarativeContextData*() const { return m_contextData; }
inline QDeclarativeContextData* operator->() const { return m_contextData; }
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
deleted file mode 100644
index 7f2e3406e6..0000000000
--- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp
+++ /dev/null
@@ -1,335 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativecontextscriptclass_p.h"
-
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativecontext_p.h"
-#include "private/qdeclarativetypenamescriptclass_p.h"
-#include "private/qdeclarativelistscriptclass_p.h"
-#include "private/qdeclarativeguard_p.h"
-
-QT_BEGIN_NAMESPACE
-
-struct ContextData : public QScriptDeclarativeClass::Object {
- ContextData() : overrideObject(0), isSharedContext(true) {}
- ContextData(QDeclarativeContextData *c, QObject *o)
- : context(c), scopeObject(o), overrideObject(0), isSharedContext(false), isUrlContext(false) {}
- QDeclarativeGuardedContextData context;
- QDeclarativeGuard<QObject> scopeObject;
- QObject *overrideObject;
- bool isSharedContext:1;
- bool isUrlContext:1;
-
- QDeclarativeContextData *getContext(QDeclarativeEngine *engine) {
- if (isSharedContext) {
- return QDeclarativeEnginePrivate::get(engine)->sharedContext;
- } else {
- return context.contextData();
- }
- }
-
- QObject *getScope(QDeclarativeEngine *engine) {
- if (isSharedContext) {
- return QDeclarativeEnginePrivate::get(engine)->sharedScope;
- } else {
- return scopeObject.data();
- }
- }
-};
-
-struct UrlContextData : public ContextData {
- UrlContextData(QDeclarativeContextData *c, QObject *o, const QString &u)
- : ContextData(c, o), url(u) {
- isUrlContext = true;
- }
- UrlContextData(const QString &u)
- : ContextData(0, 0), url(u) {
- isUrlContext = true;
- }
- QString url;
-};
-
-/*
- The QDeclarativeContextScriptClass handles property access for a QDeclarativeContext
- via QtScript.
- */
-QDeclarativeContextScriptClass::QDeclarativeContextScriptClass(QDeclarativeEngine *bindEngine)
-: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine),
- lastScopeObject(0), lastContext(0), lastData(0), lastPropertyIndex(-1)
-{
-}
-
-QDeclarativeContextScriptClass::~QDeclarativeContextScriptClass()
-{
-}
-
-QScriptValue QDeclarativeContextScriptClass::newContext(QDeclarativeContextData *context, QObject *scopeObject)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return newObject(scriptEngine, this, new ContextData(context, scopeObject));
-}
-
-QScriptValue QDeclarativeContextScriptClass::newUrlContext(QDeclarativeContextData *context, QObject *scopeObject,
- const QString &url)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return newObject(scriptEngine, this, new UrlContextData(context, scopeObject, url));
-}
-
-QScriptValue QDeclarativeContextScriptClass::newUrlContext(const QString &url)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return newObject(scriptEngine, this, new UrlContextData(url));
-}
-
-QScriptValue QDeclarativeContextScriptClass::newSharedContext()
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return newObject(scriptEngine, this, new ContextData());
-}
-
-QDeclarativeContextData *QDeclarativeContextScriptClass::contextFromValue(const QScriptValue &v)
-{
- if (scriptClass(v) != this)
- return 0;
-
- ContextData *data = (ContextData *)object(v);
- return data->getContext(engine);
-}
-
-QUrl QDeclarativeContextScriptClass::urlFromValue(const QScriptValue &v)
-{
- if (scriptClass(v) != this)
- return QUrl();
-
- ContextData *data = (ContextData *)object(v);
- if (data->isUrlContext) {
- return QUrl(static_cast<UrlContextData *>(data)->url);
- } else {
- return QUrl();
- }
-}
-
-QObject *QDeclarativeContextScriptClass::setOverrideObject(QScriptValue &v, QObject *override)
-{
- if (scriptClass(v) != this)
- return 0;
-
- ContextData *data = (ContextData *)object(v);
- QObject *rv = data->overrideObject;
- data->overrideObject = override;
- return rv;
-}
-
-QScriptClass::QueryFlags
-QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier &name,
- QScriptClass::QueryFlags flags)
-{
- Q_UNUSED(flags);
-
- lastScopeObject = 0;
- lastContext = 0;
- lastData = 0;
- lastPropertyIndex = -1;
-
- QDeclarativeContextData *bindContext = ((ContextData *)object)->getContext(engine);
- QObject *scopeObject = ((ContextData *)object)->getScope(engine);
- if (!bindContext)
- return 0;
-
- QObject *overrideObject = ((ContextData *)object)->overrideObject;
- if (overrideObject) {
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- QScriptClass::QueryFlags rv =
- ep->objectClass->queryProperty(overrideObject, name, flags, bindContext,
- QDeclarativeObjectScriptClass::ImplicitObject |
- QDeclarativeObjectScriptClass::SkipAttachedProperties);
- if (rv) {
- lastScopeObject = overrideObject;
- lastContext = bindContext;
- return rv;
- }
- }
-
- bool includeTypes = true;
- while (bindContext) {
- QScriptClass::QueryFlags rv =
- queryProperty(bindContext, scopeObject, name, flags, includeTypes);
- scopeObject = 0; // Only applies to the first context
- includeTypes = false; // Only applies to the first context
- if (rv) return rv;
- bindContext = bindContext->parent;
- }
-
- return 0;
-}
-
-QScriptClass::QueryFlags
-QDeclarativeContextScriptClass::queryProperty(QDeclarativeContextData *bindContext, QObject *scopeObject,
- const Identifier &name,
- QScriptClass::QueryFlags flags,
- bool includeTypes)
-{
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-
- lastPropertyIndex = bindContext->propertyNames?bindContext->propertyNames->value(name):-1;
- if (lastPropertyIndex != -1) {
- lastContext = bindContext;
- return QScriptClass::HandlesReadAccess;
- }
-
- if (includeTypes && bindContext->imports) {
- QDeclarativeTypeNameCache::Data *data = bindContext->imports->data(name);
-
- if (data) {
- lastData = data;
- lastContext = bindContext;
- lastScopeObject = scopeObject;
- return QScriptClass::HandlesReadAccess;
- }
- }
-
- if (scopeObject) {
- QScriptClass::QueryFlags rv =
- ep->objectClass->queryProperty(scopeObject, name, flags, bindContext,
- QDeclarativeObjectScriptClass::ImplicitObject | QDeclarativeObjectScriptClass::SkipAttachedProperties);
- if (rv) {
- lastScopeObject = scopeObject;
- lastContext = bindContext;
- return rv;
- }
- }
-
- if (bindContext->contextObject) {
- QScriptClass::QueryFlags rv =
- ep->objectClass->queryProperty(bindContext->contextObject, name, flags, bindContext,
- QDeclarativeObjectScriptClass::ImplicitObject | QDeclarativeObjectScriptClass::SkipAttachedProperties);
-
- if (rv) {
- lastScopeObject = bindContext->contextObject;
- lastContext = bindContext;
- return rv;
- }
- }
-
- return 0;
-}
-
-QDeclarativeContextScriptClass::Value
-QDeclarativeContextScriptClass::property(Object *object, const Identifier &name)
-{
- Q_UNUSED(object);
-
- QDeclarativeContextData *bindContext = lastContext;
- Q_ASSERT(bindContext);
-
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- if (lastData) {
-
- if (lastData->type) {
- return Value(scriptEngine, ep->typeNameClass->newObject(lastScopeObject, lastData->type));
- } else if (lastData->typeNamespace) {
- return Value(scriptEngine, ep->typeNameClass->newObject(lastScopeObject, lastData->typeNamespace));
- } else {
- int index = lastData->importedScriptIndex;
- if (index < bindContext->importedScripts.count()) {
- return Value(scriptEngine, bindContext->importedScripts.at(index));
- } else {
- return Value();
- }
- }
-
- } else if (lastScopeObject) {
-
- return ep->objectClass->property(lastScopeObject, name);
-
- } else if (lastPropertyIndex != -1) {
-
- QScriptValue rv;
- if (lastPropertyIndex < bindContext->idValueCount) {
- rv = ep->objectClass->newQObject(bindContext->idValues[lastPropertyIndex].data());
-
- if (ep->captureProperties)
- ep->capturedProperties << QDeclarativeEnginePrivate::CapturedProperty(&bindContext->idValues[lastPropertyIndex].bindings);
- } else {
- QDeclarativeContextPrivate *cp = bindContext->asQDeclarativeContextPrivate();
- const QVariant &value = cp->propertyValues.at(lastPropertyIndex);
- if (value.userType() == qMetaTypeId<QList<QObject*> >()) {
- rv = ep->listClass->newList(QDeclarativeListProperty<QObject>(bindContext->asQDeclarativeContext(), (void*)lastPropertyIndex, 0, QDeclarativeContextPrivate::context_count, QDeclarativeContextPrivate::context_at), qMetaTypeId<QDeclarativeListProperty<QObject> >());
- } else {
- rv = ep->scriptValueFromVariant(value);
- }
-
- if (ep->captureProperties)
- ep->capturedProperties << QDeclarativeEnginePrivate::CapturedProperty(bindContext->asQDeclarativeContext(), -1, lastPropertyIndex + cp->notifyIndex);
- }
-
- return Value(scriptEngine, rv);
-
- } else {
-
- return Value(scriptEngine, lastFunction);
-
- }
-}
-
-void QDeclarativeContextScriptClass::setProperty(Object *object, const Identifier &name,
- const QScriptValue &value)
-{
- Q_UNUSED(object);
- Q_ASSERT(lastScopeObject);
-
- QDeclarativeContextData *bindContext = lastContext;
- Q_ASSERT(bindContext);
-
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-
- ep->objectClass->setProperty(lastScopeObject, name, value, context(), bindContext);
-}
-
-QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h
index 2a5eace845..65f49268e9 100644
--- a/src/declarative/qml/qdeclarativedata_p.h
+++ b/src/declarative/qml/qdeclarativedata_p.h
@@ -57,6 +57,8 @@
#include <private/qobject_p.h>
#include "private/qdeclarativeguard_p.h"
+#include <private/qv8_p.h>
+
QT_BEGIN_NAMESPACE
class QDeclarativeCompiledData;
@@ -75,9 +77,10 @@ class Q_AUTOTEST_EXPORT QDeclarativeData : public QAbstractDeclarativeData
public:
QDeclarativeData()
: ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false),
- context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0),
- bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0),
- scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0), extendedData(0) {
+ hasTaintedV8Object(false), context(0), outerContext(0), bindings(0), nextContextObject(0),
+ prevContextObject(0), bindingBitsSize(0), bindingBits(0), lineNumber(0), columnNumber(0),
+ deferredComponent(0), deferredIdx(0), v8objectid(0), propertyCache(0), guards(0),
+ extendedData(0) {
init();
}
@@ -103,7 +106,8 @@ public:
quint32 ownContext:1;
quint32 indestructible:1;
quint32 explicitIndestructibleSet:1;
- quint32 dummy:28;
+ quint32 hasTaintedV8Object:1;
+ quint32 dummy:27;
// The context that created the C++ object
QDeclarativeContextData *context;
@@ -128,10 +132,9 @@ public:
QDeclarativeCompiledData *deferredComponent; // Can't this be found from the context?
unsigned int deferredIdx;
- // ### Can we make this QScriptValuePrivate so we incur no additional allocation
- // cost?
- QScriptValue *scriptValue;
- quint32 objectDataRefCount;
+ quint32 v8objectid;
+ v8::Persistent<v8::Object> v8object;
+
QDeclarativePropertyCache *propertyCache;
QDeclarativeGuard<QObject> *guards;
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 906af83778..ab85b2d273 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -44,7 +44,6 @@
#include "private/qdeclarativecontext_p.h"
#include "private/qdeclarativecompiler_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
#include "qdeclarative.h"
#include "qdeclarativecontext.h"
#include "qdeclarativeexpression.h"
@@ -55,9 +54,6 @@
#include "private/qdeclarativestringconverters_p.h"
#include "private/qdeclarativexmlhttprequest_p.h"
#include "private/qdeclarativesqldatabase_p.h"
-#include "private/qdeclarativescarceresourcescriptclass_p.h"
-#include "private/qdeclarativetypenamescriptclass_p.h"
-#include "private/qdeclarativelistscriptclass_p.h"
#include "qdeclarativescriptstring.h"
#include "private/qdeclarativeglobal_p.h"
#include "private/qdeclarativeworkerscript_p.h"
@@ -68,14 +64,12 @@
#include "qdeclarativeextensioninterface.h"
#include "private/qdeclarativelist_p.h"
#include "private/qdeclarativetypenamecache_p.h"
-#include "private/qdeclarativeinclude_p.h"
#include "private/qdeclarativenotifier_p.h"
#include "private/qdeclarativedebugtrace_p.h"
#include "private/qdeclarativeapplication_p.h"
#include "private/qjsdebugservice_p.h"
#include <QtCore/qmetaobject.h>
-#include <QScriptClass>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
@@ -101,7 +95,6 @@
#include <QtCore/qcryptographichash.h>
#include <private/qobject_p.h>
-#include <private/qscriptdeclarativeclass_p.h>
#include <private/qdeclarativeitemsmodule_p.h>
#include <private/qdeclarativeutilmodule_p.h>
@@ -345,16 +338,16 @@ The \c status property will be updated as the operation progresses.
If provided, \a callback is invoked when the operation completes. The callback is passed
the same object as is returned from the Qt.include() call.
*/
-// Qt.include() is implemented in qdeclarativeinclude.cpp
+// Qt.include() is implemented in qv8include.cpp
QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
: captureProperties(false), rootContext(0), isDebugging(false),
- outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0),
- objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0),
- inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0),
- inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0),
- scarceResources(0), scarceResourcesRefCount(0), typeLoader(e), importDatabase(e), uniqueId(1),
+ outputWarningsToStdErr(true), sharedContext(0), sharedScope(0),
+ cleanup(0), erroredBindings(0), inProgressCreations(0),
+ workerScriptEngine(0), componentAttached(0), inBeginCreate(false),
+ networkAccessManager(0), networkAccessManagerFactory(0),
+ scarceResourcesRefCount(0), typeLoader(e), importDatabase(e), uniqueId(1),
sgContext(0)
{
if (!qt_QmlQtModule_registered) {
@@ -366,124 +359,6 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
QSGParticlesModule::defineModule();
QDeclarativeValueTypeFactory::registerValueTypes();
}
- globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine);
-}
-
-/*!
- \qmlmethod url Qt::resolvedUrl(url url)
- Returns \a url resolved relative to the URL of the caller.
-*/
-QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url)
-{
- if (p) {
- QDeclarativeContextData *ctxt = p->getContext(context);
- if (ctxt)
- return ctxt->resolvedUrl(url);
- else
- return p->getUrl(context).resolved(url);
- }
- return baseUrl.resolved(url);
-}
-
-QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *priv)
-: p(priv), sqlQueryClass(0), namedNodeMapClass(0), nodeListClass(0)
-{
- // Note that all documentation for stuff put on the global object goes in
- // doc/src/declarative/globalobject.qdoc
-
- bool mainthread = priv != 0;
-
- QScriptValue qtObject =
- newQMetaObject(StaticQtMetaObject::get());
- globalObject().setProperty(QLatin1String("Qt"), qtObject);
-
-#ifndef QT_NO_DESKTOPSERVICES
- offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation).replace(QLatin1Char('/'), QDir::separator())
- + QDir::separator() + QLatin1String("QML")
- + QDir::separator() + QLatin1String("OfflineStorage");
-#endif
-
-#ifndef QT_NO_XMLSTREAMREADER
- qt_add_qmlxmlhttprequest(this);
-#endif
- qt_add_qmlsqldatabase(this);
- // XXX A Multimedia "Qt.Sound" class also needs to be made available,
- // XXX but we don't want a dependency in that cirection.
- // XXX When the above a done some better way, that way should also be
- // XXX used to add Qt.Sound class.
-
- //types
- if (mainthread)
- qtObject.setProperty(QLatin1String("include"), newFunction(QDeclarativeInclude::include, 2));
- else
- qtObject.setProperty(QLatin1String("include"), newFunction(QDeclarativeInclude::worker_include, 2));
-
- qtObject.setProperty(QLatin1String("isQtObject"), newFunction(QDeclarativeEnginePrivate::isQtObject, 1));
- qtObject.setProperty(QLatin1String("rgba"), newFunction(QDeclarativeEnginePrivate::rgba, 4));
- qtObject.setProperty(QLatin1String("hsla"), newFunction(QDeclarativeEnginePrivate::hsla, 4));
- qtObject.setProperty(QLatin1String("rect"), newFunction(QDeclarativeEnginePrivate::rect, 4));
- qtObject.setProperty(QLatin1String("point"), newFunction(QDeclarativeEnginePrivate::point, 2));
- qtObject.setProperty(QLatin1String("size"), newFunction(QDeclarativeEnginePrivate::size, 2));
- qtObject.setProperty(QLatin1String("vector3d"), newFunction(QDeclarativeEnginePrivate::vector3d, 3));
-
- if (mainthread) {
- //color helpers
- qtObject.setProperty(QLatin1String("lighter"), newFunction(QDeclarativeEnginePrivate::lighter, 1));
- qtObject.setProperty(QLatin1String("darker"), newFunction(QDeclarativeEnginePrivate::darker, 1));
- qtObject.setProperty(QLatin1String("tint"), newFunction(QDeclarativeEnginePrivate::tint, 2));
- }
-
-#ifndef QT_NO_DATESTRING
- //date/time formatting
- qtObject.setProperty(QLatin1String("formatDate"),newFunction(QDeclarativeEnginePrivate::formatDate, 2));
- qtObject.setProperty(QLatin1String("formatTime"),newFunction(QDeclarativeEnginePrivate::formatTime, 2));
- qtObject.setProperty(QLatin1String("formatDateTime"),newFunction(QDeclarativeEnginePrivate::formatDateTime, 2));
-#endif
-
- //misc methods
- qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1));
- qtObject.setProperty(QLatin1String("fontFamilies"),newFunction(QDeclarativeEnginePrivate::fontFamilies, 0));
- qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1));
- qtObject.setProperty(QLatin1String("btoa"),newFunction(QDeclarativeEnginePrivate::btoa, 1));
- qtObject.setProperty(QLatin1String("atob"),newFunction(QDeclarativeEnginePrivate::atob, 1));
- qtObject.setProperty(QLatin1String("quit"), newFunction(QDeclarativeEnginePrivate::quit, 0));
- qtObject.setProperty(QLatin1String("resolvedUrl"),newFunction(QDeclarativeScriptEngine::resolvedUrl, 1));
-
- if (mainthread) {
- qtObject.setProperty(QLatin1String("createQmlObject"),
- newFunction(QDeclarativeEnginePrivate::createQmlObject, 1));
- qtObject.setProperty(QLatin1String("createComponent"),
- newFunction(QDeclarativeEnginePrivate::createComponent, 1));
- }
-
- //firebug/webkit compat
- QScriptValue consoleObject = newObject();
- consoleObject.setProperty(QLatin1String("log"),newFunction(QDeclarativeEnginePrivate::consoleLog, 1));
- consoleObject.setProperty(QLatin1String("debug"),newFunction(QDeclarativeEnginePrivate::consoleLog, 1));
- globalObject().setProperty(QLatin1String("console"), consoleObject);
-
- // translation functions need to be installed
- // before the global script class is constructed (QTBUG-6437)
- installTranslatorFunctions();
-}
-
-QDeclarativeScriptEngine::~QDeclarativeScriptEngine()
-{
- delete sqlQueryClass;
- delete nodeListClass;
- delete namedNodeMapClass;
-}
-
-QScriptValue QDeclarativeScriptEngine::resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine)
-{
- QString arg = ctxt->argument(0).toString();
- QUrl r = QDeclarativeScriptEngine::get(engine)->resolvedUrl(ctxt,QUrl(arg));
- return QScriptValue(r.toString());
-}
-
-QNetworkAccessManager *QDeclarativeScriptEngine::networkAccessManager()
-{
- return p->getNetworkAccessManager();
}
QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate()
@@ -503,20 +378,6 @@ QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate()
delete rootContext;
rootContext = 0;
- delete contextClass;
- contextClass = 0;
- delete objectClass;
- objectClass = 0;
- delete scarceResourceClass;
- scarceResourceClass = 0;
- delete valueTypeClass;
- valueTypeClass = 0;
- delete typeNameClass;
- typeNameClass = 0;
- delete listClass;
- listClass = 0;
- delete globalClass;
- globalClass = 0;
for(QHash<int, QDeclarativeCompiledData*>::ConstIterator iter = m_compositeTypes.constBegin(); iter != m_compositeTypes.constEnd(); ++iter)
(*iter)->release();
@@ -579,19 +440,16 @@ void QDeclarativeEnginePrivate::init()
qRegisterMetaType<QDeclarativeScriptString>("QDeclarativeScriptString");
qRegisterMetaType<QScriptValue>("QScriptValue");
qRegisterMetaType<QDeclarativeComponent::Status>("QDeclarativeComponent::Status");
+ qRegisterMetaType<QList<QObject*> >("QList<QObject*>");
+ qRegisterMetaType<QList<int> >("QList<int>");
+ qRegisterMetaType<QDeclarativeV8Handle>("QDeclarativeV8Handle");
QDeclarativeData::init();
- contextClass = new QDeclarativeContextScriptClass(q);
- objectClass = new QDeclarativeObjectScriptClass(q);
- scarceResourceClass = new QDeclarativeScarceResourceScriptClass(q);
- valueTypeClass = new QDeclarativeValueTypeScriptClass(q);
- typeNameClass = new QDeclarativeTypeNameScriptClass(q);
- listClass = new QDeclarativeListScriptClass(q);
- rootContext = new QDeclarativeContext(q,true);
+ // Init V8 data
+ v8engine.init(q);
- QScriptValue applicationObject = objectClass->newQObject(new QDeclarativeApplication(q));
- scriptEngine.globalObject().property(QLatin1String("Qt")).setProperty(QLatin1String("application"), applicationObject);
+ rootContext = new QDeclarativeContext(q,true);
if (QCoreApplication::instance()->thread() == q->thread() &&
QDeclarativeEngineDebugServer::isDebuggingEnabled()) {
@@ -939,6 +797,14 @@ void QDeclarativeEngine::setOutputWarningsToStandardError(bool enabled)
}
/*!
+ Attempt to free unused memory.
+*/
+void QDeclarativeEngine::collectGarbage()
+{
+ QV8Engine::gc();
+}
+
+/*!
Returns the QDeclarativeContext for the \a object, or 0 if no
context has been set.
@@ -1187,19 +1053,19 @@ void QDeclarativeData::destroyed(QObject *object)
guard->objectDestroyed(object);
}
- if (scriptValue)
- delete scriptValue;
-
if (extendedData)
delete extendedData;
+ v8object.Clear(); // The WeakReference handler will clean the actual handle
+
if (ownMemory)
delete this;
}
-void QDeclarativeData::parentChanged(QObject *, QObject *parent)
+void QDeclarativeData::parentChanged(QObject *object, QObject *parent)
{
- if (!parent && scriptValue) { delete scriptValue; scriptValue = 0; }
+ Q_UNUSED(object);
+ Q_UNUSED(parent);
}
void QDeclarativeData::objectNameChanged(QObject *)
@@ -1243,44 +1109,6 @@ void QDeclarativeData::setBindingBit(QObject *obj, int bit)
bindingBits[bit / 32] |= (1 << (bit % 32));
}
-/*!
- Creates a QScriptValue allowing you to use \a object in QML script.
- \a engine is the QDeclarativeEngine it is to be created in.
-
- The QScriptValue returned is a QtScript Object, not a QtScript QObject, due
- to the special needs of QML requiring more functionality than a standard
- QtScript QObject.
-*/
-QScriptValue QDeclarativeEnginePrivate::qmlScriptObject(QObject* object,
- QDeclarativeEngine* engine)
-{
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
- return enginePriv->objectClass->newQObject(object);
-}
-
-/*!
- Returns the QDeclarativeContext for the executing QScript \a ctxt.
-*/
-QDeclarativeContextData *QDeclarativeEnginePrivate::getContext(QScriptContext *ctxt)
-{
- QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3);
- Q_ASSERT(scopeNode.isValid());
- Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
- return contextClass->contextFromValue(scopeNode);
-}
-
-/*!
- Returns the QUrl associated with the script \a ctxt for the case that there is
- no QDeclarativeContext.
-*/
-QUrl QDeclarativeEnginePrivate::getUrl(QScriptContext *ctxt)
-{
- QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3);
- Q_ASSERT(scopeNode.isValid());
- Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
- return contextClass->urlFromValue(scopeNode);
-}
-
QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url)
{
if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) {
@@ -1291,651 +1119,6 @@ QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url)
return url.toLocalFile();
}
-/*!
-\qmlmethod object Qt::createComponent(url)
-
-Returns a \l Component object created using the QML file at the specified \a url,
-or \c null if an empty string was given.
-
-The returned component's \l Component::status property indicates whether the
-component was successfully created. If the status is \c Component.Error,
-see \l Component::errorString() for an error description.
-
-Call \l {Component::createObject()}{Component.createObject()} on the returned
-component to create an object instance of the component.
-
-For example:
-
-\snippet doc/src/snippets/declarative/createComponent-simple.qml 0
-
-See \l {Dynamic Object Management in QML} for more information on using this function.
-
-To create a QML object from an arbitrary string of QML (instead of a file),
-use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
-*/
-
-QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *activeEnginePriv =
- static_cast<QDeclarativeScriptEngine*>(engine)->p;
- QDeclarativeEngine* activeEngine = activeEnginePriv->q_func();
-
- if(ctxt->argumentCount() != 1) {
- return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments"));
- } else {
-
- QString arg = ctxt->argument(0).toString();
- if (arg.isEmpty())
- return engine->nullValue();
- QUrl url = QDeclarativeScriptEngine::get(engine)->resolvedUrl(ctxt, QUrl(arg));
- QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt);
- QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine);
- QDeclarativeComponentPrivate::get(c)->creationContext = context;
- QDeclarativeData::get(c, true)->setImplicitDestructible();
- return activeEnginePriv->objectClass->newQObject(c, qMetaTypeId<QDeclarativeComponent*>());
- }
-}
-
-/*!
-\qmlmethod object Qt::createQmlObject(string qml, object parent, string filepath)
-
-Returns a new object created from the given \a string of QML which will have the specified \a parent,
-or \c null if there was an error in creating the object.
-
-If \a filepath is specified, it will be used for error reporting for the created object.
-
-Example (where \c parentItem is the id of an existing QML item):
-
-\snippet doc/src/snippets/declarative/createQmlObject.qml 0
-
-In the case of an error, a QtScript Error object is thrown. This object has an additional property,
-\c qmlErrors, which is an array of the errors encountered.
-Each object in this array has the members \c lineNumber, \c columnNumber, \c fileName and \c message.
-For example, if the above snippet had misspelled color as 'colro' then the array would contain an object like the following:
-{ "lineNumber" : 1, "columnNumber" : 32, "fileName" : "dynamicSnippet1", "message" : "Cannot assign to non-existent property \"colro\""}.
-
-Note that this function returns immediately, and therefore may not work if
-the \a qml string loads new components (that is, external QML files that have not yet been loaded).
-If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead.
-
-See \l {Dynamic Object Management in QML} for more information on using this function.
-*/
-
-QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *activeEnginePriv =
- static_cast<QDeclarativeScriptEngine*>(engine)->p;
- QDeclarativeEngine* activeEngine = activeEnginePriv->q_func();
-
- if(ctxt->argumentCount() < 2 || ctxt->argumentCount() > 3)
- return ctxt->throwError(QLatin1String("Qt.createQmlObject(): Invalid arguments"));
-
- QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt);
- Q_ASSERT(context);
-
- QString qml = ctxt->argument(0).toString();
- if (qml.isEmpty())
- return engine->nullValue();
-
- QUrl url;
- if(ctxt->argumentCount() > 2)
- url = QUrl(ctxt->argument(2).toString());
- else
- url = QUrl(QLatin1String("inline"));
-
- if (url.isValid() && url.isRelative())
- url = context->resolvedUrl(url);
-
- QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1));
- if(!parentArg)
- return ctxt->throwError(QLatin1String("Qt.createQmlObject(): Missing parent object"));
-
- QDeclarativeComponent component(activeEngine);
- component.setData(qml.toUtf8(), url);
-
- if(component.isError()) {
- QList<QDeclarativeError> errors = component.errors();
- QString errstr = QLatin1String("Qt.createQmlObject() failed to create object: ");
- QScriptValue arr = ctxt->engine()->newArray(errors.length());
- int i = 0;
- foreach (const QDeclarativeError &error, errors){
- errstr += QLatin1String("\n ") + error.toString();
- QScriptValue qmlErrObject = ctxt->engine()->newObject();
- qmlErrObject.setProperty(QLatin1String("lineNumber"), QScriptValue(error.line()));
- qmlErrObject.setProperty(QLatin1String("columnNumber"), QScriptValue(error.column()));
- qmlErrObject.setProperty(QLatin1String("fileName"), QScriptValue(error.url().toString()));
- qmlErrObject.setProperty(QLatin1String("message"), QScriptValue(error.description()));
- arr.setProperty(i++, qmlErrObject);
- }
- QScriptValue err = ctxt->throwError(errstr);
- err.setProperty(QLatin1String("qmlErrors"),arr);
- return err;
- }
-
- if (!component.isReady())
- return ctxt->throwError(QLatin1String("Qt.createQmlObject(): Component is not ready"));
-
- QObject *obj = component.beginCreate(context->asQDeclarativeContext());
- if(obj)
- QDeclarativeData::get(obj, true)->setImplicitDestructible();
- component.completeCreate();
-
- if(component.isError()) {
- QList<QDeclarativeError> errors = component.errors();
- QString errstr = QLatin1String("Qt.createQmlObject() failed to create object: ");
- QScriptValue arr = ctxt->engine()->newArray(errors.length());
- int i = 0;
- foreach (const QDeclarativeError &error, errors){
- errstr += QLatin1String("\n ") + error.toString();
- QScriptValue qmlErrObject = ctxt->engine()->newObject();
- qmlErrObject.setProperty(QLatin1String("lineNumber"), QScriptValue(error.line()));
- qmlErrObject.setProperty(QLatin1String("columnNumber"), QScriptValue(error.column()));
- qmlErrObject.setProperty(QLatin1String("fileName"), QScriptValue(error.url().toString()));
- qmlErrObject.setProperty(QLatin1String("message"), QScriptValue(error.description()));
- arr.setProperty(i++, qmlErrObject);
- }
- QScriptValue err = ctxt->throwError(errstr);
- err.setProperty(QLatin1String("qmlErrors"),arr);
- return err;
- }
-
- Q_ASSERT(obj);
-
- obj->setParent(parentArg);
-
- QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();
- for (int ii = 0; ii < functions.count(); ++ii) {
- if (QDeclarativePrivate::Parented == functions.at(ii)(obj, parentArg))
- break;
- }
-
- QDeclarativeData::get(obj, true)->setImplicitDestructible();
- return activeEnginePriv->objectClass->newQObject(obj, QMetaType::QObjectStar);
-}
-
-/*!
-\qmlmethod bool Qt::isQtObject(object)
-Returns true if \c object is a valid reference to a Qt or QML object, otherwise false.
-*/
-QScriptValue QDeclarativeEnginePrivate::isQtObject(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if (ctxt->argumentCount() == 0)
- return QScriptValue(engine, false);
-
- return QScriptValue(engine, 0 != ctxt->argument(0).toQObject());
-}
-
-/*!
-\qmlmethod Qt::vector3d(real x, real y, real z)
-Returns a Vector3D with the specified \c x, \c y and \c z.
-*/
-QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 3)
- return ctxt->throwError(QLatin1String("Qt.vector(): Invalid arguments"));
- qsreal x = ctxt->argument(0).toNumber();
- qsreal y = ctxt->argument(1).toNumber();
- qsreal z = ctxt->argument(2).toNumber();
- return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(QVariant::fromValue(QVector3D(x, y, z)));
-}
-
-/*!
-\qmlmethod string Qt::formatDate(datetime date, variant format)
-
-Returns a string representation of \c date, optionally formatted according
-to \c format.
-
-The \a date parameter may be a JavaScript \c Date object, a \l{date}{date}
-property, a QDate, or QDateTime value. The \a format parameter may be any of
-the possible format values as described for
-\l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
-
-If \a format is not specified, \a date is formatted using
-\l {Qt::DefaultLocaleShortDate}{Qt.DefaultLocaleShortDate}.
-*/
-#ifndef QT_NO_DATESTRING
-QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine)
-{
- int argCount = ctxt->argumentCount();
- if(argCount == 0 || argCount > 2)
- return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid arguments"));
-
- QDate date = ctxt->argument(0).toDateTime().date();
- Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
- if (argCount == 2) {
- QScriptValue formatArg = ctxt->argument(1);
- if (formatArg.isString()) {
- QString format = formatArg.toString();
- return engine->newVariant(QVariant::fromValue(date.toString(format)));
- } else if (formatArg.isNumber()) {
- enumFormat = Qt::DateFormat(formatArg.toUInt32());
- } else {
- return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid date format"));
- }
- }
- return engine->newVariant(QVariant::fromValue(date.toString(enumFormat)));
-}
-
-/*!
-\qmlmethod string Qt::formatTime(datetime time, variant format)
-
-Returns a string representation of \c time, optionally formatted according to
-\c format.
-
-The \a time parameter may be a JavaScript \c Date object, a QTime, or QDateTime
-value. The \a format parameter may be any of the possible format values as
-described for \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
-
-If \a format is not specified, \a time is formatted using
-\l {Qt::DefaultLocaleShortDate}{Qt.DefaultLocaleShortDate}.
-*/
-QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptEngine*engine)
-{
- int argCount = ctxt->argumentCount();
- if(argCount == 0 || argCount > 2)
- return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid arguments"));
-
- QTime time;
- QScriptValue sv = ctxt->argument(0);
- if (sv.isDate())
- time = sv.toDateTime().time();
- else if (sv.toVariant().type() == QVariant::Time)
- time = sv.toVariant().toTime();
-
- Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
- if (argCount == 2) {
- QScriptValue formatArg = ctxt->argument(1);
- if (formatArg.isString()) {
- QString format = formatArg.toString();
- return engine->newVariant(QVariant::fromValue(time.toString(format)));
- } else if (formatArg.isNumber()) {
- enumFormat = Qt::DateFormat(formatArg.toUInt32());
- } else {
- return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid time format"));
- }
- }
- return engine->newVariant(QVariant::fromValue(time.toString(enumFormat)));
-}
-
-/*!
-\qmlmethod string Qt::formatDateTime(datetime dateTime, variant format)
-
-Returns a string representation of \c datetime, optionally formatted according to
-\c format.
-
-The \a date parameter may be a JavaScript \c Date object, a \l{date}{date}
-property, a QDate, QTime, or QDateTime value.
-
-If \a format is not provided, \a dateTime is formatted using
-\l {Qt::DefaultLocaleShortDate}{Qt.DefaultLocaleShortDate}. Otherwise,
-\a format should be either.
-
-\list
-\o One of the Qt::DateFormat enumeration values, such as
- \c Qt.DefaultLocaleShortDate or \c Qt.ISODate
-\o A string that specifies the format of the returned string, as detailed below.
-\endlist
-
-If \a format specifies a format string, it should use the following expressions
-to specify the date:
-
- \table
- \header \i Expression \i Output
- \row \i d \i the day as number without a leading zero (1 to 31)
- \row \i dd \i the day as number with a leading zero (01 to 31)
- \row \i ddd
- \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
- Uses QDate::shortDayName().
- \row \i dddd
- \i the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
- Uses QDate::longDayName().
- \row \i M \i the month as number without a leading zero (1-12)
- \row \i MM \i the month as number with a leading zero (01-12)
- \row \i MMM
- \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
- Uses QDate::shortMonthName().
- \row \i MMMM
- \i the long localized month name (e.g. 'January' to 'December').
- Uses QDate::longMonthName().
- \row \i yy \i the year as two digit number (00-99)
- \row \i yyyy \i the year as four digit number
- \endtable
-
-In addition the following expressions can be used to specify the time:
-
- \table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP
- \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
- \row \i ap
- \i use am/pm display. \e ap will be replaced by either "am" or "pm".
- \endtable
-
- All other input characters will be ignored. Any sequence of characters that
- are enclosed in single quotes will be treated as text and not be used as an
- expression. Two consecutive single quotes ("''") are replaced by a single quote
- in the output.
-
-For example, if the following date/time value was specified:
-
- \code
- // 21 May 2001 14:13:09
- var dateTime = new Date(2001, 5, 21, 14, 13, 09)
- \endcode
-
-This \a dateTime value could be passed to \c Qt.formatDateTime(),
-\l {QML:Qt::formatDate()}{Qt.formatDate()} or \l {QML:Qt::formatTime()}{Qt.formatTime()}
-with the \a format values below to produce the following results:
-
- \table
- \header \i Format \i Result
- \row \i "dd.MM.yyyy" \i 21.05.2001
- \row \i "ddd MMMM d yy" \i Tue May 21 01
- \row \i "hh:mm:ss.zzz" \i 14:13:09.042
- \row \i "h:m:s ap" \i 2:13:9 pm
- \endtable
-*/
-QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScriptEngine*engine)
-{
- int argCount = ctxt->argumentCount();
- if(argCount == 0 || argCount > 2)
- return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid arguments"));
-
- QDateTime date = ctxt->argument(0).toDateTime();
- Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
- if (argCount == 2) {
- QScriptValue formatArg = ctxt->argument(1);
- if (formatArg.isString()) {
- QString format = formatArg.toString();
- return engine->newVariant(QVariant::fromValue(date.toString(format)));
- } else if (formatArg.isNumber()) {
- enumFormat = Qt::DateFormat(formatArg.toUInt32());
- } else {
- return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format"));
- }
- }
- return engine->newVariant(QVariant::fromValue(date.toString(enumFormat)));
-}
-#endif // QT_NO_DATESTRING
-
-/*!
-\qmlmethod color Qt::rgba(real red, real green, real blue, real alpha)
-
-Returns a color with the specified \c red, \c green, \c blue and \c alpha components.
-All components should be in the range 0-1 inclusive.
-*/
-QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine)
-{
- int argCount = ctxt->argumentCount();
- if(argCount < 3 || argCount > 4)
- return ctxt->throwError(QLatin1String("Qt.rgba(): Invalid arguments"));
- qsreal r = ctxt->argument(0).toNumber();
- qsreal g = ctxt->argument(1).toNumber();
- qsreal b = ctxt->argument(2).toNumber();
- qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1;
-
- if (r < 0.0) r=0.0;
- if (r > 1.0) r=1.0;
- if (g < 0.0) g=0.0;
- if (g > 1.0) g=1.0;
- if (b < 0.0) b=0.0;
- if (b > 1.0) b=1.0;
- if (a < 0.0) a=0.0;
- if (a > 1.0) a=1.0;
-
- return engine->toScriptValue(QVariant::fromValue(QColor::fromRgbF(r, g, b, a)));
-}
-
-/*!
-\qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha)
-
-Returns a color with the specified \c hue, \c saturation, \c lightness and \c alpha components.
-All components should be in the range 0-1 inclusive.
-*/
-QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine)
-{
- int argCount = ctxt->argumentCount();
- if(argCount < 3 || argCount > 4)
- return ctxt->throwError(QLatin1String("Qt.hsla(): Invalid arguments"));
- qsreal h = ctxt->argument(0).toNumber();
- qsreal s = ctxt->argument(1).toNumber();
- qsreal l = ctxt->argument(2).toNumber();
- qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1;
-
- if (h < 0.0) h=0.0;
- if (h > 1.0) h=1.0;
- if (s < 0.0) s=0.0;
- if (s > 1.0) s=1.0;
- if (l < 0.0) l=0.0;
- if (l > 1.0) l=1.0;
- if (a < 0.0) a=0.0;
- if (a > 1.0) a=1.0;
-
- return engine->toScriptValue(QVariant::fromValue(QColor::fromHslF(h, s, l, a)));
-}
-
-/*!
-\qmlmethod rect Qt::rect(int x, int y, int width, int height)
-
-Returns a \c rect with the top-left corner at \c x, \c y and the specified \c width and \c height.
-
-The returned object has \c x, \c y, \c width and \c height attributes with the given values.
-*/
-QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 4)
- return ctxt->throwError(QLatin1String("Qt.rect(): Invalid arguments"));
-
- qsreal x = ctxt->argument(0).toNumber();
- qsreal y = ctxt->argument(1).toNumber();
- qsreal w = ctxt->argument(2).toNumber();
- qsreal h = ctxt->argument(3).toNumber();
-
- return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(QVariant::fromValue(QRectF(x, y, w, h)));
-}
-
-/*!
-\qmlmethod point Qt::point(int x, int y)
-Returns a Point with the specified \c x and \c y coordinates.
-*/
-QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 2)
- return ctxt->throwError(QLatin1String("Qt.point(): Invalid arguments"));
- qsreal x = ctxt->argument(0).toNumber();
- qsreal y = ctxt->argument(1).toNumber();
- return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(QVariant::fromValue(QPointF(x, y)));
-}
-
-/*!
-\qmlmethod Qt::size(int width, int height)
-Returns a Size with the specified \c width and \c height.
-*/
-QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 2)
- return ctxt->throwError(QLatin1String("Qt.size(): Invalid arguments"));
- qsreal w = ctxt->argument(0).toNumber();
- qsreal h = ctxt->argument(1).toNumber();
- return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(QVariant::fromValue(QSizeF(w, h)));
-}
-
-/*!
-\qmlmethod color Qt::lighter(color baseColor, real factor)
-Returns a color lighter than \c baseColor by the \c factor provided.
-
-If the factor is greater than 1.0, this functions returns a lighter color.
-Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0,
-the return color is darker, but we recommend using the Qt.darker() function for this purpose.
-If the factor is 0 or negative, the return value is unspecified.
-
-The function converts the current RGB color to HSV, multiplies the value (V) component
-by factor and converts the color back to RGB.
-
-If \c factor is not supplied, returns a color 50% lighter than \c baseColor (factor 1.5).
-*/
-QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 1 && ctxt->argumentCount() != 2)
- return ctxt->throwError(QLatin1String("Qt.lighter(): Invalid arguments"));
- QVariant v = ctxt->argument(0).toVariant();
- QColor color;
- if (v.userType() == QVariant::Color)
- color = v.value<QColor>();
- else if (v.userType() == QVariant::String) {
- bool ok;
- color = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
- if (!ok)
- return engine->nullValue();
- } else
- return engine->nullValue();
- qsreal factor = 1.5;
- if (ctxt->argumentCount() == 2)
- factor = ctxt->argument(1).toNumber();
- color = color.lighter(int(qRound(factor*100.)));
- return engine->toScriptValue(QVariant::fromValue(color));
-}
-
-/*!
-\qmlmethod color Qt::darker(color baseColor, real factor)
-Returns a color darker than \c baseColor by the \c factor provided.
-
-If the factor is greater than 1.0, this function returns a darker color.
-Setting factor to 3.0 returns a color that has one-third the brightness.
-If the factor is less than 1.0, the return color is lighter, but we recommend using
-the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return
-value is unspecified.
-
-The function converts the current RGB color to HSV, divides the value (V) component
-by factor and converts the color back to RGB.
-
-If \c factor is not supplied, returns a color 50% darker than \c baseColor (factor 2.0).
-*/
-QScriptValue QDeclarativeEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 1 && ctxt->argumentCount() != 2)
- return ctxt->throwError(QLatin1String("Qt.darker(): Invalid arguments"));
- QVariant v = ctxt->argument(0).toVariant();
- QColor color;
- if (v.userType() == QVariant::Color)
- color = v.value<QColor>();
- else if (v.userType() == QVariant::String) {
- bool ok;
- color = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
- if (!ok)
- return engine->nullValue();
- } else
- return engine->nullValue();
- qsreal factor = 2.0;
- if (ctxt->argumentCount() == 2)
- factor = ctxt->argument(1).toNumber();
- color = color.darker(int(qRound(factor*100.)));
- return engine->toScriptValue(QVariant::fromValue(color));
-}
-
-/*!
-\qmlmethod bool Qt::openUrlExternally(url target)
-Attempts to open the specified \c target url in an external application, based on the user's desktop preferences. Returns true if it succeeds, and false otherwise.
-*/
-QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e)
-{
- if(ctxt->argumentCount() < 1)
- return QScriptValue(e, false);
- bool ret = false;
-#ifndef QT_NO_DESKTOPSERVICES
- ret = QDesktopServices::openUrl(QDeclarativeScriptEngine::get(e)->resolvedUrl(ctxt, QUrl(ctxt->argument(0).toString())));
-#endif
- return QScriptValue(e, ret);
-}
-
-/*!
-\qmlmethod list<string> Qt::fontFamilies()
-Returns a list of the font families available to the application.
-*/
-
-QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e)
-{
- if(ctxt->argumentCount() != 0)
- return ctxt->throwError(QLatin1String("Qt.fontFamilies(): Invalid arguments"));
-
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(e);
- QFontDatabase database;
- return p->scriptValueFromVariant(database.families());
-}
-
-/*!
-\qmlmethod string Qt::md5(data)
-Returns a hex string of the md5 hash of \c data.
-*/
-QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *)
-{
- if (ctxt->argumentCount() != 1)
- return ctxt->throwError(QLatin1String("Qt.md5(): Invalid arguments"));
-
- QByteArray data = ctxt->argument(0).toString().toUtf8();
- QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5);
-
- return QScriptValue(QLatin1String(result.toHex()));
-}
-
-/*!
-\qmlmethod string Qt::btoa(data)
-Binary to ASCII - this function returns a base64 encoding of \c data.
-*/
-QScriptValue QDeclarativeEnginePrivate::btoa(QScriptContext *ctxt, QScriptEngine *)
-{
- if (ctxt->argumentCount() != 1)
- return ctxt->throwError(QLatin1String("Qt.btoa(): Invalid arguments"));
-
- QByteArray data = ctxt->argument(0).toString().toUtf8();
-
- return QScriptValue(QLatin1String(data.toBase64()));
-}
-
-/*!
-\qmlmethod string Qt::atob(data)
-ASCII to binary - this function returns a base64 decoding of \c data.
-*/
-
-QScriptValue QDeclarativeEnginePrivate::atob(QScriptContext *ctxt, QScriptEngine *)
-{
- if (ctxt->argumentCount() != 1)
- return ctxt->throwError(QLatin1String("Qt.atob(): Invalid arguments"));
-
- QByteArray data = ctxt->argument(0).toString().toUtf8();
-
- return QScriptValue(QLatin1String(QByteArray::fromBase64(data)));
-}
-
-QScriptValue QDeclarativeEnginePrivate::consoleLog(QScriptContext *ctxt, QScriptEngine *e)
-{
- if(ctxt->argumentCount() < 1)
- return e->newVariant(QVariant(false));
-
- QByteArray msg;
-
- for (int i=0; i<ctxt->argumentCount(); ++i) {
- if (!msg.isEmpty()) msg += ' ';
- msg += ctxt->argument(i).toString().toLocal8Bit();
- // does not support firebug "%[a-z]" formatting, since firebug really
- // does just ignore the format letter, which makes it pointless.
- }
-
- qDebug("%s",msg.constData());
-
- return e->newVariant(QVariant(true));
-}
-
void QDeclarativeEnginePrivate::sendQuit()
{
Q_Q(QDeclarativeEngine);
@@ -2004,145 +1187,6 @@ void QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate *engine, const
dumpwarning(error);
}
-/*!
-\qmlmethod Qt::quit()
-This function causes the QDeclarativeEngine::quit() signal to be emitted.
-Within the \l {QML Viewer}, this causes the launcher application to exit;
-to quit a C++ application when this method is called, connect the
-QDeclarativeEngine::quit() signal to the QCoreApplication::quit() slot.
-*/
-
-QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptEngine *e)
-{
- QDeclarativeEnginePrivate *qe = get (e);
- qe->sendQuit();
- return QScriptValue();
-}
-
-/*!
- \qmlmethod color Qt::tint(color baseColor, color tintColor)
- This function allows tinting one color with another.
-
- The tint color should usually be mostly transparent, or you will not be
- able to see the underlying color. The below example provides a slight red
- tint by having the tint color be pure red which is only 1/16th opaque.
-
- \qml
- Item {
- Rectangle {
- x: 0; width: 80; height: 80
- color: "lightsteelblue"
- }
- Rectangle {
- x: 100; width: 80; height: 80
- color: Qt.tint("lightsteelblue", "#10FF0000")
- }
- }
- \endqml
- \image declarative-rect_tint.png
-
- Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color.
-*/
-QScriptValue QDeclarativeEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if(ctxt->argumentCount() != 2)
- return ctxt->throwError(QLatin1String("Qt.tint(): Invalid arguments"));
- //get color
- QVariant v = ctxt->argument(0).toVariant();
- QColor color;
- if (v.userType() == QVariant::Color)
- color = v.value<QColor>();
- else if (v.userType() == QVariant::String) {
- bool ok;
- color = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
- if (!ok)
- return engine->nullValue();
- } else
- return engine->nullValue();
-
- //get tint color
- v = ctxt->argument(1).toVariant();
- QColor tintColor;
- if (v.userType() == QVariant::Color)
- tintColor = v.value<QColor>();
- else if (v.userType() == QVariant::String) {
- bool ok;
- tintColor = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
- if (!ok)
- return engine->nullValue();
- } else
- return engine->nullValue();
-
- //tint
- QColor finalColor;
- int a = tintColor.alpha();
- if (a == 0xFF)
- finalColor = tintColor;
- else if (a == 0x00)
- finalColor = color;
- else {
- qreal a = tintColor.alphaF();
- qreal inv_a = 1.0 - a;
-
- finalColor.setRgbF(tintColor.redF() * a + color.redF() * inv_a,
- tintColor.greenF() * a + color.greenF() * inv_a,
- tintColor.blueF() * a + color.blueF() * inv_a,
- a + inv_a * color.alphaF());
- }
-
- return engine->toScriptValue(QVariant::fromValue(finalColor));
-}
-
-QScriptValue QDeclarativeEnginePrivate::scriptValueFromVariant(const QVariant &val)
-{
- if (variantIsScarceResource(val)) {
- return scarceResourceClass->newScarceResource(val);
- } else if (val.userType() == qMetaTypeId<QDeclarativeListReference>()) {
- QDeclarativeListReferencePrivate *p =
- QDeclarativeListReferencePrivate::get((QDeclarativeListReference*)val.constData());
- if (p->object) {
- return listClass->newList(p->property, p->propertyType);
- } else {
- return scriptEngine.nullValue();
- }
- } else if (val.userType() == qMetaTypeId<QList<QObject *> >()) {
- const QList<QObject *> &list = *(QList<QObject *>*)val.constData();
- QScriptValue rv = scriptEngine.newArray(list.count());
- for (int ii = 0; ii < list.count(); ++ii) {
- QObject *object = list.at(ii);
- rv.setProperty(ii, objectClass->newQObject(object));
- }
- return rv;
- } else if (QDeclarativeValueType *vt = valueTypes[val.userType()]) {
- return valueTypeClass->newObject(val, vt);
- }
-
- bool objOk;
- QObject *obj = QDeclarativeMetaType::toQObject(val, &objOk);
- if (objOk) {
- return objectClass->newQObject(obj);
- } else {
- return scriptEngine.toScriptValue(val);
- }
-}
-
-/*
- If the variant is a scarce resource (consumes a large amount of memory, or
- only a limited number of them can be held in memory at any given time without
- exhausting supply for future use) we need to release the scarce resource
- after evaluation of the javascript binding is complete.
- */
-bool QDeclarativeEnginePrivate::variantIsScarceResource(const QVariant& val)
-{
- if (val.type() == QVariant::Pixmap) {
- return true;
- } else if (val.type() == QVariant::Image) {
- return true;
- }
-
- return false;
-}
-
/*
This function should be called prior to evaluation of any js expression,
so that scarce resources are not freed prematurely (eg, if there is a
@@ -2170,45 +1214,13 @@ void QDeclarativeEnginePrivate::dereferenceScarceResources()
// note that the actual SRD is owned by the JS engine,
// so we cannot delete the SRD; but we can free the
// memory used by the variant in the SRD.
- ScarceResourceData *srd = 0;
- while (scarceResources) {
- srd = scarceResources; // srd points to the "old" (current) head of the list
- scarceResources = srd->next; // srd->next is the "new" head of the list
- if (srd->next) srd->next->prev = &scarceResources; // newHead->prev = listptr.
- srd->next = 0;
- srd->prev = 0;
- srd->releaseResource(); // release the old head node.
+ while (ScarceResourceData *sr = scarceResources.first()) {
+ sr->data = QVariant();
+ scarceResources.remove(sr);
}
}
}
-QVariant QDeclarativeEnginePrivate::scriptValueToVariant(const QScriptValue &val, int hint)
-{
- QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(val);
- if (dc == objectClass)
- return QVariant::fromValue(objectClass->toQObject(val));
- else if (dc == scarceResourceClass)
- return scarceResourceClass->toVariant(val);
- else if (dc == valueTypeClass)
- return valueTypeClass->toVariant(val);
- else if (dc == contextClass)
- return QVariant();
-
- // Convert to a QList<QObject*> only if val is an array and we were explicitly hinted
- if (hint == qMetaTypeId<QList<QObject *> >() && val.isArray()) {
- QList<QObject *> list;
- int length = val.property(QLatin1String("length")).toInt32();
- for (int ii = 0; ii < length; ++ii) {
- QScriptValue arrayItem = val.property(ii);
- QObject *d = arrayItem.toQObject();
- list << d;
- }
- return QVariant::fromValue(list);
- }
-
- return val.toVariant();
-}
-
/*!
Adds \a path as a directory where the engine searches for
installed modules in a URL-based directory structure.
@@ -2312,7 +1324,6 @@ void QDeclarativeEngine::setPluginPathList(const QStringList &paths)
d->importDatabase.setPluginPathList(paths);
}
-
/*!
Imports the plugin named \a filePath with the \a uri provided.
Returns true if the plugin was successfully imported; otherwise returns false.
@@ -2372,13 +1383,13 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur
void QDeclarativeEngine::setOfflineStoragePath(const QString& dir)
{
Q_D(QDeclarativeEngine);
- d->scriptEngine.offlineStoragePath = dir;
+ qt_qmlsqldatabase_setOfflineStoragePath(&d->v8engine, dir);
}
QString QDeclarativeEngine::offlineStoragePath() const
{
Q_D(const QDeclarativeEngine);
- return d->scriptEngine.offlineStoragePath;
+ return qt_qmlsqldatabase_getOfflineStoragePath(&d->v8engine);
}
static void voidptr_destructor(void *v)
diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h
index 476ff60ec9..e97c2d96b0 100644
--- a/src/declarative/qml/qdeclarativeengine.h
+++ b/src/declarative/qml/qdeclarativeengine.h
@@ -107,6 +107,8 @@ public:
bool outputWarningsToStandardError() const;
void setOutputWarningsToStandardError(bool);
+ void collectGarbage();
+
static QDeclarativeContext *contextForObject(const QObject *);
static void setContextForObject(QObject *, QDeclarativeContext *);
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index c690ac7bff..ba22ba95c0 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -66,81 +66,41 @@
#include "qdeclarativeimageprovider.h"
#include "private/qdeclarativeproperty_p.h"
#include "private/qdeclarativepropertycache_p.h"
-#include "private/qdeclarativeobjectscriptclass_p.h"
-#include "private/qdeclarativescarceresourcescriptclass_p.h"
-#include "private/qdeclarativecontextscriptclass_p.h"
-#include "private/qdeclarativevaluetypescriptclass_p.h"
#include "private/qdeclarativemetatype_p.h"
#include "private/qdeclarativedirparser_p.h"
+#include "private/qintrusivelist_p.h"
-#include <QtScript/QScriptClass>
-#include <QtScript/QScriptValue>
-#include <QtScript/QScriptString>
#include <QtCore/qstring.h>
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>
#include <QtCore/qstack.h>
#include <QtCore/qmutex.h>
-#include <QtScript/qscriptengine.h>
#include <private/qobject_p.h>
+#include <private/qv8engine_p.h>
+
QT_BEGIN_NAMESPACE
class QDeclarativeContext;
class QDeclarativeEngine;
class QDeclarativeContextPrivate;
class QDeclarativeExpression;
-class QDeclarativeContextScriptClass;
class QDeclarativeImportDatabase;
-class QDeclarativeObjectScriptClass;
-class QDeclarativeScarceResourceScriptClass;
class ScarceResourceData;
-class QDeclarativeTypeNameScriptClass;
-class QDeclarativeValueTypeScriptClass;
class QNetworkReply;
class QNetworkAccessManager;
class QDeclarativeNetworkAccessManagerFactory;
class QDeclarativeAbstractBinding;
-class QScriptDeclarativeClass;
-class QDeclarativeTypeNameScriptClass;
class QDeclarativeTypeNameCache;
class QDeclarativeComponentAttached;
-class QDeclarativeListScriptClass;
class QDeclarativeCleanup;
class QDeclarativeDelayedError;
class QDeclarativeWorkerScriptEngine;
-class QDeclarativeGlobalScriptClass;
class QDir;
class QSGTexture;
class QSGContext;
-class QDeclarativeScriptEngine : public QScriptEngine
-{
-public:
- QDeclarativeScriptEngine(QDeclarativeEnginePrivate *priv);
- virtual ~QDeclarativeScriptEngine();
-
- QUrl resolvedUrl(QScriptContext *context, const QUrl& url); // resolved against p's context, or baseUrl if no p
- static QScriptValue resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine);
-
- static QDeclarativeScriptEngine *get(QScriptEngine* e) { return static_cast<QDeclarativeScriptEngine*>(e); }
-
- QDeclarativeEnginePrivate *p;
-
- // User by SQL API
- QScriptClass *sqlQueryClass;
- QString offlineStoragePath;
-
- // Used by DOM Core 3 API
- QScriptClass *namedNodeMapClass;
- QScriptClass *nodeListClass;
-
- QUrl baseUrl;
-
- virtual QNetworkAccessManager *networkAccessManager();
-};
-
class Q_AUTOTEST_EXPORT QDeclarativeEnginePrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeEngine)
@@ -169,16 +129,8 @@ public:
bool outputWarningsToStdErr;
- QDeclarativeContextScriptClass *contextClass;
QDeclarativeContextData *sharedContext;
QObject *sharedScope;
- QDeclarativeObjectScriptClass *objectClass;
- QDeclarativeScarceResourceScriptClass *scarceResourceClass;
- QDeclarativeValueTypeScriptClass *valueTypeClass;
- QDeclarativeTypeNameScriptClass *typeNameClass;
- QDeclarativeListScriptClass *listClass;
- // Global script class
- QDeclarativeGlobalScriptClass *globalClass;
// Registered cleanup handlers
QDeclarativeCleanup *cleanup;
@@ -187,7 +139,8 @@ public:
QDeclarativeDelayedError *erroredBindings;
int inProgressCreations;
- QDeclarativeScriptEngine scriptEngine;
+ // V8 Engine
+ QV8Engine v8engine;
QDeclarativeWorkerScriptEngine *getWorkerScriptEngine();
QDeclarativeWorkerScriptEngine *workerScriptEngine;
@@ -242,15 +195,20 @@ public:
QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
- /*
- A scarce resource (like a large pixmap or texture) will be cached in a
- JavaScript wrapper object when accessed in a binding or other js expression.
- We need some way to automatically release that scarce resource prior to normal
- garbage collection (unless the user explicitly preserves the resource).
- */
- ScarceResourceData* scarceResources;
+ // Scarce resources are "exceptionally high cost" QVariant types where allowing the
+ // normal JavaScript GC to clean them up is likely to lead to out-of-memory or other
+ // out-of-resource situations. When such a resource is passed into JavaScript we
+ // add it to the scarceResources list and it is destroyed when we return from the
+ // JavaScript execution that created it. The user can prevent this behavior by
+ // calling preserve() on the object which removes it from this scarceResource list.
+ class ScarceResourceData {
+ public:
+ ScarceResourceData(const QVariant &data) : data(data) {}
+ QVariant data;
+ QIntrusiveListNode node;
+ };
+ QIntrusiveList<ScarceResourceData, &ScarceResourceData::node> scarceResources;
int scarceResourcesRefCount;
- static bool variantIsScarceResource(const QVariant& val);
void referenceScarceResources();
void dereferenceScarceResources();
@@ -290,9 +248,6 @@ public:
QHash<int, int> m_qmlLists;
QHash<int, QDeclarativeCompiledData *> m_compositeTypes;
- QScriptValue scriptValueFromVariant(const QVariant &);
- QVariant scriptValueToVariant(const QScriptValue &, int hint = QVariant::Invalid);
-
void sendQuit();
void warning(const QDeclarativeError &);
void warning(const QList<QDeclarativeError> &);
@@ -301,44 +256,11 @@ public:
static void warning(QDeclarativeEnginePrivate *, const QDeclarativeError &);
static void warning(QDeclarativeEnginePrivate *, const QList<QDeclarativeError> &);
- static QScriptValue qmlScriptObject(QObject*, QDeclarativeEngine*);
-
- static QScriptValue createComponent(QScriptContext*, QScriptEngine*);
- static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*);
- static QScriptValue isQtObject(QScriptContext*, QScriptEngine*);
- static QScriptValue vector3d(QScriptContext*, QScriptEngine*);
- static QScriptValue rgba(QScriptContext*, QScriptEngine*);
- static QScriptValue hsla(QScriptContext*, QScriptEngine*);
- static QScriptValue point(QScriptContext*, QScriptEngine*);
- static QScriptValue size(QScriptContext*, QScriptEngine*);
- static QScriptValue rect(QScriptContext*, QScriptEngine*);
-
- static QScriptValue lighter(QScriptContext*, QScriptEngine*);
- static QScriptValue darker(QScriptContext*, QScriptEngine*);
- static QScriptValue tint(QScriptContext*, QScriptEngine*);
-
- static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*);
- static QScriptValue fontFamilies(QScriptContext*, QScriptEngine*);
- static QScriptValue md5(QScriptContext*, QScriptEngine*);
- static QScriptValue btoa(QScriptContext*, QScriptEngine*);
- static QScriptValue atob(QScriptContext*, QScriptEngine*);
- static QScriptValue consoleLog(QScriptContext*, QScriptEngine*);
- static QScriptValue quit(QScriptContext*, QScriptEngine*);
-
-#ifndef QT_NO_DATESTRING
- static QScriptValue formatDate(QScriptContext*, QScriptEngine*);
- static QScriptValue formatTime(QScriptContext*, QScriptEngine*);
- static QScriptValue formatDateTime(QScriptContext*, QScriptEngine*);
-#endif
- static QScriptEngine *getScriptEngine(QDeclarativeEngine *e) { return &e->d_func()->scriptEngine; }
- static QDeclarativeEngine *getEngine(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p->q_func(); }
+ static QV8Engine *getV8Engine(QDeclarativeEngine *e) { return &e->d_func()->v8engine; }
static QDeclarativeEnginePrivate *get(QDeclarativeEngine *e) { return e->d_func(); }
static QDeclarativeEnginePrivate *get(QDeclarativeContext *c) { return (c && c->engine()) ? QDeclarativeEnginePrivate::get(c->engine()) : 0; }
static QDeclarativeEnginePrivate *get(QDeclarativeContextData *c) { return (c && c->engine) ? QDeclarativeEnginePrivate::get(c->engine) : 0; }
- static QDeclarativeEnginePrivate *get(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p; }
static QDeclarativeEngine *get(QDeclarativeEnginePrivate *p) { return p->q_func(); }
- QDeclarativeContextData *getContext(QScriptContext *);
- QUrl getUrl(QScriptContext *);
static QString urlToLocalFileOrQrc(const QUrl& url);
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index 8f22314530..af99f05e95 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -678,7 +678,7 @@ void QDeclarativeEngineDebugServer::setMethodBody(int objectId, const QString &m
QDeclarativePropertyCache::Data *prop =
QDeclarativePropertyCache::property(context->engine(), object, method, dummy);
- if (!prop || !(prop->flags & QDeclarativePropertyCache::Data::IsVMEFunction))
+ if (!prop || !prop->isVMEFunction())
return;
QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex);
@@ -700,7 +700,7 @@ void QDeclarativeEngineDebugServer::setMethodBody(int objectId, const QString &m
Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this
int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex);
- vmeMetaObject->setVmeMethod(prop->coreIndex, QDeclarativeExpressionPrivate::evalInObjectScope(contextData, object, jsfunction, contextData->url.toString(), lineNumber, 0));
+ vmeMetaObject->setVmeMethod(prop->coreIndex, QDeclarativeExpressionPrivate::evalFunction(contextData, object, jsfunction, contextData->url.toString(), lineNumber));
}
void QDeclarativeEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value)
diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp
index 8079cf3eea..27bd8f8147 100644
--- a/src/declarative/qml/qdeclarativeexpression.cpp
+++ b/src/declarative/qml/qdeclarativeexpression.cpp
@@ -47,12 +47,8 @@
#include "private/qdeclarativerewrite_p.h"
#include "private/qdeclarativescriptstring_p.h"
#include "private/qdeclarativecompiler_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
#include <QtCore/qdebug.h>
-#include <QtScript/qscriptprogram.h>
-
-#include <private/qscriptdeclarativeclass_p.h>
QT_BEGIN_NAMESPACE
@@ -72,26 +68,27 @@ bool QDeclarativeDelayedError::addError(QDeclarativeEnginePrivate *e)
return true;
}
-QDeclarativeQtScriptExpression::QDeclarativeQtScriptExpression()
-: dataRef(0), expressionFunctionMode(ExplicitContext), scopeObject(0), trackChange(false),
- guardList(0), guardListLength(0), guardObject(0), guardObjectNotifyIndex(-1), deleted(0)
+QDeclarativeJavaScriptExpression::QDeclarativeJavaScriptExpression()
+: m_requiresThisObject(0), m_useSharedContext(0), m_notifyOnValueChanged(0),
+ m_scopeObject(0), m_notifyObject(0), m_notifyIndex(-1)
{
}
-QDeclarativeQtScriptExpression::~QDeclarativeQtScriptExpression()
+QDeclarativeJavaScriptExpression::~QDeclarativeJavaScriptExpression()
{
- if (guardList) { delete [] guardList; guardList = 0; }
- if (dataRef) dataRef->release();
- if (deleted) *deleted = true;
}
QDeclarativeExpressionPrivate::QDeclarativeExpressionPrivate()
-: expressionFunctionValid(true), line(-1)
+: expressionFunctionValid(true), extractExpressionFromFunction(false), line(-1), dataRef(0)
{
}
QDeclarativeExpressionPrivate::~QDeclarativeExpressionPrivate()
{
+ qPersistentDispose(v8qmlscope);
+ qPersistentDispose(v8function);
+ if (dataRef) dataRef->release();
+ dataRef = 0;
}
void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, const QString &expr,
@@ -100,112 +97,62 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, const QS
expression = expr;
QDeclarativeAbstractExpression::setContext(ctxt);
- scopeObject = me;
+ setScopeObject(me);
expressionFunctionValid = false;
}
-void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, const QScriptValue &func,
+void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, v8::Handle<v8::Function> func,
QObject *me)
{
- expression = func.toString();
-
QDeclarativeAbstractExpression::setContext(ctxt);
- scopeObject = me;
+ setScopeObject(me);
- expressionFunction = func;
- expressionFunctionMode = ExplicitContext;
+ v8function = qPersistentNew<v8::Function>(func);
+ setUseSharedContext(false);
expressionFunctionValid = true;
+ extractExpressionFromFunction = true;
}
-void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, void *expr,
- QDeclarativeRefCount *rc,
+void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, const QString &expr, bool isRewritten,
QObject *me, const QString &srcUrl, int lineNumber)
{
url = srcUrl;
line = lineNumber;
- if (dataRef) dataRef->release();
- dataRef = rc;
- if (dataRef) dataRef->addref();
-
- quint32 *exprData = (quint32 *)expr;
- QDeclarativeCompiledData *dd = (QDeclarativeCompiledData *)rc;
-
- expression = QString::fromRawData((QChar *)(exprData + 2), exprData[1]);
-
- int progIdx = *(exprData);
- bool isSharedProgram = progIdx & 0x80000000;
- progIdx &= 0x7FFFFFFF;
-
- QDeclarativeEngine *engine = ctxt->engine;
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- if (isSharedProgram) {
-
- if (!dd->cachedClosures.at(progIdx)) {
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- scriptContext->pushScope(ep->contextClass->newSharedContext());
- scriptContext->pushScope(ep->globalClass->staticGlobalObject());
- dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(expression, url, line));
- scriptEngine->popContext();
- }
-
- expressionFunction = *dd->cachedClosures.at(progIdx);
- expressionFunctionMode = SharedContext;
- expressionFunctionValid = true;
+ expression = expr;
+ if (!isRewritten) {
+ expressionFunctionValid = false;
} else {
-
- if (!dd->cachedPrograms.at(progIdx)) {
- dd->cachedPrograms[progIdx] = new QScriptProgram(expression, url, line);
- }
-
- expressionFunction = evalInObjectScope(ctxt, me, *dd->cachedPrograms.at(progIdx),
- &expressionContext);
-
- expressionFunctionMode = ExplicitContext;
+ v8function = evalFunction(ctxt, me, expression, url, line, &v8qmlscope);
expressionFunctionValid = true;
}
QDeclarativeAbstractExpression::setContext(ctxt);
- scopeObject = me;
+ setScopeObject(me);
}
-QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContextData *context, QObject *object,
- const QString &program, const QString &fileName,
- int lineNumber, QScriptValue *contextObject)
+// Callee owns the persistent handle
+v8::Persistent<v8::Function>
+QDeclarativeExpressionPrivate::evalFunction(QDeclarativeContextData *ctxt, QObject *scope,
+ const QString &code, const QString &filename, int line,
+ v8::Persistent<v8::Object> *qmlscope)
{
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine);
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine);
- if (contextObject) {
- *contextObject = ep->contextClass->newContext(context, object);
- scriptContext->pushScope(*contextObject);
- } else {
- scriptContext->pushScope(ep->contextClass->newContext(context, object));
- }
- scriptContext->pushScope(ep->globalClass->staticGlobalObject());
- QScriptValue rv = ep->scriptEngine.evaluate(program, fileName, lineNumber);
- ep->scriptEngine.popContext();
- return rv;
-}
+ QDeclarativeEngine *engine = ctxt->engine;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContextData *context, QObject *object,
- const QScriptProgram &program,
- QScriptValue *contextObject)
-{
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine);
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine);
- if (contextObject) {
- *contextObject = ep->contextClass->newContext(context, object);
- scriptContext->pushScope(*contextObject);
- } else {
- scriptContext->pushScope(ep->contextClass->newContext(context, object));
- }
- scriptContext->pushScope(ep->globalClass->staticGlobalObject());
- QScriptValue rv = ep->scriptEngine.evaluate(program);
- ep->scriptEngine.popContext();
- return rv;
+ // XXX TODO: Implement script caching, like we used to do with QScriptProgram in the
+ // QtScript days
+ v8::HandleScope handle_scope;
+ v8::Context::Scope ctxtscope(ep->v8engine.context());
+
+ v8::TryCatch tc;
+ v8::Local<v8::Object> scopeobject = ep->v8engine.qmlScope(ctxt, scope);
+ v8::Local<v8::Script> script = ep->v8engine.qmlModeCompile(code, filename, line);
+ v8::Local<v8::Value> result = script->Run(scopeobject);
+ if (tc.HasCaught()) return v8::Persistent<v8::Function>();
+ if (qmlscope) *qmlscope = qPersistentNew<v8::Object>(scopeobject);
+ return qPersistentNew<v8::Function>(v8::Local<v8::Function>::Cast(result));
}
/*!
@@ -255,14 +202,14 @@ QDeclarativeExpression::QDeclarativeExpression()
}
/*! \internal */
-QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, void *expr,
- QDeclarativeRefCount *rc, QObject *me,
- const QString &url, int lineNumber,
+QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt,
+ QObject *object, const QString &expr, bool isRewritten,
+ const QString &url, int lineNumber,
QDeclarativeExpressionPrivate &dd)
: QObject(dd, 0)
{
Q_D(QDeclarativeExpression);
- d->init(ctxt, expr, rc, me, url, lineNumber);
+ d->init(ctxt, expr, isRewritten, object, url, lineNumber);
if (QDeclarativeExpression_notifyIdx == -1)
QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()");
@@ -304,7 +251,7 @@ QDeclarativeExpression::QDeclarativeExpression(const QDeclarativeScriptString &s
}
if (cdata)
- d->init(ctxtdata, (void*)cdata->datas.at(id).constData(), cdata, script.scopeObject(),
+ d->init(ctxtdata, cdata->primitives.at(id), cdata, script.scopeObject(),
cdata->name, script.d.data()->lineNumber);
else
defaultConstruction = true;
@@ -370,16 +317,26 @@ QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QO
d->setNotifyObject(this, QDeclarativeExpression_notifyIdx);
}
-/*! \internal */
-QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QObject *scope, const QScriptValue &func,
- QDeclarativeExpressionPrivate &dd)
+/*!
+ \internal
+
+ To avoid exposing v8 in the public API, functionPtr must be a pointer to a v8::Handle<v8::Function>.
+ For example:
+ v8::Handle<v8::Function> function;
+ new QDeclarativeExpression(ctxt, scope, &function, ...);
+ */
+QDeclarativeExpression::QDeclarativeExpression(QDeclarativeContextData *ctxt, QObject *scope, void *functionPtr,
+ QDeclarativeExpressionPrivate &dd)
: QObject(dd, 0)
{
+ v8::Handle<v8::Function> function = *(v8::Handle<v8::Function> *)functionPtr;
+
Q_D(QDeclarativeExpression);
- d->init(ctxt, func, scope);
+ d->init(ctxt, function, scope);
if (QDeclarativeExpression_notifyIdx == -1)
QDeclarativeExpression_notifyIdx = QDeclarativeExpression::staticMetaObject.indexOfMethod("_q_notify()");
+
d->setNotifyObject(this, QDeclarativeExpression_notifyIdx);
}
@@ -417,6 +374,13 @@ QDeclarativeContext *QDeclarativeExpression::context() const
QString QDeclarativeExpression::expression() const
{
Q_D(const QDeclarativeExpression);
+ if (d->extractExpressionFromFunction && context()->engine()) {
+ QV8Engine *v8engine = QDeclarativeEnginePrivate::getV8Engine(context()->engine());
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(v8engine->context());
+
+ return v8engine->toString(v8::Handle<v8::Value>(d->v8function));
+ }
return d->expression;
}
@@ -427,198 +391,178 @@ void QDeclarativeExpression::setExpression(const QString &expression)
{
Q_D(QDeclarativeExpression);
- d->resetNotifyOnChange();
+ d->resetNotifyOnValueChanged();
d->expression = expression;
d->expressionFunctionValid = false;
- d->expressionFunction = QScriptValue();
+ qPersistentDispose(d->v8function);
+ qPersistentDispose(d->v8qmlscope);
}
-void QDeclarativeExpressionPrivate::exceptionToError(QScriptEngine *scriptEngine,
- QDeclarativeError &error)
+void QDeclarativeExpressionPrivate::exceptionToError(v8::Handle<v8::Message> message,
+ QDeclarativeError &error)
{
- if (scriptEngine->hasUncaughtException() &&
- scriptEngine->uncaughtException().isError()) {
+ Q_ASSERT(!message.IsEmpty());
- QString fileName;
- int lineNumber = scriptEngine->uncaughtExceptionLineNumber();
+ v8::Handle<v8::Value> name = message->GetScriptResourceName();
+ v8::Handle<v8::String> description = message->Get();
+ int lineNumber = message->GetLineNumber();
- QScriptValue exception = scriptEngine->uncaughtException();
- QLatin1String fileNameProp("fileName");
+ Q_ASSERT(name->IsString());
- if (!exception.property(fileNameProp).toString().isEmpty()){
- fileName = exception.property(fileNameProp).toString();
- } else {
- fileName = QLatin1String("<Unknown File>");
- }
+ v8::Local<v8::String> file = name->ToString();
+ if (file->Length() == 0)
+ error.setUrl(QUrl(QLatin1String("<Unknown File>")));
+ else
+ error.setUrl(QUrl(QV8Engine::toStringStatic(file)));
- error.setUrl(QUrl(fileName));
- error.setLine(lineNumber);
- error.setColumn(-1);
- error.setDescription(exception.toString());
- } else {
- error = QDeclarativeError();
- }
-}
+ error.setLine(lineNumber);
+ error.setColumn(-1);
-bool QDeclarativeQtScriptExpression::notifyOnValueChange() const
-{
- return trackChange;
+ QString qDescription = QV8Engine::toStringStatic(description);
+ if (qDescription.startsWith(QLatin1String("Uncaught ")))
+ qDescription = qDescription.mid(9 /* strlen("Uncaught ") */);
+
+ error.setDescription(qDescription);
}
-void QDeclarativeQtScriptExpression::setNotifyOnValueChange(bool notify)
+void QDeclarativeJavaScriptExpression::setNotifyOnValueChanged(bool v)
{
- trackChange = notify;
- if (!notify && guardList)
- clearGuards();
+ m_notifyOnValueChanged = v;
+ if (!v) guardList.clear();
}
-void QDeclarativeQtScriptExpression::resetNotifyOnChange()
+void QDeclarativeJavaScriptExpression::resetNotifyOnValueChanged()
{
- clearGuards();
+ guardList.clear();
}
-void QDeclarativeQtScriptExpression::setNotifyObject(QObject *object, int notifyIndex)
+void QDeclarativeJavaScriptExpression::setNotifyObject(QObject *object, int index)
{
- if (guardList) clearGuards();
+ guardList.clear();
- if (!object || notifyIndex == -1) {
- guardObject = 0;
- notifyIndex = -1;
- } else {
- guardObject = object;
- guardObjectNotifyIndex = notifyIndex;
+ m_notifyObject = object;
+ m_notifyIndex = index;
+ if (!object || index == -1) {
+ m_notifyObject = 0;
+ m_notifyIndex = -1;
}
}
-void QDeclarativeQtScriptExpression::setEvaluateFlags(EvaluateFlags flags)
-{
- evalFlags = flags;
-}
-
-QDeclarativeQtScriptExpression::EvaluateFlags QDeclarativeQtScriptExpression::evaluateFlags() const
-{
- return evalFlags;
-}
-
-QScriptValue QDeclarativeQtScriptExpression::scriptValue(QObject *secondaryScope, bool *isUndefined)
+v8::Local<v8::Value> QDeclarativeJavaScriptExpression::evaluate(v8::Handle<v8::Function> function, bool *isUndefined)
{
Q_ASSERT(context() && context()->engine);
- Q_ASSERT(!trackChange || (guardObject && guardObjectNotifyIndex != -1));
+ Q_ASSERT(!notifyOnValueChanged() || (m_notifyObject && m_notifyIndex != -1));
- if (!expressionFunction.isValid()) {
+ if (function.IsEmpty() || function->IsUndefined()) {
if (isUndefined) *isUndefined = true;
- return QScriptValue();
+ return v8::Local<v8::Value>();
}
- DeleteWatcher watcher(this);
-
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context()->engine);
bool lastCaptureProperties = ep->captureProperties;
QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties;
- ep->captureProperties = trackChange;
- ep->capturedProperties.copyAndClear(lastCapturedProperties);
-
- QScriptValue value = eval(secondaryScope, isUndefined);
+ ep->captureProperties = notifyOnValueChanged();
- if (!watcher.wasDeleted() && trackChange) {
- if (ep->capturedProperties.count() == 0) {
+ if (ep->capturedProperties.count())
+ ep->capturedProperties.copyAndClear(lastCapturedProperties);
- if (guardList) clearGuards();
+ QDeclarativeContextData *lastSharedContext = 0;
+ QObject *lastSharedScope = 0;
- } else {
+ bool sharedContext = useSharedContext();
- updateGuards(ep->capturedProperties);
+ // All code that follows must check with watcher before it accesses data members
+ // incase we have been deleted.
+ QDeclarativeDeleteWatcher watcher(this);
- }
+ if (sharedContext) {
+ lastSharedContext = ep->sharedContext;
+ lastSharedScope = ep->sharedScope;
+ ep->sharedContext = context();
+ ep->sharedScope = scopeObject();
}
- lastCapturedProperties.copyAndClear(ep->capturedProperties);
- ep->captureProperties = lastCaptureProperties;
-
- return value;
-}
-
-QScriptValue QDeclarativeQtScriptExpression::eval(QObject *secondaryScope, bool *isUndefined)
-{
- Q_ASSERT(context() && context()->engine);
-
- DeleteWatcher watcher(this);
-
- QDeclarativeEngine *engine = context()->engine;
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+ v8::Local<v8::Value> result;
+ {
+ v8::TryCatch try_catch;
+ v8::Handle<v8::Object> This = ep->v8engine.global();
+ if (scopeObject() && requiresThisObject()) {
+ v8::Handle<v8::Value> value = ep->v8engine.newQObject(scopeObject());
+ if (value->IsObject()) This = v8::Handle<v8::Object>::Cast(value);
+ }
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+ result = function->Call(This, 0, 0);
- QDeclarativeContextData *oldSharedContext = 0;
- QObject *oldSharedScope = 0;
- QObject *oldOverride = 0;
- bool isShared = (expressionFunctionMode == SharedContext);
+ if (isUndefined)
+ *isUndefined = try_catch.HasCaught() || result->IsUndefined();
- if (isShared) {
- oldSharedContext = ep->sharedContext;
- oldSharedScope = ep->sharedScope;
- ep->sharedContext = context();
- ep->sharedScope = scopeObject;
- } else {
- oldOverride = ep->contextClass->setOverrideObject(expressionContext, secondaryScope);
+ if (watcher.wasDeleted()) {
+ } else if (try_catch.HasCaught()) {
+ v8::Context::Scope scope(ep->v8engine.context());
+ v8::Local<v8::Message> message = try_catch.Message();
+ if (!message.IsEmpty()) {
+ QDeclarativeExpressionPrivate::exceptionToError(message, error);
+ } else {
+ error = QDeclarativeError();
+ }
+ } else {
+ error = QDeclarativeError();
+ }
}
- QScriptValue thisObject;
- if (evalFlags & RequiresThisObject)
- thisObject = ep->objectClass->newQObject(scopeObject);
- QScriptValue svalue = expressionFunction.call(thisObject); // This could cause this c++ object to be deleted
-
- if (isShared) {
- ep->sharedContext = oldSharedContext;
- ep->sharedScope = oldSharedScope;
- } else if (!watcher.wasDeleted()) {
- ep->contextClass->setOverrideObject(expressionContext, oldOverride);
+ if (sharedContext) {
+ ep->sharedContext = lastSharedContext;
+ ep->sharedScope = lastSharedScope;
}
- if (isUndefined)
- *isUndefined = svalue.isUndefined() || scriptEngine->hasUncaughtException();
+ if (!watcher.wasDeleted() && notifyOnValueChanged()) {
+ guardList.updateGuards(m_notifyObject, m_notifyIndex, expressionString(),
+ ep->capturedProperties);
+ }
- // Handle exception
- if (scriptEngine->hasUncaughtException()) {
- if (!watcher.wasDeleted())
- QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
+ if (lastCapturedProperties.count())
+ lastCapturedProperties.copyAndClear(ep->capturedProperties);
+ else
+ ep->capturedProperties.clear();
- scriptEngine->clearExceptions();
- return QScriptValue();
- } else {
- if (!watcher.wasDeleted())
- error = QDeclarativeError();
+ ep->captureProperties = lastCaptureProperties;
- return svalue;
- }
+ return result;
}
-void QDeclarativeQtScriptExpression::updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties)
+void QDeclarativeJavaScriptExpression::GuardList::updateGuards(QObject *notifyObject, int notifyIndex,
+ const QStringRef &expression,
+ const CapturedProperties &properties)
{
- Q_ASSERT(guardObject);
- Q_ASSERT(guardObjectNotifyIndex != -1);
+ Q_ASSERT(notifyObject);
+ Q_ASSERT(notifyIndex != -1);
- if (properties.count() != guardListLength) {
+ if (properties.count() == 0) {
+ clear();
+ return;
+ }
+
+ if (properties.count() != length) {
QDeclarativeNotifierEndpoint *newGuardList = new QDeclarativeNotifierEndpoint[properties.count()];
- for (int ii = 0; ii < qMin(guardListLength, properties.count()); ++ii)
- guardList[ii].copyAndClear(newGuardList[ii]);
+ for (int ii = 0; ii < qMin(length, properties.count()); ++ii)
+ endpoints[ii].copyAndClear(newGuardList[ii]);
- delete [] guardList;
- guardList = newGuardList;
- guardListLength = properties.count();
+ delete [] endpoints;
+ endpoints = newGuardList;
+ length = properties.count();
}
bool outputWarningHeader = false;
bool noChanges = true;
for (int ii = 0; ii < properties.count(); ++ii) {
- QDeclarativeNotifierEndpoint &guard = guardList[ii];
+ QDeclarativeNotifierEndpoint &guard = endpoints[ii];
const QDeclarativeEnginePrivate::CapturedProperty &property = properties.at(ii);
- guard.target = guardObject;
- guard.targetMethod = guardObjectNotifyIndex;
+ guard.target = notifyObject;
+ guard.targetMethod = notifyIndex;
if (property.notifier != 0) {
@@ -630,7 +574,7 @@ void QDeclarativeQtScriptExpression::updateGuards(const QPODVector<QDeclarativeE
bool existing = false;
for (int jj = 0; !existing && jj < ii; ++jj)
- if (guardList[jj].isConnected(property.notifier))
+ if (endpoints[jj].isConnected(property.notifier))
existing = true;
if (existing) {
@@ -652,7 +596,7 @@ void QDeclarativeQtScriptExpression::updateGuards(const QPODVector<QDeclarativeE
bool existing = false;
for (int jj = 0; !existing && jj < ii; ++jj)
- if (guardList[jj].isConnected(property.object, property.notifyIndex))
+ if (endpoints[jj].isConnected(property.object, property.notifyIndex))
existing = true;
if (existing) {
@@ -663,7 +607,7 @@ void QDeclarativeQtScriptExpression::updateGuards(const QPODVector<QDeclarativeE
}
}
- } else {
+ } else if (!expression.isEmpty()) {
if (!outputWarningHeader) {
outputWarningHeader = true;
qWarning() << "QDeclarativeExpression: Expression" << expression
@@ -678,31 +622,31 @@ void QDeclarativeQtScriptExpression::updateGuards(const QPODVector<QDeclarativeE
}
}
-QScriptValue QDeclarativeExpressionPrivate::scriptValue(QObject *secondaryScope, bool *isUndefined)
+// Must be called with a valid handle scope
+v8::Local<v8::Value> QDeclarativeExpressionPrivate::v8value(QObject *secondaryScope, bool *isUndefined)
{
if (!expressionFunctionValid) {
- QDeclarativeEngine *engine = context()->engine;
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- expressionContext = ep->contextClass->newContext(context(), scopeObject);
- scriptContext->pushScope(expressionContext);
- scriptContext->pushScope(ep->globalClass->staticGlobalObject());
-
QDeclarativeRewrite::RewriteBinding rewriteBinding;
rewriteBinding.setName(name);
bool ok = true;
const QString code = rewriteBinding(expression, &ok);
- if (ok)
- expressionFunction = scriptEngine->evaluate(code, url, line);
-
- scriptEngine->popContext();
- expressionFunctionMode = ExplicitContext;
+ if (ok) v8function = evalFunction(context(), scopeObject(), code, url, line, &v8qmlscope);
+ setUseSharedContext(false);
expressionFunctionValid = true;
}
- return QDeclarativeQtScriptExpression::scriptValue(secondaryScope, isUndefined);
+
+ if (secondaryScope) {
+ v8::Local<v8::Value> result;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context()->engine);
+ QObject *restoreSecondaryScope = 0;
+ restoreSecondaryScope = ep->v8engine.contextWrapper()->setSecondaryScope(v8qmlscope, secondaryScope);
+ result = evaluate(v8function, isUndefined);
+ ep->v8engine.contextWrapper()->setSecondaryScope(v8qmlscope, restoreSecondaryScope);
+ return result;
+ } else {
+ return evaluate(v8function, isUndefined);
+ }
}
QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined)
@@ -715,10 +659,19 @@ QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isU
}
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(q->engine());
+ QVariant rv;
+
ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation.
- QVariant retn(ep->scriptValueToVariant(scriptValue(secondaryScope, isUndefined), qMetaTypeId<QList<QObject*> >()));
+
+ {
+ v8::HandleScope handle_scope;
+ v8::Local<v8::Value> result = v8value(secondaryScope, isUndefined);
+ rv = ep->v8engine.toVariant(result, qMetaTypeId<QList<QObject*> >());
+ }
+
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
- return retn;
+
+ return rv;
}
/*!
@@ -743,7 +696,7 @@ value changes.
bool QDeclarativeExpression::notifyOnValueChanged() const
{
Q_D(const QDeclarativeExpression);
- return d->notifyOnValueChange();
+ return d->notifyOnValueChanged();
}
/*!
@@ -765,7 +718,7 @@ bool QDeclarativeExpression::notifyOnValueChanged() const
void QDeclarativeExpression::setNotifyOnValueChanged(bool notifyOnChange)
{
Q_D(QDeclarativeExpression);
- d->setNotifyOnValueChange(notifyOnChange);
+ d->setNotifyOnValueChanged(notifyOnChange);
}
/*!
@@ -808,7 +761,7 @@ void QDeclarativeExpression::setSourceLocation(const QString &url, int line)
QObject *QDeclarativeExpression::scopeObject() const
{
Q_D(const QDeclarativeExpression);
- return d->scopeObject;
+ return d->scopeObject();
}
/*!
@@ -854,13 +807,6 @@ void QDeclarativeExpressionPrivate::_q_notify()
emitValueChanged();
}
-void QDeclarativeQtScriptExpression::clearGuards()
-{
- delete [] guardList;
- guardList = 0;
- guardListLength = 0;
-}
-
/*!
\fn void QDeclarativeExpression::valueChanged()
diff --git a/src/declarative/qml/qdeclarativeexpression.h b/src/declarative/qml/qdeclarativeexpression.h
index b76205c82e..edd93a1240 100644
--- a/src/declarative/qml/qdeclarativeexpression.h
+++ b/src/declarative/qml/qdeclarativeexpression.h
@@ -60,7 +60,6 @@ class QDeclarativeEngine;
class QDeclarativeContext;
class QDeclarativeExpressionPrivate;
class QDeclarativeContextData;
-class QScriptValue;
class Q_DECLARATIVE_EXPORT QDeclarativeExpression : public QObject
{
Q_OBJECT
@@ -97,10 +96,10 @@ Q_SIGNALS:
protected:
QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &,
QDeclarativeExpressionPrivate &dd);
- QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QScriptValue &,
+ QDeclarativeExpression(QDeclarativeContextData *, QObject *, void *,
QDeclarativeExpressionPrivate &dd);
- QDeclarativeExpression(QDeclarativeContextData *, void *, QDeclarativeRefCount *rc,
- QObject *me, const QString &, int, QDeclarativeExpressionPrivate &dd);
+ QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &, bool,
+ const QString &, int, QDeclarativeExpressionPrivate &dd);
private:
QDeclarativeExpression(QDeclarativeContextData *, QObject *, const QString &);
diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h
index 27d437d5b7..2a26c26700 100644
--- a/src/declarative/qml/qdeclarativeexpression_p.h
+++ b/src/declarative/qml/qdeclarativeexpression_p.h
@@ -55,10 +55,10 @@
#include "qdeclarativeexpression.h"
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativeguard_p.h"
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativeguard_p.h>
-#include <QtScript/qscriptvalue.h>
+#include <private/qv8engine_p.h>
QT_BEGIN_NAMESPACE
@@ -107,72 +107,84 @@ private:
QDeclarativeDelayedError **prevError;
};
-class QDeclarativeQtScriptExpression : public QDeclarativeAbstractExpression,
- public QDeclarativeDelayedError
+class QDeclarativeDeleteWatchable
{
public:
- enum Mode { SharedContext, ExplicitContext };
-
- enum EvaluateFlag { RequiresThisObject = 0x01 };
- Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
-
- QDeclarativeQtScriptExpression();
- virtual ~QDeclarativeQtScriptExpression();
+ inline QDeclarativeDeleteWatchable();
+ inline ~QDeclarativeDeleteWatchable();
+private:
+ friend class QDeclarativeDeleteWatcher;
+ bool *m_wasDeleted;
+};
- QDeclarativeRefCount *dataRef;
+class QDeclarativeDeleteWatcher {
+public:
+ inline QDeclarativeDeleteWatcher(QDeclarativeDeleteWatchable *data);
+ inline ~QDeclarativeDeleteWatcher();
+ inline bool wasDeleted() const;
+private:
+ void *operator new(size_t);
+ bool *m_wasDeleted;
+ bool m_wasDeletedStorage;
+ QDeclarativeDeleteWatchable *m_d;
+};
- QString expression;
+class QDeclarativeJavaScriptExpression : public QDeclarativeAbstractExpression,
+ public QDeclarativeDelayedError,
+ public QDeclarativeDeleteWatchable
+{
+public:
+ QDeclarativeJavaScriptExpression();
+ virtual ~QDeclarativeJavaScriptExpression();
- Mode expressionFunctionMode;
- QScriptValue expressionFunction;
+ v8::Local<v8::Value> evaluate(v8::Handle<v8::Function>, bool *isUndefined);
- QScriptValue expressionContext; // Only used in ExplicitContext
- QObject *scopeObject; // Only used in SharedContext
+ inline bool requiresThisObject() const;
+ inline void setRequiresThisObject(bool v);
+ inline bool useSharedContext() const;
+ inline void setUseSharedContext(bool v);
+ inline bool notifyOnValueChanged() const;
- bool notifyOnValueChange() const;
- void setNotifyOnValueChange(bool);
- void resetNotifyOnChange();
+ void setNotifyOnValueChanged(bool v);
+ void resetNotifyOnValueChanged();
void setNotifyObject(QObject *, int );
- void setEvaluateFlags(EvaluateFlags flags);
- EvaluateFlags evaluateFlags() const;
-
- QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined);
+ inline QObject *scopeObject() const;
+ inline void setScopeObject(QObject *v);
- class DeleteWatcher {
- public:
- inline DeleteWatcher(QDeclarativeQtScriptExpression *data);
- inline ~DeleteWatcher();
- inline bool wasDeleted() const;
- private:
- bool *m_wasDeleted;
- bool m_wasDeletedStorage;
- QDeclarativeQtScriptExpression *m_d;
- };
+protected:
+ inline virtual QStringRef expressionString();
private:
- void clearGuards();
- QScriptValue eval(QObject *secondaryScope, bool *isUndefined);
- void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties);
+ quint32 m_requiresThisObject:1;
+ quint32 m_useSharedContext:1;
+ quint32 m_notifyOnValueChanged:1;
+ quint32 m_dummy:29;
- bool trackChange;
+ QObject *m_scopeObject;
+ QObject *m_notifyObject;
+ int m_notifyIndex;
- QDeclarativeNotifierEndpoint *guardList;
- int guardListLength;
+ class GuardList {
+ public:
+ inline GuardList();
+ inline ~GuardList();
+ void inline clear();
- QObject *guardObject;
- int guardObjectNotifyIndex;
- bool *deleted;
+ typedef QPODVector<QDeclarativeEnginePrivate::CapturedProperty> CapturedProperties;
+ void updateGuards(QObject *guardObject, int guardObjectNotifyIndex,
+ const QStringRef &expression, const CapturedProperties &properties);
- EvaluateFlags evalFlags;
+ private:
+ QDeclarativeNotifierEndpoint *endpoints;
+ int length;
+ };
+ GuardList guardList;
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeQtScriptExpression::EvaluateFlags)
-
-
class QDeclarativeExpression;
class QString;
-class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeQtScriptExpression
+class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeJavaScriptExpression
{
Q_DECLARE_PUBLIC(QDeclarativeExpression)
public:
@@ -180,54 +192,142 @@ public:
~QDeclarativeExpressionPrivate();
void init(QDeclarativeContextData *, const QString &, QObject *);
- void init(QDeclarativeContextData *, const QScriptValue &, QObject *);
- void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int);
+ void init(QDeclarativeContextData *, v8::Handle<v8::Function>, QObject *);
+ void init(QDeclarativeContextData *, const QString &, bool, QObject *, const QString &, int);
QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0);
- QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0);
- static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) {
- return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
- }
- static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) {
- return expr->q_func();
- }
+ v8::Local<v8::Value> v8value(QObject *secondaryScope = 0, bool *isUndefined = 0);
+
+ static inline QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr);
+ static inline QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr);
void _q_notify();
virtual void emitValueChanged();
- static void exceptionToError(QScriptEngine *, QDeclarativeError &);
- static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &,
- int, QScriptValue *);
- static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &,
- QScriptValue *);
+ static void exceptionToError(v8::Handle<v8::Message>, QDeclarativeError &);
+ static v8::Persistent<v8::Function> evalFunction(QDeclarativeContextData *ctxt, QObject *scope,
+ const QString &code, const QString &filename, int line,
+ v8::Persistent<v8::Object> *qmlscope = 0);
bool expressionFunctionValid:1;
+ bool extractExpressionFromFunction:1;
+
+ inline virtual QStringRef expressionString();
+
+ QString expression;
+
+ v8::Persistent<v8::Object> v8qmlscope;
+ v8::Persistent<v8::Function> v8function;
QString url; // This is a QString for a reason. QUrls are slooooooow...
int line;
QByteArray name; //function name, hint for the debugger
+
+ QDeclarativeRefCount *dataRef;
};
-QDeclarativeQtScriptExpression::DeleteWatcher::DeleteWatcher(QDeclarativeQtScriptExpression *data)
+QDeclarativeDeleteWatchable::QDeclarativeDeleteWatchable()
+: m_wasDeleted(0)
+{
+}
+
+QDeclarativeDeleteWatchable::~QDeclarativeDeleteWatchable()
+{
+ if (m_wasDeleted) *m_wasDeleted = true;
+}
+
+QDeclarativeDeleteWatcher::QDeclarativeDeleteWatcher(QDeclarativeDeleteWatchable *data)
: m_wasDeletedStorage(false), m_d(data)
{
- if (!m_d->deleted)
- m_d->deleted = &m_wasDeletedStorage;
- m_wasDeleted = m_d->deleted;
+ if (!m_d->m_wasDeleted)
+ m_d->m_wasDeleted = &m_wasDeletedStorage;
+ m_wasDeleted = m_d->m_wasDeleted;
}
-QDeclarativeQtScriptExpression::DeleteWatcher::~DeleteWatcher()
+QDeclarativeDeleteWatcher::~QDeclarativeDeleteWatcher()
{
- if (false == *m_wasDeleted && m_wasDeleted == m_d->deleted)
- m_d->deleted = 0;
+ if (false == *m_wasDeleted && m_wasDeleted == m_d->m_wasDeleted)
+ m_d->m_wasDeleted = 0;
}
-bool QDeclarativeQtScriptExpression::DeleteWatcher::wasDeleted() const
+bool QDeclarativeDeleteWatcher::wasDeleted() const
{
return *m_wasDeleted;
}
+bool QDeclarativeJavaScriptExpression::requiresThisObject() const
+{
+ return m_requiresThisObject;
+}
+
+void QDeclarativeJavaScriptExpression::setRequiresThisObject(bool v)
+{
+ m_requiresThisObject = v;
+}
+
+bool QDeclarativeJavaScriptExpression::useSharedContext() const
+{
+ return m_useSharedContext;
+}
+
+void QDeclarativeJavaScriptExpression::setUseSharedContext(bool v)
+{
+ m_useSharedContext = v;
+}
+
+bool QDeclarativeJavaScriptExpression::notifyOnValueChanged() const
+{
+ return m_notifyOnValueChanged;
+}
+
+QObject *QDeclarativeJavaScriptExpression::scopeObject() const
+{
+ return m_scopeObject;
+}
+
+void QDeclarativeJavaScriptExpression::setScopeObject(QObject *v)
+{
+ m_scopeObject = v;
+}
+
+QStringRef QDeclarativeJavaScriptExpression::expressionString()
+{
+ return QStringRef();
+}
+
+QDeclarativeJavaScriptExpression::GuardList::GuardList()
+: endpoints(0), length(0)
+{
+}
+
+QDeclarativeJavaScriptExpression::GuardList::~GuardList()
+{
+ clear();
+}
+
+void QDeclarativeJavaScriptExpression::GuardList::clear()
+{
+ delete [] endpoints;
+ endpoints = 0;
+ length = 0;
+}
+
+QDeclarativeExpressionPrivate *QDeclarativeExpressionPrivate::get(QDeclarativeExpression *expr)
+{
+ return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
+}
+
+QDeclarativeExpression *QDeclarativeExpressionPrivate::get(QDeclarativeExpressionPrivate *expr)
+{
+ return expr->q_func();
+}
+
+QStringRef QDeclarativeExpressionPrivate::expressionString()
+{
+ return QStringRef(&expression);
+}
+
QT_END_NAMESPACE
#endif // QDECLARATIVEEXPRESSION_P_H
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
deleted file mode 100644
index f465d9c4ac..0000000000
--- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativeglobalscriptclass_p.h"
-
-#include <QtCore/qstringlist.h>
-#include <QtCore/qvector.h>
-#include <QtScript/qscriptstring.h>
-#include <QtScript/qscriptengine.h>
-#include <QtScript/qscriptvalueiterator.h>
-
-#include <private/qscriptdeclarativeclass_p.h>
-
-QT_BEGIN_NAMESPACE
-
-/*
- Used to prevent any writes to the global object.
-*/
-QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engine)
-: QScriptClass(engine)
-{
- QString eval = QLatin1String("eval");
- QString version = QLatin1String("version");
-
- QScriptValue originalGlobalObject = engine->globalObject();
-
- QScriptValue newGlobalObject = engine->newObject();
-
- {
- QScriptValueIterator iter(originalGlobalObject);
- QVector<QString> names;
- QVector<QScriptValue> values;
- QVector<QScriptValue::PropertyFlags> flags;
- while (iter.hasNext()) {
- iter.next();
-
- QString name = iter.name();
-
- if (name == version)
- continue;
-
- if (name != eval) {
- names.append(name);
- values.append(iter.value());
- flags.append(iter.flags() | QScriptValue::Undeletable);
- }
- newGlobalObject.setProperty(iter.scriptName(), iter.value());
-
- m_illegalNames.insert(name);
- }
- m_staticGlobalObject = QScriptDeclarativeClass::newStaticScopeObject(
- engine, names.size(), names.constData(), values.constData(), flags.constData());
- }
-
- newGlobalObject.setScriptClass(this);
- engine->setGlobalObject(newGlobalObject);
-}
-
-QScriptClass::QueryFlags
-QDeclarativeGlobalScriptClass::queryProperty(const QScriptValue &object,
- const QScriptString &name,
- QueryFlags flags, uint *id)
-{
- Q_UNUSED(object);
- Q_UNUSED(name);
- Q_UNUSED(flags);
- Q_UNUSED(id);
- return HandlesWriteAccess;
-}
-
-void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object,
- const QScriptString &name,
- uint id, const QScriptValue &value)
-{
- Q_UNUSED(object);
- Q_UNUSED(id);
- Q_UNUSED(value);
- QString error = QLatin1String("Invalid write to global property \"") +
- name.toString() + QLatin1Char('\"');
- engine()->currentContext()->throwError(error);
-}
-
-/* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */
-void QDeclarativeGlobalScriptClass::explicitSetProperty(const QStringList &names, const QList<QScriptValue> &values)
-{
- Q_ASSERT(names.count() == values.count());
- QScriptValue globalObject = engine()->globalObject();
-
- QScriptValue v = engine()->newObject();
-
- QScriptValueIterator iter(v);
- while (iter.hasNext()) {
- iter.next();
- v.setProperty(iter.scriptName(), iter.value());
- }
-
- for (int ii = 0; ii < names.count(); ++ii) {
- const QString &name = names.at(ii);
- const QScriptValue &value = values.at(ii);
- v.setProperty(name, value);
- }
-
- v.setScriptClass(this);
-
- engine()->setGlobalObject(v);
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp
deleted file mode 100644
index bf2cd617e2..0000000000
--- a/src/declarative/qml/qdeclarativeinclude.cpp
+++ /dev/null
@@ -1,310 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "qdeclarativeinclude_p.h"
-
-#include <QtScript/qscriptengine.h>
-#include <QtNetwork/qnetworkrequest.h>
-#include <QtNetwork/qnetworkreply.h>
-#include <QtCore/qfile.h>
-
-#include <private/qdeclarativeengine_p.h>
-#include <private/qdeclarativeglobalscriptclass_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QDeclarativeInclude::QDeclarativeInclude(const QUrl &url,
- QDeclarativeEngine *engine,
- QScriptContext *ctxt)
-: QObject(engine), m_engine(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0)
-{
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- m_context = ep->contextClass->contextFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
-
- m_scope[0] = QScriptDeclarativeClass::scopeChainValue(ctxt, -4);
- m_scope[1] = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
-
- m_scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- m_network = QDeclarativeScriptEngine::get(m_scriptEngine)->networkAccessManager();
-
- m_result = resultValue(m_scriptEngine);
-
- QNetworkRequest request;
- request.setUrl(url);
-
- m_reply = m_network->get(request);
- QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
-}
-
-QDeclarativeInclude::~QDeclarativeInclude()
-{
- delete m_reply;
-}
-
-QScriptValue QDeclarativeInclude::resultValue(QScriptEngine *engine, Status status)
-{
- QScriptValue result = engine->newObject();
- result.setProperty(QLatin1String("OK"), QScriptValue(engine, Ok));
- result.setProperty(QLatin1String("LOADING"), QScriptValue(engine, Loading));
- result.setProperty(QLatin1String("NETWORK_ERROR"), QScriptValue(engine, NetworkError));
- result.setProperty(QLatin1String("EXCEPTION"), QScriptValue(engine, Exception));
-
- result.setProperty(QLatin1String("status"), QScriptValue(engine, status));
- return result;
-}
-
-QScriptValue QDeclarativeInclude::result() const
-{
- return m_result;
-}
-
-void QDeclarativeInclude::setCallback(const QScriptValue &c)
-{
- m_callback = c;
-}
-
-QScriptValue QDeclarativeInclude::callback() const
-{
- return m_callback;
-}
-
-#define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15
-void QDeclarativeInclude::finished()
-{
- m_redirectCount++;
-
- if (m_redirectCount < INCLUDE_MAXIMUM_REDIRECT_RECURSION) {
- QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
- if (redirect.isValid()) {
- m_url = m_url.resolved(redirect.toUrl());
- delete m_reply;
-
- QNetworkRequest request;
- request.setUrl(m_url);
-
- m_reply = m_network->get(request);
- QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
- return;
- }
- }
-
- if (m_reply->error() == QNetworkReply::NoError) {
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(m_engine);
-
- QByteArray data = m_reply->readAll();
-
- QString code = QString::fromUtf8(data);
-
- QString urlString = m_url.toString();
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(m_scriptEngine);
- scriptContext->pushScope(ep->contextClass->newUrlContext(m_context, 0, urlString));
- scriptContext->pushScope(m_scope[0]);
-
- scriptContext->pushScope(m_scope[1]);
- scriptContext->setActivationObject(m_scope[1]);
- QDeclarativeScriptParser::extractPragmas(code);
-
- m_scriptEngine->evaluate(code, urlString, 1);
-
- m_scriptEngine->popContext();
-
- if (m_scriptEngine->hasUncaughtException()) {
- m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Exception));
- m_result.setProperty(QLatin1String("exception"), m_scriptEngine->uncaughtException());
- m_scriptEngine->clearExceptions();
- } else {
- m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Ok));
- }
- } else {
- m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, NetworkError));
- }
-
- callback(m_scriptEngine, m_callback, m_result);
-
- disconnect();
- deleteLater();
-}
-
-void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback, QScriptValue &status)
-{
- if (callback.isValid()) {
- QScriptValue args = engine->newArray(1);
- args.setProperty(0, status);
- callback.call(QScriptValue(), args);
- }
-}
-
-/*
- Documented in qdeclarativeengine.cpp
-*/
-QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if (ctxt->argumentCount() == 0)
- return engine->undefinedValue();
-
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-
- QUrl contextUrl = ep->contextClass->urlFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
- if (contextUrl.isEmpty())
- return ctxt->throwError(QLatin1String("Qt.include(): Can only be called from JavaScript files"));
-
- QString urlString = ctxt->argument(0).toString();
- QUrl url(urlString);
- if (url.isRelative()) {
- url = QUrl(contextUrl).resolved(url);
- urlString = url.toString();
- }
-
- QString localFile = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
-
- QScriptValue func = ctxt->argument(1);
- if (!func.isFunction())
- func = QScriptValue();
-
- QScriptValue result;
- if (localFile.isEmpty()) {
- QDeclarativeInclude *i =
- new QDeclarativeInclude(url, QDeclarativeEnginePrivate::getEngine(engine), ctxt);
-
- if (func.isValid())
- i->setCallback(func);
-
- result = i->result();
- } else {
-
- QFile f(localFile);
- if (f.open(QIODevice::ReadOnly)) {
- QByteArray data = f.readAll();
- QString code = QString::fromUtf8(data);
-
- QDeclarativeContextData *context =
- ep->contextClass->contextFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
-
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
- scriptContext->pushScope(ep->contextClass->newUrlContext(context, 0, urlString));
- scriptContext->pushScope(ep->globalClass->staticGlobalObject());
- QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
- scriptContext->pushScope(scope);
- scriptContext->setActivationObject(scope);
- QDeclarativeScriptParser::extractPragmas(code);
-
- engine->evaluate(code, urlString, 1);
-
- engine->popContext();
-
- if (engine->hasUncaughtException()) {
- result = resultValue(engine, Exception);
- result.setProperty(QLatin1String("exception"), engine->uncaughtException());
- engine->clearExceptions();
- } else {
- result = resultValue(engine, Ok);
- }
- callback(engine, func, result);
- } else {
- result = resultValue(engine, NetworkError);
- callback(engine, func, result);
- }
- }
-
- return result;
-}
-
-QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEngine *engine)
-{
- if (ctxt->argumentCount() == 0)
- return engine->undefinedValue();
-
- QString urlString = ctxt->argument(0).toString();
- QUrl url(ctxt->argument(0).toString());
- if (url.isRelative()) {
- QString contextUrl = QScriptDeclarativeClass::scopeChainValue(ctxt, -3).data().toString();
- Q_ASSERT(!contextUrl.isEmpty());
-
- url = QUrl(contextUrl).resolved(url);
- urlString = url.toString();
- }
-
- QString localFile = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
-
- QScriptValue func = ctxt->argument(1);
- if (!func.isFunction())
- func = QScriptValue();
-
- QScriptValue result;
- if (!localFile.isEmpty()) {
-
- QFile f(localFile);
- if (f.open(QIODevice::ReadOnly)) {
- QByteArray data = f.readAll();
- QString code = QString::fromUtf8(data);
-
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
- QScriptValue urlContext = engine->newObject();
- urlContext.setData(QScriptValue(engine, urlString));
- scriptContext->pushScope(urlContext);
-
- QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4);
- scriptContext->pushScope(scope);
- scriptContext->setActivationObject(scope);
- QDeclarativeScriptParser::extractPragmas(code);
-
- engine->evaluate(code, urlString, 1);
-
- engine->popContext();
-
- if (engine->hasUncaughtException()) {
- result = resultValue(engine, Exception);
- result.setProperty(QLatin1String("exception"), engine->uncaughtException());
- engine->clearExceptions();
- } else {
- result = resultValue(engine, Ok);
- }
- callback(engine, func, result);
- } else {
- result = resultValue(engine, NetworkError);
- callback(engine, func, result);
- }
- }
-
- return result;
-}
-
-QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeinstruction.cpp b/src/declarative/qml/qdeclarativeinstruction.cpp
index 79a2a1cc34..f99351bde5 100644
--- a/src/declarative/qml/qdeclarativeinstruction.cpp
+++ b/src/declarative/qml/qdeclarativeinstruction.cpp
@@ -168,15 +168,21 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx)
case QDeclarativeInstruction::AssignCustomType:
qWarning().nospace() << idx << "\t\t" << "ASSIGN_CUSTOMTYPE\t" << instr->assignCustomType.propertyIndex << "\t" << instr->assignCustomType.primitive << "\t" << instr->assignCustomType.type;
break;
+ case QDeclarativeInstruction::InitV8Bindings:
+ qWarning().nospace() << idx << "\t\t" << "INIT_V8_BINDING\t" << instr->initV8Bindings.program << "\t" << instr->initV8Bindings.programIndex << "\t" << instr->initV8Bindings.line;
+ break;
case QDeclarativeInstruction::StoreBinding:
qWarning().nospace() << idx << "\t\t" << "STORE_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t" << instr->assignBinding.context;
break;
case QDeclarativeInstruction::StoreBindingOnAlias:
qWarning().nospace() << idx << "\t\t" << "STORE_BINDING_ALIAS\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t" << instr->assignBinding.context;
break;
- case QDeclarativeInstruction::StoreCompiledBinding:
+ case QDeclarativeInstruction::StoreV4Binding:
qWarning().nospace() << idx << "\t\t" << "STORE_COMPILED_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t" << instr->assignBinding.context;
break;
+ case QDeclarativeInstruction::StoreV8Binding:
+ qWarning().nospace() << idx << "\t\t" << "STORE_V8_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t" << instr->assignBinding.context;
+ break;
case QDeclarativeInstruction::StoreValueSource:
qWarning().nospace() << idx << "\t\t" << "STORE_VALUE_SOURCE\t" << instr->assignValueSource.property << "\t" << instr->assignValueSource.castValue;
break;
diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h
index 3db55a66d3..a48c44c32e 100644
--- a/src/declarative/qml/qdeclarativeinstruction_p.h
+++ b/src/declarative/qml/qdeclarativeinstruction_p.h
@@ -95,9 +95,11 @@ QT_BEGIN_NAMESPACE
F(StoreImportedScript, storeScript) \
F(StoreScriptString, storeScriptString) \
F(BeginObject, begin) \
+ F(InitV8Bindings, initV8Bindings) \
F(StoreBinding, assignBinding) \
F(StoreBindingOnAlias, assignBinding) \
- F(StoreCompiledBinding, assignBinding) \
+ F(StoreV4Binding, assignBinding) \
+ F(StoreV8Binding, assignBinding) \
F(StoreValueSource, assignValueSource) \
F(StoreValueInterceptor, assignValueInterceptor) \
F(StoreObjectQList, common) \
@@ -182,6 +184,12 @@ union QDeclarativeInstruction
int owner;
int castValue;
};
+ struct instr_initV8Bindings {
+ QML_INSTR_HEADER
+ int program;
+ ushort programIndex;
+ ushort line;
+ };
struct instr_assignBinding {
QML_INSTR_HEADER
unsigned int property;
@@ -360,13 +368,8 @@ union QDeclarativeInstruction
QML_INSTR_HEADER
int propertyIndex;
struct QPoint {
-#if defined(Q_OS_MAC)
- int yp;
- int xp;
-#else
int xp;
int yp;
-#endif
} point;
};
struct instr_storePointF {
@@ -411,6 +414,7 @@ union QDeclarativeInstruction
instr_setId setId;
instr_assignValueSource assignValueSource;
instr_assignValueInterceptor assignValueInterceptor;
+ instr_initV8Bindings initV8Bindings;
instr_assignBinding assignBinding;
instr_fetch fetch;
instr_fetchValue fetchValue;
diff --git a/src/declarative/qml/qdeclarativeintegercache.cpp b/src/declarative/qml/qdeclarativeintegercache.cpp
index 09beb13340..ef99c63086 100644
--- a/src/declarative/qml/qdeclarativeintegercache.cpp
+++ b/src/declarative/qml/qdeclarativeintegercache.cpp
@@ -41,34 +41,21 @@
#include "private/qdeclarativeintegercache_p.h"
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativemetatype_p.h"
-
QT_BEGIN_NAMESPACE
-QDeclarativeIntegerCache::QDeclarativeIntegerCache(QDeclarativeEngine *e)
-: QDeclarativeCleanup(e), engine(e)
+QDeclarativeIntegerCache::QDeclarativeIntegerCache()
{
}
QDeclarativeIntegerCache::~QDeclarativeIntegerCache()
{
- clear();
-}
-
-void QDeclarativeIntegerCache::clear()
-{
- qDeleteAll(stringCache);
- stringCache.clear();
- identifierCache.clear();
- engine = 0;
}
QString QDeclarativeIntegerCache::findId(int value) const
{
for (StringCache::ConstIterator iter = stringCache.begin();
iter != stringCache.end(); ++iter) {
- if (iter.value() && iter.value()->value == value)
+ if (iter.value() == value)
return iter.key();
}
return QString();
@@ -78,19 +65,13 @@ void QDeclarativeIntegerCache::add(const QString &id, int value)
{
Q_ASSERT(!stringCache.contains(id));
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
-
- // ### use contextClass
- Data *d = new Data(enginePriv->objectClass->createPersistentIdentifier(id), value);
-
- stringCache.insert(id, d);
- identifierCache.insert(d->identifier, d);
+ stringCache.insert(id, value);
}
int QDeclarativeIntegerCache::value(const QString &id)
{
- Data *d = stringCache.value(id);
- return d?d->value:-1;
+ int *rv = stringCache.value(id);
+ return rv?*rv:-1;
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeintegercache_p.h b/src/declarative/qml/qdeclarativeintegercache_p.h
index 79506cc764..a66457cede 100644
--- a/src/declarative/qml/qdeclarativeintegercache_p.h
+++ b/src/declarative/qml/qdeclarativeintegercache_p.h
@@ -54,51 +54,35 @@
//
#include "private/qdeclarativerefcount_p.h"
-#include "private/qdeclarativecleanup_p.h"
-
-#include <QtCore/qhash.h>
-
-#include <private/qscriptdeclarativeclass_p.h>
+#include "private/qhashedstring_p.h"
QT_BEGIN_NAMESPACE
class QDeclarativeType;
class QDeclarativeEngine;
-class QDeclarativeIntegerCache : public QDeclarativeRefCount, public QDeclarativeCleanup
+class QDeclarativeIntegerCache : public QDeclarativeRefCount
{
public:
- QDeclarativeIntegerCache(QDeclarativeEngine *);
+ QDeclarativeIntegerCache();
virtual ~QDeclarativeIntegerCache();
inline int count() const;
void add(const QString &, int);
+
int value(const QString &);
- QString findId(int value) const;
- inline int value(const QScriptDeclarativeClass::Identifier &id) const;
+ inline int value(const QHashedV8String &);
-protected:
- virtual void clear();
+ QString findId(int value) const;
private:
- struct Data : public QScriptDeclarativeClass::PersistentIdentifier {
- Data(const QScriptDeclarativeClass::PersistentIdentifier &i, int v)
- : QScriptDeclarativeClass::PersistentIdentifier(i), value(v) {}
-
- int value;
- };
-
- typedef QHash<QString, Data *> StringCache;
- typedef QHash<QScriptDeclarativeClass::Identifier, Data *> IdentifierCache;
-
+ typedef QStringHash<int> StringCache;
StringCache stringCache;
- IdentifierCache identifierCache;
- QDeclarativeEngine *engine;
};
-int QDeclarativeIntegerCache::value(const QScriptDeclarativeClass::Identifier &id) const
+int QDeclarativeIntegerCache::value(const QHashedV8String &name)
{
- Data *d = identifierCache.value(id);
- return d?d->value:-1;
+ int *result = stringCache.value(name);
+ return result?*result:-1;
}
int QDeclarativeIntegerCache::count() const
diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp
index ff3dfc9458..458812a896 100644
--- a/src/declarative/qml/qdeclarativelist.cpp
+++ b/src/declarative/qml/qdeclarativelist.cpp
@@ -139,7 +139,7 @@ QDeclarativeListReference::QDeclarativeListReference(QObject *object, const char
QDeclarativePropertyCache::Data *data =
QDeclarativePropertyCache::property(engine, object, QLatin1String(property), local);
- if (!data || !(data->flags & QDeclarativePropertyCache::Data::IsQList)) return;
+ if (!data || !data->isQList()) return;
QDeclarativeEnginePrivate *p = engine?QDeclarativeEnginePrivate::get(engine):0;
diff --git a/src/declarative/qml/qdeclarativelistscriptclass.cpp b/src/declarative/qml/qdeclarativelistscriptclass.cpp
deleted file mode 100644
index 782cb4013e..0000000000
--- a/src/declarative/qml/qdeclarativelistscriptclass.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativelistscriptclass_p.h"
-
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativeguard_p.h"
-#include "private/qdeclarativelist_p.h"
-
-QT_BEGIN_NAMESPACE
-
-struct ListData : public QScriptDeclarativeClass::Object {
- QDeclarativeGuard<QObject> object;
- QDeclarativeListProperty<QObject> property;
- int propertyType;
-};
-
-QDeclarativeListScriptClass::QDeclarativeListScriptClass(QDeclarativeEngine *e)
-: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(e)), engine(e)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- Q_UNUSED(scriptEngine);
-
- m_lengthId = createPersistentIdentifier(QLatin1String("length"));
-}
-
-QDeclarativeListScriptClass::~QDeclarativeListScriptClass()
-{
-}
-
-QScriptValue QDeclarativeListScriptClass::newList(QObject *object, int propId, int propType)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- if (!object || propId == -1)
- return scriptEngine->nullValue();
-
- ListData *data = new ListData;
- data->object = object;
- data->propertyType = propType;
- void *args[] = { &data->property, 0 };
- QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args);
-
- return newObject(scriptEngine, this, data);
-}
-
-QScriptValue QDeclarativeListScriptClass::newList(const QDeclarativeListProperty<QObject> &prop, int propType)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- ListData *data = new ListData;
- data->object = prop.object;
- data->property = prop;
- data->propertyType = propType;
-
- return newObject(scriptEngine, this, data);
-}
-
-QScriptClass::QueryFlags
-QDeclarativeListScriptClass::queryProperty(Object *object, const Identifier &name,
- QScriptClass::QueryFlags flags)
-{
- Q_UNUSED(object);
- Q_UNUSED(flags);
- if (name == m_lengthId.identifier)
- return QScriptClass::HandlesReadAccess;
-
- bool ok = false;
- quint32 idx = toArrayIndex(name, &ok);
-
- if (ok) {
- lastIndex = idx;
- return QScriptClass::HandlesReadAccess;
- } else {
- return 0;
- }
-}
-
-QDeclarativeListScriptClass::Value QDeclarativeListScriptClass::property(Object *obj, const Identifier &name)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
-
- ListData *data = (ListData *)obj;
- if (!data->object)
- return Value();
-
- quint32 count = data->property.count?data->property.count(&data->property):0;
-
- if (name == m_lengthId.identifier)
- return Value(scriptEngine, count);
- else if (lastIndex < count && data->property.at)
- return Value(scriptEngine, enginePriv->objectClass->newQObject(data->property.at(&data->property, lastIndex)));
- else
- return Value();
-}
-
-QVariant QDeclarativeListScriptClass::toVariant(Object *obj, bool *ok)
-{
- ListData *data = (ListData *)obj;
-
- if (!data->object) {
- if (ok) *ok = false;
- return QVariant();
- }
-
- return QVariant::fromValue(QDeclarativeListReferencePrivate::init(data->property, data->propertyType, engine));
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp
index 73ed23ba9d..aab5f63f08 100644
--- a/src/declarative/qml/qdeclarativemetatype.cpp
+++ b/src/declarative/qml/qdeclarativemetatype.cpp
@@ -1099,8 +1099,10 @@ QT_END_NAMESPACE
#include <QtGui/qvector3d.h>
#include <QtGui/qvector4d.h>
#include <QtGui/qquaternion.h>
+#include <private/qv8engine_p.h>
Q_DECLARE_METATYPE(QScriptValue);
+Q_DECLARE_METATYPE(QDeclarativeV8Handle);
QT_BEGIN_NAMESPACE
@@ -1181,6 +1183,7 @@ bool QDeclarativeMetaType::canCopy(int type)
default:
if (type == qMetaTypeId<QVariant>() ||
type == qMetaTypeId<QScriptValue>() ||
+ type == qMetaTypeId<QDeclarativeV8Handle>() ||
typeCategory(type) != Unknown) {
return true;
}
@@ -1403,6 +1406,9 @@ bool QDeclarativeMetaType::copy(int type, void *data, const void *copy)
} else if (type == qMetaTypeId<QScriptValue>()) {
*static_cast<NS(QScriptValue) *>(data) = *static_cast<const NS(QScriptValue)*>(copy);
return true;
+ } else if (type == qMetaTypeId<QDeclarativeV8Handle>()) {
+ *static_cast<NS(QDeclarativeV8Handle) *>(data) = *static_cast<const NS(QDeclarativeV8Handle)*>(copy);
+ return true;
} else if (typeCategory(type) != Unknown) {
*static_cast<void **>(data) = *static_cast<void* const *>(copy);
return true;
@@ -1610,6 +1616,9 @@ bool QDeclarativeMetaType::copy(int type, void *data, const void *copy)
} else if (type == qMetaTypeId<QScriptValue>()) {
*static_cast<NS(QScriptValue) *>(data) = NS(QScriptValue)();
return true;
+ } else if (type == qMetaTypeId<QDeclarativeV8Handle>()) {
+ *static_cast<NS(QDeclarativeV8Handle) *>(data) = NS(QDeclarativeV8Handle)();
+ return true;
} else if (typeCategory(type) != Unknown) {
*static_cast<void **>(data) = 0;
return true;
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
deleted file mode 100644
index 53f702ce51..0000000000
--- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
+++ /dev/null
@@ -1,1226 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativeobjectscriptclass_p.h"
-
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativecontext_p.h"
-#include "private/qdeclarativedata_p.h"
-#include "private/qdeclarativetypenamescriptclass_p.h"
-#include "private/qdeclarativelistscriptclass_p.h"
-#include "private/qdeclarativebinding_p.h"
-#include "private/qdeclarativeguard_p.h"
-#include "private/qdeclarativevmemetaobject_p.h"
-
-#include <QtCore/qtimer.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtScript/qscriptcontextinfo.h>
-
-Q_DECLARE_METATYPE(QScriptValue)
-
-#if defined(__GNUC__)
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
-// The code in this file does not violate strict aliasing, but GCC thinks it does
-// so turn off the warnings for us to have a clean build
-# pragma GCC diagnostic ignored "-Wstrict-aliasing"
-# endif
-#endif
-
-QT_BEGIN_NAMESPACE
-
-struct ObjectData : public QScriptDeclarativeClass::Object {
- ObjectData(QObject *o, int t) : object(o), type(t) {
- if (o) {
- QDeclarativeData *ddata = QDeclarativeData::get(object, true);
- if (ddata) ddata->objectDataRefCount++;
- }
- }
-
- virtual ~ObjectData() {
- if (object && !object->parent()) {
- QDeclarativeData *ddata = QDeclarativeData::get(object, false);
- if (ddata && !ddata->indestructible && 0 == --ddata->objectDataRefCount)
- object->deleteLater();
- }
- }
-
- QDeclarativeGuard<QObject> object;
- int type;
-};
-
-/*
- The QDeclarativeObjectScriptClass handles property access for QObjects
- via QtScript. It is also used to provide a more useful API in
- QtScript for QML.
- */
-QDeclarativeObjectScriptClass::QDeclarativeObjectScriptClass(QDeclarativeEngine *bindEngine)
-: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)),
- methods(bindEngine), lastData(0), engine(bindEngine)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- m_destroy = scriptEngine->newFunction(destroy);
- m_destroyId = createPersistentIdentifier(QLatin1String("destroy"));
- m_toString = scriptEngine->newFunction(tostring);
- m_toStringId = createPersistentIdentifier(QLatin1String("toString"));
-}
-
-QDeclarativeObjectScriptClass::~QDeclarativeObjectScriptClass()
-{
-}
-
-QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- if (!object)
- return scriptEngine->nullValue();
-// return newObject(scriptEngine, this, new ObjectData(object, type));
-
- if (QObjectPrivate::get(object)->wasDeleted)
- return scriptEngine->undefinedValue();
-
- QDeclarativeData *ddata = QDeclarativeData::get(object, true);
-
- if (!ddata) {
- return scriptEngine->undefinedValue();
- } else if (!ddata->indestructible && !object->parent()) {
- return newObject(scriptEngine, this, new ObjectData(object, type));
- } else if (!ddata->scriptValue) {
- ddata->scriptValue = new QScriptValue(newObject(scriptEngine, this, new ObjectData(object, type)));
- return *ddata->scriptValue;
- } else if (ddata->scriptValue->engine() == QDeclarativeEnginePrivate::getScriptEngine(engine)) {
- return *ddata->scriptValue;
- } else {
- return newObject(scriptEngine, this, new ObjectData(object, type));
- }
-}
-
-QObject *QDeclarativeObjectScriptClass::toQObject(const QScriptValue &value) const
-{
- return value.toQObject();
-}
-
-int QDeclarativeObjectScriptClass::objectType(const QScriptValue &value) const
-{
- if (scriptClass(value) != this)
- return QVariant::Invalid;
-
- Object *o = object(value);
- return ((ObjectData*)(o))->type;
-}
-
-QScriptClass::QueryFlags
-QDeclarativeObjectScriptClass::queryProperty(Object *object, const Identifier &name,
- QScriptClass::QueryFlags flags)
-{
- return queryProperty(toQObject(object), name, flags, 0);
-}
-
-QScriptClass::QueryFlags
-QDeclarativeObjectScriptClass::queryProperty(QObject *obj, const Identifier &name,
- QScriptClass::QueryFlags flags, QDeclarativeContextData *evalContext,
- QueryHints hints)
-{
- Q_UNUSED(flags);
- lastData = 0;
- lastTNData = 0;
-
- if (name == m_destroyId.identifier ||
- name == m_toStringId.identifier)
- return QScriptClass::HandlesReadAccess;
-
- if (!obj)
- return 0;
-
- QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine);
- lastData = QDeclarativePropertyCache::property(engine, obj, name, local);
- if ((hints & ImplicitObject) && lastData && lastData->revision != 0) {
-
- QDeclarativeData *ddata = QDeclarativeData::get(obj);
- if (ddata && ddata->propertyCache && !ddata->propertyCache->isAllowedInRevision(lastData))
- return 0;
- }
-
- if (lastData)
- return QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess;
-
- if (!(hints & SkipAttachedProperties)) {
- if (!evalContext && context()) {
- // Global object, QScriptContext activation object, QDeclarativeContext object
- QScriptValue scopeNode = scopeChainValue(context(), -3);
- if (scopeNode.isValid()) {
- Q_ASSERT(scriptClass(scopeNode) == enginePrivate->contextClass);
-
- evalContext = enginePrivate->contextClass->contextFromValue(scopeNode);
- }
- }
-
- if (evalContext && evalContext->imports) {
- QDeclarativeTypeNameCache::Data *data = evalContext->imports->data(name);
- if (data) {
- lastTNData = data;
- return QScriptClass::HandlesReadAccess;
- }
- }
- }
-
- if (!(hints & ImplicitObject)) {
- local.coreIndex = -1;
- lastData = &local;
- return QScriptClass::HandlesWriteAccess;
- }
-
- return 0;
-}
-
-QDeclarativeObjectScriptClass::Value
-QDeclarativeObjectScriptClass::property(Object *object, const Identifier &name)
-{
- return property(toQObject(object), name);
-}
-
-QDeclarativeObjectScriptClass::Value
-QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- if (name == m_destroyId.identifier)
- return Value(scriptEngine, m_destroy);
- else if (name == m_toStringId.identifier)
- return Value(scriptEngine, m_toString);
-
- if (lastData && !lastData->isValid())
- return Value();
-
- Q_ASSERT(obj);
-
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
-
- if (lastTNData) {
-
- if (lastTNData->type)
- return Value(scriptEngine, enginePriv->typeNameClass->newObject(obj, lastTNData->type));
- else
- return Value(scriptEngine, enginePriv->typeNameClass->newObject(obj, lastTNData->typeNamespace));
-
- } else if (lastData->flags & QDeclarativePropertyCache::Data::IsFunction) {
- if (lastData->flags & QDeclarativePropertyCache::Data::IsVMEFunction) {
- return Value(scriptEngine, ((QDeclarativeVMEMetaObject *)(obj->metaObject()))->vmeMethod(lastData->coreIndex));
- } else {
- // Uncomment to use QtScript method call logic
- // QScriptValue sobj = scriptEngine->newQObject(obj);
- // return Value(scriptEngine, sobj.property(toString(name)));
- return Value(scriptEngine, methods.newMethod(obj, lastData));
- }
- } else {
- if (enginePriv->captureProperties && !(lastData->flags & QDeclarativePropertyCache::Data::IsConstant)) {
- if (lastData->coreIndex == 0) {
- enginePriv->capturedProperties <<
- QDeclarativeEnginePrivate::CapturedProperty(QDeclarativeData::get(obj, true)->objectNameNotifier());
- } else {
- enginePriv->capturedProperties <<
- QDeclarativeEnginePrivate::CapturedProperty(obj, lastData->coreIndex, lastData->notifyIndex);
- }
- }
-
- if (QDeclarativeValueTypeFactory::isValueType((uint)lastData->propType)) {
- QDeclarativeValueType *valueType = enginePriv->valueTypes[lastData->propType];
- if (valueType)
- return Value(scriptEngine, enginePriv->valueTypeClass->newObject(obj, lastData->coreIndex, valueType));
- }
-
- if (lastData->flags & QDeclarativePropertyCache::Data::IsQList) {
- return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, lastData->propType));
- } else if (lastData->flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
- QObject *rv = 0;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, newQObject(rv, lastData->propType));
- } else if (lastData->flags & QDeclarativePropertyCache::Data::IsQScriptValue) {
- QScriptValue rv = scriptEngine->nullValue();
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::QReal) {
- qreal rv = 0;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::Int || lastData->flags & QDeclarativePropertyCache::Data::IsEnumType) {
- int rv = 0;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::Bool) {
- bool rv = false;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::QString) {
- QString rv;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::UInt) {
- uint rv = 0;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::Float) {
- float rv = 0;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else if (lastData->propType == QMetaType::Double) {
- double rv = 0;
- void *args[] = { &rv, 0 };
- QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);
- return Value(scriptEngine, rv);
- } else {
- QVariant var = obj->metaObject()->property(lastData->coreIndex).read(obj);
- return Value(scriptEngine, enginePriv->scriptValueFromVariant(var));
- }
- }
-}
-
-void QDeclarativeObjectScriptClass::setProperty(Object *object,
- const Identifier &name,
- const QScriptValue &value)
-{
- return setProperty(toQObject(object), name, value, context());
-}
-
-void QDeclarativeObjectScriptClass::setProperty(QObject *obj,
- const Identifier &name,
- const QScriptValue &value,
- QScriptContext *context,
- QDeclarativeContextData *evalContext)
-{
- Q_UNUSED(name);
-
- Q_ASSERT(obj);
- Q_ASSERT(lastData);
- Q_ASSERT(context);
-
- if (!lastData->isValid()) {
- QString error = QLatin1String("Cannot assign to non-existent property \"") +
- toString(name) + QLatin1Char('\"');
- context->throwError(error);
- return;
- }
-
- if (!(lastData->flags & QDeclarativePropertyCache::Data::IsWritable) &&
- !(lastData->flags & QDeclarativePropertyCache::Data::IsQList)) {
- QString error = QLatin1String("Cannot assign to read-only property \"") +
- toString(name) + QLatin1Char('\"');
- context->throwError(error);
- return;
- }
-
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
-
- if (!evalContext) {
- // Global object, QScriptContext activation object, QDeclarativeContext object
- QScriptValue scopeNode = scopeChainValue(context, -3);
- if (scopeNode.isValid()) {
- Q_ASSERT(scriptClass(scopeNode) == enginePriv->contextClass);
-
- evalContext = enginePriv->contextClass->contextFromValue(scopeNode);
- }
- }
-
- QDeclarativeBinding *newBinding = 0;
- if (value.isFunction() && !value.isRegExp()) {
- QScriptContextInfo ctxtInfo(context);
- QDeclarativePropertyCache::ValueTypeData valueTypeData;
-
- newBinding = new QDeclarativeBinding(value, obj, evalContext);
- newBinding->setSourceLocation(ctxtInfo.fileName(), ctxtInfo.functionStartLineNumber());
- newBinding->setTarget(QDeclarativePropertyPrivate::restore(*lastData, valueTypeData, obj, evalContext));
- if (newBinding->expression().contains(QLatin1String("this")))
- newBinding->setEvaluateFlags(newBinding->evaluateFlags() | QDeclarativeBinding::RequiresThisObject);
- }
-
- QDeclarativeAbstractBinding *delBinding =
- QDeclarativePropertyPrivate::setBinding(obj, lastData->coreIndex, -1, newBinding);
- if (delBinding)
- delBinding->destroy();
-
- if (value.isNull() && lastData->flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
- QObject *o = 0;
- int status = -1;
- int flags = 0;
- void *argv[] = { &o, 0, &status, &flags };
- QMetaObject::metacall(obj, QMetaObject::WriteProperty, lastData->coreIndex, argv);
- } else if (value.isUndefined() && lastData->flags & QDeclarativePropertyCache::Data::IsResettable) {
- void *a[] = { 0 };
- QMetaObject::metacall(obj, QMetaObject::ResetProperty, lastData->coreIndex, a);
- } else if (value.isUndefined() && lastData->propType == qMetaTypeId<QVariant>()) {
- QDeclarativePropertyPrivate::write(obj, *lastData, QVariant(), evalContext);
- } else if (value.isUndefined()) {
- QString error = QLatin1String("Cannot assign [undefined] to ") +
- QLatin1String(QMetaType::typeName(lastData->propType));
- context->throwError(error);
- } else if (value.isFunction() && !value.isRegExp()) {
- // this is handled by the binding creation above
- } else {
- //### expand optimization for other known types
- if (lastData->propType == QMetaType::Int && value.isNumber()) {
- int rawValue = qRound(value.toNumber());
- int status = -1;
- int flags = 0;
- void *a[] = { (void *)&rawValue, 0, &status, &flags };
- QMetaObject::metacall(obj, QMetaObject::WriteProperty,
- lastData->coreIndex, a);
- return;
- } else if (lastData->propType == QMetaType::QReal && value.isNumber()) {
- qreal rawValue = qreal(value.toNumber());
- int status = -1;
- int flags = 0;
- void *a[] = { (void *)&rawValue, 0, &status, &flags };
- QMetaObject::metacall(obj, QMetaObject::WriteProperty,
- lastData->coreIndex, a);
- return;
- } else if (lastData->propType == QMetaType::QString && value.isString()) {
- const QString &rawValue = value.toString();
- int status = -1;
- int flags = 0;
- void *a[] = { (void *)&rawValue, 0, &status, &flags };
- QMetaObject::metacall(obj, QMetaObject::WriteProperty,
- lastData->coreIndex, a);
- return;
- }
-
- QVariant v;
- if (lastData->flags & QDeclarativePropertyCache::Data::IsQList)
- v = enginePriv->scriptValueToVariant(value, qMetaTypeId<QList<QObject *> >());
- else
- v = enginePriv->scriptValueToVariant(value, lastData->propType);
-
- if (!QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext)) {
- const char *valueType = 0;
- if (v.userType() == QVariant::Invalid) valueType = "null";
- else valueType = QMetaType::typeName(v.userType());
-
- QString error = QLatin1String("Cannot assign ") +
- QLatin1String(valueType) +
- QLatin1String(" to ") +
- QLatin1String(QMetaType::typeName(lastData->propType));
- context->throwError(error);
- }
- }
-}
-
-bool QDeclarativeObjectScriptClass::isQObject() const
-{
- return true;
-}
-
-QObject *QDeclarativeObjectScriptClass::toQObject(Object *object, bool *ok)
-{
- if (ok) *ok = true;
-
- ObjectData *data = (ObjectData*)object;
- return data->object.data();
-}
-
-QScriptValue QDeclarativeObjectScriptClass::tostring(QScriptContext *context, QScriptEngine *)
-{
- QObject* obj = context->thisObject().toQObject();
-
- QString ret;
- if(obj){
- QString objectName = obj->objectName();
-
- ret += QString::fromUtf8(obj->metaObject()->className());
- ret += QLatin1String("(0x");
- ret += QString::number((quintptr)obj,16);
-
- if (!objectName.isEmpty()) {
- ret += QLatin1String(", \"");
- ret += objectName;
- ret += QLatin1Char('\"');
- }
-
- ret += QLatin1Char(')');
- }else{
- ret += QLatin1String("null");
- }
- return QScriptValue(ret);
-}
-
-QScriptValue QDeclarativeObjectScriptClass::destroy(QScriptContext *context, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
- QScriptValue that = context->thisObject();
-
- if (scriptClass(that) != p->objectClass)
- return engine->undefinedValue();
-
- ObjectData *data = (ObjectData *)p->objectClass->object(that);
- if (!data->object)
- return engine->undefinedValue();
-
- QDeclarativeData *ddata = QDeclarativeData::get(data->object, false);
- if (!ddata || ddata->indestructible)
- return engine->currentContext()->throwError(QLatin1String("Invalid attempt to destroy() an indestructible object"));
-
- QObject *obj = data->object;
- int delay = 0;
- if (context->argumentCount() > 0)
- delay = context->argument(0).toInt32();
- if (delay > 0)
- QTimer::singleShot(delay, obj, SLOT(deleteLater()));
- else
- obj->deleteLater();
-
- return engine->undefinedValue();
-}
-
-QStringList QDeclarativeObjectScriptClass::propertyNames(Object *object)
-{
- QObject *obj = toQObject(object);
- if (!obj)
- return QStringList();
-
- QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine);
-
- QDeclarativePropertyCache *cache = 0;
- QDeclarativeData *ddata = QDeclarativeData::get(obj);
- if (ddata)
- cache = ddata->propertyCache;
- if (!cache) {
- cache = enginePrivate->cache(obj);
- if (cache) {
- if (ddata) { cache->addref(); ddata->propertyCache = cache; }
- } else {
- // Not cachable - fall back to QMetaObject (eg. dynamic meta object)
- // XXX QDeclarativeOpenMetaObject has a cache, so this is suboptimal.
- // XXX This is a workaround for QTBUG-9420.
- const QMetaObject *mo = obj->metaObject();
- QStringList r;
- int pc = mo->propertyCount();
- int po = mo->propertyOffset();
- for (int i=po; i<pc; ++i)
- r += QString::fromUtf8(mo->property(i).name());
- return r;
- }
- }
- return cache->propertyNames();
-}
-
-bool QDeclarativeObjectScriptClass::compare(Object *o1, Object *o2)
-{
- ObjectData *d1 = (ObjectData *)o1;
- ObjectData *d2 = (ObjectData *)o2;
-
- return d1 == d2 || d1->object == d2->object;
-}
-
-struct MethodData : public QScriptDeclarativeClass::Object {
- MethodData(QObject *o, const QDeclarativePropertyCache::Data &d) : object(o), data(d) {}
-
- QDeclarativeGuard<QObject> object;
- QDeclarativePropertyCache::Data data;
-};
-
-QDeclarativeObjectMethodScriptClass::QDeclarativeObjectMethodScriptClass(QDeclarativeEngine *bindEngine)
-: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)),
- engine(bindEngine)
-{
- qRegisterMetaType<QList<QObject *> >("QList<QObject *>");
-
- setSupportsCall(true);
-
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- m_connect = scriptEngine->newFunction(connect);
- m_connectId = createPersistentIdentifier(QLatin1String("connect"));
- m_disconnect = scriptEngine->newFunction(disconnect);
- m_disconnectId = createPersistentIdentifier(QLatin1String("disconnect"));
-}
-
-QDeclarativeObjectMethodScriptClass::~QDeclarativeObjectMethodScriptClass()
-{
-}
-
-QScriptValue QDeclarativeObjectMethodScriptClass::newMethod(QObject *object, const QDeclarativePropertyCache::Data *method)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return newObject(scriptEngine, this, new MethodData(object, *method));
-}
-
-QScriptValue QDeclarativeObjectMethodScriptClass::connect(QScriptContext *context, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
-
- QScriptValue that = context->thisObject();
- if (&p->objectClass->methods != scriptClass(that))
- return engine->undefinedValue();
-
- MethodData *data = (MethodData *)object(that);
-
- if (!data->object || context->argumentCount() == 0)
- return engine->undefinedValue();
-
- QByteArray signal("2");
- signal.append(data->object->metaObject()->method(data->data.coreIndex).signature());
-
- if (context->argumentCount() == 1) {
- qScriptConnect(data->object, signal.constData(), QScriptValue(), context->argument(0));
- } else {
- qScriptConnect(data->object, signal.constData(), context->argument(0), context->argument(1));
- }
-
- return engine->undefinedValue();
-}
-
-QScriptValue QDeclarativeObjectMethodScriptClass::disconnect(QScriptContext *context, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
-
- QScriptValue that = context->thisObject();
- if (&p->objectClass->methods != scriptClass(that))
- return engine->undefinedValue();
-
- MethodData *data = (MethodData *)object(that);
-
- if (!data->object || context->argumentCount() == 0)
- return engine->undefinedValue();
-
- QByteArray signal("2");
- signal.append(data->object->metaObject()->method(data->data.coreIndex).signature());
-
- if (context->argumentCount() == 1) {
- qScriptDisconnect(data->object, signal.constData(), QScriptValue(), context->argument(0));
- } else {
- qScriptDisconnect(data->object, signal.constData(), context->argument(0), context->argument(1));
- }
-
- return engine->undefinedValue();
-}
-
-QScriptClass::QueryFlags
-QDeclarativeObjectMethodScriptClass::queryProperty(Object *, const Identifier &name,
- QScriptClass::QueryFlags flags)
-{
- Q_UNUSED(flags);
- if (name == m_connectId.identifier || name == m_disconnectId.identifier)
- return QScriptClass::HandlesReadAccess;
- else
- return 0;
-
-}
-
-QDeclarativeObjectMethodScriptClass::Value
-QDeclarativeObjectMethodScriptClass::property(Object *, const Identifier &name)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- if (name == m_connectId.identifier)
- return Value(scriptEngine, m_connect);
- else if (name == m_disconnectId.identifier)
- return Value(scriptEngine, m_disconnect);
- else
- return Value();
-}
-
-namespace {
-struct MetaCallArgument {
- inline MetaCallArgument();
- inline ~MetaCallArgument();
- inline void *dataPtr();
-
- inline void initAsType(int type, QDeclarativeEngine *);
- void fromScriptValue(int type, QDeclarativeEngine *, const QScriptValue &);
- inline QScriptDeclarativeClass::Value toValue(QDeclarativeEngine *);
-
-private:
- MetaCallArgument(const MetaCallArgument &);
-
- inline void cleanup();
-
- char data[4 * sizeof(void *)];
- int type;
- bool isObjectType;
-};
-}
-
-MetaCallArgument::MetaCallArgument()
-: type(QVariant::Invalid), isObjectType(false)
-{
-}
-
-MetaCallArgument::~MetaCallArgument()
-{
- cleanup();
-}
-
-void MetaCallArgument::cleanup()
-{
- if (type == QMetaType::QString) {
- ((QString *)&data)->~QString();
- } else if (type == -1 || type == qMetaTypeId<QVariant>()) {
- ((QVariant *)&data)->~QVariant();
- } else if (type == qMetaTypeId<QScriptValue>()) {
- ((QScriptValue *)&data)->~QScriptValue();
- } else if (type == qMetaTypeId<QList<QObject *> >()) {
- ((QList<QObject *> *)&data)->~QList<QObject *>();
- }
-}
-
-void *MetaCallArgument::dataPtr()
-{
- if (type == -1)
- return ((QVariant *)data)->data();
- else
- return (void *)&data;
-}
-
-void MetaCallArgument::initAsType(int callType, QDeclarativeEngine *e)
-{
- if (type != 0) { cleanup(); type = 0; }
- if (callType == 0) return;
-
- QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(e);
-
- if (callType == qMetaTypeId<QScriptValue>()) {
- new (&data) QScriptValue(engine->undefinedValue());
- type = callType;
- } else if (callType == QMetaType::Int ||
- callType == QMetaType::UInt ||
- callType == QMetaType::Bool ||
- callType == QMetaType::Double ||
- callType == QMetaType::Float) {
- type = callType;
- } else if (callType == QMetaType::QObjectStar) {
- *((QObject **)&data) = 0;
- type = callType;
- } else if (callType == QMetaType::QString) {
- new (&data) QString();
- type = callType;
- } else if (callType == qMetaTypeId<QVariant>()) {
- type = callType;
- new (&data) QVariant();
- } else if (callType == qMetaTypeId<QList<QObject *> >()) {
- type = callType;
- new (&data) QList<QObject *>();
- } else {
- type = -1;
- new (&data) QVariant(callType, (void *)0);
- }
-}
-
-void MetaCallArgument::fromScriptValue(int callType, QDeclarativeEngine *engine, const QScriptValue &value)
-{
- if (type != 0) { cleanup(); type = 0; }
-
- if (callType == qMetaTypeId<QScriptValue>()) {
- new (&data) QScriptValue(value);
- type = qMetaTypeId<QScriptValue>();
- } else if (callType == QMetaType::Int) {
- *((int *)&data) = int(value.toInt32());
- type = callType;
- } else if (callType == QMetaType::UInt) {
- *((uint *)&data) = uint(value.toUInt32());
- type = callType;
- } else if (callType == QMetaType::Bool) {
- *((bool *)&data) = value.toBool();
- type = callType;
- } else if (callType == QMetaType::Double) {
- *((double *)&data) = double(value.toNumber());
- type = callType;
- } else if (callType == QMetaType::Float) {
- *((float *)&data) = float(value.toNumber());
- type = callType;
- } else if (callType == QMetaType::QString) {
- if (value.isNull() || value.isUndefined())
- new (&data) QString();
- else
- new (&data) QString(value.toString());
- type = callType;
- } else if (callType == QMetaType::QObjectStar) {
- *((QObject **)&data) = value.toQObject();
- type = callType;
- } else if (callType == qMetaTypeId<QVariant>()) {
- new (&data) QVariant(QDeclarativeEnginePrivate::get(engine)->scriptValueToVariant(value));
- type = callType;
- } else if (callType == qMetaTypeId<QList<QObject*> >()) {
- QList<QObject *> *list = new (&data) QList<QObject *>();
- if (value.isArray()) {
- int length = value.property(QLatin1String("length")).toInt32();
- for (int ii = 0; ii < length; ++ii) {
- QScriptValue arrayItem = value.property(ii);
- QObject *d = arrayItem.toQObject();
- list->append(d);
- }
- } else if (QObject *d = value.toQObject()) {
- list->append(d);
- }
- type = callType;
- } else {
- new (&data) QVariant();
- type = -1;
-
- QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(engine);
- QVariant v = priv->scriptValueToVariant(value);
- if (v.userType() == callType) {
- *((QVariant *)&data) = v;
- } else if (v.canConvert((QVariant::Type)callType)) {
- *((QVariant *)&data) = v;
- ((QVariant *)&data)->convert((QVariant::Type)callType);
- } else if (const QMetaObject *mo = priv->rawMetaObjectForType(callType)) {
- QObject *obj = priv->toQObject(v);
-
- if (obj) {
- const QMetaObject *objMo = obj->metaObject();
- while (objMo && objMo != mo) objMo = objMo->superClass();
- if (!objMo) obj = 0;
- }
-
- *((QVariant *)&data) = QVariant(callType, &obj);
- } else {
- *((QVariant *)&data) = QVariant(callType, (void *)0);
- }
- }
-}
-
-QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e)
-{
- QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(e);
-
- if (type == qMetaTypeId<QScriptValue>()) {
- return QScriptDeclarativeClass::Value(engine, *((QScriptValue *)&data));
- } else if (type == QMetaType::Int) {
- return QScriptDeclarativeClass::Value(engine, *((int *)&data));
- } else if (type == QMetaType::UInt) {
- return QScriptDeclarativeClass::Value(engine, *((uint *)&data));
- } else if (type == QMetaType::Bool) {
- return QScriptDeclarativeClass::Value(engine, *((bool *)&data));
- } else if (type == QMetaType::Double) {
- return QScriptDeclarativeClass::Value(engine, *((double *)&data));
- } else if (type == QMetaType::Float) {
- return QScriptDeclarativeClass::Value(engine, *((float *)&data));
- } else if (type == QMetaType::QString) {
- return QScriptDeclarativeClass::Value(engine, *((QString *)&data));
- } else if (type == QMetaType::QObjectStar) {
- QObject *object = *((QObject **)&data);
- if (object)
- QDeclarativeData::get(object, true)->setImplicitDestructible();
- QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e);
- return QScriptDeclarativeClass::Value(engine, priv->objectClass->newQObject(object));
- } else if (type == qMetaTypeId<QList<QObject *> >()) {
- QList<QObject *> &list = *(QList<QObject *>*)&data;
- QScriptValue rv = engine->newArray(list.count());
- QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e);
- for (int ii = 0; ii < list.count(); ++ii) {
- QObject *object = list.at(ii);
- QDeclarativeData::get(object, true)->setImplicitDestructible();
- rv.setProperty(ii, priv->objectClass->newQObject(object));
- }
- return QScriptDeclarativeClass::Value(engine, rv);
- } else if (type == -1 || type == qMetaTypeId<QVariant>()) {
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(e);
- QScriptValue rv = ep->scriptValueFromVariant(*((QVariant *)&data));
- if (rv.isQObject()) {
- QObject *object = rv.toQObject();
- if (object)
- QDeclarativeData::get(object, true)->setImplicitDestructible();
- }
- return QScriptDeclarativeClass::Value(engine, rv);
- } else {
- return QScriptDeclarativeClass::Value();
- }
-}
-
-int QDeclarativeObjectMethodScriptClass::enumType(const QMetaObject *meta, const QString &strname)
-{
- QByteArray str = strname.toUtf8();
- QByteArray scope;
- QByteArray name;
- int scopeIdx = str.lastIndexOf("::");
- if (scopeIdx != -1) {
- scope = str.left(scopeIdx);
- name = str.mid(scopeIdx + 2);
- } else {
- name = str;
- }
- for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
- QMetaEnum m = meta->enumerator(i);
- if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
- return QVariant::Int;
- }
- return QVariant::Invalid;
-}
-
-QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call(Object *o, QScriptContext *ctxt)
-{
- MethodData *method = static_cast<MethodData *>(o);
-
- if (method->data.relatedIndex == -1)
- return callPrecise(method->object, method->data, ctxt);
- else
- return callOverloaded(method, ctxt);
-}
-
-QDeclarativeObjectMethodScriptClass::Value
-QDeclarativeObjectMethodScriptClass::callPrecise(QObject *object, const QDeclarativePropertyCache::Data &data,
- QScriptContext *ctxt)
-{
- if (data.flags & QDeclarativePropertyCache::Data::HasArguments) {
-
- QMetaMethod m = object->metaObject()->method(data.coreIndex);
- QList<QByteArray> argTypeNames = m.parameterTypes();
- QVarLengthArray<int, 9> argTypes(argTypeNames.count());
-
- // ### Cache
- for (int ii = 0; ii < argTypeNames.count(); ++ii) {
- argTypes[ii] = QMetaType::type(argTypeNames.at(ii));
- if (argTypes[ii] == QVariant::Invalid)
- argTypes[ii] = enumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii)));
- if (argTypes[ii] == QVariant::Invalid)
- return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii)))));
- }
-
- if (argTypes.count() > ctxt->argumentCount())
- return Value(ctxt, ctxt->throwError(QLatin1String("Insufficient arguments")));
-
- return callMethod(object, data.coreIndex, data.propType, argTypes.count(), argTypes.data(), ctxt);
-
- } else {
-
- return callMethod(object, data.coreIndex, data.propType, 0, 0, ctxt);
-
- }
-}
-
-QDeclarativeObjectMethodScriptClass::Value
-QDeclarativeObjectMethodScriptClass::callMethod(QObject *object, int index,
- int returnType, int argCount, int *argTypes,
- QScriptContext *ctxt)
-{
- if (argCount > 0) {
-
- QVarLengthArray<MetaCallArgument, 9> args(argCount + 1);
- args[0].initAsType(returnType, engine);
-
- for (int ii = 0; ii < argCount; ++ii)
- args[ii + 1].fromScriptValue(argTypes[ii], engine, ctxt->argument(ii));
-
- QVarLengthArray<void *, 9> argData(args.count());
- for (int ii = 0; ii < args.count(); ++ii)
- argData[ii] = args[ii].dataPtr();
-
- QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, argData.data());
-
- return args[0].toValue(engine);
-
- } else if (returnType != 0) {
-
- MetaCallArgument arg;
- arg.initAsType(returnType, engine);
-
- void *args[] = { arg.dataPtr() };
-
- QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, args);
-
- return arg.toValue(engine);
-
- } else {
-
- void *args[] = { 0 };
- QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, args);
- return Value();
-
- }
-}
-
-/*!
-Resolve the overloaded method to call. The algorithm works conceptually like this:
- 1. Resolve the set of overloads it is *possible* to call.
- Impossible overloads include those that have too many parameters or have parameters
- of unknown type.
- 2. Filter the set of overloads to only contain those with the closest number of
- parameters.
- For example, if we are called with 3 parameters and there are 2 overloads that
- take 2 parameters and one that takes 3, eliminate the 2 parameter overloads.
- 3. Find the best remaining overload based on its match score.
- If two or more overloads have the same match score, call the last one. The match
- score is constructed by adding the matchScore() result for each of the parameters.
-*/
-QDeclarativeObjectMethodScriptClass::Value
-QDeclarativeObjectMethodScriptClass::callOverloaded(MethodData *method, QScriptContext *ctxt)
-{
- int argumentCount = ctxt->argumentCount();
-
- QDeclarativePropertyCache::Data *best = 0;
- int bestParameterScore = INT_MAX;
- int bestMatchScore = INT_MAX;
-
- QDeclarativePropertyCache::Data dummy;
- QDeclarativePropertyCache::Data *attempt = &method->data;
-
- do {
- QList<QByteArray> methodArgTypeNames;
-
- if (attempt->flags & QDeclarativePropertyCache::Data::HasArguments)
- methodArgTypeNames = method->object->metaObject()->method(attempt->coreIndex).parameterTypes();
-
- int methodArgumentCount = methodArgTypeNames.count();
-
- if (methodArgumentCount > argumentCount)
- continue; // We don't have sufficient arguments to call this method
-
- int methodParameterScore = argumentCount - methodArgumentCount;
- if (methodParameterScore > bestParameterScore)
- continue; // We already have a better option
-
- int methodMatchScore = 0;
- QVarLengthArray<int, 9> methodArgTypes(methodArgumentCount);
-
- bool unknownArgument = false;
- for (int ii = 0; ii < methodArgumentCount; ++ii) {
- methodArgTypes[ii] = QMetaType::type(methodArgTypeNames.at(ii));
- if (methodArgTypes[ii] == QVariant::Invalid)
- methodArgTypes[ii] = enumType(method->object->metaObject(),
- QString::fromLatin1(methodArgTypeNames.at(ii)));
- if (methodArgTypes[ii] == QVariant::Invalid) {
- unknownArgument = true;
- break;
- }
- methodMatchScore += matchScore(ctxt->argument(ii), methodArgTypes[ii], methodArgTypeNames.at(ii));
- }
- if (unknownArgument)
- continue; // We don't understand all the parameters
-
- if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) {
- best = attempt;
- bestParameterScore = methodParameterScore;
- bestMatchScore = methodMatchScore;
- }
-
- if (bestParameterScore == 0 && bestMatchScore == 0)
- break; // We can't get better than that
-
- } while((attempt = relatedMethod(method->object, attempt, dummy)) != 0);
-
- if (best) {
- return callPrecise(method->object, *best, ctxt);
- } else {
- QString error = QLatin1String("Unable to determine callable overload. Candidates are:");
- QDeclarativePropertyCache::Data *candidate = &method->data;
- while (candidate) {
- error += QLatin1String("\n ") + QString::fromUtf8(method->object->metaObject()->method(candidate->coreIndex).signature());
- candidate = relatedMethod(method->object, candidate, dummy);
- }
- return Value(ctxt, ctxt->throwError(error));
- }
-}
-
-/*!
- Returns the match score for converting \a actual to be of type \a conversionType. A
- zero score means "perfect match" whereas a higher score is worse.
-
- The conversion table is copied out of the QtScript callQtMethod() function.
-*/
-int QDeclarativeObjectMethodScriptClass::matchScore(const QScriptValue &actual, int conversionType,
- const QByteArray &conversionTypeName)
-{
- if (actual.isNumber()) {
- switch (conversionType) {
- case QMetaType::Double:
- return 0;
- case QMetaType::Float:
- return 1;
- case QMetaType::LongLong:
- case QMetaType::ULongLong:
- return 2;
- case QMetaType::Long:
- case QMetaType::ULong:
- return 3;
- case QMetaType::Int:
- case QMetaType::UInt:
- return 4;
- case QMetaType::Short:
- case QMetaType::UShort:
- return 5;
- break;
- case QMetaType::Char:
- case QMetaType::UChar:
- return 6;
- default:
- return 10;
- }
- } else if (actual.isString()) {
- switch (conversionType) {
- case QMetaType::QString:
- return 0;
- default:
- return 10;
- }
- } else if (actual.isBoolean()) {
- switch (conversionType) {
- case QMetaType::Bool:
- return 0;
- default:
- return 10;
- }
- } else if (actual.isDate()) {
- switch (conversionType) {
- case QMetaType::QDateTime:
- return 0;
- case QMetaType::QDate:
- return 1;
- case QMetaType::QTime:
- return 2;
- default:
- return 10;
- }
- } else if (actual.isRegExp()) {
- switch (conversionType) {
- case QMetaType::QRegExp:
- return 0;
- default:
- return 10;
- }
- } else if (actual.isVariant()) {
- if (conversionType == qMetaTypeId<QVariant>())
- return 0;
- else if (actual.toVariant().userType() == conversionType)
- return 0;
- else
- return 10;
- } else if (actual.isArray()) {
- switch (conversionType) {
- case QMetaType::QStringList:
- case QMetaType::QVariantList:
- return 5;
- default:
- return 10;
- }
- } else if (actual.isQObject()) {
- switch (conversionType) {
- case QMetaType::QObjectStar:
- return 0;
- default:
- return 10;
- }
- } else if (actual.isNull()) {
- switch (conversionType) {
- case QMetaType::VoidStar:
- case QMetaType::QObjectStar:
- return 0;
- default:
- if (!conversionTypeName.endsWith('*'))
- return 10;
- else
- return 0;
- }
- } else {
- return 10;
- }
-}
-
-static inline int QMetaObject_methods(const QMetaObject *metaObject)
-{
- struct Private
- {
- int revision;
- int className;
- int classInfoCount, classInfoData;
- int methodCount, methodData;
- };
-
- return reinterpret_cast<const Private *>(metaObject->d.data)->methodCount;
-}
-
-static QByteArray QMetaMethod_name(const QMetaMethod &m)
-{
- QByteArray sig = m.signature();
- int paren = sig.indexOf('(');
- if (paren == -1)
- return sig;
- else
- return sig.left(paren);
-}
-
-/*!
-Returns the next related method, if one, or 0.
-*/
-QDeclarativePropertyCache::Data *
-QDeclarativeObjectMethodScriptClass::relatedMethod(QObject *object, QDeclarativePropertyCache::Data *current,
- QDeclarativePropertyCache::Data &dummy)
-{
- QDeclarativePropertyCache *cache = QDeclarativeData::get(object)->propertyCache;
- if (current->relatedIndex == -1)
- return 0;
-
- if (cache) {
- return cache->method(current->relatedIndex);
- } else {
- const QMetaObject *mo = object->metaObject();
- int methodOffset = mo->methodCount() - QMetaObject_methods(mo);
-
- while (methodOffset > current->relatedIndex) {
- mo = mo->superClass();
- methodOffset -= QMetaObject_methods(mo);
- }
-
- QMetaMethod method = mo->method(current->relatedIndex);
- dummy.load(method);
-
- // Look for overloaded methods
- QByteArray methodName = QMetaMethod_name(method);
- for (int ii = current->relatedIndex - 1; ii >= methodOffset; --ii) {
- if (methodName == QMetaMethod_name(mo->method(ii))) {
- dummy.relatedIndex = ii;
- return &dummy;
- }
- }
-
- return &dummy;
- }
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
deleted file mode 100644
index f1f1ab25d0..0000000000
--- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEOBJECTSCRIPTCLASS_P_H
-#define QDECLARATIVEOBJECTSCRIPTCLASS_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "private/qdeclarativepropertycache_p.h"
-#include "private/qdeclarativetypenamecache_p.h"
-
-#include <private/qscriptdeclarativeclass_p.h>
-#include <QtScript/qscriptengine.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeEngine;
-class QScriptContext;
-class QScriptEngine;
-class QDeclarativeContextData;
-class MethodData;
-
-class Q_AUTOTEST_EXPORT QDeclarativeObjectMethodScriptClass : public QScriptDeclarativeClass
-{
-public:
- QDeclarativeObjectMethodScriptClass(QDeclarativeEngine *);
- ~QDeclarativeObjectMethodScriptClass();
-
- QScriptValue newMethod(QObject *, const QDeclarativePropertyCache::Data *);
-
-protected:
- virtual Value call(Object *, QScriptContext *);
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags);
- virtual Value property(Object *, const Identifier &);
-
-private:
- int enumType(const QMetaObject *, const QString &);
-
- Value callPrecise(QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *);
- Value callOverloaded(MethodData *, QScriptContext *);
- Value callMethod(QObject *, int index, int returnType, int argCount, int *argTypes, QScriptContext *ctxt);
-
- int matchScore(const QScriptValue &, int, const QByteArray &);
- QDeclarativePropertyCache::Data *relatedMethod(QObject *, QDeclarativePropertyCache::Data *current,
- QDeclarativePropertyCache::Data &dummy);
-
- PersistentIdentifier m_connectId;
- PersistentIdentifier m_disconnectId;
- QScriptValue m_connect;
- QScriptValue m_disconnect;
-
- static QScriptValue connect(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue disconnect(QScriptContext *context, QScriptEngine *engine);
-
- QDeclarativeEngine *engine;
-};
-
-class Q_AUTOTEST_EXPORT QDeclarativeObjectScriptClass : public QScriptDeclarativeClass
-{
-public:
- QDeclarativeObjectScriptClass(QDeclarativeEngine *);
- ~QDeclarativeObjectScriptClass();
-
- QScriptValue newQObject(QObject *, int type = QMetaType::QObjectStar);
-
- QObject *toQObject(const QScriptValue &) const;
- int objectType(const QScriptValue &) const;
-
- enum QueryHint {
- ImplicitObject = 0x01,
- SkipAttachedProperties = 0x02
- };
- Q_DECLARE_FLAGS(QueryHints, QueryHint)
-
- QScriptClass::QueryFlags queryProperty(QObject *, const Identifier &,
- QScriptClass::QueryFlags flags,
- QDeclarativeContextData *evalContext,
- QueryHints hints = 0);
-
- Value property(QObject *, const Identifier &);
-
- void setProperty(QObject *, const Identifier &name, const QScriptValue &,
- QScriptContext *context, QDeclarativeContextData *evalContext = 0);
- virtual QStringList propertyNames(Object *);
- virtual bool compare(Object *, Object *);
-
-protected:
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
- QScriptClass::QueryFlags flags);
-
- virtual Value property(Object *, const Identifier &);
- virtual void setProperty(Object *, const Identifier &name, const QScriptValue &);
- virtual bool isQObject() const;
- virtual QObject *toQObject(Object *, bool *ok = 0);
-
-private:
- friend class QDeclarativeObjectMethodScriptClass;
- QDeclarativeObjectMethodScriptClass methods;
-
- QDeclarativeTypeNameCache::Data *lastTNData;
- QDeclarativePropertyCache::Data *lastData;
- QDeclarativePropertyCache::Data local;
-
- PersistentIdentifier m_destroyId;
- PersistentIdentifier m_toStringId;
- QScriptValue m_destroy;
- QScriptValue m_toString;
-
- static QScriptValue tostring(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue destroy(QScriptContext *context, QScriptEngine *engine);
-
- QDeclarativeEngine *engine;
-};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeObjectScriptClass::QueryHints);
-
-QT_END_NAMESPACE
-
-#endif // QDECLARATIVEOBJECTSCRIPTCLASS_P_H
-
diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp
index cd671bc293..0447ea3227 100644
--- a/src/declarative/qml/qdeclarativeparser.cpp
+++ b/src/declarative/qml/qdeclarativeparser.cpp
@@ -66,7 +66,7 @@ using namespace QDeclarativeJS;
using namespace QDeclarativeParser;
QDeclarativeParser::Object::Object()
-: type(-1), majorVersion(-1), minorVersion(-1), idIndex(-1), metatype(0), synthCache(0), defaultProperty(0), parserStatusCast(-1)
+: type(-1), idIndex(-1), metatype(0), synthCache(0), defaultProperty(0), parserStatusCast(-1)
{
}
diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h
index 722f9fbd5e..59c41ef8de 100644
--- a/src/declarative/qml/qdeclarativeparser_p.h
+++ b/src/declarative/qml/qdeclarativeparser_p.h
@@ -77,13 +77,13 @@ namespace QDeclarativeJS { namespace AST { class Node; } }
/*
XXX
- These types are created (and owned) by the QDeclarativeXmlParser and consumed by the
+ These types are created (and owned) by the QDeclarativeScriptParser and consumed by the
QDeclarativeCompiler. During the compilation phase the compiler will update some of
- the fields for both its own use and for the use of the upcoming QDeclarativeDom API.
+ the fields for its own use.
The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
reasons (there used to be more in this namespace) and will be cleaned up and
- migrated into a more appropriate location shortly.
+ migrated into a more appropriate location eventually.
*/
namespace QDeclarativeParser
{
@@ -124,12 +124,6 @@ namespace QDeclarativeParser
// QDeclarativeCompiledData::types array, or -1 if the object is a property
// group.
int type;
- // The url of this object if it is an external type. Used by the DOM
- QUrl url;
-
- // version information if type is defined in library or C++
- int majorVersion;
- int minorVersion;
// The fully-qualified name of this type
QByteArray typeName;
@@ -366,7 +360,6 @@ namespace QDeclarativeParser
LocationSpan location;
LocationRange listValueRange;
- QList<int> listCommaPositions;
};
}
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index ae28049eed..088379e8d2 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -54,6 +54,7 @@
#include "private/qdeclarativelist_p.h"
#include "private/qdeclarativecompiler_p.h"
#include "private/qdeclarativevmemetaobject_p.h"
+#include "private/qdeclarativeexpression_p.h"
#include <QStringList>
#include <QtCore/qdebug.h>
@@ -254,7 +255,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QDeclarativePropertyCache::property(engine, obj, pathName, local);
if (!property) return; // Not a property
- if (property->flags & QDeclarativePropertyCache::Data::IsFunction)
+ if (property->isFunction())
return; // Not an object property
if (ii == (path.count() - 2) && QDeclarativeValueTypeFactory::isValueType(property->propType)) {
@@ -276,7 +277,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
return;
} else {
- if (!(property->flags & QDeclarativePropertyCache::Data::IsQObjectDerived))
+ if (!property->isQObject())
return; // Not an object property
void *args[] = { &currentObject, 0 };
@@ -310,7 +311,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QDeclarativePropertyCache::Data local;
QDeclarativePropertyCache::Data *property =
QDeclarativePropertyCache::property(engine, currentObject, terminal, local);
- if (property && !(property->flags & QDeclarativePropertyCache::Data::IsFunction)) {
+ if (property && !property->isFunction()) {
object = currentObject;
core = *property;
nameCache = terminal;
@@ -370,9 +371,9 @@ QDeclarativePropertyPrivate::propertyTypeCategory() const
return QDeclarativeProperty::InvalidCategory;
else if (QDeclarativeValueTypeFactory::isValueType((uint)type))
return QDeclarativeProperty::Normal;
- else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived)
+ else if (core.isQObject())
return QDeclarativeProperty::Object;
- else if (core.flags & QDeclarativePropertyCache::Data::IsQList)
+ else if (core.isQList())
return QDeclarativeProperty::List;
else
return QDeclarativeProperty::Normal;
@@ -420,8 +421,9 @@ bool QDeclarativeProperty::operator==(const QDeclarativeProperty &other) const
// category is intentially omitted here as it is generated
// from the other members
return d->object == other.d->object &&
- d->core == other.d->core &&
- d->valueType == other.d->valueType;
+ d->core.coreIndex == other.d->core.coreIndex &&
+ d->valueType.valueTypeCoreIdx == other.d->valueType.valueTypeCoreIdx &&
+ d->valueType.valueTypePropType == other.d->valueType.valueTypePropType;
}
/*!
@@ -455,7 +457,7 @@ int QDeclarativePropertyPrivate::propertyType() const
QDeclarativeProperty::Type QDeclarativePropertyPrivate::type() const
{
- if (core.flags & QDeclarativePropertyCache::Data::IsFunction)
+ if (core.isFunction())
return QDeclarativeProperty::SignalProperty;
else if (core.isValid())
return QDeclarativeProperty::Property;
@@ -518,12 +520,12 @@ bool QDeclarativeProperty::isWritable() const
return false;
if (!d->object)
return false;
- if (d->core.flags & QDeclarativePropertyCache::Data::IsQList) //list
+ if (d->core.isQList()) //list
return true;
- else if (d->core.flags & QDeclarativePropertyCache::Data::IsFunction) //signal handler
+ else if (d->core.isFunction()) //signal handler
return false;
- else if (d->core.isValid()) //normal property
- return d->core.flags & QDeclarativePropertyCache::Data::IsWritable;
+ else if (d->core.isValid()) //normal property
+ return d->core.isWritable();
else
return false;
}
@@ -549,7 +551,7 @@ bool QDeclarativeProperty::isResettable() const
if (!d)
return false;
if (type() & Property && d->core.isValid() && d->object)
- return d->core.flags & QDeclarativePropertyCache::Data::IsResettable;
+ return d->core.isResettable();
else
return false;
}
@@ -680,7 +682,7 @@ QDeclarativePropertyPrivate::binding(QObject *object, int coreIndex, int valueTy
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
- if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
+ if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));
@@ -721,7 +723,7 @@ void QDeclarativePropertyPrivate::findAliasTarget(QObject *object, int bindingIn
if (data) {
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
- if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
+ if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));
QObject *aObject = 0; int aCoreIndex = -1; int aValueTypeIndex = -1;
@@ -755,7 +757,7 @@ QDeclarativePropertyPrivate::setBinding(QObject *object, int coreIndex, int valu
if (data) {
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
- if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
+ if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));
@@ -809,7 +811,7 @@ QDeclarativePropertyPrivate::setBindingNoEnable(QObject *object, int coreIndex,
if (data) {
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
- if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
+ if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));
@@ -992,14 +994,14 @@ QVariant QDeclarativePropertyPrivate::readValueProperty()
if (!ep) delete valueType;
return rv;
- } else if (core.flags & QDeclarativePropertyCache::Data::IsQList) {
+ } else if (core.isQList()) {
QDeclarativeListProperty<QObject> prop;
void *args[] = { &prop, 0 };
QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args);
return QVariant::fromValue(QDeclarativeListReferencePrivate::init(prop, core.propType, engine));
- } else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
+ } else if (core.isQObject()) {
QObject *rv = 0;
void *args[] = { &rv, 0 };
@@ -1075,7 +1077,7 @@ bool QDeclarativePropertyPrivate::writeValueProperty(const QVariant &value, Writ
writeBack->read(object, core.coreIndex);
QDeclarativePropertyCache::Data data = core;
- data.flags = valueType.flags;
+ data.setFlags(valueType.flags);
data.coreIndex = valueType.valueTypeCoreIdx;
data.propType = valueType.valueTypePropType;
rv = write(writeBack, data, value, context, flags);
@@ -1099,7 +1101,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
int coreIdx = property.coreIndex;
int status = -1; //for dbus
- if (property.flags & QDeclarativePropertyCache::Data::IsEnumType) {
+ if (property.isEnum()) {
QMetaProperty prop = object->metaObject()->property(property.coreIndex);
QVariant v = value;
// Enum values come through the script engine as doubles
@@ -1151,7 +1153,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
void *a[] = { (void *)&value, 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
- } else if (property.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
+ } else if (property.isQObject()) {
const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType());
@@ -1178,7 +1180,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
return false;
}
- } else if (property.flags & QDeclarativePropertyCache::Data::IsQList) {
+ } else if (property.isQList()) {
const QMetaObject *listType = 0;
if (enginePriv) {
@@ -1245,6 +1247,105 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
return true;
}
+// Returns true if successful, false if an error description was set on expression
+bool QDeclarativePropertyPrivate::writeBinding(const QDeclarativeProperty &that,
+ QDeclarativeJavaScriptExpression *expression,
+ v8::Handle<v8::Value> result, bool isUndefined,
+ WriteFlags flags)
+{
+ QV8Engine *engine = QDeclarativeEnginePrivate::getV8Engine(expression->context()->engine);
+
+ QDeclarativePropertyPrivate *pp = that.d;
+
+ if (!pp)
+ return true;
+
+ QObject *object = that.object();
+ int type = that.propertyType();
+
+#define QUICK_STORE(cpptype, conversion) \
+ { \
+ cpptype o = (conversion); \
+ int status = -1; \
+ void *argv[] = { &o, 0, &status, &flags }; \
+ QMetaObject::metacall(object, QMetaObject::WriteProperty, pp->core.coreIndex, argv); \
+ return true; \
+ } \
+
+
+ if (object && pp->valueType.valueTypeCoreIdx == -1) {
+ switch (type) {
+ case QMetaType::Int:
+ if (result->IsInt32())
+ QUICK_STORE(int, result->Int32Value())
+ else if (result->IsNumber())
+ QUICK_STORE(int, qRound(result->NumberValue()))
+ break;
+ case QMetaType::Double:
+ if (result->IsNumber())
+ QUICK_STORE(double, result->NumberValue())
+ break;
+ case QMetaType::Float:
+ if (result->IsNumber())
+ QUICK_STORE(float, result->NumberValue())
+ break;
+ case QMetaType::QString:
+ if (result->IsString())
+ QUICK_STORE(QString, engine->toString(result))
+ break;
+ default:
+ break;
+ }
+ }
+
+#undef QUICK_STORE
+
+ QDeclarativeDeleteWatcher watcher(expression);
+
+ QVariant value;
+
+ if (isUndefined) {
+ } else if (that.propertyTypeCategory() == QDeclarativeProperty::List) {
+ value = engine->toVariant(result, qMetaTypeId<QList<QObject *> >());
+ } else if (result->IsNull() && that.propertyTypeCategory() == QDeclarativeProperty::Object) {
+ value = QVariant::fromValue((QObject *)0);
+ } else {
+ value = engine->toVariant(result, type);
+ }
+
+ if (expression->error.isValid()) {
+ return false;
+ } else if (isUndefined && that.isResettable()) {
+ that.reset();
+ } else if (isUndefined && type == qMetaTypeId<QVariant>()) {
+ QDeclarativePropertyPrivate::write(that, QVariant(), flags);
+ } else if (isUndefined) {
+ expression->error.setDescription(QLatin1String("Unable to assign [undefined] to ") +
+ QLatin1String(QMetaType::typeName(type)) +
+ QLatin1String(" ") + that.name());
+ return false;
+ } else if (result->IsFunction()) {
+ expression->error.setDescription(QLatin1String("Unable to assign a function to a property."));
+ return false;
+ } else if (object && !QDeclarativePropertyPrivate::write(that, value, flags)) {
+
+ if (watcher.wasDeleted())
+ return true;
+
+ const char *valueType = 0;
+ if (value.userType() == QVariant::Invalid) valueType = "null";
+ else valueType = QMetaType::typeName(value.userType());
+
+ expression->error.setDescription(QLatin1String("Unable to assign ") +
+ QLatin1String(valueType) +
+ QLatin1String(" to ") +
+ QLatin1String(QMetaType::typeName(type)));
+ return false;
+ }
+
+ return true;
+}
+
const QMetaObject *QDeclarativePropertyPrivate::rawMetaObjectForType(QDeclarativeEnginePrivate *engine, int userType)
{
if (engine) {
@@ -1334,7 +1435,7 @@ bool QDeclarativeProperty::reset() const
}
bool QDeclarativePropertyPrivate::write(const QDeclarativeProperty &that,
- const QVariant &value, WriteFlags flags)
+ const QVariant &value, WriteFlags flags)
{
if (!that.d)
return false;
@@ -1503,7 +1604,7 @@ QDeclarativePropertyPrivate::restore(const QDeclarativePropertyCache::Data &data
prop.d = new QDeclarativePropertyPrivate;
prop.d->object = object;
prop.d->context = ctxt;
- prop.d->engine = ctxt->engine;
+ prop.d->engine = ctxt?ctxt->engine:0;
prop.d->core = data;
prop.d->valueType = valueType;
@@ -1602,7 +1703,7 @@ static inline void flush_vme_signal(const QObject *object, int index)
if (data && data->propertyCache) {
QDeclarativePropertyCache::Data *property = data->propertyCache->method(index);
- if (property && property->flags & QDeclarativePropertyCache::Data::IsVMESignal) {
+ if (property && property->isVMESignal()) {
const QMetaObject *metaObject = object->metaObject();
int methodOffset = metaObject->methodOffset();
diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h
index 4f53adb71c..efebf0ca48 100644
--- a/src/declarative/qml/qdeclarativeproperty_p.h
+++ b/src/declarative/qml/qdeclarativeproperty_p.h
@@ -63,8 +63,9 @@
QT_BEGIN_NAMESPACE
class QDeclarativeContext;
-class QDeclarativeEnginePrivate;
class QDeclarativeExpression;
+class QDeclarativeEnginePrivate;
+class QDeclarativeJavaScriptExpression;
class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePropertyPrivate : public QDeclarativeRefCount
{
public:
@@ -131,6 +132,10 @@ public:
static QDeclarativeExpression *setSignalExpression(const QDeclarativeProperty &that,
QDeclarativeExpression *) ;
static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags);
+ static bool writeBinding(const QDeclarativeProperty &that,
+ QDeclarativeJavaScriptExpression *expression,
+ v8::Handle<v8::Value> result, bool isUndefined,
+ WriteFlags flags);
static int valueTypeCoreIndex(const QDeclarativeProperty &that);
static int bindingIndex(const QDeclarativeProperty &that);
static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp
index 0fa4e24725..8dba8e4350 100644
--- a/src/declarative/qml/qdeclarativepropertycache.cpp
+++ b/src/declarative/qml/qdeclarativepropertycache.cpp
@@ -43,45 +43,92 @@
#include "private/qdeclarativeengine_p.h"
#include "private/qdeclarativebinding_p.h"
+#include "private/qv8engine_p.h"
+
+#include <private/qmetaobject_p.h>
+
#include <QtCore/qdebug.h>
Q_DECLARE_METATYPE(QScriptValue)
+Q_DECLARE_METATYPE(QDeclarativeV8Handle);
QT_BEGIN_NAMESPACE
-QDeclarativePropertyCache::Data::Flags QDeclarativePropertyCache::Data::flagsForProperty(const QMetaProperty &p, QDeclarativeEngine *engine)
+// Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
+// to load
+static QDeclarativePropertyCache::Data::Flags fastFlagsForProperty(const QMetaProperty &p)
{
- int propType = p.userType();
-
- Flags flags;
+ QDeclarativePropertyCache::Data::Flags flags;
if (p.isConstant())
- flags |= Data::IsConstant;
+ flags |= QDeclarativePropertyCache::Data::IsConstant;
if (p.isWritable())
- flags |= Data::IsWritable;
+ flags |= QDeclarativePropertyCache::Data::IsWritable;
if (p.isResettable())
- flags |= Data::IsResettable;
+ flags |= QDeclarativePropertyCache::Data::IsResettable;
if (p.isFinal())
- flags |= Data::IsFinal;
+ flags |= QDeclarativePropertyCache::Data::IsFinal;
+ if (p.isEnumType())
+ flags |= QDeclarativePropertyCache::Data::IsEnumType;
+
+ return flags;
+}
- if (propType == qMetaTypeId<QDeclarativeBinding *>()) {
- flags |= Data::IsQmlBinding;
+// Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
+// load
+static QDeclarativePropertyCache::Data::Flags flagsForPropertyType(int propType, QDeclarativeEngine *engine)
+{
+ QDeclarativePropertyCache::Data::Flags flags;
+
+ if (propType < QMetaType::User && propType != QMetaType::QObjectStar && propType != QMetaType::QWidgetStar) {
+ } else if (propType == qMetaTypeId<QDeclarativeBinding *>()) {
+ flags |= QDeclarativePropertyCache::Data::IsQmlBinding;
} else if (propType == qMetaTypeId<QScriptValue>()) {
- flags |= Data::IsQScriptValue;
- } else if (p.isEnumType()) {
- flags |= Data::IsEnumType;
+ flags |= QDeclarativePropertyCache::Data::IsQScriptValue;
+ } else if (propType == qMetaTypeId<QDeclarativeV8Handle>()) {
+ flags |= QDeclarativePropertyCache::Data::IsV8Handle;
} else {
- QDeclarativeMetaType::TypeCategory cat = engine ? QDeclarativeEnginePrivate::get(engine)->typeCategory(propType)
- : QDeclarativeMetaType::typeCategory(propType);
+ QDeclarativeMetaType::TypeCategory cat =
+ engine ? QDeclarativeEnginePrivate::get(engine)->typeCategory(propType)
+ : QDeclarativeMetaType::typeCategory(propType);
+
if (cat == QDeclarativeMetaType::Object)
- flags |= Data::IsQObjectDerived;
+ flags |= QDeclarativePropertyCache::Data::IsQObjectDerived;
else if (cat == QDeclarativeMetaType::List)
- flags |= Data::IsQList;
+ flags |= QDeclarativePropertyCache::Data::IsQList;
}
return flags;
}
+QDeclarativePropertyCache::Data::Flags
+QDeclarativePropertyCache::Data::flagsForProperty(const QMetaProperty &p, QDeclarativeEngine *engine)
+{
+ return fastFlagsForProperty(p) | flagsForPropertyType(p.userType(), engine);
+}
+
+void QDeclarativePropertyCache::Data::lazyLoad(const QMetaProperty &p, QDeclarativeEngine *engine)
+{
+ Q_UNUSED(engine);
+
+ coreIndex = p.propertyIndex();
+ notifyIndex = p.notifySignalIndex();
+ revision = p.revision();
+
+ flags = fastFlagsForProperty(p);
+
+ int type = p.type();
+ if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
+ propType = type;
+ flags |= QDeclarativePropertyCache::Data::IsQObjectDerived;
+ } else if (type == QVariant::UserType || type == -1) {
+ propTypeName = p.typeName();
+ flags |= QDeclarativePropertyCache::Data::NotFullyResolved;
+ } else {
+ propType = type;
+ }
+}
+
void QDeclarativePropertyCache::Data::load(const QMetaProperty &p, QDeclarativeEngine *engine)
{
propType = p.userType();
@@ -89,7 +136,7 @@ void QDeclarativePropertyCache::Data::load(const QMetaProperty &p, QDeclarativeE
propType = qMetaTypeId<QVariant>();
coreIndex = p.propertyIndex();
notifyIndex = p.notifySignalIndex();
- flags = flagsForProperty(p, engine);
+ flags = fastFlagsForProperty(p) | flagsForPropertyType(propType, engine);
revision = p.revision();
}
@@ -106,18 +153,54 @@ void QDeclarativePropertyCache::Data::load(const QMetaMethod &m)
if (returnType)
propType = QMetaType::type(returnType);
- QList<QByteArray> params = m.parameterTypes();
- if (!params.isEmpty())
+ const char *signature = m.signature();
+ while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
+
+ ++signature;
+ if (*signature != ')') {
flags |= Data::HasArguments;
+ if (0 == ::strcmp(signature, "QDeclarativeV8Function*)")) {
+ flags |= Data::IsV8Function;
+ }
+ }
+
revision = m.revision();
}
+void QDeclarativePropertyCache::Data::lazyLoad(const QMetaMethod &m)
+{
+ coreIndex = m.methodIndex();
+ relatedIndex = -1;
+ flags |= Data::IsFunction;
+ if (m.methodType() == QMetaMethod::Signal)
+ flags |= Data::IsSignal;
+ propType = QVariant::Invalid;
+
+ const char *returnType = m.typeName();
+ if (returnType && *returnType) {
+ propTypeName = returnType;
+ flags |= Data::NotFullyResolved;
+ }
+
+ const char *signature = m.signature();
+ while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
+
+ ++signature;
+ if (*signature != ')') {
+ flags |= Data::HasArguments;
+ if (0 == ::strcmp(signature, "QDeclarativeV8Function*)")) {
+ flags |= Data::IsV8Function;
+ }
+ }
+
+ revision = m.revision();
+}
/*!
Creates a new empty QDeclarativePropertyCache.
*/
QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e)
-: QDeclarativeCleanup(e), engine(e)
+: QDeclarativeCleanup(e), engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0)
{
Q_ASSERT(engine);
}
@@ -126,7 +209,7 @@ QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e)
Creates a new QDeclarativePropertyCache of \a metaObject.
*/
QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e, const QMetaObject *metaObject)
-: QDeclarativeCleanup(e), engine(e)
+: QDeclarativeCleanup(e), engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0)
{
Q_ASSERT(engine);
Q_ASSERT(metaObject);
@@ -141,31 +224,16 @@ QDeclarativePropertyCache::~QDeclarativePropertyCache()
void QDeclarativePropertyCache::clear()
{
- for (int ii = 0; ii < indexCache.count(); ++ii) {
- if (indexCache.at(ii)) indexCache.at(ii)->release();
- }
-
- for (int ii = 0; ii < methodIndexCache.count(); ++ii) {
- RData *data = methodIndexCache.at(ii);
- if (data) data->release();
- }
+ if (parent) parent->release();
+ parent = 0;
- for (StringCache::ConstIterator iter = stringCache.begin();
- iter != stringCache.end(); ++iter) {
- RData *data = (*iter);
- data->release();
- }
-
- for (IdentifierCache::ConstIterator iter = identifierCache.begin();
- iter != identifierCache.end(); ++iter) {
- RData *data = (*iter);
- data->release();
- }
+ propertyIndexCacheStart = 0;
+ methodIndexCacheStart = 0;
- indexCache.clear();
+ propertyIndexCache.clear();
methodIndexCache.clear();
stringCache.clear();
- identifierCache.clear();
+ qPersistentDispose(constructor);
}
QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObject *metaObject,
@@ -213,25 +281,17 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj
return rv;
}
-QDeclarativePropertyCache *QDeclarativePropertyCache::copy() const
+QDeclarativePropertyCache *QDeclarativePropertyCache::copy()
{
QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine);
- cache->indexCache = indexCache;
- cache->methodIndexCache = methodIndexCache;
+ cache->parent = this;
+ cache->parent->addref();
+ cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
+ cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
cache->stringCache = stringCache;
- cache->identifierCache = identifierCache;
cache->allowedRevisionCache = allowedRevisionCache;
- for (int ii = 0; ii < indexCache.count(); ++ii) {
- if (indexCache.at(ii)) indexCache.at(ii)->addref();
- }
- for (int ii = 0; ii < methodIndexCache.count(); ++ii) {
- if (methodIndexCache.at(ii)) methodIndexCache.at(ii)->addref();
- }
- for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
- (*iter)->addref();
- for (IdentifierCache::ConstIterator iter = identifierCache.begin(); iter != identifierCache.end(); ++iter)
- (*iter)->addref();
+ // We specifically do *NOT* copy the constructor
return cache;
}
@@ -248,88 +308,101 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
{
Q_UNUSED(revision);
+ qPersistentDispose(constructor); // Now invalid
+
+ bool dynamicMetaObject = isDynamicMetaObject(metaObject);
+
allowedRevisionCache.append(0);
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
int methodCount = metaObject->methodCount();
// 3 to block the destroyed signal and the deleteLater() slot
int methodOffset = qMax(3, metaObject->methodOffset());
- methodIndexCache.resize(methodCount);
+ methodIndexCache.resize(methodCount - methodIndexCacheStart);
for (int ii = methodOffset; ii < methodCount; ++ii) {
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
- QString methodName = QString::fromUtf8(m.signature());
- int parenIdx = methodName.indexOf(QLatin1Char('('));
- Q_ASSERT(parenIdx != -1);
- methodName = methodName.left(parenIdx);
+ // Extract method name
+ const char *signature = m.signature();
+ const char *cptr = signature;
+ while (*cptr != '(') { Q_ASSERT(*cptr != 0); ++cptr; }
+ QString str = dynamicMetaObject?QString::fromUtf8(signature, cptr - signature):
+ QString::fromLatin1(signature, cptr - signature);
+ QHashedString methodName(str);
- RData *data = new RData;
- data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName);
- methodIndexCache[ii] = data;
+ Data *data = &methodIndexCache[ii - methodIndexCacheStart];
- data->load(m);
- if (m.methodType() == QMetaMethod::Slot || m.methodType() == QMetaMethod::Method)
- data->flags |= methodFlags;
- else if (m.methodType() == QMetaMethod::Signal)
+ data->lazyLoad(m);
+ if (data->isSignal())
data->flags |= signalFlags;
+ else
+ data->flags |= methodFlags;
+
+ if (!dynamicMetaObject)
+ data->flags |= Data::IsDirect;
data->metaObjectOffset = allowedRevisionCache.count() - 1;
- if (stringCache.contains(methodName)) {
- RData *old = stringCache[methodName];
+ if (Data **old = stringCache.value(methodName)) {
// We only overload methods in the same class, exactly like C++
- if (old->flags & Data::IsFunction && old->coreIndex >= methodOffset)
- data->relatedIndex = old->coreIndex;
- data->overrideIndexIsProperty = !bool(old->flags & Data::IsFunction);
- data->overrideIndex = old->coreIndex;
- stringCache[methodName]->release();
- identifierCache[data->identifier.identifier]->release();
+ if ((*old)->flags & Data::IsFunction && (*old)->coreIndex >= methodOffset)
+ data->relatedIndex = (*old)->coreIndex;
+ data->overrideIndexIsProperty = !bool((*old)->flags & Data::IsFunction);
+ data->overrideIndex = (*old)->coreIndex;
}
stringCache.insert(methodName, data);
- identifierCache.insert(data->identifier.identifier, data);
- data->addref();
- data->addref();
}
int propCount = metaObject->propertyCount();
int propOffset = metaObject->propertyOffset();
- indexCache.resize(propCount);
+ propertyIndexCache.resize(propCount - propertyIndexCacheStart);
for (int ii = propOffset; ii < propCount; ++ii) {
QMetaProperty p = metaObject->property(ii);
if (!p.isScriptable())
continue;
- QString propName = QString::fromUtf8(p.name());
+ QString str = dynamicMetaObject?QString::fromUtf8(p.name()):
+ QString::fromLatin1(p.name());
+ QHashedString propName(str);
- RData *data = new RData;
- data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName);
- indexCache[ii] = data;
+ Data *data = &propertyIndexCache[ii - propertyIndexCacheStart];
- data->load(p, engine);
+ data->lazyLoad(p, engine);
data->flags |= propertyFlags;
+ if (!dynamicMetaObject)
+ data->flags |= Data::IsDirect;
+
data->metaObjectOffset = allowedRevisionCache.count() - 1;
- if (stringCache.contains(propName)) {
- RData *old = stringCache[propName];
- data->overrideIndexIsProperty = !bool(old->flags & Data::IsFunction);
- data->overrideIndex = old->coreIndex;
- stringCache[propName]->release();
- identifierCache[data->identifier.identifier]->release();
+ if (Data **old = stringCache.value(propName)) {
+ data->overrideIndexIsProperty = !bool((*old)->flags & Data::IsFunction);
+ data->overrideIndex = (*old)->coreIndex;
}
stringCache.insert(propName, data);
- identifierCache.insert(data->identifier.identifier, data);
- data->addref();
- data->addref();
}
}
+void QDeclarativePropertyCache::resolve(Data *data) const
+{
+ Q_ASSERT(data->notFullyResolved());
+
+ data->propType = QMetaType::type(data->propTypeName);
+ if (QVariant::Type(data->propType) == QVariant::LastType)
+ data->propType = qMetaTypeId<QVariant>();
+
+
+ if (!(data->flags & Data::IsFunction))
+ data->flags |= flagsForPropertyType(data->propType, engine);
+
+ data->flags &= ~Data::NotFullyResolved;
+}
+
void QDeclarativePropertyCache::updateRecur(QDeclarativeEngine *engine, const QMetaObject *metaObject)
{
if (!metaObject)
@@ -348,7 +421,7 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb
clear();
// Optimization to prevent unnecessary reallocation of lists
- indexCache.reserve(metaObject->propertyCount());
+ propertyIndexCache.reserve(metaObject->propertyCount());
methodIndexCache.reserve(metaObject->methodCount());
updateRecur(engine,metaObject);
@@ -357,25 +430,37 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb
QDeclarativePropertyCache::Data *
QDeclarativePropertyCache::property(int index) const
{
- if (index < 0 || index >= indexCache.count())
+ if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
return 0;
+
+ if (index < propertyIndexCacheStart)
+ return parent->property(index);
- return indexCache.at(index);
+ Data *rv = const_cast<Data *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
+ if (rv->notFullyResolved()) resolve(rv);
+ return rv;
}
QDeclarativePropertyCache::Data *
QDeclarativePropertyCache::method(int index) const
{
- if (index < 0 || index >= methodIndexCache.count())
+ if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
return 0;
- return methodIndexCache.at(index);
+ if (index < methodIndexCacheStart)
+ return parent->method(index);
+
+ Data *rv = const_cast<Data *>(&methodIndexCache.at(index - methodIndexCacheStart));
+ if (rv->notFullyResolved()) resolve(rv);
+ return rv;
}
QDeclarativePropertyCache::Data *
QDeclarativePropertyCache::property(const QString &str) const
{
- return stringCache.value(str);
+ QDeclarativePropertyCache::Data **rv = stringCache.value(str);
+ if (rv && (*rv)->notFullyResolved()) resolve(*rv);
+ return rv?*rv:0;
}
QString QDeclarativePropertyCache::Data::name(QObject *object)
@@ -407,29 +492,38 @@ QString QDeclarativePropertyCache::Data::name(const QMetaObject *metaObject)
QStringList QDeclarativePropertyCache::propertyNames() const
{
- return stringCache.keys();
+ QStringList keys;
+ for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
+ keys.append(iter.key());
+ return keys;
}
-QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
- const QScriptDeclarativeClass::Identifier &name, Data &local)
+QDeclarativePropertyCache::Data *
+QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
+ const QHashedV8String &name, Data &local)
{
- QDeclarativePropertyCache::Data *rv = 0;
-
- QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine);
-
+ // XXX Optimize for worker script case where engine isn't available
QDeclarativePropertyCache *cache = 0;
- QDeclarativeData *ddata = QDeclarativeData::get(obj);
- if (ddata && ddata->propertyCache && ddata->propertyCache->qmlEngine() == engine)
- cache = ddata->propertyCache;
- if (!cache) {
- cache = enginePrivate->cache(obj);
- if (cache && ddata && !ddata->propertyCache) { cache->addref(); ddata->propertyCache = cache; }
+ if (engine) {
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+
+ QDeclarativeData *ddata = QDeclarativeData::get(obj);
+ if (ddata && ddata->propertyCache && ddata->propertyCache->qmlEngine() == engine) // XXX aakenend
+ cache = ddata->propertyCache;
+ if (!cache) {
+ cache = ep->cache(obj);
+ if (cache && ddata && !ddata->propertyCache) { cache->addref(); ddata->propertyCache = cache; }
+ }
}
+ QDeclarativePropertyCache::Data *rv = 0;
+
if (cache) {
rv = cache->property(name);
} else {
- local = QDeclarativePropertyCache::create(obj->metaObject(), enginePrivate->objectClass->toString(name));
+ QString strname = QV8Engine::toStringStatic(name.string());
+ // QString strname = ep->v8engine.toString(name);
+ local = QDeclarativePropertyCache::create(obj->metaObject(), strname);
if (local.isValid())
rv = &local;
}
@@ -437,8 +531,9 @@ QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(QDeclarativ
return rv;
}
-QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
- const QString &name, Data &local)
+QDeclarativePropertyCache::Data *
+QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
+ const QString &name, Data &local)
{
QDeclarativePropertyCache::Data *rv = 0;
@@ -470,4 +565,12 @@ QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(QDeclarativ
return rv;
}
+static inline const QMetaObjectPrivate *priv(const uint* data)
+{ return reinterpret_cast<const QMetaObjectPrivate*>(data); }
+
+bool QDeclarativePropertyCache::isDynamicMetaObject(const QMetaObject *mo)
+{
+ return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h
index 7e34748c6c..1787e6ad14 100644
--- a/src/declarative/qml/qdeclarativepropertycache_p.h
+++ b/src/declarative/qml/qdeclarativepropertycache_p.h
@@ -57,6 +57,7 @@
#include "private/qdeclarativecleanup_p.h"
#include "private/qdeclarativenotifier_p.h"
+#include "private/qhashedstring_p.h"
#include <QtCore/qvector.h>
#include <QtScript/private/qscriptdeclarativeclass_p.h>
@@ -64,6 +65,8 @@ QT_BEGIN_NAMESPACE
class QDeclarativeEngine;
class QMetaProperty;
+class QV8Engine;
+class QV8QObjectWrapper;
class Q_AUTOTEST_EXPORT QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarativeCleanup
{
@@ -80,32 +83,62 @@ public:
NoFlags = 0x00000000,
// Can apply to all properties, except IsFunction
- IsConstant = 0x00000001,
- IsWritable = 0x00000002,
- IsResettable = 0x00000004,
- IsAlias = 0x00000008,
- IsFinal = 0x00000010,
+ IsConstant = 0x00000001, // Has CONST flag
+ IsWritable = 0x00000002, // Has WRITE function
+ IsResettable = 0x00000004, // Has RESET function
+ IsAlias = 0x00000008, // Is a QML alias to another property
+ IsFinal = 0x00000010, // Has FINAL flag
+ IsDirect = 0x00000020, // Exists on a C++ QMetaObject
// These are mutualy exclusive
- IsFunction = 0x00000020,
- IsQObjectDerived = 0x00000040,
- IsEnumType = 0x00000080,
- IsQList = 0x00000100,
- IsQmlBinding = 0x00000200,
- IsQScriptValue = 0x00000400,
+ IsFunction = 0x00000040, // Is an invokable
+ IsQObjectDerived = 0x00000080, // Property type is a QObject* derived type
+ IsEnumType = 0x00000100, // Property type is an enum
+ IsQList = 0x00000200, // Property type is a QML list
+ IsQmlBinding = 0x00000400, // Property type is a QDeclarativeBinding*
+ IsQScriptValue = 0x00000800, // Property type is a QScriptValue
+ IsV8Handle = 0x00001000, // Property type is a QDeclarativeV8Handle
// Apply only to IsFunctions
- IsVMEFunction = 0x00000800,
- HasArguments = 0x00001000,
- IsSignal = 0x00002000,
- IsVMESignal = 0x00004000
+ IsVMEFunction = 0x00002000, // Function was added by QML
+ HasArguments = 0x00004000, // Function takes arguments
+ IsSignal = 0x00008000, // Function is a signal
+ IsVMESignal = 0x00010000, // Signal was added by QML
+ IsV8Function = 0x00020000, // Function takes QDeclarativeV8Function* args
+
+ // Internal QDeclarativePropertyCache flags
+ NotFullyResolved = 0x00040000 // True if the type data is to be lazily resolved
};
Q_DECLARE_FLAGS(Flags, Flag)
+ Flags getFlags() const { return flags; }
+ void setFlags(Flags f) { flags = f; }
+
bool isValid() const { return coreIndex != -1; }
- Flags flags;
- int propType;
+ bool isConstant() const { return flags & IsConstant; }
+ bool isWritable() const { return flags & IsWritable; }
+ bool isResettable() const { return flags & IsResettable; }
+ bool isAlias() const { return flags & IsAlias; }
+ bool isFinal() const { return flags & IsFinal; }
+ bool isDirect() const { return flags & IsDirect; }
+ bool isFunction() const { return flags & IsFunction; }
+ bool isQObject() const { return flags & IsQObjectDerived; }
+ bool isEnum() const { return flags & IsEnumType; }
+ bool isQList() const { return flags & IsQList; }
+ bool isQmlBinding() const { return flags & IsQmlBinding; }
+ bool isQScriptValue() const { return flags & IsQScriptValue; }
+ bool isV8Handle() const { return flags & IsV8Handle; }
+ bool isVMEFunction() const { return flags & IsVMEFunction; }
+ bool hasArguments() const { return flags & HasArguments; }
+ bool isSignal() const { return flags & IsSignal; }
+ bool isVMESignal() const { return flags & IsVMESignal; }
+ bool isV8Function() const { return flags & IsV8Function; }
+
+ union {
+ int propType; // When !NotFullyResolved
+ const char *propTypeName; // When NotFullyResolved
+ };
int coreIndex;
union {
int notifyIndex; // When !IsFunction
@@ -121,6 +154,13 @@ public:
void load(const QMetaMethod &);
QString name(QObject *);
QString name(const QMetaObject *);
+
+ private:
+ void lazyLoad(const QMetaProperty &, QDeclarativeEngine *engine = 0);
+ void lazyLoad(const QMetaMethod &);
+ bool notFullyResolved() const { return flags & NotFullyResolved; }
+ friend class QDeclarativePropertyCache;
+ Flags flags;
};
struct ValueTypeData {
@@ -133,7 +173,7 @@ public:
void update(QDeclarativeEngine *, const QMetaObject *);
- QDeclarativePropertyCache *copy() const;
+ QDeclarativePropertyCache *copy();
void append(QDeclarativeEngine *, const QMetaObject *, Data::Flag propertyFlags = Data::NoFlags,
Data::Flag methodFlags = Data::NoFlags, Data::Flag signalFlags = Data::NoFlags);
void append(QDeclarativeEngine *, const QMetaObject *, int revision, Data::Flag propertyFlags = Data::NoFlags,
@@ -141,7 +181,7 @@ public:
static Data create(const QMetaObject *, const QString &);
- inline Data *property(const QScriptDeclarativeClass::Identifier &id) const;
+ inline Data *property(const QHashedV8String &) const;
Data *property(const QString &) const;
Data *property(int) const;
Data *method(int) const;
@@ -151,38 +191,44 @@ public:
inline bool isAllowedInRevision(Data *) const;
inline QDeclarativeEngine *qmlEngine() const;
- static Data *property(QDeclarativeEngine *, QObject *, const QScriptDeclarativeClass::Identifier &, Data &);
static Data *property(QDeclarativeEngine *, QObject *, const QString &, Data &);
+ static Data *property(QDeclarativeEngine *, QObject *, const QHashedV8String &, Data &);
+ static bool isDynamicMetaObject(const QMetaObject *);
protected:
virtual void clear();
private:
friend class QDeclarativeEnginePrivate;
+ friend class QV8QObjectWrapper;
- struct RData : public Data, public QDeclarativeRefCount {
- QScriptDeclarativeClass::PersistentIdentifier identifier;
- };
+ // Implemented in v8/qv8qobjectwrapper.cpp
+ v8::Local<v8::Object> newQObject(QObject *, QV8Engine *);
- typedef QVector<RData *> IndexCache;
- typedef QHash<QString, RData *> StringCache;
- typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache;
+ typedef QVector<Data> IndexCache;
+ typedef QStringHash<Data *> StringCache;
typedef QVector<int> AllowedRevisionCache;
+ void resolve(Data *) const;
void updateRecur(QDeclarativeEngine *, const QMetaObject *);
QDeclarativeEngine *engine;
- IndexCache indexCache;
+
+ QDeclarativePropertyCache *parent;
+ int propertyIndexCacheStart;
+ int methodIndexCacheStart;
+
+ IndexCache propertyIndexCache;
IndexCache methodIndexCache;
StringCache stringCache;
- IdentifierCache identifierCache;
AllowedRevisionCache allowedRevisionCache;
+ v8::Persistent<v8::Function> constructor;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyCache::Data::Flags);
QDeclarativePropertyCache::Data::Data()
-: flags(0), propType(0), coreIndex(-1), notifyIndex(-1), overrideIndexIsProperty(false), overrideIndex(-1),
- revision(0), metaObjectOffset(-1)
+: propType(0), coreIndex(-1), notifyIndex(-1), overrideIndexIsProperty(false), overrideIndex(-1),
+ revision(0), metaObjectOffset(-1), flags(0)
{
}
@@ -202,15 +248,9 @@ QDeclarativePropertyCache::overrideData(Data *data) const
return 0;
if (data->overrideIndexIsProperty)
- return indexCache.at(data->overrideIndex);
+ return property(data->overrideIndex);
else
- return methodIndexCache.at(data->overrideIndex);
-}
-
-QDeclarativePropertyCache::Data *
-QDeclarativePropertyCache::property(const QScriptDeclarativeClass::Identifier &id) const
-{
- return identifierCache.value(id);
+ return method(data->overrideIndex);
}
QDeclarativePropertyCache::ValueTypeData::ValueTypeData()
@@ -236,6 +276,13 @@ QDeclarativeEngine *QDeclarativePropertyCache::qmlEngine() const
return engine;
}
+QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(const QHashedV8String &str) const
+{
+ QDeclarativePropertyCache::Data **rv = stringCache.value(str);
+ if (rv && (*rv)->notFullyResolved()) resolve(*rv);
+ return rv?*rv:0;
+}
+
QT_END_NAMESPACE
#endif // QDECLARATIVEPROPERTYCACHE_P_H
diff --git a/src/declarative/qml/qdeclarativerefcount_p.h b/src/declarative/qml/qdeclarativerefcount_p.h
index 3bbb7b0ff3..381327098c 100644
--- a/src/declarative/qml/qdeclarativerefcount_p.h
+++ b/src/declarative/qml/qdeclarativerefcount_p.h
@@ -73,6 +73,73 @@ private:
int refCount;
};
+template<class T>
+class QDeclarativeRefPointer
+{
+public:
+ inline QDeclarativeRefPointer();
+ inline QDeclarativeRefPointer(T *);
+ inline QDeclarativeRefPointer(const QDeclarativeRefPointer<T> &);
+ inline ~QDeclarativeRefPointer();
+
+ inline QDeclarativeRefPointer<T> &operator=(const QDeclarativeRefPointer<T> &o);
+ inline QDeclarativeRefPointer<T> &operator=(T *);
+
+ inline bool isNull() const { return !o; }
+
+ inline T* operator->() const { return o; }
+ inline T& operator*() const { return *o; }
+ inline operator T*() const { return o; }
+ inline T* data() const { return o; }
+
+private:
+ T *o;
+};
+
+template<class T>
+QDeclarativeRefPointer<T>::QDeclarativeRefPointer()
+: o(0)
+{
+}
+
+template<class T>
+QDeclarativeRefPointer<T>::QDeclarativeRefPointer(T *o)
+: o(o)
+{
+ if (o) o->addref();
+}
+
+template<class T>
+QDeclarativeRefPointer<T>::QDeclarativeRefPointer(const QDeclarativeRefPointer<T> &other)
+: o(other.o)
+{
+ if (o) o->addref();
+}
+
+template<class T>
+QDeclarativeRefPointer<T>::~QDeclarativeRefPointer()
+{
+ if (o) o->release();
+}
+
+template<class T>
+QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::operator=(const QDeclarativeRefPointer<T> &other)
+{
+ if (other.o) other.o->addref();
+ if (o) o->release();
+ o = other.o;
+ return *this;
+}
+
+template<class T>
+QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::operator=(T *other)
+{
+ if (other) other->addref();
+ if (o) o->release();
+ o = other;
+ return *this;
+}
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/declarative/qml/qdeclarativerewrite.cpp b/src/declarative/qml/qdeclarativerewrite.cpp
index 2e5cebb1d1..bff296b00b 100644
--- a/src/declarative/qml/qdeclarativerewrite.cpp
+++ b/src/declarative/qml/qdeclarativerewrite.cpp
@@ -135,7 +135,7 @@ QString RewriteBinding::operator()(QDeclarativeJS::AST::Node *node, const QStrin
if (rewriteDump()) {
qWarning() << "To:";
- qWarning() << qPrintable(code);
+ qWarning() << qPrintable(codeCopy);
qWarning() << "=============================================================";
}
diff --git a/src/declarative/qml/qdeclarativescarceresourcescriptclass.cpp b/src/declarative/qml/qdeclarativescarceresourcescriptclass.cpp
deleted file mode 100644
index d8c11ac35e..0000000000
--- a/src/declarative/qml/qdeclarativescarceresourcescriptclass.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativescarceresourcescriptclass_p.h"
-
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativecontext_p.h"
-#include "private/qdeclarativedata_p.h"
-#include "private/qdeclarativetypenamescriptclass_p.h"
-#include "private/qdeclarativelistscriptclass_p.h"
-#include "private/qdeclarativebinding_p.h"
-#include "private/qdeclarativeguard_p.h"
-#include "private/qdeclarativevmemetaobject_p.h"
-
-#include <QtCore/qtimer.h>
-#include <QtCore/qvarlengtharray.h>
-#include <QtScript/qscriptcontextinfo.h>
-
-Q_DECLARE_METATYPE(QScriptValue);
-
-QT_BEGIN_NAMESPACE
-
-QDeclarativeScarceResourceScriptClass::QDeclarativeScarceResourceScriptClass(QDeclarativeEngine *bindEngine)
- : QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- // Properties of this type can be explicitly preserved by clients,
- // which prevents the scarce resource from being automatically
- // released after the binding has been evaluated.
- m_preserve = scriptEngine->newFunction(preserve);
- m_preserveId = createPersistentIdentifier(QLatin1String("preserve"));
-
- // Similarly, they can be explicitly destroyed by clients,
- // which releases the scarce resource.
- m_destroy = scriptEngine->newFunction(destroy);
- m_destroyId = createPersistentIdentifier(QLatin1String("destroy"));
-}
-
-QDeclarativeScarceResourceScriptClass::~QDeclarativeScarceResourceScriptClass()
-{
-}
-
-/*
- Returns a JavaScript object whose instance data is a new scarce resource data.
- The scarce resource is added to the doubly-linked-list of scarce resources in the engine
- so that the scarce resource can be released after evaluation completes.
- */
-QScriptValue QDeclarativeScarceResourceScriptClass::newScarceResource(const QVariant &v)
-{
- // create the scarce resource
- ScarceResourceData *srd = new ScarceResourceData(v);
-
- // insert into the linked list
- QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine);
- srd->insertInto(&enginePrivate->scarceResources);
- Q_ASSERT(enginePrivate->scarceResourcesRefCount > 0);
-
- // return the javascript object with the scarce resource instance data
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- return QScriptDeclarativeClass::newObject(scriptEngine, this, srd); // JSC takes ownership of srd.
-}
-
-QVariant QDeclarativeScarceResourceScriptClass::toVariant(Object *object, bool *ok)
-{
- ScarceResourceData *obj = static_cast<ScarceResourceData*>(object);
- if (ok) *ok = true;
- return obj->resource;
-}
-
-QVariant QDeclarativeScarceResourceScriptClass::toVariant(const QScriptValue &value)
-{
- Q_ASSERT(scriptClass(value) == this);
-
- return toVariant(object(value), 0);
-}
-
-// The destroy() and preserve() function properties are readable.
-QScriptClass::QueryFlags
-QDeclarativeScarceResourceScriptClass::queryProperty(Object *object, const Identifier &name,
- QScriptClass::QueryFlags flags)
-{
- Q_UNUSED(object)
- Q_UNUSED(flags)
-
- if (name == m_destroyId.identifier || name == m_preserveId.identifier)
- return (QScriptClass::HandlesReadAccess);
- return 0;
-}
-
-// Return the (function) values which may be evaluated by clients.
-QDeclarativeScarceResourceScriptClass::Value
-QDeclarativeScarceResourceScriptClass::property(Object *object, const Identifier &name)
-{
- Q_UNUSED(object)
-
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- // functions
- if (name == m_preserveId.identifier)
- return Value(scriptEngine, m_preserve);
- else if (name == m_destroyId.identifier)
- return Value(scriptEngine, m_destroy);
-
- return Value();
-}
-
-/*
- This method is called when the user explicitly calls the "preserve" method of a scarce resource in JavaScript
- within the specified evaluation context \a context of the script engine \a engine.
- Calling this function signifies that the user explicitly wants to preserve the resource rather than let it
- be automatically released once evaluation of the expression is complete.
- This function removes the internal scarce resource from the declarative engine's linked list of scarce resources
- to release after evaluation of the expression completes. This means that the resource will only be truly
- released when the JavaScript engine's garbage collector is run.
-
- Example:
- \qml
- function getIcon(model) {
- var icon = model.avatar; // a pixmap property
- icon.preserve(); // explicitly preserves the resource
- return icon; // a valid variant will be returned
- }
- \endqml
- */
-QScriptValue QDeclarativeScarceResourceScriptClass::preserve(QScriptContext *context, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
- QScriptValue that = context->thisObject();
-
- if (scriptClass(that) != p->scarceResourceClass)
- return engine->undefinedValue();
-
- // The client wishes to preserve the resource in this SRD.
- ScarceResourceData *data = static_cast<ScarceResourceData *>(p->scarceResourceClass->object(that));
- if (!data)
- return engine->undefinedValue();
-
- // remove node from list, without releasing the resource.
- data->removeNode();
-
- return engine->undefinedValue();
-}
-
-/*
- This method is called when the user explicitly calls the "destroy" method of a scarce resource in JavaScript
- within the specified evaluation context \a context of the script engine \a engine.
- Calling this function signifies that the user explicitly wants to release the resource.
- This function sets the internal scarce resource variant to the invalid variant, in order to release the original resource,
- and then removes the resource from the declarative engine's linked-list of scarce resources to
- to release after evaluation of the expression completes, as it has already been released.
-
- Example:
- \qml
- function getIcon(model) {
- var icon = model.avatar; // a pixmap property
- icon.destroy(); // explicitly releases the resource
- return icon; // an invalid variant will be returned
- }
- \endqml
- */
-QScriptValue QDeclarativeScarceResourceScriptClass::destroy(QScriptContext *context, QScriptEngine *engine)
-{
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
- QScriptValue that = context->thisObject();
-
- if (scriptClass(that) != p->scarceResourceClass)
- return engine->undefinedValue();
-
- // the client wishes to release the resource in this SRD.
- ScarceResourceData *data = static_cast<ScarceResourceData *>(p->scarceResourceClass->object(that));
- if (!data)
- return engine->undefinedValue();
-
- // release the resource and remove the node from the list.
- data->releaseResource();
-
- return engine->undefinedValue();
-}
-
-QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativescarceresourcescriptclass_p.h b/src/declarative/qml/qdeclarativescarceresourcescriptclass_p.h
deleted file mode 100644
index ef96db6545..0000000000
--- a/src/declarative/qml/qdeclarativescarceresourcescriptclass_p.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVESCARCERESOURCESCRIPTCLASS_P_H
-#define QDECLARATIVESCARCERESOURCESCRIPTCLASS_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "private/qdeclarativepropertycache_p.h"
-#include "private/qdeclarativetypenamecache_p.h"
-
-#include <private/qscriptdeclarativeclass_p.h>
-#include <QtScript/qscriptengine.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeEngine;
-
-/*
- Scarce resources (like pixmaps and textures) are managed manually
- in that the variant will be set to the invalid variant once the
- JavaScript engine has finished using the JavaScript object whose
- instance data is the ScarceResourceData (but before the garbage
- collector frees the JavaScript object itself).
-
- The engine stores a doubly-linked-list of scarce resources which
- will to be cleaned up after a binding is successfully evaluated
- (unless the user explicitly preserves the scarce resource).
-
- A ScarceResourceData pointer should not be deleted manually, as
- all instances of a ScarceResourceData should be owned by the
- JavaScript engine.
- */
-struct ScarceResourceData : public QScriptDeclarativeClass::Object {
- ScarceResourceData(const QVariant &v) : resource(v), prev(0), next(0)
- {
- }
-
- virtual ~ScarceResourceData()
- {
- releaseResource();
- }
-
- // Insert this resource into the given list of resources.
- void insertInto(ScarceResourceData **list)
- {
- // This node becomes the head of the list.
- next = *list; // so our next = old list head
- *list = this; // list now points to us (we're the head)
- prev = list; // as we're the head, our prev ptr becomes the list ptr.
-
- // and the next node's prev pointer must contain a ptr to our next ptr,
- // since per definition, prev always contains a pointer to the previous node's "next" ptr,
- // and the "this" node is the "this->next" node's "prev" node.
- if (next) next->prev = &next;
- }
-
- // Remove this resource from the list of resources, without releasing the resource.
- void removeNode()
- {
- // whatever previously pointed to this node (ie, as that node's "next" node)
- // should now point to our next node (since we no longer exist in the list).
- // and the next node's prev ptr should point to our prev node.
- if (prev) *prev = next;
- if (next) next->prev = prev;
- prev = 0;
- next = 0;
- }
-
- // Release this resource, and remove from the list.
- void releaseResource()
- {
- resource = QVariant();
- removeNode();
- }
-
- QVariant resource;
-
- // prev always contains a pointer to the previous node's "next" ptr.
- // :. for the head node, [*prev] will be engine->scarceResources
- // :. for every other node, [*prev] will be the previous node's "next" ptr.
- ScarceResourceData **prev;
- ScarceResourceData *next;
-};
-
-class Q_AUTOTEST_EXPORT QDeclarativeScarceResourceScriptClass : public QScriptDeclarativeClass
-{
-public:
- QDeclarativeScarceResourceScriptClass(QDeclarativeEngine *);
- ~QDeclarativeScarceResourceScriptClass();
-
- // Creates a new JavaScript object whose instance data is the scarce resource v
- QScriptValue newScarceResource(const QVariant &v);
-
- // inherited from QScriptDeclarativeClass
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
- QScriptClass::QueryFlags flags);
- virtual Value property(Object *, const Identifier &);
- virtual QVariant toVariant(Object *, bool *ok = 0);
- QVariant toVariant(const QScriptValue &value);
-
-private:
- PersistentIdentifier m_preserveId;
- PersistentIdentifier m_destroyId;
- QScriptValue m_preserve;
- QScriptValue m_destroy;
-
- static QScriptValue preserve(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue destroy(QScriptContext *context, QScriptEngine *engine);
-
- QDeclarativeEngine *engine;
-};
-
-QT_END_NAMESPACE
-
-#endif // QDECLARATIVESCARCERESOURCESCRIPTCLASS_P_H
diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp
index df1dec5efc..3f843295d7 100644
--- a/src/declarative/qml/qdeclarativescriptparser.cpp
+++ b/src/declarative/qml/qdeclarativescriptparser.cpp
@@ -740,19 +740,6 @@ bool ProcessAST::visit(AST::UiScriptBinding *node)
return false;
}
-static QList<int> collectCommas(AST::UiArrayMemberList *members)
-{
- QList<int> commas;
-
- if (members) {
- for (AST::UiArrayMemberList *it = members->next; it; it = it->next) {
- commas.append(it->commaToken.offset);
- }
- }
-
- return commas;
-}
-
// UiObjectMember: UiQualifiedId T_COLON T_LBRACKET UiArrayMemberList T_RBRACKET ;
bool ProcessAST::visit(AST::UiArrayBinding *node)
{
@@ -781,9 +768,6 @@ bool ProcessAST::visit(AST::UiArrayBinding *node)
prop->listValueRange.offset = node->lbracketToken.offset;
prop->listValueRange.length = node->rbracketToken.offset + node->rbracketToken.length - node->lbracketToken.offset;
- // Store the positions of the comma token too, again for the DOM to be able to retrieve it.
- prop->listCommaPositions = collectCommas(node->members);
-
while (propertyCount--)
_stateStack.pop();
diff --git a/src/declarative/qml/qdeclarativesqldatabase.cpp b/src/declarative/qml/qdeclarativesqldatabase.cpp
index 588b6bf306..df072ed02d 100644
--- a/src/declarative/qml/qdeclarativesqldatabase.cpp
+++ b/src/declarative/qml/qdeclarativesqldatabase.cpp
@@ -47,101 +47,21 @@
#include "private/qdeclarativeengine_p.h"
#include <QtCore/qobject.h>
-#include <QtScript/qscriptvalue.h>
-#include <QtScript/qscriptvalueiterator.h>
-#include <QtScript/qscriptcontext.h>
-#include <QtScript/qscriptengine.h>
-#include <QtScript/qscriptclasspropertyiterator.h>
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlerror.h>
#include <QtSql/qsqlrecord.h>
+#include <QtGui/qdesktopservices.h>
#include <QtCore/qstack.h>
#include <QtCore/qcryptographichash.h>
#include <QtCore/qsettings.h>
#include <QtCore/qdir.h>
#include <QtCore/qdebug.h>
-Q_DECLARE_METATYPE(QSqlDatabase)
-Q_DECLARE_METATYPE(QSqlQuery)
+#include <private/qv8engine_p.h>
QT_BEGIN_NAMESPACE
-class QDeclarativeSqlQueryScriptClass: public QScriptClass {
-public:
- QDeclarativeSqlQueryScriptClass(QScriptEngine *engine) : QScriptClass(engine)
- {
- str_length = engine->toStringHandle(QLatin1String("length"));
- str_forwardOnly = engine->toStringHandle(QLatin1String("forwardOnly")); // not in HTML5 (an optimization)
- }
-
- QueryFlags queryProperty(const QScriptValue &,
- const QScriptString &name,
- QueryFlags flags, uint *)
- {
- if (flags & HandlesReadAccess) {
- if (name == str_length) {
- return HandlesReadAccess;
- } else if (name == str_forwardOnly) {
- return flags;
- }
- }
- if (flags & HandlesWriteAccess)
- if (name == str_forwardOnly)
- return flags;
- return 0;
- }
-
- QScriptValue property(const QScriptValue &object,
- const QScriptString &name, uint)
- {
- QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
- if (name == str_length) {
- int s = query.size();
- if (s<0) {
- // Inefficient.
- if (query.last()) {
- return query.at()+1;
- } else {
- return 0;
- }
- } else {
- return s;
- }
- } else if (name == str_forwardOnly) {
- return query.isForwardOnly();
- }
- return engine()->undefinedValue();
- }
-
- void setProperty(QScriptValue &object,
- const QScriptString &name, uint, const QScriptValue & value)
- {
- if (name == str_forwardOnly) {
- QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
- query.setForwardOnly(value.toBool());
- }
- }
-
- QScriptValue::PropertyFlags propertyFlags(const QScriptValue &/*object*/, const QScriptString &name, uint /*id*/)
- {
- if (name == str_length) {
- return QScriptValue::Undeletable
- | QScriptValue::SkipInEnumeration;
- }
- return QScriptValue::Undeletable;
- }
-
-private:
- QScriptString str_length;
- QScriptString str_forwardOnly;
-};
-
-// If the spec changes to allow iteration, check git history...
-// class QDeclarativeSqlQueryScriptClassPropertyIterator : public QScriptClassPropertyIterator
-
-
-
enum SqlException {
UNKNOWN_ERR,
DATABASE_ERR,
@@ -165,90 +85,227 @@ static const char* sqlerror[] = {
0
};
-#define THROW_SQL(error, desc) \
+#define THROW_SQL(error, desc)
+
+#define V8THROW_SQL(error, desc) \
{ \
- QScriptValue errorValue = context->throwError(desc); \
- errorValue.setProperty(QLatin1String("code"), error); \
- return errorValue; \
+ v8::Local<v8::Value> v = v8::Exception::Error(engine->toString(desc)); \
+ v->ToObject()->Set(v8::String::New("code"), v8::Integer::New(error)); \
+ v8::ThrowException(v); \
+ return v8::Handle<v8::Value>(); \
+}
+
+#define V8THROW_REFERENCE(string) { \
+ v8::ThrowException(v8::Exception::ReferenceError(v8::String::New(string))); \
+ return v8::Handle<v8::Value>(); \
+}
+
+#define V8THROW_REFERENCE_VOID(string) { \
+ v8::ThrowException(v8::Exception::ReferenceError(v8::String::New(string))); \
+ return; \
}
-static QString qmlsqldatabase_databasesPath(QScriptEngine *engine)
+struct QDeclarativeSqlDatabaseData {
+ QDeclarativeSqlDatabaseData(QV8Engine *engine);
+ ~QDeclarativeSqlDatabaseData();
+
+ QString offlineStoragePath;
+ v8::Persistent<v8::Function> constructor;
+ v8::Persistent<v8::Function> queryConstructor;
+ v8::Persistent<v8::Function> rowsConstructor;
+
+ static inline QDeclarativeSqlDatabaseData *data(QV8Engine *e) {
+ return (QDeclarativeSqlDatabaseData *)e->sqlDatabaseData();
+ }
+ static inline QDeclarativeSqlDatabaseData *data(void *d) {
+ return (QDeclarativeSqlDatabaseData *)d;
+ }
+};
+
+class QV8SqlDatabaseResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(SQLDatabaseType)
+
+public:
+ enum Type { Database, Query, Rows };
+
+ QV8SqlDatabaseResource(QV8Engine *e)
+ : QV8ObjectResource(e), type(Database), inTransaction(false), readonly(false), forwardOnly(false) {}
+
+ Type type;
+ QSqlDatabase database;
+
+ QString version; // type == Database
+
+ bool inTransaction; // type == Query
+ bool readonly; // type == Query
+
+ QSqlQuery query; // type == Rows
+ bool forwardOnly; // type == Rows
+};
+
+static v8::Handle<v8::Value> qmlsqldatabase_version(v8::Local<v8::String> property, const v8::AccessorInfo& info)
{
- QDeclarativeScriptEngine *qmlengine = static_cast<QDeclarativeScriptEngine*>(engine);
- return qmlengine->offlineStoragePath
- + QDir::separator() + QLatin1String("Databases");
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(info.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Database)
+ V8THROW_REFERENCE("Not a SQLDatabase object");
+
+ return r->engine->toString(r->version);
}
-static void qmlsqldatabase_initDatabasesPath(QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlsqldatabase_rows_length(v8::Local<v8::String> property, const v8::AccessorInfo& info)
{
- QDir().mkpath(qmlsqldatabase_databasesPath(engine));
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(info.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Rows)
+ V8THROW_REFERENCE("Not a SQLDatabase::Rows object");
+
+ int s = r->query.size();
+ if (s < 0) {
+ // Inefficient
+ if (r->query.last()) {
+ s = r->query.at() + 1;
+ } else {
+ s = 0;
+ }
+ }
+ return v8::Integer::New(s);
}
-static QString qmlsqldatabase_databaseFile(const QString& connectionName, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlsqldatabase_rows_forwardOnly(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info)
{
- return qmlsqldatabase_databasesPath(engine) + QDir::separator()
- + connectionName;
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(info.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Rows)
+ V8THROW_REFERENCE("Not a SQLDatabase::Rows object");
+
+ return v8::Boolean::New(r->query.isForwardOnly());
}
+static void qmlsqldatabase_rows_setForwardOnly(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo& info)
+{
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(info.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Rows)
+ V8THROW_REFERENCE_VOID("Not a SQLDatabase::Rows object");
+
+ r->query.setForwardOnly(value->BooleanValue());
+}
-static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine *engine)
+QDeclarativeSqlDatabaseData::~QDeclarativeSqlDatabaseData()
{
- QSqlQuery query = qscriptvalue_cast<QSqlQuery>(context->thisObject().data());
- int i = context->argument(0).toNumber();
- if (query.at() == i || query.seek(i)) { // Qt 4.6 doesn't optimize seek(at())
- QSqlRecord r = query.record();
- QScriptValue row = engine->newObject();
- for (int j=0; j<r.count(); ++j) {
- row.setProperty(r.fieldName(j), QScriptValue(engine,r.value(j).toString()));
+ qPersistentDispose(constructor);
+ qPersistentDispose(queryConstructor);
+}
+
+static QString qmlsqldatabase_databasesPath(QV8Engine *engine)
+{
+ return QDeclarativeSqlDatabaseData::data(engine)->offlineStoragePath +
+ QDir::separator() + QLatin1String("Databases");
+}
+
+static void qmlsqldatabase_initDatabasesPath(QV8Engine *engine)
+{
+ QDir().mkpath(qmlsqldatabase_databasesPath(engine));
+}
+
+static QString qmlsqldatabase_databaseFile(const QString& connectionName, QV8Engine *engine)
+{
+ return qmlsqldatabase_databasesPath(engine) + QDir::separator() + connectionName;
+}
+
+static v8::Handle<v8::Value> qmlsqldatabase_rows_index(QV8SqlDatabaseResource *r, uint32_t index)
+{
+ if (r->query.at() == index || r->query.seek(index)) {
+
+ QSqlRecord record = r->query.record();
+ // XXX optimize
+ v8::Local<v8::Object> row = v8::Object::New();
+ for (int ii = 0; ii < record.count(); ++ii) {
+ row->Set(r->engine->toString(record.fieldName(ii)),
+ r->engine->toString(record.value(ii).toString()));
}
return row;
+ } else {
+ return v8::Undefined();
}
- return engine->undefinedValue();
}
-static QScriptValue qmlsqldatabase_executeSql_outsidetransaction(QScriptContext *context, QScriptEngine * /*engine*/)
+static v8::Handle<v8::Value> qmlsqldatabase_rows_index(uint32_t index, const v8::AccessorInfo& info)
{
- THROW_SQL(DATABASE_ERR,QDeclarativeEngine::tr("executeSql called outside transaction()"));
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(info.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Rows)
+ V8THROW_REFERENCE("Not a SQLDatabase::Rows object");
+
+ return qmlsqldatabase_rows_index(r, index);
}
-static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlsqldatabase_rows_item(const v8::Arguments& args)
{
- QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject());
- QString sql = context->argument(0).toString();
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(args.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Rows)
+ V8THROW_REFERENCE("Not a SQLDatabase::Rows object");
+
+ return qmlsqldatabase_rows_index(r, args.Length()?args[0]->Uint32Value():0);
+}
+
+static v8::Handle<v8::Value> qmlsqldatabase_executeSql(const v8::Arguments& args)
+{
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(args.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Query)
+ V8THROW_REFERENCE("Not a SQLDatabase::Query object");
+
+ QV8Engine *engine = r->engine;
+
+ if (!r->inTransaction)
+ V8THROW_SQL(DATABASE_ERR,QDeclarativeEngine::tr("executeSql called outside transaction()"));
+
+ QSqlDatabase db = r->database;
+
+ QString sql = engine->toString(args[0]);
+
+ if (r->readonly && !sql.startsWith(QLatin1String("SELECT"),Qt::CaseInsensitive)) {
+ V8THROW_SQL(SYNTAX_ERR, QDeclarativeEngine::tr("Read-only Transaction"));
+ }
+
QSqlQuery query(db);
bool err = false;
- QScriptValue result;
+ v8::Handle<v8::Value> result = v8::Undefined();
if (query.prepare(sql)) {
- if (context->argumentCount() > 1) {
- QScriptValue values = context->argument(1);
- if (values.isObject()) {
- if (values.isArray()) {
- int size = values.property(QLatin1String("length")).toInt32();
- for (int i = 0; i < size; ++i)
- query.bindValue(i, values.property(i).toVariant());
- } else {
- for (QScriptValueIterator it(values); it.hasNext();) {
- it.next();
- query.bindValue(it.name(),it.value().toVariant());
- }
- }
+ if (args.Length() > 1) {
+ v8::Local<v8::Value> values = args[1];
+ if (values->IsArray()) {
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(values);
+ uint32_t size = array->Length();
+ for (uint32_t ii = 0; ii < size; ++ii)
+ query.bindValue(ii, engine->toVariant(array->Get(ii), -1));
+ } else if (values->IsObject() && !values->ToObject()->GetExternalResource()) {
+ v8::Local<v8::Object> object = values->ToObject();
+ v8::Local<v8::Array> names = object->GetPropertyNames();
+ uint32_t size = names->Length();
+ for (uint32_t ii = 0; ii < size; ++ii)
+ query.bindValue(engine->toString(names->Get(ii)),
+ engine->toVariant(object->Get(names->Get(ii)), -1));
} else {
- query.bindValue(0,values.toVariant());
+ query.bindValue(0, engine->toVariant(values, -1));
}
}
if (query.exec()) {
- result = engine->newObject();
- QDeclarativeScriptEngine *qmlengine = static_cast<QDeclarativeScriptEngine*>(engine);
- if (!qmlengine->sqlQueryClass)
- qmlengine->sqlQueryClass = new QDeclarativeSqlQueryScriptClass(engine);
- QScriptValue rows = engine->newObject(qmlengine->sqlQueryClass);
- rows.setData(engine->newVariant(QVariant::fromValue(query)));
- rows.setProperty(QLatin1String("item"), engine->newFunction(qmlsqldatabase_item,1), QScriptValue::SkipInEnumeration);
- result.setProperty(QLatin1String("rows"),rows);
- result.setProperty(QLatin1String("rowsAffected"),query.numRowsAffected());
- result.setProperty(QLatin1String("insertId"),query.lastInsertId().toString());
+ v8::Handle<v8::Object> rows = QDeclarativeSqlDatabaseData::data(engine)->rowsConstructor->NewInstance();
+ QV8SqlDatabaseResource *r = new QV8SqlDatabaseResource(engine);
+ r->type = QV8SqlDatabaseResource::Rows;
+ r->database = db;
+ r->query = query;
+ rows->SetExternalResource(r);
+
+ v8::Local<v8::Object> resultObject = v8::Object::New();
+ result = resultObject;
+ // XXX optimize
+ resultObject->Set(v8::String::New("rowsAffected"), v8::Integer::New(query.numRowsAffected()));
+ resultObject->Set(v8::String::New("insertId"), engine->toString(query.lastInsertId().toString()));
+ resultObject->Set(v8::String::New("rows"), rows);
} else {
err = true;
}
@@ -256,117 +313,138 @@ static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEn
err = true;
}
if (err)
- THROW_SQL(DATABASE_ERR,query.lastError().text());
+ V8THROW_SQL(DATABASE_ERR,query.lastError().text());
+
return result;
}
-static QScriptValue qmlsqldatabase_executeSql_readonly(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlsqldatabase_changeVersion(const v8::Arguments& args)
{
- QString sql = context->argument(0).toString();
- if (sql.startsWith(QLatin1String("SELECT"),Qt::CaseInsensitive)) {
- return qmlsqldatabase_executeSql(context,engine);
- } else {
- THROW_SQL(SYNTAX_ERR,QDeclarativeEngine::tr("Read-only Transaction"))
- }
-}
+ if (args.Length() < 2)
+ return v8::Undefined();
-static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScriptEngine *engine)
-{
- if (context->argumentCount() < 2)
- return engine->undefinedValue();
-
- QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject());
- QString from_version = context->argument(0).toString();
- QString to_version = context->argument(1).toString();
- QScriptValue callback = context->argument(2);
-
- QScriptValue instance = engine->newObject();
- instance.setProperty(QLatin1String("executeSql"), engine->newFunction(qmlsqldatabase_executeSql,1));
- QScriptValue tx = engine->newVariant(instance,QVariant::fromValue(db));
-
- QString foundvers = context->thisObject().property(QLatin1String("version")).toString();
- if (from_version!=foundvers) {
- THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("Version mismatch: expected %1, found %2").arg(from_version).arg(foundvers));
- return engine->undefinedValue();
- }
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(args.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Database)
+ V8THROW_REFERENCE("Not a SQLDatabase object");
+
+ QV8Engine *engine = r->engine;
+
+ QSqlDatabase db = r->database;
+ QString from_version = engine->toString(args[0]);
+ QString to_version = engine->toString(args[1]);
+ v8::Handle<v8::Value> callback = args[2];
+
+ if (from_version != r->version)
+ V8THROW_SQL(VERSION_ERR, QDeclarativeEngine::tr("Version mismatch: expected %1, found %2").arg(from_version).arg(r->version));
+
+ v8::Local<v8::Object> instance = QDeclarativeSqlDatabaseData::data(engine)->queryConstructor->NewInstance();
+ QV8SqlDatabaseResource *r2 = new QV8SqlDatabaseResource(engine);
+ r2->type = QV8SqlDatabaseResource::Query;
+ r2->database = db;
+ r2->version = r->version;
+ r2->inTransaction = true;
+ instance->SetExternalResource(r2);
bool ok = true;
- if (callback.isFunction()) {
+ if (callback->IsFunction()) {
ok = false;
db.transaction();
- callback.call(QScriptValue(), QScriptValueList() << tx);
- if (engine->hasUncaughtException()) {
+
+ v8::TryCatch tc;
+ v8::Handle<v8::Value> callbackArgs[] = { instance };
+ v8::Handle<v8::Function>::Cast(callback)->Call(engine->global(), 1, callbackArgs);
+
+ if (tc.HasCaught()) {
+ db.rollback();
+ tc.ReThrow();
+ return v8::Handle<v8::Value>();
+ } else if (!db.commit()) {
db.rollback();
+ V8THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("SQL transaction failed"));
} else {
- if (!db.commit()) {
- db.rollback();
- THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("SQL transaction failed"));
- } else {
- ok = true;
- }
+ ok = true;
}
}
+ r2->inTransaction = false;
+
if (ok) {
- context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly);
+ r2->version = to_version;
#ifndef QT_NO_SETTINGS
QSettings ini(qmlsqldatabase_databaseFile(db.connectionName(),engine) + QLatin1String(".ini"), QSettings::IniFormat);
ini.setValue(QLatin1String("Version"), to_version);
#endif
}
- return engine->undefinedValue();
+ return v8::Undefined();
}
-static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, QScriptEngine *engine, bool readOnly)
+static v8::Handle<v8::Value> qmlsqldatabase_transaction_shared(const v8::Arguments& args, bool readOnly)
{
- QSqlDatabase db = qscriptvalue_cast<QSqlDatabase>(context->thisObject());
- QScriptValue callback = context->argument(0);
- if (!callback.isFunction())
- THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("transaction: missing callback"));
-
- QScriptValue instance = engine->newObject();
- instance.setProperty(QLatin1String("executeSql"),
- engine->newFunction(readOnly ? qmlsqldatabase_executeSql_readonly : qmlsqldatabase_executeSql,1));
- QScriptValue tx = engine->newVariant(instance,QVariant::fromValue(db));
+ QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(args.This());
+ if (!r || r->type != QV8SqlDatabaseResource::Database)
+ V8THROW_REFERENCE("Not a SQLDatabase object");
+
+ QV8Engine *engine = r->engine;
+
+ if (args.Length() == 0 || !args[0]->IsFunction())
+ V8THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("transaction: missing callback"));
+
+ QSqlDatabase db = r->database;
+ v8::Handle<v8::Function> callback = v8::Handle<v8::Function>::Cast(args[0]);
+
+ v8::Local<v8::Object> instance = QDeclarativeSqlDatabaseData::data(engine)->queryConstructor->NewInstance();
+ QV8SqlDatabaseResource *q = new QV8SqlDatabaseResource(engine);
+ q->type = QV8SqlDatabaseResource::Query;
+ q->database = db;
+ q->readonly = readOnly;
+ q->inTransaction = true;
+ instance->SetExternalResource(q);
db.transaction();
- callback.call(QScriptValue(), QScriptValueList() << tx);
- instance.setProperty(QLatin1String("executeSql"),
- engine->newFunction(qmlsqldatabase_executeSql_outsidetransaction));
- if (engine->hasUncaughtException()) {
+ v8::TryCatch tc;
+ v8::Handle<v8::Value> callbackArgs[] = { instance };
+ callback->Call(engine->global(), 1, callbackArgs);
+
+ q->inTransaction = false;
+
+ if (tc.HasCaught()) {
+ db.rollback();
+ tc.ReThrow();
+ return v8::Handle<v8::Value>();
+ } else if (!db.commit()) {
db.rollback();
- } else {
- if (!db.commit())
- db.rollback();
}
- return engine->undefinedValue();
+
+ return v8::Undefined();
}
-static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlsqldatabase_transaction(const v8::Arguments& args)
{
- return qmlsqldatabase_transaction_shared(context,engine,false);
+ return qmlsqldatabase_transaction_shared(args, false);
}
-static QScriptValue qmlsqldatabase_read_transaction(QScriptContext *context, QScriptEngine *engine)
+
+static v8::Handle<v8::Value> qmlsqldatabase_read_transaction(const v8::Arguments& args)
{
- return qmlsqldatabase_transaction_shared(context,engine,true);
+ return qmlsqldatabase_transaction_shared(args, true);
}
/*
Currently documented in doc/src/declarative/globalobject.qdoc
*/
-static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlsqldatabase_open_sync(const v8::Arguments& args)
{
#ifndef QT_NO_SETTINGS
+ QV8Engine *engine = V8ENGINE();
qmlsqldatabase_initDatabasesPath(engine);
QSqlDatabase database;
- QString dbname = context->argument(0).toString();
- QString dbversion = context->argument(1).toString();
- QString dbdescription = context->argument(2).toString();
- int dbestimatedsize = context->argument(3).toNumber();
- QScriptValue dbcreationCallback = context->argument(4);
+ QString dbname = engine->toString(args[0]);
+ QString dbversion = engine->toString(args[1]);
+ QString dbdescription = engine->toString(args[2]);
+ int dbestimatedsize = args[3]->Int32Value();
+ v8::Handle<v8::Value> dbcreationCallback = args[4];
QCryptographicHash md5(QCryptographicHash::Md5);
md5.addData(dbname.toUtf8());
@@ -383,13 +461,13 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng
database = QSqlDatabase::database(dbid);
version = ini.value(QLatin1String("Version")).toString();
if (version != dbversion && !dbversion.isEmpty() && !version.isEmpty())
- THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
+ V8THROW_SQL(VERSION_ERR, QDeclarativeEngine::tr("SQL: database version mismatch"));
} else {
created = !QFile::exists(basename+QLatin1String(".sqlite"));
database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid);
if (created) {
ini.setValue(QLatin1String("Name"), dbname);
- if (dbcreationCallback.isFunction())
+ if (dbcreationCallback->IsFunction())
version = QString();
ini.setValue(QLatin1String("Version"), version);
ini.setValue(QLatin1String("Description"), dbdescription);
@@ -398,7 +476,7 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng
} else {
if (!dbversion.isEmpty() && ini.value(QLatin1String("Version")) != dbversion) {
// Incompatible
- THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
+ V8THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
}
version = ini.value(QLatin1String("Version")).toString();
}
@@ -408,35 +486,96 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng
database.open();
}
- QScriptValue instance = engine->newObject();
- instance.setProperty(QLatin1String("transaction"), engine->newFunction(qmlsqldatabase_transaction,1));
- instance.setProperty(QLatin1String("readTransaction"), engine->newFunction(qmlsqldatabase_read_transaction,1));
- instance.setProperty(QLatin1String("version"), version, QScriptValue::ReadOnly);
- instance.setProperty(QLatin1String("changeVersion"), engine->newFunction(qmlsqldatabase_change_version,3));
-
- QScriptValue result = engine->newVariant(instance,QVariant::fromValue(database));
-
- if (created && dbcreationCallback.isFunction()) {
- dbcreationCallback.call(QScriptValue(), QScriptValueList() << result);
+ v8::Local<v8::Object> instance = QDeclarativeSqlDatabaseData::data(engine)->constructor->NewInstance();
+ QV8SqlDatabaseResource *r = new QV8SqlDatabaseResource(engine);
+ r->database = database;
+ r->version = version;
+ instance->SetExternalResource(r);
+
+ if (created && dbcreationCallback->IsFunction()) {
+ v8::TryCatch tc;
+ v8::Handle<v8::Function> callback = v8::Handle<v8::Function>::Cast(dbcreationCallback);
+ v8::Handle<v8::Value> args[] = { instance };
+ callback->Call(engine->global(), 1, args);
+ if (tc.HasCaught()) {
+ tc.ReThrow();
+ return v8::Handle<v8::Value>();
+ }
}
- return result;
+ return instance;
#else
- return engine->undefinedValue();
+ return v8::Undefined();
#endif // QT_NO_SETTINGS
}
-void qt_add_qmlsqldatabase(QScriptEngine *engine)
+QDeclarativeSqlDatabaseData::QDeclarativeSqlDatabaseData(QV8Engine *engine)
{
- QScriptValue openDatabase = engine->newFunction(qmlsqldatabase_open_sync, 4);
- engine->globalObject().setProperty(QLatin1String("openDatabaseSync"), openDatabase);
+ QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
+ offlineStoragePath = dataLocation.replace(QLatin1Char('/'), QDir::separator()) +
+ QDir::separator() + QLatin1String("QML") +
+ QDir::separator() + QLatin1String("OfflineStorage");
- QScriptValue sqlExceptionPrototype = engine->newObject();
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->PrototypeTemplate()->Set(v8::String::New("transaction"),
+ V8FUNCTION(qmlsqldatabase_transaction, engine));
+ ft->PrototypeTemplate()->Set(v8::String::New("readTransaction"),
+ V8FUNCTION(qmlsqldatabase_read_transaction, engine));
+ ft->PrototypeTemplate()->SetAccessor(v8::String::New("version"), qmlsqldatabase_version);
+ ft->PrototypeTemplate()->Set(v8::String::New("changeVersion"),
+ V8FUNCTION(qmlsqldatabase_changeVersion, engine));
+ constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->PrototypeTemplate()->Set(v8::String::New("executeSql"),
+ V8FUNCTION(qmlsqldatabase_executeSql, engine));
+ queryConstructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->PrototypeTemplate()->Set(v8::String::New("item"), V8FUNCTION(qmlsqldatabase_rows_item, engine));
+ ft->PrototypeTemplate()->SetAccessor(v8::String::New("length"), qmlsqldatabase_rows_length);
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("forwardOnly"), qmlsqldatabase_rows_forwardOnly,
+ qmlsqldatabase_rows_setForwardOnly);
+ ft->InstanceTemplate()->SetIndexedPropertyHandler(qmlsqldatabase_rows_index);
+ rowsConstructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+}
+
+void *qt_add_qmlsqldatabase(QV8Engine *engine)
+{
+ v8::Local<v8::Function> openDatabase = V8FUNCTION(qmlsqldatabase_open_sync, engine);
+ engine->global()->Set(v8::String::New("openDatabaseSync"), openDatabase);
+
+ v8::PropertyAttribute attributes = (v8::PropertyAttribute)(v8::ReadOnly | v8::DontEnum | v8::DontDelete);
+ v8::Local<v8::Object> sqlExceptionPrototype = v8::Object::New();
for (int i=0; sqlerror[i]; ++i)
- sqlExceptionPrototype.setProperty(QLatin1String(sqlerror[i]),
- i,QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
+ sqlExceptionPrototype->Set(v8::String::New(sqlerror[i]), v8::Integer::New(i), attributes);
+ engine->global()->Set(v8::String::New("SQLException"), sqlExceptionPrototype);
+
+ return (void *)new QDeclarativeSqlDatabaseData(engine);
+}
+
+void qt_rem_qmlsqldatabase(QV8Engine *engine, void *d)
+{
+ QDeclarativeSqlDatabaseData *data = (QDeclarativeSqlDatabaseData *)d;
+ delete data;
+}
- engine->globalObject().setProperty(QLatin1String("SQLException"), sqlExceptionPrototype);
+void qt_qmlsqldatabase_setOfflineStoragePath(QV8Engine *engine, const QString &path)
+{
+ QDeclarativeSqlDatabaseData::data(engine)->offlineStoragePath = path;
+}
+
+QString qt_qmlsqldatabase_getOfflineStoragePath(const QV8Engine *engine)
+{
+ return QDeclarativeSqlDatabaseData::data(const_cast<QV8Engine *>(engine))->offlineStoragePath;
}
/*
diff --git a/src/declarative/qml/qdeclarativesqldatabase_p.h b/src/declarative/qml/qdeclarativesqldatabase_p.h
index 04adcefcec..337f717b1e 100644
--- a/src/declarative/qml/qdeclarativesqldatabase_p.h
+++ b/src/declarative/qml/qdeclarativesqldatabase_p.h
@@ -58,8 +58,12 @@
QT_BEGIN_NAMESPACE
-class QScriptEngine;
-void qt_add_qmlsqldatabase(QScriptEngine *engine);
+class QV8Engine;
+
+void *qt_add_qmlsqldatabase(QV8Engine *engine);
+void qt_rem_qmlsqldatabase(QV8Engine *engine, void *);
+void qt_qmlsqldatabase_setOfflineStoragePath(QV8Engine *engine, const QString &);
+QString qt_qmlsqldatabase_getOfflineStoragePath(const QV8Engine *);
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativetypeloader.cpp b/src/declarative/qml/qdeclarativetypeloader.cpp
index a413305e28..47c90bd186 100644
--- a/src/declarative/qml/qdeclarativetypeloader.cpp
+++ b/src/declarative/qml/qdeclarativetypeloader.cpp
@@ -1053,11 +1053,6 @@ void QDeclarativeTypeData::resolveTypes()
if (ref.type) {
ref.majorVersion = majorVersion;
ref.minorVersion = minorVersion;
- foreach (QDeclarativeParser::Object *obj, parserRef->refObjects) {
- // store namespace for DOM
- obj->majorVersion = majorVersion;
- obj->minorVersion = minorVersion;
- }
} else {
ref.typeData = typeLoader()->get(url);
addDependency(ref.typeData);
@@ -1100,6 +1095,9 @@ void QDeclarativeScriptData::clear()
for (int ii = 0; ii < scripts.count(); ++ii)
scripts.at(ii)->release();
scripts.clear();
+
+ qPersistentDispose(m_program);
+ qPersistentDispose(m_value);
}
QDeclarativeScriptBlob::QDeclarativeScriptBlob(const QUrl &url, QDeclarativeTypeLoader *loader)
@@ -1228,7 +1226,13 @@ void QDeclarativeScriptBlob::done()
m_imports.populateCache(m_scriptData->importCache, engine);
m_scriptData->pragmas = m_pragmas;
- m_scriptData->m_program = QScriptProgram(m_source, finalUrl().toString());
+
+ // XXX TODO: Handle errors that occur duing the script compile
+ QV8Engine *v8engine = &QDeclarativeEnginePrivate::get(engine)->v8engine;
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(v8engine->context());
+ v8::Local<v8::Script> program = v8engine->qmlModeCompile(m_source, finalUrl().toString(), 1);
+ m_scriptData->m_program = qPersistentNew<v8::Script>(program);
}
QDeclarativeQmldirData::QDeclarativeQmldirData(const QUrl &url)
diff --git a/src/declarative/qml/qdeclarativetypeloader_p.h b/src/declarative/qml/qdeclarativetypeloader_p.h
index 05873df4ca..20e16750cf 100644
--- a/src/declarative/qml/qdeclarativetypeloader_p.h
+++ b/src/declarative/qml/qdeclarativetypeloader_p.h
@@ -64,6 +64,8 @@
#include <private/qdeclarativedirparser_p.h>
#include <private/qdeclarativeimport_p.h>
+#include <private/qv8_p.h>
+
QT_BEGIN_NAMESPACE
class QDeclarativeScriptData;
@@ -307,8 +309,10 @@ private:
friend class QDeclarativeScriptBlob;
bool m_loaded;
- QScriptProgram m_program;
- QScriptValue m_value;
+ v8::Persistent<v8::Script> m_program;
+ v8::Persistent<v8::Object> m_value;
+// QScriptProgram m_program;
+// QScriptValue m_value;
};
class Q_AUTOTEST_EXPORT QDeclarativeScriptBlob : public QDeclarativeDataBlob
diff --git a/src/declarative/qml/qdeclarativetypenamecache.cpp b/src/declarative/qml/qdeclarativetypenamecache.cpp
index 8a1b4bff43..23183aa9fb 100644
--- a/src/declarative/qml/qdeclarativetypenamecache.cpp
+++ b/src/declarative/qml/qdeclarativetypenamecache.cpp
@@ -57,9 +57,7 @@ QDeclarativeTypeNameCache::~QDeclarativeTypeNameCache()
void QDeclarativeTypeNameCache::clear()
{
- qDeleteAll(stringCache);
stringCache.clear();
- identifierCache.clear();
m_moduleApi = 0;
engine = 0;
}
@@ -69,14 +67,9 @@ void QDeclarativeTypeNameCache::add(const QString &name, int importedScriptIndex
if (stringCache.contains(name))
return;
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-
- RData *data = new RData;
- // ### Use typename class
- data->identifier = ep->objectClass->createPersistentIdentifier(name);
- data->importedScriptIndex = importedScriptIndex;
+ Data data;
+ data.importedScriptIndex = importedScriptIndex;
stringCache.insert(name, data);
- identifierCache.insert(data->identifier.identifier, data);
}
void QDeclarativeTypeNameCache::add(const QString &name, QDeclarativeType *type)
@@ -84,14 +77,9 @@ void QDeclarativeTypeNameCache::add(const QString &name, QDeclarativeType *type)
if (stringCache.contains(name))
return;
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-
- RData *data = new RData;
- // ### Use typename class
- data->identifier = ep->objectClass->createPersistentIdentifier(name);
- data->type = type;
+ Data data;
+ data.type = type;
stringCache.insert(name, data);
- identifierCache.insert(data->identifier.identifier, data);
}
void QDeclarativeTypeNameCache::add(const QString &name, QDeclarativeTypeNameCache *typeNamespace)
@@ -101,13 +89,10 @@ void QDeclarativeTypeNameCache::add(const QString &name, QDeclarativeTypeNameCac
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- RData *data = new RData;
- // ### Use typename class
- data->identifier = ep->objectClass->createPersistentIdentifier(name);
- data->typeNamespace = typeNamespace;
- stringCache.insert(name, data);
- identifierCache.insert(data->identifier.identifier, data);
+ Data data;
typeNamespace->addref();
+ data.typeNamespace = typeNamespace;
+ stringCache.insert(name, data);
}
QDeclarativeTypeNameCache::Data *QDeclarativeTypeNameCache::data(const QString &id) const
diff --git a/src/declarative/qml/qdeclarativetypenamecache_p.h b/src/declarative/qml/qdeclarativetypenamecache_p.h
index 497633b993..abf18ce384 100644
--- a/src/declarative/qml/qdeclarativetypenamecache_p.h
+++ b/src/declarative/qml/qdeclarativetypenamecache_p.h
@@ -59,6 +59,8 @@
#include <private/qscriptdeclarativeclass_p.h>
+#include <private/qhashedstring_p.h>
+
QT_BEGIN_NAMESPACE
class QDeclarativeType;
@@ -71,7 +73,9 @@ public:
struct Data {
inline Data();
+ inline Data(const Data &);
inline ~Data();
+ inline Data &operator=(const Data &);
QDeclarativeType *type;
QDeclarativeTypeNameCache *typeNamespace;
int importedScriptIndex;
@@ -82,7 +86,7 @@ public:
void add(const QString &, QDeclarativeTypeNameCache *);
Data *data(const QString &) const;
- inline Data *data(const QScriptDeclarativeClass::Identifier &id) const;
+ inline Data *data(const QHashedV8String &) const;
inline bool isEmpty() const;
inline QDeclarativeMetaType::ModuleApiInstance *moduleApi() const;
@@ -92,14 +96,10 @@ protected:
virtual void clear();
private:
- struct RData : public Data {
- QScriptDeclarativeClass::PersistentIdentifier identifier;
- };
- typedef QHash<QString, RData *> StringCache;
- typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache;
+ typedef QStringHash<Data> StringCache;
StringCache stringCache;
- IdentifierCache identifierCache;
+
QDeclarativeEngine *engine;
QDeclarativeMetaType::ModuleApiInstance *m_moduleApi;
};
@@ -114,14 +114,25 @@ QDeclarativeTypeNameCache::Data::~Data()
if (typeNamespace) typeNamespace->release();
}
-QDeclarativeTypeNameCache::Data *QDeclarativeTypeNameCache::data(const QScriptDeclarativeClass::Identifier &id) const
+bool QDeclarativeTypeNameCache::isEmpty() const
{
- return identifierCache.value(id);
+ return stringCache.isEmpty();
}
-bool QDeclarativeTypeNameCache::isEmpty() const
+QDeclarativeTypeNameCache::Data::Data(const QDeclarativeTypeNameCache::Data &o)
+: type(o.type), typeNamespace(o.typeNamespace), importedScriptIndex(o.importedScriptIndex)
+{
+ if (typeNamespace) typeNamespace->addref();
+}
+
+QDeclarativeTypeNameCache::Data &QDeclarativeTypeNameCache::Data::operator=(const QDeclarativeTypeNameCache::Data &o)
{
- return identifierCache.isEmpty();
+ if (o.typeNamespace) o.typeNamespace->addref();
+ if (typeNamespace) typeNamespace->release();
+ type = o.type;
+ typeNamespace = o.typeNamespace;
+ importedScriptIndex = o.importedScriptIndex;
+ return *this;
}
QDeclarativeMetaType::ModuleApiInstance *QDeclarativeTypeNameCache::moduleApi() const
@@ -129,6 +140,11 @@ QDeclarativeMetaType::ModuleApiInstance *QDeclarativeTypeNameCache::moduleApi()
return m_moduleApi;
}
+QDeclarativeTypeNameCache::Data *QDeclarativeTypeNameCache::data(const QHashedV8String &name) const
+{
+ return stringCache.value(name);
+}
+
QT_END_NAMESPACE
#endif // QDECLARATIVETYPENAMECACHE_P_H
diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
deleted file mode 100644
index 32fcdb4c08..0000000000
--- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativetypenamescriptclass_p.h"
-
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativetypenamecache_p.h"
-
-QT_BEGIN_NAMESPACE
-
-struct TypeNameData : public QScriptDeclarativeClass::Object {
- TypeNameData(QObject *o, QDeclarativeType *t, QDeclarativeTypeNameScriptClass::TypeNameMode m) : object(o), type(t), typeNamespace(0), mode(m) {}
- TypeNameData(QObject *o, QDeclarativeTypeNameCache *n, QDeclarativeTypeNameScriptClass::TypeNameMode m) : object(o), type(0), typeNamespace(n), mode(m) {
- if (typeNamespace) typeNamespace->addref();
- }
- ~TypeNameData() {
- if (typeNamespace) typeNamespace->release();
- }
-
- QObject *object;
- QDeclarativeType *type;
- QDeclarativeTypeNameCache *typeNamespace;
- QDeclarativeTypeNameScriptClass::TypeNameMode mode;
-};
-
-QDeclarativeTypeNameScriptClass::QDeclarativeTypeNameScriptClass(QDeclarativeEngine *bindEngine)
-: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)),
- engine(bindEngine), object(0), type(0), api(0)
-{
-}
-
-QDeclarativeTypeNameScriptClass::~QDeclarativeTypeNameScriptClass()
-{
-}
-
-QScriptValue QDeclarativeTypeNameScriptClass::newObject(QObject *object, QDeclarativeType *type, TypeNameMode mode)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return QScriptDeclarativeClass::newObject(scriptEngine, this, new TypeNameData(object, type, mode));
-}
-
-QScriptValue QDeclarativeTypeNameScriptClass::newObject(QObject *object, QDeclarativeTypeNameCache *ns, TypeNameMode mode)
-{
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- return QScriptDeclarativeClass::newObject(scriptEngine, this, new TypeNameData(object, ns, mode));
-}
-
-QScriptClass::QueryFlags
-QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &name,
- QScriptClass::QueryFlags flags)
-{
- Q_UNUSED(flags);
-
- TypeNameData *data = (TypeNameData *)obj;
-
- object = 0;
- type = 0;
- api = 0;
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-
- if (data->typeNamespace) {
- QDeclarativeTypeNameCache::Data *d = data->typeNamespace->data(name);
- if (d && d->type) {
- type = d->type;
- return QScriptClass::HandlesReadAccess;
- } else if (QDeclarativeMetaType::ModuleApiInstance *moduleApi = data->typeNamespace->moduleApi()) {
- if (moduleApi->scriptCallback) {
- moduleApi->scriptApi = moduleApi->scriptCallback(engine, &ep->scriptEngine);
- moduleApi->scriptCallback = 0;
- moduleApi->qobjectCallback = 0;
- } else if (moduleApi->qobjectCallback) {
- moduleApi->qobjectApi = moduleApi->qobjectCallback(engine, &ep->scriptEngine);
- moduleApi->scriptCallback = 0;
- moduleApi->qobjectCallback = 0;
- }
-
- api = moduleApi;
- if (api->qobjectApi) {
- return ep->objectClass->queryProperty(api->qobjectApi, name, flags, 0,
- QDeclarativeObjectScriptClass::SkipAttachedProperties);
- } else {
- return QScriptClass::HandlesReadAccess;
- }
-
- return 0;
-
- } else {
- return 0;
- }
-
- } else if (data->type) {
-
- if (startsWithUpper(name)) {
- QString strName = toString(name);
- // Must be an enum
- if (data->mode == IncludeEnums) {
- // ### Optimize
- QByteArray enumName = strName.toUtf8();
- const QMetaObject *metaObject = data->type->baseMetaObject();
- for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) {
- QMetaEnum e = metaObject->enumerator(ii);
- int value = e.keyToValue(enumName.constData());
- if (value != -1) {
- enumValue = value;
- return QScriptClass::HandlesReadAccess;
- }
- }
- }
- return 0;
- } else if (data->object) {
- // Must be an attached property
- object = qmlAttachedPropertiesObjectById(data->type->attachedPropertiesId(), data->object);
- if (!object) return 0;
- return ep->objectClass->queryProperty(object, name, flags, 0);
- }
-
- }
-
- return 0;
-}
-
-QDeclarativeTypeNameScriptClass::Value
-QDeclarativeTypeNameScriptClass::property(Object *obj, const Identifier &name)
-{
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- if (type) {
- return Value(scriptEngine, newObject(((TypeNameData *)obj)->object, type, ((TypeNameData *)obj)->mode));
- } else if (object) {
- return ep->objectClass->property(object, name);
- } else if (api && api->qobjectApi) {
- return ep->objectClass->property(api->qobjectApi, name);
- } else if (api) {
- return propertyValue(api->scriptApi, name);
- } else {
- return Value(scriptEngine, enumValue);
- }
-}
-
-void QDeclarativeTypeNameScriptClass::setProperty(Object *, const Identifier &n, const QScriptValue &v)
-{
- Q_ASSERT(!type);
-
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
- if (api) {
- Q_ASSERT(api->qobjectApi);
- ep->objectClass->setProperty(api->qobjectApi, n, v, context());
- } else {
- Q_ASSERT(object);
- ep->objectClass->setProperty(object, n, v, context());
- }
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp
deleted file mode 100644
index c5e5a3006a..0000000000
--- a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp
+++ /dev/null
@@ -1,242 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module 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 "private/qdeclarativevaluetypescriptclass_p.h"
-
-#include "private/qdeclarativebinding_p.h"
-#include "private/qdeclarativeproperty_p.h"
-#include "private/qdeclarativeengine_p.h"
-#include "private/qdeclarativeguard_p.h"
-
-#include <QtScript/qscriptcontextinfo.h>
-
-QT_BEGIN_NAMESPACE
-
-struct QDeclarativeValueTypeObject : public QScriptDeclarativeClass::Object {
- enum Type { Reference, Copy };
- QDeclarativeValueTypeObject(Type t) : objectType(t) {}
- Type objectType;
- QDeclarativeValueType *type;
-};
-
-struct QDeclarativeValueTypeReference : public QDeclarativeValueTypeObject {
- QDeclarativeValueTypeReference() : QDeclarativeValueTypeObject(Reference) {}
- QDeclarativeGuard<QObject> object;
- int property;
-};
-
-struct QDeclarativeValueTypeCopy : public QDeclarativeValueTypeObject {
- QDeclarativeValueTypeCopy() : QDeclarativeValueTypeObject(Copy) {}
- QVariant value;
-};
-
-QDeclarativeValueTypeScriptClass::QDeclarativeValueTypeScriptClass(QDeclarativeEngine *bindEngine)
-: QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine)
-{
-}
-
-QDeclarativeValueTypeScriptClass::~QDeclarativeValueTypeScriptClass()
-{
-}
-
-QScriptValue QDeclarativeValueTypeScriptClass::newObject(QObject *object, int coreIndex, QDeclarativeValueType *type)
-{
- QDeclarativeValueTypeReference *ref = new QDeclarativeValueTypeReference;
- ref->type = type;
- ref->object = object;
- ref->property = coreIndex;
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- return QScriptDeclarativeClass::newObject(scriptEngine, this, ref);
-}
-
-QScriptValue QDeclarativeValueTypeScriptClass::newObject(const QVariant &v, QDeclarativeValueType *type)
-{
- QDeclarativeValueTypeCopy *copy = new QDeclarativeValueTypeCopy;
- copy->type = type;
- copy->value = v;
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- return QScriptDeclarativeClass::newObject(scriptEngine, this, copy);
-}
-
-QScriptClass::QueryFlags
-QDeclarativeValueTypeScriptClass::queryProperty(Object *obj, const Identifier &name,
- QScriptClass::QueryFlags)
-{
- QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj);
-
- m_lastIndex = -1;
-
- QByteArray propName = toString(name).toUtf8();
-
- m_lastIndex = o->type->metaObject()->indexOfProperty(propName.constData());
- if (m_lastIndex == -1)
- return 0;
-
- QScriptClass::QueryFlags rv = 0;
-
- if (o->objectType == QDeclarativeValueTypeObject::Reference) {
- QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(o);
-
- if (!ref->object)
- return 0;
-
- QMetaProperty prop = ref->object->metaObject()->property(m_lastIndex);
-
- rv = QScriptClass::HandlesReadAccess;
- if (prop.isWritable())
- rv |= QScriptClass::HandlesWriteAccess;
- } else {
- rv = QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess;
- }
-
- return rv;
-}
-
-QDeclarativeValueTypeScriptClass::Value QDeclarativeValueTypeScriptClass::property(Object *obj, const Identifier &)
-{
- QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj);
-
- QVariant rv;
- if (o->objectType == QDeclarativeValueTypeObject::Reference) {
- QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj);
-
- QMetaProperty p = ref->type->metaObject()->property(m_lastIndex);
- ref->type->read(ref->object, ref->property);
- rv = p.read(ref->type);
- } else {
- QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj);
-
- QMetaProperty p = copy->type->metaObject()->property(m_lastIndex);
- copy->type->setValue(copy->value);
- rv = p.read(copy->type);
- }
-
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
- return Value(scriptEngine, static_cast<QDeclarativeEnginePrivate *>(QObjectPrivate::get(engine))->scriptValueFromVariant(rv));
-}
-
-void QDeclarativeValueTypeScriptClass::setProperty(Object *obj, const Identifier &,
- const QScriptValue &value)
-{
- QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj);
-
- QVariant v = QDeclarativeEnginePrivate::get(engine)->scriptValueToVariant(value);
-
- if (o->objectType == QDeclarativeValueTypeObject::Reference) {
- QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj);
-
- ref->type->read(ref->object, ref->property);
- QMetaProperty p = ref->type->metaObject()->property(m_lastIndex);
-
- QDeclarativeBinding *newBinding = 0;
- if (value.isFunction() && !value.isRegExp()) {
- QDeclarativeContextData *ctxt = QDeclarativeEnginePrivate::get(engine)->getContext(context());
-
- QDeclarativePropertyCache::Data cacheData;
- cacheData.flags = QDeclarativePropertyCache::Data::IsWritable;
- cacheData.propType = ref->object->metaObject()->property(ref->property).userType();
- cacheData.coreIndex = ref->property;
-
- QDeclarativePropertyCache::ValueTypeData valueTypeData;
- valueTypeData.valueTypeCoreIdx = m_lastIndex;
- valueTypeData.valueTypePropType = p.userType();
-
- newBinding = new QDeclarativeBinding(value, ref->object, ctxt);
- QScriptContextInfo ctxtInfo(context());
- newBinding->setSourceLocation(ctxtInfo.fileName(), ctxtInfo.functionStartLineNumber());
- QDeclarativeProperty prop = QDeclarativePropertyPrivate::restore(cacheData, valueTypeData, ref->object, ctxt);
- newBinding->setTarget(prop);
- if (newBinding->expression().contains(QLatin1String("this")))
- newBinding->setEvaluateFlags(newBinding->evaluateFlags() | QDeclarativeBinding::RequiresThisObject);
- }
-
- QDeclarativeAbstractBinding *delBinding =
- QDeclarativePropertyPrivate::setBinding(ref->object, ref->property, m_lastIndex, newBinding);
- if (delBinding)
- delBinding->destroy();
-
- if (p.isEnumType() && (QMetaType::Type)v.type() == QMetaType::Double)
- v = v.toInt();
- p.write(ref->type, v);
- ref->type->write(ref->object, ref->property, 0);
-
- } else {
- QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj);
- copy->type->setValue(copy->value);
- QMetaProperty p = copy->type->metaObject()->property(m_lastIndex);
- p.write(copy->type, v);
- copy->value = copy->type->value();
- }
-}
-
-QVariant QDeclarativeValueTypeScriptClass::toVariant(Object *obj, bool *ok)
-{
- QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj);
-
- if (o->objectType == QDeclarativeValueTypeObject::Reference) {
- QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj);
-
- if (ok) *ok = true;
-
- if (ref->object) {
- ref->type->read(ref->object, ref->property);
- return ref->type->value();
- }
- } else {
- QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj);
-
- if (ok) *ok = true;
-
- return copy->value;
- }
-
- return QVariant();
-}
-
-QVariant QDeclarativeValueTypeScriptClass::toVariant(const QScriptValue &value)
-{
- Q_ASSERT(scriptClass(value) == this);
-
- return toVariant(object(value), 0);
-}
-
-QT_END_NAMESPACE
-
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index 8959f1775f..96b71acf76 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -58,8 +58,8 @@
#include "private/qdeclarativebinding_p_p.h"
#include "private/qdeclarativecontext_p.h"
#include "private/qdeclarativev4bindings_p.h"
+#include "private/qv8bindings_p.h"
#include "private/qdeclarativeglobal_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
#include "qdeclarativescriptstring.h"
#include "qdeclarativescriptstring_p.h"
@@ -192,8 +192,10 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
parserStatus = QDeclarativeEnginePrivate::SimpleList<QDeclarativeParserStatus>(instr.parserStatusSize);
if (instr.contextCache != -1)
ctxt->setIdPropertyData(comp->contextCaches.at(instr.contextCache));
- if (instr.compiledBinding != -1)
- ctxt->optimizedBindings = new QDeclarativeV4Bindings(datas.at(instr.compiledBinding).constData(), ctxt);
+ if (instr.compiledBinding != -1) {
+ const char *v4data = datas.at(instr.compiledBinding).constData();
+ ctxt->v4bindings = new QDeclarativeV4Bindings(v4data, ctxt);
+ }
QML_END_INSTR(Init)
QML_BEGIN_INSTR(Done)
@@ -658,6 +660,11 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
status->classBegin();
QML_END_INSTR(BeginObject)
+ QML_BEGIN_INSTR(InitV8Bindings)
+ ctxt->v8bindings = new QV8Bindings(primitives.at(instr.program), instr.programIndex,
+ instr.line, comp, ctxt);
+ QML_END_INSTR(InitV8Bindings)
+
QML_BEGIN_INSTR(StoreBinding)
QObject *target =
stack.at(stack.count() - 1 - instr.owner);
@@ -672,7 +679,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
if ((stack.count() - instr.owner) == 1 && bindingSkipList.testBit(coreIndex))
break;
- QDeclarativeBinding *bind = new QDeclarativeBinding((void *)datas.at(instr.value).constData(), comp, context, ctxt, comp->name, instr.line, 0);
+ QDeclarativeBinding *bind = new QDeclarativeBinding(primitives.at(instr.value), true,
+ context, ctxt, comp->name, instr.line);
bindValues.append(bind);
bind->m_mePtr = &bindValues.values[bindValues.count - 1];
bind->setTarget(mp);
@@ -694,7 +702,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
if ((stack.count() - instr.owner) == 1 && bindingSkipList.testBit(coreIndex))
break;
- QDeclarativeBinding *bind = new QDeclarativeBinding((void *)datas.at(instr.value).constData(), comp, context, ctxt, comp->name, instr.line, 0);
+ QDeclarativeBinding *bind = new QDeclarativeBinding(primitives.at(instr.value), true,
+ context, ctxt, comp->name, instr.line);
bindValues.append(bind);
bind->m_mePtr = &bindValues.values[bindValues.count - 1];
bind->setTarget(mp);
@@ -703,7 +712,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
if (old) { old->destroy(); }
QML_END_INSTR(StoreBindingOnAlias)
- QML_BEGIN_INSTR(StoreCompiledBinding)
+ QML_BEGIN_INSTR(StoreV4Binding)
QObject *target =
stack.at(stack.count() - 1 - instr.owner);
QObject *scope =
@@ -714,11 +723,32 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
break;
QDeclarativeAbstractBinding *binding =
- ctxt->optimizedBindings->configBinding(instr.value, target, scope, property);
+ ctxt->v4bindings->configBinding(instr.value, target, scope, property);
bindValues.append(binding);
binding->m_mePtr = &bindValues.values[bindValues.count - 1];
binding->addToObject(target, property);
- QML_END_INSTR(StoreCompiledBinding)
+ QML_END_INSTR(StoreV4Binding)
+
+ QML_BEGIN_INSTR(StoreV8Binding)
+ QObject *target =
+ stack.at(stack.count() - 1 - instr.owner);
+ QObject *scope =
+ stack.at(stack.count() - 1 - instr.context);
+
+ QDeclarativeProperty mp =
+ QDeclarativePropertyPrivate::restore(datas.at(instr.property), target, ctxt);
+
+ int coreIndex = mp.index();
+
+ if ((stack.count() - instr.owner) == 1 && bindingSkipList.testBit(coreIndex))
+ break;
+
+ QDeclarativeAbstractBinding *binding =
+ ctxt->v8bindings->configBinding(instr.value, target, scope, mp, instr.line);
+ bindValues.append(binding);
+ binding->m_mePtr = &bindValues.values[bindValues.count - 1];
+ binding->addToObject(target, QDeclarativePropertyPrivate::bindingIndex(mp));
+ QML_END_INSTR(StoreV8Binding)
QML_BEGIN_INSTR(StoreValueSource)
QObject *obj = stack.pop();
@@ -965,69 +995,78 @@ QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContextData
}
}
-QScriptValue QDeclarativeVME::run(QDeclarativeContextData *parentCtxt, QDeclarativeScriptData *script)
+v8::Persistent<v8::Object> QDeclarativeVME::run(QDeclarativeContextData *parentCtxt, QDeclarativeScriptData *script)
{
if (script->m_loaded)
- return script->m_value;
+ return qPersistentNew<v8::Object>(script->m_value);
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(parentCtxt->engine);
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(parentCtxt->engine);
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(parentCtxt->engine);
+ QV8Engine *v8engine = &ep->v8engine;
bool shared = script->pragmas & QDeclarativeParser::Object::ScriptBlock::Shared;
- // Create the script context if required
- QDeclarativeContextData *ctxt = 0;
- if (!shared) {
- ctxt = new QDeclarativeContextData;
- ctxt->isInternal = true;
- ctxt->url = script->url;
-
- // For backward compatibility, if there are no imports, we need to use the
- // imports from the parent context. See QTBUG-17518.
- if (!script->importCache->isEmpty()) {
- ctxt->imports = script->importCache;
- } else {
- ctxt->imports = parentCtxt->imports;
- ctxt->importedScripts = parentCtxt->importedScripts;
- }
-
- if (ctxt->imports) {
- ctxt->imports->addref();
- }
+ QDeclarativeContextData *effectiveCtxt = parentCtxt;
+ if (shared)
+ effectiveCtxt = 0;
- ctxt->setParent(parentCtxt, true);
+ // Create the script context if required
+ QDeclarativeContextData *ctxt = new QDeclarativeContextData;
+ ctxt->isInternal = true;
+ ctxt->isJSContext = true;
+ if (shared)
+ ctxt->isPragmaLibraryContext = true;
+ else
+ ctxt->isPragmaLibraryContext = parentCtxt->isPragmaLibraryContext;
+ ctxt->url = script->url;
+
+ // For backward compatibility, if there are no imports, we need to use the
+ // imports from the parent context. See QTBUG-17518.
+ if (!script->importCache->isEmpty()) {
+ ctxt->imports = script->importCache;
+ } else if (effectiveCtxt) {
+ ctxt->imports = effectiveCtxt->imports;
+ ctxt->importedScripts = effectiveCtxt->importedScripts;
+ for (int ii = 0; ii < ctxt->importedScripts.count(); ++ii)
+ ctxt->importedScripts[ii] = qPersistentNew<v8::Object>(ctxt->importedScripts[ii]);
+ }
- for (int ii = 0; ii < script->scripts.count(); ++ii)
- ctxt->importedScripts << run(ctxt, script->scripts.at(ii)->scriptData());
+ if (ctxt->imports) {
+ ctxt->imports->addref();
}
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- if (shared) {
- scriptContext->pushScope(enginePriv->contextClass->newUrlContext(script->url.toString())); // XXX toString()?
- } else {
- scriptContext->pushScope(enginePriv->contextClass->newUrlContext(ctxt, 0, script->url.toString()));
+ if (effectiveCtxt)
+ ctxt->setParent(effectiveCtxt, true);
+
+ for (int ii = 0; ii < script->scripts.count(); ++ii) {
+ ctxt->importedScripts << run(ctxt, script->scripts.at(ii)->scriptData());
}
- scriptContext->pushScope(enginePriv->globalClass->staticGlobalObject());
- QScriptValue scope = QScriptDeclarativeClass::newStaticScopeObject(scriptEngine);
- scriptContext->pushScope(scope);
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(v8engine->context());
- scriptEngine->evaluate(script->m_program);
+ v8::Local<v8::Object> qmlglobal = v8engine->qmlScope(ctxt, 0);
- if (scriptEngine->hasUncaughtException()) {
- QDeclarativeError error;
- QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
- enginePriv->warning(error);
- }
+ v8::TryCatch try_catch;
+ script->m_program->Run(qmlglobal);
- scriptEngine->popContext();
+ v8::Persistent<v8::Object> rv;
+
+ if (try_catch.HasCaught()) {
+ v8::Local<v8::Message> message = try_catch.Message();
+ if (!message.IsEmpty()) {
+ QDeclarativeError error;
+ QDeclarativeExpressionPrivate::exceptionToError(message, error);
+ ep->warning(error);
+ }
+ }
+ rv = qPersistentNew<v8::Object>(qmlglobal);
if (shared) {
+ script->m_value = qPersistentNew<v8::Object>(qmlglobal);
script->m_loaded = true;
- script->m_value = scope;
}
- return scope;
+ return rv;
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativevme_p.h b/src/declarative/qml/qdeclarativevme_p.h
index b255e7fa55..dd23f1c62f 100644
--- a/src/declarative/qml/qdeclarativevme_p.h
+++ b/src/declarative/qml/qdeclarativevme_p.h
@@ -59,6 +59,8 @@
#include <QtCore/QString>
#include <QtCore/QStack>
+#include <private/qv8_p.h>
+
QT_BEGIN_NAMESPACE
class QObject;
@@ -103,7 +105,6 @@ public:
QObject *run(QDeclarativeContextData *, QDeclarativeCompiledData *,
int start = -1, const QBitField & = QBitField());
- QScriptValue run(QDeclarativeContextData *, QDeclarativeScriptData *);
void runDeferred(QObject *);
@@ -111,6 +112,8 @@ public:
QList<QDeclarativeError> errors() const;
private:
+ v8::Persistent<v8::Object> run(QDeclarativeContextData *, QDeclarativeScriptData *);
+
QObject *run(QDeclarativeVMEStack<QObject *> &,
QDeclarativeContextData *, QDeclarativeCompiledData *,
int start, const QBitField &);
diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp
index 78519b2601..247c1aa533 100644
--- a/src/declarative/qml/qdeclarativevmemetaobject.cpp
+++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp
@@ -383,7 +383,7 @@ QDeclarativeVMEMetaObject::QDeclarativeVMEMetaObject(QObject *obj,
const QDeclarativeVMEMetaData *meta,
QDeclarativeCompiledData *cdata)
: object(obj), compiledData(cdata), ctxt(QDeclarativeData::get(obj, true)->outerContext),
- metaData(meta), data(0), methods(0), parent(0)
+ metaData(meta), data(0), v8methods(0), parent(0)
{
compiledData->addref();
@@ -418,7 +418,10 @@ QDeclarativeVMEMetaObject::~QDeclarativeVMEMetaObject()
compiledData->release();
delete parent;
delete [] data;
- delete [] methods;
+
+ for (int ii = 0; v8methods && ii < metaData->methodCount; ++ii) {
+ qPersistentDispose(v8methods[ii]);
+ }
}
int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
@@ -649,27 +652,34 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(ctxt->engine);
ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation.
- QScriptValue function = method(id);
-
- QScriptValueList args;
+ v8::Handle<v8::Function> function = method(id);
QDeclarativeVMEMetaData::MethodData *data = metaData->methodData() + id;
+
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(ep->v8engine.context());
+ v8::Handle<v8::Value> *args = 0;
+
if (data->parameterCount) {
- for (int ii = 0; ii < data->parameterCount; ++ii) {
- args << ep->scriptValueFromVariant(*(QVariant *)a[ii + 1]);
- }
+ args = new v8::Handle<v8::Value>[data->parameterCount];
+ for (int ii = 0; ii < data->parameterCount; ++ii)
+ args[ii] = ep->v8engine.fromVariant(*(QVariant *)a[ii + 1]);
}
- QScriptValue rv = function.call(ep->objectClass->newQObject(object), args);
- if (ep->scriptEngine.hasUncaughtException()) {
+ v8::TryCatch try_catch;
+
+ v8::Local<v8::Value> result = function->Call(ep->v8engine.global(), data->parameterCount, args);
+
+ QVariant rv;
+ if (try_catch.HasCaught()) {
QDeclarativeError error;
- QDeclarativeExpressionPrivate::exceptionToError(&ep->scriptEngine, error);
- if (error.isValid()) {
+ QDeclarativeExpressionPrivate::exceptionToError(try_catch.Message(), error);
+ if (error.isValid())
ep->warning(error);
- }
+ if (a[0]) *(QVariant *)a[0] = QVariant();
+ } else {
+ if (a[0]) *(QVariant *)a[0] = ep->v8engine.toVariant(result, 0);
}
- if (a[0]) *reinterpret_cast<QVariant *>(a[0]) = ep->scriptValueToVariant(rv);
-
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
return -1;
}
@@ -683,12 +693,12 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
return object->qt_metacall(c, _id, a);
}
-QScriptValue QDeclarativeVMEMetaObject::method(int index)
+v8::Handle<v8::Function> QDeclarativeVMEMetaObject::method(int index)
{
- if (!methods)
- methods = new QScriptValue[metaData->methodCount];
+ if (!v8methods)
+ v8methods = new v8::Persistent<v8::Function>[metaData->methodCount];
- if (!methods[index].isValid()) {
+ if (v8methods[index].IsEmpty()) {
QDeclarativeVMEMetaData::MethodData *data = metaData->methodData() + index;
const QChar *body =
@@ -696,17 +706,17 @@ QScriptValue QDeclarativeVMEMetaObject::method(int index)
QString code = QString::fromRawData(body, data->bodyLength);
- // XXX Use QScriptProgram
// XXX We should evaluate all methods in a single big script block to
// improve the call time between dynamic methods defined on the same
// object
- methods[index] = QDeclarativeExpressionPrivate::evalInObjectScope(ctxt, object, code, ctxt->url.toString(),
- data->lineNumber, 0);
+ v8methods[index] = QDeclarativeExpressionPrivate::evalFunction(ctxt, object, code, ctxt->url.toString(),
+ data->lineNumber);
}
- return methods[index];
+ return v8methods[index];
}
+#if 0
QScriptValue QDeclarativeVMEMetaObject::readVarProperty(int id)
{
if (data[id].dataType() == qMetaTypeId<QScriptValue>())
@@ -716,22 +726,28 @@ QScriptValue QDeclarativeVMEMetaObject::readVarProperty(int id)
else
return QDeclarativeEnginePrivate::get(ctxt->engine)->scriptValueFromVariant(data[id].asQVariant());
}
+#endif
QVariant QDeclarativeVMEMetaObject::readVarPropertyAsVariant(int id)
{
+#if 0
if (data[id].dataType() == qMetaTypeId<QScriptValue>())
return QDeclarativeEnginePrivate::get(ctxt->engine)->scriptValueToVariant(data[id].asQScriptValue());
- else if (data[id].dataType() == QMetaType::QObjectStar)
+ else
+#endif
+ if (data[id].dataType() == QMetaType::QObjectStar)
return QVariant::fromValue(data[id].asQObject());
else
return data[id].asQVariant();
}
+#if 0
void QDeclarativeVMEMetaObject::writeVarProperty(int id, const QScriptValue &value)
{
data[id].setValue(value);
activate(object, methodOffset + id, 0);
}
+#endif
void QDeclarativeVMEMetaObject::writeVarProperty(int id, const QVariant &value)
{
@@ -803,7 +819,7 @@ int QDeclarativeVMEMetaObject::vmeMethodLineNumber(int index)
return data->lineNumber;
}
-QScriptValue QDeclarativeVMEMetaObject::vmeMethod(int index)
+v8::Handle<v8::Function> QDeclarativeVMEMetaObject::vmeMethod(int index)
{
if (index < methodOffset) {
Q_ASSERT(parent);
@@ -814,7 +830,8 @@ QScriptValue QDeclarativeVMEMetaObject::vmeMethod(int index)
return method(index - methodOffset - plainSignals);
}
-void QDeclarativeVMEMetaObject::setVmeMethod(int index, const QScriptValue &value)
+// Used by debugger
+void QDeclarativeVMEMetaObject::setVmeMethod(int index, v8::Persistent<v8::Function> value)
{
if (index < methodOffset) {
Q_ASSERT(parent);
@@ -823,11 +840,16 @@ void QDeclarativeVMEMetaObject::setVmeMethod(int index, const QScriptValue &valu
int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount;
Q_ASSERT(index >= (methodOffset + plainSignals) && index < (methodOffset + plainSignals + metaData->methodCount));
- if (!methods)
- methods = new QScriptValue[metaData->methodCount];
- methods[index - methodOffset - plainSignals] = value;
+ if (!v8methods)
+ v8methods = new v8::Persistent<v8::Function>[metaData->methodCount];
+
+ int methodIndex = index - methodOffset - plainSignals;
+ if (!v8methods[methodIndex].IsEmpty())
+ qPersistentDispose(v8methods[methodIndex]);
+ v8methods[methodIndex] = value;
}
+#if 0
QScriptValue QDeclarativeVMEMetaObject::vmeProperty(int index)
{
if (index < propOffset) {
@@ -845,6 +867,7 @@ void QDeclarativeVMEMetaObject::setVMEProperty(int index, const QScriptValue &v)
}
return writeVarProperty(index - propOffset, v);
}
+#endif
bool QDeclarativeVMEMetaObject::aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const
{
diff --git a/src/declarative/qml/qdeclarativevmemetaobject_p.h b/src/declarative/qml/qdeclarativevmemetaobject_p.h
index 373f1a81b3..991c79a4ef 100644
--- a/src/declarative/qml/qdeclarativevmemetaobject_p.h
+++ b/src/declarative/qml/qdeclarativevmemetaobject_p.h
@@ -69,6 +69,8 @@
#include "private/qdeclarativecompiler_p.h"
#include "private/qdeclarativecontext_p.h"
+#include <private/qv8_p.h>
+
QT_BEGIN_NAMESPACE
#define QML_ALIAS_FLAG_PTR 0x00000001
@@ -140,11 +142,13 @@ public:
bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
void registerInterceptor(int index, int valueIndex, QDeclarativePropertyValueInterceptor *interceptor);
- QScriptValue vmeMethod(int index);
+ v8::Handle<v8::Function> vmeMethod(int index);
int vmeMethodLineNumber(int index);
- void setVmeMethod(int index, const QScriptValue &);
+ void setVmeMethod(int index, v8::Persistent<v8::Function>);
+#if 0
QScriptValue vmeProperty(int index);
void setVMEProperty(int index, const QScriptValue &);
+#endif
void connectAliasSignal(int index);
@@ -167,12 +171,14 @@ private:
QBitArray aInterceptors;
QHash<int, QPair<int, QDeclarativePropertyValueInterceptor*> > interceptors;
- QScriptValue *methods;
- QScriptValue method(int);
+ v8::Persistent<v8::Function> *v8methods;
+ v8::Handle<v8::Function> method(int);
+#if 0
QScriptValue readVarProperty(int);
- QVariant readVarPropertyAsVariant(int);
void writeVarProperty(int, const QScriptValue &);
+#endif
+ QVariant readVarPropertyAsVariant(int);
void writeVarProperty(int, const QVariant &);
QAbstractDynamicMetaObject *parent;
diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp
index f887084edb..b519573ccf 100644
--- a/src/declarative/qml/qdeclarativeworkerscript.cpp
+++ b/src/declarative/qml/qdeclarativeworkerscript.cpp
@@ -58,6 +58,8 @@
#include <QtDeclarative/qdeclarativeinfo.h>
#include "qdeclarativenetworkaccessmanagerfactory.h"
+#include <private/qv8engine_p.h>
+#include <private/qv8worker_p.h>
QT_BEGIN_NAMESPACE
@@ -66,15 +68,15 @@ class WorkerDataEvent : public QEvent
public:
enum Type { WorkerData = QEvent::User };
- WorkerDataEvent(int workerId, const QVariant &data);
+ WorkerDataEvent(int workerId, const QByteArray &data);
virtual ~WorkerDataEvent();
int workerId() const;
- QVariant data() const;
+ QByteArray data() const;
private:
int m_id;
- QVariant m_data;
+ QByteArray m_data;
};
class WorkerLoadEvent : public QEvent
@@ -128,27 +130,28 @@ public:
QDeclarativeWorkerScriptEnginePrivate(QDeclarativeEngine *eng);
- struct ScriptEngine : public QDeclarativeScriptEngine
+ class WorkerEngine : public QV8Engine
{
- ScriptEngine(QDeclarativeWorkerScriptEnginePrivate *parent) : QDeclarativeScriptEngine(0), p(parent), accessManager(0) {}
- ~ScriptEngine() { delete accessManager; }
+ public:
+ WorkerEngine(QDeclarativeWorkerScriptEnginePrivate *parent);
+ ~WorkerEngine();
+
+ void init();
+ virtual QNetworkAccessManager *networkAccessManager();
+
QDeclarativeWorkerScriptEnginePrivate *p;
- QNetworkAccessManager *accessManager;
- virtual QNetworkAccessManager *networkAccessManager() {
- if (!accessManager) {
- if (p->qmlengine && p->qmlengine->networkAccessManagerFactory()) {
- accessManager = p->qmlengine->networkAccessManagerFactory()->create(this);
- } else {
- accessManager = new QNetworkAccessManager(this);
- }
- }
- return accessManager;
- }
+ v8::Local<v8::Function> sendFunction(int id);
+ void callOnMessage(v8::Handle<v8::Object> object, v8::Handle<v8::Value> arg);
+ private:
+ v8::Persistent<v8::Function> onmessage;
+ v8::Persistent<v8::Function> createsend;
+ QNetworkAccessManager *accessManager;
};
- ScriptEngine *workerEngine;
- static QDeclarativeWorkerScriptEnginePrivate *get(QScriptEngine *e) {
- return static_cast<ScriptEngine *>(e)->p;
+
+ WorkerEngine *workerEngine;
+ static QDeclarativeWorkerScriptEnginePrivate *get(QV8Engine *e) {
+ return static_cast<WorkerEngine *>(e)->p;
}
QDeclarativeEngine *qmlengine;
@@ -158,26 +161,21 @@ public:
struct WorkerScript {
WorkerScript();
+ ~WorkerScript();
int id;
QUrl source;
bool initialized;
QDeclarativeWorkerScript *owner;
- QScriptValue object;
-
- QScriptValue callback;
+ v8::Persistent<v8::Object> object;
};
QHash<int, WorkerScript *> workers;
- QScriptValue getWorker(int);
+ v8::Handle<v8::Object> getWorker(WorkerScript *);
int m_nextId;
- static QVariant scriptValueToVariant(const QScriptValue &);
- static QScriptValue variantToScriptValue(const QVariant &, QScriptEngine *);
-
- static QScriptValue onMessage(QScriptContext *ctxt, QScriptEngine *engine);
- static QScriptValue sendMessage(QScriptContext *ctxt, QScriptEngine *engine);
+ static v8::Handle<v8::Value> sendMessage(const v8::Arguments &args);
signals:
void stopThread();
@@ -186,75 +184,133 @@ protected:
virtual bool event(QEvent *);
private:
- void processMessage(int, const QVariant &);
+ void processMessage(int, const QByteArray &);
void processLoad(int, const QUrl &);
- void reportScriptException(WorkerScript *);
+ void reportScriptException(WorkerScript *, const QDeclarativeError &error);
};
-QDeclarativeWorkerScriptEnginePrivate::QDeclarativeWorkerScriptEnginePrivate(QDeclarativeEngine *engine)
-: workerEngine(0), qmlengine(engine), m_nextId(0)
+QDeclarativeWorkerScriptEnginePrivate::WorkerEngine::WorkerEngine(QDeclarativeWorkerScriptEnginePrivate *parent)
+: p(parent), accessManager(0)
{
}
-QScriptValue QDeclarativeWorkerScriptEnginePrivate::onMessage(QScriptContext *ctxt, QScriptEngine *engine)
+QDeclarativeWorkerScriptEnginePrivate::WorkerEngine::~WorkerEngine()
+{
+ qPersistentDispose(createsend);
+ qPersistentDispose(onmessage);
+ delete accessManager;
+}
+
+void QDeclarativeWorkerScriptEnginePrivate::WorkerEngine::init()
{
- QDeclarativeWorkerScriptEnginePrivate *p = QDeclarativeWorkerScriptEnginePrivate::get(engine);
+ QV8Engine::init(0);
- int id = ctxt->thisObject().data().toVariant().toInt();
+#define CALL_ONMESSAGE_SCRIPT \
+ "(function(object, message) { "\
+ "var isfunction = false; "\
+ "try { "\
+ "isfunction = object.WorkerScript.onMessage instanceof Function; "\
+ "} catch (e) {}" \
+ "if (isfunction) "\
+ "object.WorkerScript.onMessage(message); "\
+ "})"
- WorkerScript *script = p->workers.value(id);
- if (!script)
- return engine->undefinedValue();
+#define SEND_MESSAGE_CREATE_SCRIPT \
+ "(function(method, engine) { "\
+ "return (function(id) { "\
+ "return (function(message) { "\
+ "if (arguments.length) method(engine, id, message); "\
+ "}); "\
+ "}); "\
+ "})"
+
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(context());
+
+ {
+ v8::Local<v8::Script> onmessagescript = v8::Script::New(v8::String::New(CALL_ONMESSAGE_SCRIPT));
+ onmessage = qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(onmessagescript->Run()));
+ }
+ {
+ v8::Local<v8::Script> createsendscript = v8::Script::New(v8::String::New(SEND_MESSAGE_CREATE_SCRIPT));
+ v8::Local<v8::Function> createsendconstructor = v8::Local<v8::Function>::Cast(createsendscript->Run());
+
+ v8::Handle<v8::Value> args[] = {
+ V8FUNCTION(QDeclarativeWorkerScriptEnginePrivate::sendMessage, this)
+ };
+ v8::Local<v8::Value> createsendvalue = createsendconstructor->Call(global(), 1, args);
+
+ createsend = qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(createsendvalue));
+ }
+}
- if (ctxt->argumentCount() >= 1)
- script->callback = ctxt->argument(0);
+// Requires handle and context scope
+v8::Local<v8::Function> QDeclarativeWorkerScriptEnginePrivate::WorkerEngine::sendFunction(int id)
+{
+ v8::Handle<v8::Value> args[] = { v8::Integer::New(id) };
+ return v8::Local<v8::Function>::Cast(createsend->Call(global(), 1, args));
+}
+
+// Requires handle and context scope
+void QDeclarativeWorkerScriptEnginePrivate::WorkerEngine::callOnMessage(v8::Handle<v8::Object> object,
+ v8::Handle<v8::Value> arg)
+{
+ v8::Handle<v8::Value> args[] = { object, arg };
+ onmessage->Call(global(), 2, args);
+}
+
+QNetworkAccessManager *QDeclarativeWorkerScriptEnginePrivate::WorkerEngine::networkAccessManager()
+{
+ if (!accessManager) {
+ if (p->qmlengine && p->qmlengine->networkAccessManagerFactory()) {
+ accessManager = p->qmlengine->networkAccessManagerFactory()->create(p);
+ } else {
+ accessManager = new QNetworkAccessManager(p);
+ }
+ }
+ return accessManager;
+}
- return script->callback;
+QDeclarativeWorkerScriptEnginePrivate::QDeclarativeWorkerScriptEnginePrivate(QDeclarativeEngine *engine)
+: workerEngine(0), qmlengine(engine), m_nextId(0)
+{
}
-QScriptValue QDeclarativeWorkerScriptEnginePrivate::sendMessage(QScriptContext *ctxt, QScriptEngine *engine)
+v8::Handle<v8::Value> QDeclarativeWorkerScriptEnginePrivate::sendMessage(const v8::Arguments &args)
{
- if (!ctxt->argumentCount())
- return engine->undefinedValue();
+ WorkerEngine *engine = (WorkerEngine*)V8ENGINE();
- QDeclarativeWorkerScriptEnginePrivate *p = QDeclarativeWorkerScriptEnginePrivate::get(engine);
+ int id = args[1]->Int32Value();
- int id = ctxt->thisObject().data().toVariant().toInt();
+ QByteArray data = QV8Worker::serialize(args[2], engine);
- WorkerScript *script = p->workers.value(id);
+ QMutexLocker(&engine->p->m_lock);
+ WorkerScript *script = engine->p->workers.value(id);
if (!script)
- return engine->undefinedValue();
-
- QMutexLocker(&p->m_lock);
+ return v8::Undefined();
if (script->owner)
- QCoreApplication::postEvent(script->owner,
- new WorkerDataEvent(0, scriptValueToVariant(ctxt->argument(0))));
+ QCoreApplication::postEvent(script->owner, new WorkerDataEvent(0, data));
- return engine->undefinedValue();
+ return v8::Undefined();
}
-QScriptValue QDeclarativeWorkerScriptEnginePrivate::getWorker(int id)
+// Requires handle scope and context scope
+v8::Handle<v8::Object> QDeclarativeWorkerScriptEnginePrivate::getWorker(WorkerScript *script)
{
- QHash<int, WorkerScript *>::ConstIterator iter = workers.find(id);
-
- if (iter == workers.end())
- return workerEngine->nullValue();
-
- WorkerScript *script = *iter;
if (!script->initialized) {
-
script->initialized = true;
- script->object = workerEngine->newObject();
- QScriptValue api = workerEngine->newObject();
- api.setData(script->id);
+ script->object = qPersistentNew<v8::Object>(workerEngine->contextWrapper()->urlScope(script->source));
+
+ workerEngine->contextWrapper()->setReadOnly(script->object, false);
- api.setProperty(QLatin1String("onMessage"), workerEngine->newFunction(onMessage),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- api.setProperty(QLatin1String("sendMessage"), workerEngine->newFunction(sendMessage));
+ v8::Local<v8::Object> api = v8::Object::New();
+ api->Set(v8::String::New("sendMessage"), workerEngine->sendFunction(script->id));
- script->object.setProperty(QLatin1String("WorkerScript"), api);
+ script->object->Set(v8::String::New("WorkerScript"), api);
+
+ workerEngine->contextWrapper()->setReadOnly(script->object, true);
}
return script->object;
@@ -262,6 +318,7 @@ QScriptValue QDeclarativeWorkerScriptEnginePrivate::getWorker(int id)
bool QDeclarativeWorkerScriptEnginePrivate::event(QEvent *event)
{
+ // XXX must handle remove request
if (event->type() == (QEvent::Type)WorkerDataEvent::WorkerData) {
WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event);
processMessage(workerEvent->workerId(), workerEvent->data());
@@ -278,22 +335,24 @@ bool QDeclarativeWorkerScriptEnginePrivate::event(QEvent *event)
}
}
-void QDeclarativeWorkerScriptEnginePrivate::processMessage(int id, const QVariant &data)
+void QDeclarativeWorkerScriptEnginePrivate::processMessage(int id, const QByteArray &data)
{
WorkerScript *script = workers.value(id);
if (!script)
return;
- if (script->callback.isFunction()) {
- QScriptValue args = workerEngine->newArray(1);
- args.setProperty(0, variantToScriptValue(data, workerEngine));
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(workerEngine->context());
- script->callback.call(script->object, args);
+ v8::Handle<v8::Value> value = QV8Worker::deserialize(data, workerEngine);
- if (workerEngine->hasUncaughtException()) {
- reportScriptException(script);
- workerEngine->clearExceptions();
- }
+ v8::TryCatch tc;
+ workerEngine->callOnMessage(script->object, value);
+
+ if (tc.HasCaught()) {
+ QDeclarativeError error;
+ QDeclarativeExpressionPrivate::exceptionToError(tc.Message(), error);
+ reportScriptException(script, error);
}
}
@@ -308,44 +367,41 @@ void QDeclarativeWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url)
if (f.open(QIODevice::ReadOnly)) {
QByteArray data = f.readAll();
QString sourceCode = QString::fromUtf8(data);
-
- QScriptValue activation = getWorker(id);
-
- QScriptContext *ctxt = QScriptDeclarativeClass::pushCleanContext(workerEngine);
- QScriptValue urlContext = workerEngine->newObject();
- urlContext.setData(QScriptValue(workerEngine, url.toString()));
- ctxt->pushScope(urlContext);
- ctxt->pushScope(activation);
- ctxt->setActivationObject(activation);
QDeclarativeScriptParser::extractPragmas(sourceCode);
- workerEngine->baseUrl = url;
- workerEngine->evaluate(sourceCode);
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(workerEngine->context());
WorkerScript *script = workers.value(id);
- if (script) {
- script->source = url;
- if (workerEngine->hasUncaughtException()) {
- reportScriptException(script);
- workerEngine->clearExceptions();
- }
+ if (!script)
+ return;
+ script->source = url;
+ v8::Handle<v8::Object> activation = getWorker(script);
+ if (activation.IsEmpty())
+ return;
+
+ // XXX ???
+ // workerEngine->baseUrl = url;
+
+ v8::TryCatch tc;
+ v8::Local<v8::Script> program = workerEngine->qmlModeCompile(sourceCode, url.toString());
+
+ if (!tc.HasCaught())
+ program->Run(activation);
+
+ if (tc.HasCaught()) {
+ QDeclarativeError error;
+ QDeclarativeExpressionPrivate::exceptionToError(tc.Message(), error);
+ reportScriptException(script, error);
}
-
- workerEngine->popContext();
} else {
qWarning().nospace() << "WorkerScript: Cannot find source file " << url.toString();
}
}
-void QDeclarativeWorkerScriptEnginePrivate::reportScriptException(WorkerScript *script)
+void QDeclarativeWorkerScriptEnginePrivate::reportScriptException(WorkerScript *script,
+ const QDeclarativeError &error)
{
- if (!script || !workerEngine->hasUncaughtException())
- return;
-
- QDeclarativeError error;
- QDeclarativeExpressionPrivate::exceptionToError(workerEngine, error);
- error.setUrl(script->source);
-
QDeclarativeWorkerScriptEnginePrivate *p = QDeclarativeWorkerScriptEnginePrivate::get(workerEngine);
QMutexLocker(&p->m_lock);
@@ -353,109 +409,7 @@ void QDeclarativeWorkerScriptEnginePrivate::reportScriptException(WorkerScript *
QCoreApplication::postEvent(script->owner, new WorkerErrorEvent(error));
}
-QVariant QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(const QScriptValue &value)
-{
- if (value.isBool()) {
- return QVariant(value.toBool());
- } else if (value.isString()) {
- return QVariant(value.toString());
- } else if (value.isNumber()) {
- return QVariant((qreal)value.toNumber());
- } else if (value.isDate()) {
- return QVariant(value.toDateTime());
-#ifndef QT_NO_REGEXP
- } else if (value.isRegExp()) {
- return QVariant(value.toRegExp());
-#endif
- } else if (value.isArray()) {
- QVariantList list;
-
- quint32 length = (quint32)value.property(QLatin1String("length")).toNumber();
-
- for (quint32 ii = 0; ii < length; ++ii) {
- QVariant v = scriptValueToVariant(value.property(ii));
- list << v;
- }
-
- return QVariant(list);
- } else if (value.isQObject()) {
- QDeclarativeListModel *lm = qobject_cast<QDeclarativeListModel *>(value.toQObject());
- if (lm) {
- QDeclarativeListModelWorkerAgent *agent = lm->agent();
- if (agent) {
- QDeclarativeListModelWorkerAgent::VariantRef v(agent);
- return QVariant::fromValue(v);
- } else {
- return QVariant();
- }
- } else {
- // No other QObject's are allowed to be sent
- return QVariant();
- }
- } else if (value.isObject()) {
- QVariantHash hash;
-
- QScriptValueIterator iter(value);
-
- while (iter.hasNext()) {
- iter.next();
- hash.insert(iter.name(), scriptValueToVariant(iter.value()));
- }
-
- return QVariant(hash);
- }
-
- return QVariant();
-
-}
-
-QScriptValue QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(const QVariant &value, QScriptEngine *engine)
-{
- if (value.userType() == QVariant::Bool) {
- return QScriptValue(value.toBool());
- } else if (value.userType() == QVariant::String) {
- return QScriptValue(value.toString());
- } else if (value.userType() == QMetaType::QReal) {
- return QScriptValue(value.toReal());
- } else if (value.userType() == QVariant::DateTime) {
- return engine->newDate(value.toDateTime());
-#ifndef QT_NO_REGEXP
- } else if (value.userType() == QVariant::RegExp) {
- return engine->newRegExp(value.toRegExp());
-#endif
- } else if (value.userType() == qMetaTypeId<QDeclarativeListModelWorkerAgent::VariantRef>()) {
- QDeclarativeListModelWorkerAgent::VariantRef vr = qvariant_cast<QDeclarativeListModelWorkerAgent::VariantRef>(value);
- if (vr.a->scriptEngine() == 0)
- vr.a->setScriptEngine(engine);
- else if (vr.a->scriptEngine() != engine)
- return engine->nullValue();
- QScriptValue o = engine->newQObject(vr.a);
- o.setData(engine->newVariant(value)); // Keeps the agent ref so that it is cleaned up on gc
- return o;
- } else if (value.userType() == QMetaType::QVariantList) {
- QVariantList list = qvariant_cast<QVariantList>(value);
- QScriptValue rv = engine->newArray(list.count());
-
- for (quint32 ii = 0; ii < quint32(list.count()); ++ii)
- rv.setProperty(ii, variantToScriptValue(list.at(ii), engine));
-
- return rv;
- } else if (value.userType() == QMetaType::QVariantHash) {
-
- QVariantHash hash = qvariant_cast<QVariantHash>(value);
-
- QScriptValue rv = engine->newObject();
-
- for (QVariantHash::ConstIterator iter = hash.begin(); iter != hash.end(); ++iter)
- rv.setProperty(iter.key(), variantToScriptValue(iter.value(), engine));
-
- return rv;
- } else {
- return engine->nullValue();
- }
-}
-
-WorkerDataEvent::WorkerDataEvent(int workerId, const QVariant &data)
+WorkerDataEvent::WorkerDataEvent(int workerId, const QByteArray &data)
: QEvent((QEvent::Type)WorkerData), m_id(workerId), m_data(data)
{
}
@@ -469,7 +423,7 @@ int WorkerDataEvent::workerId() const
return m_id;
}
-QVariant WorkerDataEvent::data() const
+QByteArray WorkerDataEvent::data() const
{
return m_data;
}
@@ -523,8 +477,6 @@ QDeclarativeWorkerScriptEngine::QDeclarativeWorkerScriptEngine(QDeclarativeEngin
QDeclarativeWorkerScriptEngine::~QDeclarativeWorkerScriptEngine()
{
d->m_lock.lock();
- qDeleteAll(d->workers);
- d->workers.clear();
QCoreApplication::postEvent(d, new QEvent((QEvent::Type)QDeclarativeWorkerScriptEnginePrivate::WorkerDestroyEvent));
d->m_lock.unlock();
@@ -537,9 +489,16 @@ QDeclarativeWorkerScriptEnginePrivate::WorkerScript::WorkerScript()
{
}
+QDeclarativeWorkerScriptEnginePrivate::WorkerScript::~WorkerScript()
+{
+ qPersistentDispose(object);
+}
+
int QDeclarativeWorkerScriptEngine::registerWorkerScript(QDeclarativeWorkerScript *owner)
{
- QDeclarativeWorkerScriptEnginePrivate::WorkerScript *script = new QDeclarativeWorkerScriptEnginePrivate::WorkerScript;
+ typedef QDeclarativeWorkerScriptEnginePrivate::WorkerScript WorkerScript;
+ WorkerScript *script = new WorkerScript;
+
script->id = d->m_nextId++;
script->owner = owner;
@@ -560,7 +519,7 @@ void QDeclarativeWorkerScriptEngine::executeUrl(int id, const QUrl &url)
QCoreApplication::postEvent(d, new WorkerLoadEvent(id, url));
}
-void QDeclarativeWorkerScriptEngine::sendMessage(int id, const QVariant &data)
+void QDeclarativeWorkerScriptEngine::sendMessage(int id, const QByteArray &data)
{
QCoreApplication::postEvent(d, new WorkerDataEvent(id, data));
}
@@ -569,7 +528,11 @@ void QDeclarativeWorkerScriptEngine::run()
{
d->m_lock.lock();
- d->workerEngine = new QDeclarativeWorkerScriptEnginePrivate::ScriptEngine(d);
+ v8::Isolate *isolate = v8::Isolate::New();
+ isolate->Enter();
+
+ d->workerEngine = new QDeclarativeWorkerScriptEnginePrivate::WorkerEngine(d);
+ d->workerEngine->init();
d->m_wait.wakeAll();
@@ -577,7 +540,13 @@ void QDeclarativeWorkerScriptEngine::run()
exec();
+ qDeleteAll(d->workers);
+ d->workers.clear();
+
delete d->workerEngine; d->workerEngine = 0;
+
+ isolate->Exit();
+ isolate->Dispose();
}
@@ -677,14 +646,18 @@ void QDeclarativeWorkerScript::setSource(const QUrl &source)
of ListModel objects, any modifications by the other thread to an object
passed in \c message will not be reflected in the original object.
*/
-void QDeclarativeWorkerScript::sendMessage(const QScriptValue &message)
+void QDeclarativeWorkerScript::sendMessage(QDeclarativeV8Function *args)
{
if (!engine()) {
qWarning("QDeclarativeWorkerScript: Attempt to send message before WorkerScript establishment");
return;
}
- m_engine->sendMessage(m_scriptId, QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(message));
+ v8::Handle<v8::Value> argument = v8::Undefined();
+ if (args->Length() != 0)
+ argument = (*args)[0];
+
+ m_engine->sendMessage(m_scriptId, QV8Worker::serialize(argument, args->engine()));
}
void QDeclarativeWorkerScript::classBegin()
@@ -731,11 +704,12 @@ bool QDeclarativeWorkerScript::event(QEvent *event)
if (event->type() == (QEvent::Type)WorkerDataEvent::WorkerData) {
QDeclarativeEngine *engine = qmlEngine(this);
if (engine) {
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event);
- QScriptValue value =
- QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(workerEvent->data(), scriptEngine);
- emit message(value);
+ QV8Engine *v8engine = &QDeclarativeEnginePrivate::get(engine)->v8engine;
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(v8engine->context());
+ v8::Handle<v8::Value> value = QV8Worker::deserialize(workerEvent->data(), v8engine);
+ emit message(QDeclarativeV8Handle::fromHandle(value));
}
return true;
} else if (event->type() == (QEvent::Type)WorkerErrorEvent::WorkerError) {
diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h
index af3a0188f9..85910b16e9 100644
--- a/src/declarative/qml/qdeclarativeworkerscript_p.h
+++ b/src/declarative/qml/qdeclarativeworkerscript_p.h
@@ -78,7 +78,7 @@ public:
int registerWorkerScript(QDeclarativeWorkerScript *);
void removeWorkerScript(int);
void executeUrl(int, const QUrl &);
- void sendMessage(int, const QVariant &);
+ void sendMessage(int, const QByteArray &);
protected:
virtual void run();
@@ -87,6 +87,8 @@ private:
QDeclarativeWorkerScriptEnginePrivate *d;
};
+class QDeclarativeV8Function;
+class QDeclarativeV8Handle;
class Q_AUTOTEST_EXPORT QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
@@ -101,11 +103,11 @@ public:
void setSource(const QUrl &);
public slots:
- void sendMessage(const QScriptValue &);
+ void sendMessage(QDeclarativeV8Function*);
signals:
void sourceChanged();
- void message(const QScriptValue &messageObject);
+ void message(const QDeclarativeV8Handle &messageObject);
protected:
virtual void classBegin();
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
index f74995ba0a..33875fef88 100644
--- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp
+++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
@@ -41,6 +41,8 @@
#include "private/qdeclarativexmlhttprequest_p.h"
+#include <private/qv8engine_p.h>
+
#include "qdeclarativeengine.h"
#include "private/qdeclarativeengine_p.h"
#include "private/qdeclarativerefcount_p.h"
@@ -82,17 +84,17 @@
#define VALIDATION_ERR 16
#define TYPE_MISMATCH_ERR 17
-#define THROW_DOM(error, desc) \
-{ \
- QScriptValue errorValue = context->throwError(QLatin1String(desc)); \
- errorValue.setProperty(QLatin1String("code"), error); \
- return errorValue; \
-}
+#define V8THROW_DOM(error, string) { \
+ v8::Local<v8::Value> v = v8::Exception::Error(v8::String::New(string)); \
+ v->ToObject()->Set(v8::String::New("code"), v8::Integer::New(error)); \
+ v8::ThrowException(v); \
+ return v8::Handle<v8::Value>(); \
+}
-#define THROW_SYNTAX(desc) \
- return context->throwError(QScriptContext::SyntaxError, QLatin1String(desc));
-#define THROW_REFERENCE(desc) \
- return context->throwError(QScriptContext::ReferenceError, QLatin1String(desc));
+#define V8THROW_REFERENCE(string) { \
+ v8::ThrowException(v8::Exception::ReferenceError(v8::String::New(string))); \
+ return v8::Handle<v8::Value>(); \
+}
#define D(arg) (arg)->release()
#define A(arg) (arg)->addref()
@@ -101,6 +103,59 @@ QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(xhrDump, QML_XHR_DUMP);
+struct QDeclarativeXMLHttpRequestData {
+ QDeclarativeXMLHttpRequestData();
+ ~QDeclarativeXMLHttpRequestData();
+
+ v8::Persistent<v8::Function> nodeFunction;
+
+ v8::Persistent<v8::Object> namedNodeMapPrototype;
+ v8::Persistent<v8::Object> nodeListPrototype;
+ v8::Persistent<v8::Object> nodePrototype;
+ v8::Persistent<v8::Object> elementPrototype;
+ v8::Persistent<v8::Object> attrPrototype;
+ v8::Persistent<v8::Object> characterDataPrototype;
+ v8::Persistent<v8::Object> textPrototype;
+ v8::Persistent<v8::Object> cdataPrototype;
+ v8::Persistent<v8::Object> documentPrototype;
+
+ v8::Local<v8::Object> newNode();
+};
+
+static inline QDeclarativeXMLHttpRequestData *xhrdata(QV8Engine *engine)
+{
+ return (QDeclarativeXMLHttpRequestData *)engine->xmlHttpRequestData();
+}
+
+QDeclarativeXMLHttpRequestData::QDeclarativeXMLHttpRequestData()
+{
+}
+
+QDeclarativeXMLHttpRequestData::~QDeclarativeXMLHttpRequestData()
+{
+ qPersistentDispose(nodeFunction);
+ qPersistentDispose(namedNodeMapPrototype);
+ qPersistentDispose(nodeListPrototype);
+ qPersistentDispose(nodePrototype);
+ qPersistentDispose(elementPrototype);
+ qPersistentDispose(attrPrototype);
+ qPersistentDispose(characterDataPrototype);
+ qPersistentDispose(textPrototype);
+ qPersistentDispose(cdataPrototype);
+ qPersistentDispose(documentPrototype);
+}
+
+v8::Local<v8::Object> QDeclarativeXMLHttpRequestData::newNode()
+{
+ if (nodeFunction.IsEmpty()) {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ nodeFunction = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+
+ return nodeFunction->NewInstance();
+}
+
namespace {
class DocumentImpl;
@@ -169,86 +224,53 @@ class NamedNodeMap
{
public:
// JS API
- static QScriptValue length(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> length(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> indexed(uint32_t index, const v8::AccessorInfo& info);
+ static v8::Handle<v8::Value> named(v8::Local<v8::String> property, const v8::AccessorInfo& args);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
- static QScriptValue create(QScriptEngine *, NodeImpl *, QList<NodeImpl *> *);
-
- NamedNodeMap();
- NamedNodeMap(const NamedNodeMap &);
- ~NamedNodeMap();
- bool isNull();
-
- NodeImpl *d;
- QList<NodeImpl *> *list;
-private:
- NamedNodeMap &operator=(const NamedNodeMap &);
-};
-
-class NamedNodeMapClass : public QScriptClass
-{
-public:
- NamedNodeMapClass(QScriptEngine *engine) : QScriptClass(engine) {}
-
- virtual QueryFlags queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id);
- virtual QScriptValue property(const QScriptValue &object, const QScriptString &name, uint id);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
+ static v8::Handle<v8::Value> create(QV8Engine *, NodeImpl *, QList<NodeImpl *> *);
};
class NodeList
{
public:
// JS API
- static QScriptValue length(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> length(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> indexed(uint32_t index, const v8::AccessorInfo& info);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
- static QScriptValue create(QScriptEngine *, NodeImpl *);
-
- NodeList();
- NodeList(const NodeList &);
- ~NodeList();
- bool isNull();
-
- NodeImpl *d;
-private:
- NodeList &operator=(const NodeList &);
-};
-
-class NodeListClass : public QScriptClass
-{
-public:
- NodeListClass(QScriptEngine *engine) : QScriptClass(engine) {}
- virtual QueryFlags queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id);
- virtual QScriptValue property(const QScriptValue &object, const QScriptString &name, uint id);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
+ static v8::Handle<v8::Value> create(QV8Engine *, NodeImpl *);
};
class Node
{
public:
// JS API
- static QScriptValue nodeName(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue nodeValue(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue nodeType(QScriptContext *context, QScriptEngine *engine);
-
- static QScriptValue parentNode(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue childNodes(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue firstChild(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue lastChild(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue previousSibling(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue nextSibling(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue attributes(QScriptContext *context, QScriptEngine *engine);
-
- //static QScriptValue ownerDocument(QScriptContext *context, QScriptEngine *engine);
- //static QScriptValue namespaceURI(QScriptContext *context, QScriptEngine *engine);
- //static QScriptValue prefix(QScriptContext *context, QScriptEngine *engine);
- //static QScriptValue localName(QScriptContext *context, QScriptEngine *engine);
- //static QScriptValue baseURI(QScriptContext *context, QScriptEngine *engine);
- //static QScriptValue textContent(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> nodeName(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> nodeValue(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> nodeType(v8::Local<v8::String>, const v8::AccessorInfo& args);
+
+ static v8::Handle<v8::Value> parentNode(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> childNodes(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> firstChild(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> lastChild(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> previousSibling(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> nextSibling(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> attributes(v8::Local<v8::String>, const v8::AccessorInfo& args);
+
+ //static v8::Handle<v8::Value> ownerDocument(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ //static v8::Handle<v8::Value> namespaceURI(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ //static v8::Handle<v8::Value> prefix(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ //static v8::Handle<v8::Value> localName(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ //static v8::Handle<v8::Value> baseURI(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ //static v8::Handle<v8::Value> textContent(v8::Local<v8::String>, const v8::AccessorInfo& args);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
- static QScriptValue create(QScriptEngine *, NodeImpl *);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
+ static v8::Handle<v8::Value> create(QV8Engine *, NodeImpl *);
Node();
Node(const Node &o);
@@ -265,68 +287,82 @@ class Element : public Node
{
public:
// C++ API
- static QScriptValue prototype(QScriptEngine *);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
};
class Attr : public Node
{
public:
// JS API
- static QScriptValue name(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue specified(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue value(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue ownerElement(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue schemaTypeInfo(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue isId(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> name(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> specified(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> value(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> ownerElement(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> schemaTypeInfo(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> isId(v8::Local<v8::String>, const v8::AccessorInfo& args);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
};
class CharacterData : public Node
{
public:
// JS API
- static QScriptValue length(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> length(v8::Local<v8::String>, const v8::AccessorInfo& args);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
};
class Text : public CharacterData
{
public:
// JS API
- static QScriptValue isElementContentWhitespace(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue wholeText(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> isElementContentWhitespace(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> wholeText(v8::Local<v8::String>, const v8::AccessorInfo& args);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
};
class CDATA : public Text
{
public:
// C++ API
- static QScriptValue prototype(QScriptEngine *);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
};
class Document : public Node
{
public:
// JS API
- static QScriptValue xmlVersion(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue xmlEncoding(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue xmlStandalone(QScriptContext *context, QScriptEngine *engine);
- static QScriptValue documentElement(QScriptContext *context, QScriptEngine *engine);
+ static v8::Handle<v8::Value> xmlVersion(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> xmlEncoding(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> xmlStandalone(v8::Local<v8::String>, const v8::AccessorInfo& args);
+ static v8::Handle<v8::Value> documentElement(v8::Local<v8::String>, const v8::AccessorInfo& args);
// C++ API
- static QScriptValue prototype(QScriptEngine *);
- static QScriptValue load(QScriptEngine *engine, const QByteArray &data);
+ static v8::Handle<v8::Object> prototype(QV8Engine *);
+ static v8::Handle<v8::Value> load(QV8Engine *engine, const QByteArray &data);
};
}
+class QDeclarativeDOMNodeResource : public QV8ObjectResource, public Node
+{
+ V8_RESOURCE_TYPE(DOMNodeType);
+public:
+ QDeclarativeDOMNodeResource(QV8Engine *e);
+
+ QList<NodeImpl *> *list; // Only used in NamedNodeMap
+};
+
+QDeclarativeDOMNodeResource::QDeclarativeDOMNodeResource(QV8Engine *e)
+: QV8ObjectResource(e), list(0)
+{
+}
+
QT_END_NAMESPACE
Q_DECLARE_METATYPE(Node)
@@ -345,152 +381,174 @@ void NodeImpl::release()
D(document);
}
-QScriptValue Node::nodeName(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::nodeName(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- switch (node.d->type) {
+ switch (r->d->type) {
case NodeImpl::Document:
- return QScriptValue(QLatin1String("#document"));
+ return v8::String::New("#document");
case NodeImpl::CDATA:
- return QScriptValue(QLatin1String("#cdata-section"));
+ return v8::String::New("#cdata-section");
case NodeImpl::Text:
- return QScriptValue(QLatin1String("#text"));
+ return v8::String::New("#text");
default:
- return QScriptValue(node.d->name);
+ return engine->toString(r->d->name);
}
}
-QScriptValue Node::nodeValue(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::nodeValue(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (node.d->type == NodeImpl::Document ||
- node.d->type == NodeImpl::DocumentFragment ||
- node.d->type == NodeImpl::DocumentType ||
- node.d->type == NodeImpl::Element ||
- node.d->type == NodeImpl::Entity ||
- node.d->type == NodeImpl::EntityReference ||
- node.d->type == NodeImpl::Notation)
- return engine->nullValue();
+ if (r->d->type == NodeImpl::Document ||
+ r->d->type == NodeImpl::DocumentFragment ||
+ r->d->type == NodeImpl::DocumentType ||
+ r->d->type == NodeImpl::Element ||
+ r->d->type == NodeImpl::Entity ||
+ r->d->type == NodeImpl::EntityReference ||
+ r->d->type == NodeImpl::Notation)
+ return v8::Null();
- return QScriptValue(node.d->data);
+ return engine->toString(r->d->data);
}
-QScriptValue Node::nodeType(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::nodeType(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
- return QScriptValue(node.d->type);
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ return v8::Integer::New(r->d->type);
}
-QScriptValue Node::parentNode(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::parentNode(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (node.d->parent) return Node::create(engine, node.d->parent);
- else return engine->nullValue();
+ if (r->d->parent) return Node::create(engine, r->d->parent);
+ else return v8::Null();
}
-QScriptValue Node::childNodes(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::childNodes(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return NodeList::create(engine, node.d);
+ return NodeList::create(engine, r->d);
}
-QScriptValue Node::firstChild(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::firstChild(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (node.d->children.isEmpty()) return engine->nullValue();
- else return Node::create(engine, node.d->children.first());
+ if (r->d->children.isEmpty()) return v8::Null();
+ else return Node::create(engine, r->d->children.first());
}
-QScriptValue Node::lastChild(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::lastChild(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (node.d->children.isEmpty()) return engine->nullValue();
- else return Node::create(engine, node.d->children.last());
+ if (r->d->children.isEmpty()) return v8::Null();
+ else return Node::create(engine, r->d->children.last());
}
-QScriptValue Node::previousSibling(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::previousSibling(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (!node.d->parent) return engine->nullValue();
+ if (!r->d->parent) return v8::Null();
- for (int ii = 0; ii < node.d->parent->children.count(); ++ii) {
- if (node.d->parent->children.at(ii) == node.d) {
- if (ii == 0) return engine->nullValue();
- else return Node::create(engine, node.d->parent->children.at(ii - 1));
+ for (int ii = 0; ii < r->d->parent->children.count(); ++ii) {
+ if (r->d->parent->children.at(ii) == r->d) {
+ if (ii == 0) return v8::Null();
+ else return Node::create(engine, r->d->parent->children.at(ii - 1));
}
}
- return engine->nullValue();
+ return v8::Null();
}
-QScriptValue Node::nextSibling(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::nextSibling(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (!node.d->parent) return engine->nullValue();
+ if (!r->d->parent) return v8::Null();
- for (int ii = 0; ii < node.d->parent->children.count(); ++ii) {
- if (node.d->parent->children.at(ii) == node.d) {
- if ((ii + 1) == node.d->parent->children.count()) return engine->nullValue();
- else return Node::create(engine, node.d->parent->children.at(ii + 1));
+ for (int ii = 0; ii < r->d->parent->children.count(); ++ii) {
+ if (r->d->parent->children.at(ii) == r->d) {
+ if ((ii + 1) == r->d->parent->children.count()) return v8::Null();
+ else return Node::create(engine, r->d->parent->children.at(ii + 1));
}
}
- return engine->nullValue();
+ return v8::Null();
}
-QScriptValue Node::attributes(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Node::attributes(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- if (node.d->type != NodeImpl::Element)
- return engine->nullValue();
+ if (r->d->type != NodeImpl::Element)
+ return v8::Null();
else
- return NamedNodeMap::create(engine, node.d, &node.d->attributes);
-}
-
-QScriptValue Node::prototype(QScriptEngine *engine)
-{
- QScriptValue proto = engine->newObject();
-
- proto.setProperty(QLatin1String("nodeName"), engine->newFunction(nodeName), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("nodeValue"), engine->newFunction(nodeValue), QScriptValue::ReadOnly | QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- proto.setProperty(QLatin1String("nodeType"), engine->newFunction(nodeType), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("parentNode"), engine->newFunction(parentNode), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("childNodes"), engine->newFunction(childNodes), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("firstChild"), engine->newFunction(firstChild), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("lastChild"), engine->newFunction(lastChild), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("previousSibling"), engine->newFunction(previousSibling), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("nextSibling"), engine->newFunction(nextSibling), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("attributes"), engine->newFunction(attributes), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ return NamedNodeMap::create(engine, r->d, &r->d->attributes);
+}
+
+v8::Handle<v8::Object> Node::prototype(QV8Engine *engine)
+{
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->nodePrototype.IsEmpty()) {
+ d->nodePrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->nodePrototype->SetAccessor(v8::String::New("nodeName"), nodeName,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("nodeValue"), nodeValue,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("nodeType"), nodeType,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("parentNode"), parentNode,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("childNodes"), childNodes,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("firstChild"), firstChild,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("lastChild"), lastChild,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("previousSibling"), previousSibling,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("nextSibling"), nextSibling,
+ 0, v8::External::Wrap(engine));
+ d->nodePrototype->SetAccessor(v8::String::New("attributes"), attributes,
+ 0, v8::External::Wrap(engine));
+ engine->freezeObject(d->nodePrototype);
+ }
+ return d->nodePrototype;
}
-QScriptValue Node::create(QScriptEngine *engine, NodeImpl *data)
+v8::Handle<v8::Value> Node::create(QV8Engine *engine, NodeImpl *data)
{
- QScriptValue instance = engine->newObject();
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ v8::Local<v8::Object> instance = d->newNode();
switch (data->type) {
case NodeImpl::Attr:
- instance.setPrototype(Attr::prototype(engine));
+ instance->SetPrototype(Attr::prototype(engine));
break;
case NodeImpl::Comment:
case NodeImpl::Document:
@@ -500,138 +558,171 @@ QScriptValue Node::create(QScriptEngine *engine, NodeImpl *data)
case NodeImpl::EntityReference:
case NodeImpl::Notation:
case NodeImpl::ProcessingInstruction:
- return QScriptValue();
+ return v8::Undefined();
case NodeImpl::CDATA:
- instance.setPrototype(CDATA::prototype(engine));
+ instance->SetPrototype(CDATA::prototype(engine));
break;
case NodeImpl::Text:
- instance.setPrototype(Text::prototype(engine));
+ instance->SetPrototype(Text::prototype(engine));
break;
case NodeImpl::Element:
- instance.setPrototype(Element::prototype(engine));
+ instance->SetPrototype(Element::prototype(engine));
break;
}
- Node node;
- node.d = data;
+ QDeclarativeDOMNodeResource *r = new QDeclarativeDOMNodeResource(engine);
+ r->d = data;
if (data) A(data);
+ instance->SetExternalResource(r);
- return engine->newVariant(instance, QVariant::fromValue(node));
-}
-
-QScriptValue Element::prototype(QScriptEngine *engine)
-{
- QScriptValue proto = engine->newObject();
- proto.setPrototype(Node::prototype(engine));
-
- proto.setProperty(QLatin1String("tagName"), engine->newFunction(nodeName), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
-}
-
-QScriptValue Attr::prototype(QScriptEngine *engine)
-{
- QScriptValue proto = engine->newObject();
- proto.setPrototype(Node::prototype(engine));
-
- proto.setProperty(QLatin1String("name"), engine->newFunction(name), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("value"), engine->newFunction(value), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("ownerElement"), engine->newFunction(ownerElement), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ return instance;
}
-QScriptValue Attr::name(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Object> Element::prototype(QV8Engine *engine)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
-
- return QScriptValue(node.d->name);
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->elementPrototype.IsEmpty()) {
+ d->elementPrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->elementPrototype->SetPrototype(Node::prototype(engine));
+ d->elementPrototype->SetAccessor(v8::String::New("tagName"), nodeName,
+ 0, v8::External::Wrap(engine));
+ engine->freezeObject(d->elementPrototype);
+ }
+ return d->elementPrototype;
+}
+
+v8::Handle<v8::Object> Attr::prototype(QV8Engine *engine)
+{
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->attrPrototype.IsEmpty()) {
+ d->attrPrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->attrPrototype->SetPrototype(Node::prototype(engine));
+ d->attrPrototype->SetAccessor(v8::String::New("name"), name,
+ 0, v8::External::Wrap(engine));
+ d->attrPrototype->SetAccessor(v8::String::New("value"), value,
+ 0, v8::External::Wrap(engine));
+ d->attrPrototype->SetAccessor(v8::String::New("ownerElement"), ownerElement,
+ 0, v8::External::Wrap(engine));
+ engine->freezeObject(d->attrPrototype);
+ }
+ return d->attrPrototype;
}
-QScriptValue Attr::value(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Attr::name(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return QScriptValue(node.d->data);
+ return engine->toString(r->d->name);
}
-QScriptValue Attr::ownerElement(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Attr::value(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return Node::create(engine, node.d->parent);
+ return engine->toString(r->d->data);
}
-QScriptValue CharacterData::length(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Attr::ownerElement(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return QScriptValue(node.d->data.length());
+ return Node::create(engine, r->d->parent);
}
-QScriptValue CharacterData::prototype(QScriptEngine *engine)
+v8::Handle<v8::Value> CharacterData::length(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- QScriptValue proto = engine->newObject();
- proto.setPrototype(Node::prototype(engine));
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- proto.setProperty(QLatin1String("data"), engine->newFunction(nodeValue), QScriptValue::ReadOnly | QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- proto.setProperty(QLatin1String("length"), engine->newFunction(length), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ return v8::Integer::New(r->d->data.length());
}
-QScriptValue Text::isElementContentWhitespace(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Object> CharacterData::prototype(QV8Engine *engine)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
-
- return node.d->data.trimmed().isEmpty();
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->characterDataPrototype.IsEmpty()) {
+ d->characterDataPrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->characterDataPrototype->SetPrototype(Node::prototype(engine));
+ d->characterDataPrototype->SetAccessor(v8::String::New("data"), nodeValue,
+ 0, v8::External::Wrap(engine));
+ d->characterDataPrototype->SetAccessor(v8::String::New("length"), length,
+ 0, v8::External::Wrap(engine));
+ engine->freezeObject(d->characterDataPrototype);
+ }
+ return d->characterDataPrototype;
}
-QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Text::isElementContentWhitespace(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- Node node = qscriptvalue_cast<Node>(context->thisObject());
- if (node.isNull()) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return node.d->data;
+ return v8::Boolean::New(r->d->data.trimmed().isEmpty());
}
-QScriptValue Text::prototype(QScriptEngine *engine)
+v8::Handle<v8::Value> Text::wholeText(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- QScriptValue proto = engine->newObject();
- proto.setPrototype(CharacterData::prototype(engine));
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- proto.setProperty(QLatin1String("isElementContentWhitespace"), engine->newFunction(isElementContentWhitespace), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- proto.setProperty(QLatin1String("wholeText"), engine->newFunction(wholeText), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ return engine->toString(r->d->data);
}
-QScriptValue CDATA::prototype(QScriptEngine *engine)
+v8::Handle<v8::Object> Text::prototype(QV8Engine *engine)
{
- QScriptValue proto = engine->newObject();
- proto.setPrototype(Text::prototype(engine));
- return proto;
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->textPrototype.IsEmpty()) {
+ d->textPrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->textPrototype->SetPrototype(CharacterData::prototype(engine));
+ d->textPrototype->SetAccessor(v8::String::New("isElementContentWhitespace"), isElementContentWhitespace,
+ 0, v8::External::Wrap(engine));
+ d->textPrototype->SetAccessor(v8::String::New("wholeText"), wholeText,
+ 0, v8::External::Wrap(engine));
+ engine->freezeObject(d->textPrototype);
+ }
+ return d->textPrototype;
}
-QScriptValue Document::prototype(QScriptEngine *engine)
+v8::Handle<v8::Object> CDATA::prototype(QV8Engine *engine)
{
- QScriptValue proto = engine->newObject();
- proto.setPrototype(Node::prototype(engine));
-
- proto.setProperty(QLatin1String("xmlVersion"), engine->newFunction(xmlVersion), QScriptValue::ReadOnly | QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- proto.setProperty(QLatin1String("xmlEncoding"), engine->newFunction(xmlEncoding), QScriptValue::ReadOnly | QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- proto.setProperty(QLatin1String("xmlStandalone"), engine->newFunction(xmlStandalone), QScriptValue::ReadOnly | QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- proto.setProperty(QLatin1String("documentElement"), engine->newFunction(documentElement), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->cdataPrototype.IsEmpty()) {
+ d->cdataPrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->cdataPrototype->SetPrototype(Text::prototype(engine));
+ engine->freezeObject(d->cdataPrototype);
+ }
+ return d->cdataPrototype;
+}
+
+v8::Handle<v8::Object> Document::prototype(QV8Engine *engine)
+{
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->documentPrototype.IsEmpty()) {
+ d->documentPrototype = qPersistentNew<v8::Object>(v8::Object::New());
+ d->documentPrototype->SetPrototype(Node::prototype(engine));
+ d->documentPrototype->SetAccessor(v8::String::New("xmlVersion"), xmlVersion,
+ 0, v8::External::Wrap(engine));
+ d->documentPrototype->SetAccessor(v8::String::New("xmlEncoding"), xmlEncoding,
+ 0, v8::External::Wrap(engine));
+ d->documentPrototype->SetAccessor(v8::String::New("xmlStandalone"), xmlStandalone,
+ 0, v8::External::Wrap(engine));
+ d->documentPrototype->SetAccessor(v8::String::New("documentElement"), documentElement,
+ 0, v8::External::Wrap(engine));
+ engine->freezeObject(d->documentPrototype);
+ }
+ return d->documentPrototype;
}
-QScriptValue Document::load(QScriptEngine *engine, const QByteArray &data)
+v8::Handle<v8::Value> Document::load(QV8Engine *engine, const QByteArray &data)
{
Q_ASSERT(engine);
@@ -709,14 +800,15 @@ QScriptValue Document::load(QScriptEngine *engine, const QByteArray &data)
if (!document || reader.hasError()) {
if (document) D(document);
- return engine->nullValue();
+ return v8::Null();
}
- QScriptValue instance = engine->newObject();
- instance.setPrototype(Document::prototype(engine));
- Node documentNode;
- documentNode.d = document;
- return engine->newVariant(instance, QVariant::fromValue(documentNode));
+ v8::Local<v8::Object> instance = xhrdata(engine)->newNode();
+ QDeclarativeDOMNodeResource *r = new QDeclarativeDOMNodeResource(engine);
+ r->d = document;
+ instance->SetExternalResource(r);
+ instance->SetPrototype(Document::prototype(engine));
+ return instance;
}
Node::Node()
@@ -740,221 +832,164 @@ bool Node::isNull() const
return d == 0;
}
-QScriptValue NamedNodeMap::length(QScriptContext *context, QScriptEngine *engine)
-{
- NamedNodeMap map = qscriptvalue_cast<NamedNodeMap>(context->thisObject().data());
- if (map.isNull()) return engine->undefinedValue();
-
- return QScriptValue(map.list->count());
-}
-
-QScriptValue NamedNodeMap::prototype(QScriptEngine *engine)
+v8::Handle<v8::Value> NamedNodeMap::length(v8::Local<v8::String>, const v8::AccessorInfo &args)
{
- QScriptValue proto = engine->newObject();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- proto.setProperty(QLatin1String("length"), engine->newFunction(length), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ return v8::Integer::New(r->list->count());
}
-QScriptValue NamedNodeMap::create(QScriptEngine *engine, NodeImpl *data, QList<NodeImpl *> *list)
+v8::Handle<v8::Value> NamedNodeMap::indexed(uint32_t index, const v8::AccessorInfo& args)
{
- QScriptValue instance = engine->newObject();
- instance.setPrototype(NamedNodeMap::prototype(engine));
-
- NamedNodeMap map;
- map.d = data;
- map.list = list;
- if (data) A(data);
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r || !r->list) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- instance.setData(engine->newVariant(QVariant::fromValue(map)));
-
- if (!QDeclarativeScriptEngine::get(engine)->namedNodeMapClass)
- QDeclarativeScriptEngine::get(engine)->namedNodeMapClass= new NamedNodeMapClass(engine);
-
- instance.setScriptClass(QDeclarativeScriptEngine::get(engine)->namedNodeMapClass);
-
- return instance;
-}
-
-NamedNodeMap::NamedNodeMap()
-: d(0), list(0)
-{
-}
-
-NamedNodeMap::NamedNodeMap(const NamedNodeMap &o)
-: d(o.d), list(o.list)
-{
- if (d) A(d);
-}
-
-NamedNodeMap::~NamedNodeMap()
-{
- if (d) D(d);
+ if (index < r->list->count()) {
+ return Node::create(engine, r->list->at(index));
+ } else {
+ return v8::Undefined();
+ }
}
-bool NamedNodeMap::isNull()
+v8::Handle<v8::Value> NamedNodeMap::named(v8::Local<v8::String> property, const v8::AccessorInfo& args)
{
- return d == 0;
-}
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r || !r->list) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
-QScriptValue NodeList::length(QScriptContext *context, QScriptEngine *engine)
-{
- NodeList list = qscriptvalue_cast<NodeList>(context->thisObject().data());
- if (list.isNull()) return engine->undefinedValue();
+ QString str = engine->toString(property);
+ for (int ii = 0; ii < r->list->count(); ++ii) {
+ if (r->list->at(ii)->name == str) {
+ return Node::create(engine, r->list->at(ii));
+ }
+ }
- return QScriptValue(list.d->children.count());
+ return v8::Undefined();
}
-QScriptValue NodeList::prototype(QScriptEngine *engine)
+v8::Handle<v8::Object> NamedNodeMap::prototype(QV8Engine *engine)
{
- QScriptValue proto = engine->newObject();
-
- proto.setProperty(QLatin1String("length"), engine->newFunction(length), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
-
- return proto;
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->namedNodeMapPrototype.IsEmpty()) {
+ v8::Local<v8::ObjectTemplate> ot = v8::ObjectTemplate::New();
+ ot->SetAccessor(v8::String::New("length"), length, 0, v8::External::Wrap(engine));
+ ot->SetIndexedPropertyHandler(indexed, 0, 0, 0, 0, v8::External::Wrap(engine));
+ ot->SetFallbackPropertyHandler(named, 0, 0, 0, 0, v8::External::Wrap(engine));
+ d->namedNodeMapPrototype = qPersistentNew<v8::Object>(ot->NewInstance());
+ engine->freezeObject(d->namedNodeMapPrototype);
+ }
+ return d->namedNodeMapPrototype;
}
-QScriptValue NodeList::create(QScriptEngine *engine, NodeImpl *data)
+v8::Handle<v8::Value> NamedNodeMap::create(QV8Engine *engine, NodeImpl *data, QList<NodeImpl *> *list)
{
- QScriptValue instance = engine->newObject();
- instance.setPrototype(NodeList::prototype(engine));
-
- NodeList list;
- list.d = data;
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ v8::Local<v8::Object> instance = d->newNode();
+ instance->SetPrototype(NamedNodeMap::prototype(engine));
+ QDeclarativeDOMNodeResource *r = new QDeclarativeDOMNodeResource(engine);
+ r->d = data;
+ r->list = list;
if (data) A(data);
-
- instance.setData(engine->newVariant(QVariant::fromValue(list)));
-
- if (!QDeclarativeScriptEngine::get(engine)->nodeListClass)
- QDeclarativeScriptEngine::get(engine)->nodeListClass= new NodeListClass(engine);
-
- instance.setScriptClass(QDeclarativeScriptEngine::get(engine)->nodeListClass);
-
+ instance->SetExternalResource(r);
return instance;
}
-NodeList::NodeList()
-: d(0)
-{
-}
-
-NodeList::NodeList(const NodeList &o)
-: d(o.d)
-{
- if (d) A(d);
-}
-
-NodeList::~NodeList()
-{
- if (d) D(d);
-}
-
-bool NodeList::isNull()
+v8::Handle<v8::Value> NodeList::indexed(uint32_t index, const v8::AccessorInfo& args)
{
- return d == 0;
-}
-
-NamedNodeMapClass::QueryFlags NamedNodeMapClass::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
-{
- if (!(flags & HandlesReadAccess))
- return 0;
-
- NamedNodeMap map = qscriptvalue_cast<NamedNodeMap>(object.data());
- Q_ASSERT(!map.isNull());
-
- bool ok = false;
- QString nameString = name.toString();
- uint index = nameString.toUInt(&ok);
- if (ok) {
- if ((uint)map.list->count() <= index)
- return 0;
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- *id = index;
- return HandlesReadAccess;
+ if (index < r->d->children.count()) {
+ return Node::create(engine, r->d->children.at(index));
} else {
- for (int ii = 0; ii < map.list->count(); ++ii) {
- if (map.list->at(ii) && map.list->at(ii)->name == nameString) {
- *id = ii;
- return HandlesReadAccess;
- }
- }
+ return v8::Undefined();
}
-
- return 0;
}
-QScriptValue NamedNodeMapClass::property(const QScriptValue &object, const QScriptString &, uint id)
+v8::Handle<v8::Value> NodeList::length(v8::Local<v8::String>, const v8::AccessorInfo& args)
{
- NamedNodeMap map = qscriptvalue_cast<NamedNodeMap>(object.data());
- return Node::create(engine(), map.list->at(id));
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
+
+ return v8::Integer::New(r->d->children.count());
}
-NodeListClass::QueryFlags NodeListClass::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
+v8::Handle<v8::Object> NodeList::prototype(QV8Engine *engine)
{
- if (!(flags & HandlesReadAccess))
- return 0;
-
- bool ok = false;
- uint index = name.toString().toUInt(&ok);
- if (!ok)
- return 0;
-
- NodeList list = qscriptvalue_cast<NodeList>(object.data());
- if (list.isNull() || (uint)list.d->children.count() <= index)
- return 0; // ### I think we're meant to raise an exception
-
- *id = index;
- return HandlesReadAccess;
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ if (d->nodeListPrototype.IsEmpty()) {
+ v8::Local<v8::ObjectTemplate> ot = v8::ObjectTemplate::New();
+ ot->SetAccessor(v8::String::New("length"), length, 0, v8::External::Wrap(engine));
+ ot->SetIndexedPropertyHandler(indexed, 0, 0, 0, 0, v8::External::Wrap(engine));
+ d->nodeListPrototype = qPersistentNew<v8::Object>(ot->NewInstance());
+ engine->freezeObject(d->nodeListPrototype);
+ }
+ return d->nodeListPrototype;
}
-QScriptValue NodeListClass::property(const QScriptValue &object, const QScriptString &, uint id)
+v8::Handle<v8::Value> NodeList::create(QV8Engine *engine, NodeImpl *data)
{
- NodeList list = qscriptvalue_cast<NodeList>(object.data());
- return Node::create(engine(), list.d->children.at(id));
+ QDeclarativeXMLHttpRequestData *d = xhrdata(engine);
+ v8::Local<v8::Object> instance = d->newNode();
+ instance->SetPrototype(NodeList::prototype(engine));
+ QDeclarativeDOMNodeResource *r = new QDeclarativeDOMNodeResource(engine);
+ r->d = data;
+ if (data) A(data);
+ instance->SetExternalResource(r);
+ return instance;
}
-QScriptValue Document::documentElement(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Document::documentElement(v8::Local<v8::String>, const v8::AccessorInfo& args)
{
- Node document = qscriptvalue_cast<Node>(context->thisObject());
- if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r || r->d->type != NodeImpl::Document) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return Node::create(engine, static_cast<DocumentImpl *>(document.d)->root);
+ return Node::create(engine, static_cast<DocumentImpl *>(r->d)->root);
}
-QScriptValue Document::xmlStandalone(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Document::xmlStandalone(v8::Local<v8::String>, const v8::AccessorInfo& args)
{
- Node document = qscriptvalue_cast<Node>(context->thisObject());
- if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r || r->d->type != NodeImpl::Document) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return QScriptValue(static_cast<DocumentImpl *>(document.d)->isStandalone);
+ return v8::Boolean::New(static_cast<DocumentImpl *>(r->d)->isStandalone);
}
-QScriptValue Document::xmlVersion(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Document::xmlVersion(v8::Local<v8::String>, const v8::AccessorInfo& args)
{
- Node document = qscriptvalue_cast<Node>(context->thisObject());
- if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r || r->d->type != NodeImpl::Document) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return QScriptValue(static_cast<DocumentImpl *>(document.d)->version);
+ return engine->toString(static_cast<DocumentImpl *>(r->d)->version);
}
-QScriptValue Document::xmlEncoding(QScriptContext *context, QScriptEngine *engine)
+v8::Handle<v8::Value> Document::xmlEncoding(v8::Local<v8::String>, const v8::AccessorInfo& args)
{
- Node document = qscriptvalue_cast<Node>(context->thisObject());
- if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
+ QDeclarativeDOMNodeResource *r = v8_resource_cast<QDeclarativeDOMNodeResource>(args.This());
+ if (!r || r->d->type != NodeImpl::Document) return v8::Undefined();
+ QV8Engine *engine = V8ENGINE();
- return QScriptValue(static_cast<DocumentImpl *>(document.d)->encoding);
+ return engine->toString(static_cast<DocumentImpl *>(r->d)->encoding);
}
-class QDeclarativeXMLHttpRequest : public QObject
+class QDeclarativeXMLHttpRequest : public QObject, public QV8ObjectResource
{
Q_OBJECT
+V8_RESOURCE_TYPE(XMLHttpRequestType)
public:
enum State { Unsent = 0,
Opened = 1, HeadersReceived = 2,
Loading = 3, Done = 4 };
- QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager);
+ QDeclarativeXMLHttpRequest(QV8Engine *engine, QNetworkAccessManager *manager);
virtual ~QDeclarativeXMLHttpRequest();
bool sendFlag() const;
@@ -963,13 +998,14 @@ public:
int replyStatus() const;
QString replyStatusText() const;
- QScriptValue open(QScriptValue *me, const QString &, const QUrl &);
+ v8::Handle<v8::Value> open(v8::Handle<v8::Object> me, const QString &, const QUrl &);
+ v8::Handle<v8::Value> send(v8::Handle<v8::Object> me, const QByteArray &);
+ v8::Handle<v8::Value> abort(v8::Handle<v8::Object> me);
void addHeader(const QString &, const QString &);
QString header(const QString &name);
QString headers();
- QScriptValue send(QScriptValue *me, const QByteArray &);
- QScriptValue abort(QScriptValue *me);
+
QString responseBody();
const QByteArray & rawResponseBody() const;
@@ -1005,10 +1041,12 @@ private:
#endif
void readEncoding();
- QScriptValue m_me; // Set to the data object while a send() is ongoing (to access the callback)
+ v8::Handle<v8::Object> getMe() const;
+ void setMe(v8::Handle<v8::Object> me);
+ v8::Persistent<v8::Object> m_me;
- QScriptValue dispatchCallback(QScriptValue *me);
- void printError(const QScriptValue&);
+ void dispatchCallback(v8::Handle<v8::Object> me);
+ void printError(v8::Handle<v8::Message>);
int m_status;
QString m_statusText;
@@ -1020,8 +1058,8 @@ private:
QNetworkAccessManager *networkAccessManager() { return m_nam; }
};
-QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager)
-: m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
+QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest(QV8Engine *engine, QNetworkAccessManager *manager)
+: QV8ObjectResource(engine), m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager)
{
}
@@ -1056,7 +1094,8 @@ QString QDeclarativeXMLHttpRequest::replyStatusText() const
return m_statusText;
}
-QScriptValue QDeclarativeXMLHttpRequest::open(QScriptValue *me, const QString &method, const QUrl &url)
+v8::Handle<v8::Value> QDeclarativeXMLHttpRequest::open(v8::Handle<v8::Object> me, const QString &method,
+ const QUrl &url)
{
destroyNetwork();
m_sendFlag = false;
@@ -1065,7 +1104,8 @@ QScriptValue QDeclarativeXMLHttpRequest::open(QScriptValue *me, const QString &m
m_method = method;
m_url = url;
m_state = Opened;
- return dispatchCallback(me);
+ dispatchCallback(me);
+ return v8::Undefined();
}
void QDeclarativeXMLHttpRequest::addHeader(const QString &name, const QString &value)
@@ -1178,20 +1218,21 @@ void QDeclarativeXMLHttpRequest::requestFromUrl(const QUrl &url)
this, SLOT(finished()));
}
-QScriptValue QDeclarativeXMLHttpRequest::send(QScriptValue *me, const QByteArray &data)
+v8::Handle<v8::Value> QDeclarativeXMLHttpRequest::send(v8::Handle<v8::Object> me, const QByteArray &data)
{
m_errorFlag = false;
m_sendFlag = true;
m_redirectCount = 0;
m_data = data;
- m_me = *me;
+
+ setMe(me);
requestFromUrl(m_url);
- return QScriptValue();
+ return v8::Undefined();
}
-QScriptValue QDeclarativeXMLHttpRequest::abort(QScriptValue *me)
+v8::Handle<v8::Value> QDeclarativeXMLHttpRequest::abort(v8::Handle<v8::Object> me)
{
destroyNetwork();
m_responseEntityBody = QByteArray();
@@ -1204,16 +1245,31 @@ QScriptValue QDeclarativeXMLHttpRequest::abort(QScriptValue *me)
m_state = Done;
m_sendFlag = false;
- QScriptValue cbv = dispatchCallback(me);
- if (cbv.isError()) return cbv;
+ dispatchCallback(me);
}
m_state = Unsent;
- return QScriptValue();
+
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Object> QDeclarativeXMLHttpRequest::getMe() const
+{
+ return m_me;
+}
+
+void QDeclarativeXMLHttpRequest::setMe(v8::Handle<v8::Object> me)
+{
+ qPersistentDispose(m_me);
+
+ if (!me.IsEmpty())
+ m_me = qPersistentNew<v8::Object>(me);
}
void QDeclarativeXMLHttpRequest::downloadProgress(qint64 bytes)
{
+ v8::HandleScope handle_scope;
+
Q_UNUSED(bytes)
m_status =
m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@@ -1224,16 +1280,18 @@ void QDeclarativeXMLHttpRequest::downloadProgress(qint64 bytes)
if (m_state < HeadersReceived) {
m_state = HeadersReceived;
fillHeadersList ();
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
}
bool wasEmpty = m_responseEntityBody.isEmpty();
m_responseEntityBody.append(m_network->readAll());
if (wasEmpty && !m_responseEntityBody.isEmpty()) {
m_state = Loading;
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
}
}
@@ -1251,6 +1309,8 @@ static const char *errorToString(QNetworkReply::NetworkError error)
void QDeclarativeXMLHttpRequest::error(QNetworkReply::NetworkError error)
{
+ v8::HandleScope handle_scope;
+
Q_UNUSED(error)
m_status =
m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@@ -1274,20 +1334,25 @@ void QDeclarativeXMLHttpRequest::error(QNetworkReply::NetworkError error)
error == QNetworkReply::AuthenticationRequiredError ||
error == QNetworkReply::ContentReSendError) {
m_state = Loading;
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
} else {
m_errorFlag = true;
}
m_state = Done;
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
+
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
}
#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION 15
void QDeclarativeXMLHttpRequest::finished()
{
+ v8::HandleScope handle_scope;
+
m_redirectCount++;
if (m_redirectCount < XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION) {
QVariant redirect = m_network->attribute(QNetworkRequest::RedirectionTargetAttribute);
@@ -1307,8 +1372,9 @@ void QDeclarativeXMLHttpRequest::finished()
if (m_state < HeadersReceived) {
m_state = HeadersReceived;
fillHeadersList ();
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
}
m_responseEntityBody.append(m_network->readAll());
readEncoding();
@@ -1326,14 +1392,17 @@ void QDeclarativeXMLHttpRequest::finished()
destroyNetwork();
if (m_state < Loading) {
m_state = Loading;
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
}
m_state = Done;
- QScriptValue cbv = dispatchCallback(&m_me);
- if (cbv.isError()) printError(cbv);
- m_me = QScriptValue();
+ v8::TryCatch tc;
+ dispatchCallback(m_me);
+ if (tc.HasCaught()) printError(tc.Message());
+
+ setMe(v8::Handle<v8::Object>());
}
@@ -1411,17 +1480,25 @@ const QByteArray &QDeclarativeXMLHttpRequest::rawResponseBody() const
return m_responseEntityBody;
}
-QScriptValue QDeclarativeXMLHttpRequest::dispatchCallback(QScriptValue *me)
+// Requires a TryCatch scope
+void QDeclarativeXMLHttpRequest::dispatchCallback(v8::Handle<v8::Object> me)
{
- QScriptValue v = me->property(QLatin1String("callback"));
- return v.call();
+ v8::Local<v8::Value> callback = me->Get(v8::String::New("onreadystatechange"));
+ if (callback->IsFunction()) {
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(callback);
+
+ f->Call(me, 0, 0);
+ }
}
-void QDeclarativeXMLHttpRequest::printError(const QScriptValue& sv)
+// Must have a handle scope
+void QDeclarativeXMLHttpRequest::printError(v8::Handle<v8::Message> message)
{
+ v8::Context::Scope scope(engine->context());
+
QDeclarativeError error;
- QDeclarativeExpressionPrivate::exceptionToError(sv.engine(), error);
- QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate::get(sv.engine()), error);
+ QDeclarativeExpressionPrivate::exceptionToError(message, error);
+ QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate::get(engine->engine()), error);
}
void QDeclarativeXMLHttpRequest::destroyNetwork()
@@ -1434,72 +1511,69 @@ void QDeclarativeXMLHttpRequest::destroyNetwork()
}
// XMLHttpRequest methods
-static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_open(const v8::Arguments &args)
{
- QScriptValue dataObject = context->thisObject().data();
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(dataObject.toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(args.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- if (context->argumentCount() < 2 || context->argumentCount() > 5)
- THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
+ if (args.Length() < 2 || args.Length() > 5)
+ V8THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
+
+ QV8Engine *engine = r->engine;
// Argument 0 - Method
- QString method = context->argument(0).toString().toUpper();
+ QString method = engine->toString(args[0]).toUpper();
if (method != QLatin1String("GET") &&
method != QLatin1String("PUT") &&
method != QLatin1String("HEAD") &&
method != QLatin1String("POST") &&
method != QLatin1String("DELETE"))
- THROW_DOM(SYNTAX_ERR, "Unsupported HTTP method type");
-
+ V8THROW_DOM(SYNTAX_ERR, "Unsupported HTTP method type");
// Argument 1 - URL
- QUrl url = QUrl::fromEncoded(context->argument(1).toString().toUtf8());
+ QUrl url = QUrl::fromEncoded(engine->toString(args[1]).toUtf8());
- if (url.isRelative()) {
- url = QDeclarativeScriptEngine::get(engine)->resolvedUrl(context,url);
- }
+ if (url.isRelative())
+ url = engine->callingContext()->resolvedUrl(url);
// Argument 2 - async (optional)
- if (context->argumentCount() > 2 && !context->argument(2).toBoolean())
- THROW_DOM(NOT_SUPPORTED_ERR, "Synchronous XMLHttpRequest calls are not supported");
-
+ if (args.Length() > 2 && !args[2]->BooleanValue())
+ V8THROW_DOM(NOT_SUPPORTED_ERR, "Synchronous XMLHttpRequest calls are not supported");
// Argument 3/4 - user/pass (optional)
QString username, password;
- if (context->argumentCount() > 3)
- username = context->argument(3).toString();
- if (context->argumentCount() > 4)
- password = context->argument(4).toString();
-
+ if (args.Length() > 3)
+ username = engine->toString(args[3]);
+ if (args.Length() > 4)
+ password = engine->toString(args[4]);
// Clear the fragment (if any)
url.setFragment(QString());
+
// Set username/password
if (!username.isNull()) url.setUserName(username);
if (!password.isNull()) url.setPassword(password);
- return request->open(&dataObject, method, url);
+ return r->open(args.This(), method, url);
}
-static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_setRequestHeader(const v8::Arguments &args)
{
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
-
- if (context->argumentCount() != 2)
- THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(args.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
+ if (args.Length() != 2)
+ V8THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
- if (request->readyState() != QDeclarativeXMLHttpRequest::Opened ||
- request->sendFlag())
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ if (r->readyState() != QDeclarativeXMLHttpRequest::Opened || r->sendFlag())
+ V8THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ QV8Engine *engine = r->engine;
- QString name = context->argument(0).toString();
- QString value = context->argument(1).toString();
+ QString name = engine->toString(args[0]);
+ QString value = engine->toString(args[1]);
// ### Check that name and value are well formed
@@ -1524,237 +1598,243 @@ static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context,
nameUpper == QLatin1String("VIA") ||
nameUpper.startsWith(QLatin1String("PROXY-")) ||
nameUpper.startsWith(QLatin1String("SEC-")))
- return engine->undefinedValue();
+ return v8::Undefined();
- request->addHeader(nameUpper, value);
+ r->addHeader(nameUpper, value);
- return engine->undefinedValue();
+ return v8::Undefined();
}
-static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngine *)
+static v8::Handle<v8::Value> qmlxmlhttprequest_send(const v8::Arguments &args)
{
- QScriptValue dataObject = context->thisObject().data();
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(dataObject.toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(args.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- if (request->readyState() != QDeclarativeXMLHttpRequest::Opened)
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ QV8Engine *engine = r->engine;
- if (request->sendFlag())
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ if (r->readyState() != QDeclarativeXMLHttpRequest::Opened ||
+ r->sendFlag())
+ V8THROW_DOM(INVALID_STATE_ERR, "Invalid state");
QByteArray data;
- if (context->argumentCount() > 0)
- data = context->argument(0).toString().toUtf8();
+ if (args.Length() > 0)
+ data = engine->toString(args[0]).toUtf8();
- return request->send(&dataObject, data);
+ return r->send(args.This(), data);
}
-static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngine *)
+static v8::Handle<v8::Value> qmlxmlhttprequest_abort(const v8::Arguments &args)
{
- QScriptValue dataObject = context->thisObject().data();
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(dataObject.toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(args.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- return request->abort(&dataObject);
+ return r->abort(args.This());
}
-static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_getResponseHeader(const v8::Arguments &args)
{
- Q_UNUSED(engine)
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(args.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- if (context->argumentCount() != 1)
- THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
+ QV8Engine *engine = r->engine;
- if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
- request->readyState() != QDeclarativeXMLHttpRequest::Done &&
- request->readyState() != QDeclarativeXMLHttpRequest::HeadersReceived)
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ if (args.Length() != 1)
+ V8THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
- QString headerName = context->argument(0).toString();
+ if (r->readyState() != QDeclarativeXMLHttpRequest::Loading &&
+ r->readyState() != QDeclarativeXMLHttpRequest::Done &&
+ r->readyState() != QDeclarativeXMLHttpRequest::HeadersReceived)
+ V8THROW_DOM(INVALID_STATE_ERR, "Invalid state");
- return QScriptValue(request->header(headerName));
+ return engine->toString(r->header(engine->toString(args[0])));
}
-static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_getAllResponseHeaders(const v8::Arguments &args)
{
- Q_UNUSED(engine)
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(args.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
+
+ QV8Engine *engine = r->engine;
- if (context->argumentCount() != 0)
- THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
+ if (args.Length() != 0)
+ V8THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
- if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
- request->readyState() != QDeclarativeXMLHttpRequest::Done &&
- request->readyState() != QDeclarativeXMLHttpRequest::HeadersReceived)
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ if (r->readyState() != QDeclarativeXMLHttpRequest::Loading &&
+ r->readyState() != QDeclarativeXMLHttpRequest::Done &&
+ r->readyState() != QDeclarativeXMLHttpRequest::HeadersReceived)
+ V8THROW_DOM(INVALID_STATE_ERR, "Invalid state");
- return QScriptValue(request->headers());
+ return engine->toString(r->headers());
}
// XMLHttpRequest properties
-static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_readyState(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info)
{
- Q_UNUSED(engine)
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(info.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- return QScriptValue(request->readyState());
+ return v8::Integer::NewFromUnsigned(r->readyState());
}
-static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_status(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info)
{
- Q_UNUSED(engine)
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(info.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- if (request->readyState() == QDeclarativeXMLHttpRequest::Unsent ||
- request->readyState() == QDeclarativeXMLHttpRequest::Opened)
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ if (r->readyState() == QDeclarativeXMLHttpRequest::Unsent ||
+ r->readyState() == QDeclarativeXMLHttpRequest::Opened)
+ V8THROW_DOM(INVALID_STATE_ERR, "Invalid state");
- if (request->errorFlag())
- return QScriptValue(0);
+ if (r->errorFlag())
+ return v8::Integer::New(0);
else
- return QScriptValue(request->replyStatus());
+ return v8::Integer::New(r->replyStatus());
}
-static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_statusText(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info)
{
- Q_UNUSED(engine)
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(info.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- if (request->readyState() == QDeclarativeXMLHttpRequest::Unsent ||
- request->readyState() == QDeclarativeXMLHttpRequest::Opened)
- THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+ QV8Engine *engine = r->engine;
- if (request->errorFlag())
- return QScriptValue(0);
+ if (r->readyState() == QDeclarativeXMLHttpRequest::Unsent ||
+ r->readyState() == QDeclarativeXMLHttpRequest::Opened)
+ V8THROW_DOM(INVALID_STATE_ERR, "Invalid state");
+
+ if (r->errorFlag())
+ return engine->toString(QString());
else
- return QScriptValue(request->replyStatusText());
+ return engine->toString(r->replyStatusText());
}
-static QScriptValue qmlxmlhttprequest_responseText(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_responseText(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info)
{
- Q_UNUSED(engine)
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(info.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
+
+ QV8Engine *engine = r->engine;
- if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
- request->readyState() != QDeclarativeXMLHttpRequest::Done)
- return QScriptValue(QString());
+ if (r->readyState() != QDeclarativeXMLHttpRequest::Loading &&
+ r->readyState() != QDeclarativeXMLHttpRequest::Done)
+ return engine->toString(QString());
else
- return QScriptValue(request->responseBody());
+ return engine->toString(r->responseBody());
}
-static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_responseXML(v8::Local<v8::String> property,
+ const v8::AccessorInfo& info)
{
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(context->thisObject().data().toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ QDeclarativeXMLHttpRequest *r = v8_resource_cast<QDeclarativeXMLHttpRequest>(info.This());
+ if (!r)
+ V8THROW_REFERENCE("Not an XMLHttpRequest object");
- if (!request->receivedXml() ||
- (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
- request->readyState() != QDeclarativeXMLHttpRequest::Done))
- return engine->nullValue();
- else
- return Document::load(engine, request->rawResponseBody());
+ if (!r->receivedXml() ||
+ (r->readyState() != QDeclarativeXMLHttpRequest::Loading &&
+ r->readyState() != QDeclarativeXMLHttpRequest::Done)) {
+ return v8::Null();
+ } else {
+ return Document::load(r->engine, r->rawResponseBody());
+ }
}
-static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine)
+static v8::Handle<v8::Value> qmlxmlhttprequest_new(const v8::Arguments &args)
{
- Q_UNUSED(engine);
- QScriptValue dataObject = context->thisObject().data();
- QDeclarativeXMLHttpRequest *request = qobject_cast<QDeclarativeXMLHttpRequest *>(dataObject.toQObject());
- if (!request)
- THROW_REFERENCE("Not an XMLHttpRequest object");
+ if (args.IsConstructCall()) {
+ QV8Engine *engine = V8ENGINE();
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
+
+ QDeclarativeXMLHttpRequest *r = new QDeclarativeXMLHttpRequest(engine, engine->networkAccessManager());
+ args.This()->SetExternalResource(r);
- if (context->argumentCount()) {
- QScriptValue v = context->argument(0);
- dataObject.setProperty(QLatin1String("callback"), v);
- return v;
+ return args.This();
} else {
- return dataObject.property(QLatin1String("callback"));
+ return v8::Undefined();
}
}
-// Constructor
-static QScriptValue qmlxmlhttprequest_new(QScriptContext *context, QScriptEngine *engine)
+#define NEWFUNCTION(function) v8::FunctionTemplate::New(function)->GetFunction()
+
+void qt_rem_qmlxmlhttprequest(QV8Engine *engine, void *d)
{
- if (context->isCalledAsConstructor()) {
- context->thisObject().setData(engine->newQObject(new QDeclarativeXMLHttpRequest(QDeclarativeScriptEngine::get(engine)->networkAccessManager()), QScriptEngine::ScriptOwnership));
- }
- return engine->undefinedValue();
+ QDeclarativeXMLHttpRequestData *data = (QDeclarativeXMLHttpRequestData *)d;
+ delete data;
}
-void qt_add_qmlxmlhttprequest(QScriptEngine *engine)
+void *qt_add_qmlxmlhttprequest(QV8Engine *engine)
{
- QScriptValue prototype = engine->newObject();
+ v8::PropertyAttribute attributes = (v8::PropertyAttribute)(v8::ReadOnly | v8::DontEnum | v8::DontDelete);
+
+ // XMLHttpRequest
+ v8::Local<v8::FunctionTemplate> xmlhttprequest = v8::FunctionTemplate::New(qmlxmlhttprequest_new,
+ v8::External::Wrap(engine));
+ xmlhttprequest->InstanceTemplate()->SetHasExternalResource(true);
// Methods
- prototype.setProperty(QLatin1String("open"), engine->newFunction(qmlxmlhttprequest_open, 2));
- prototype.setProperty(QLatin1String("setRequestHeader"), engine->newFunction(qmlxmlhttprequest_setRequestHeader, 2));
- prototype.setProperty(QLatin1String("send"), engine->newFunction(qmlxmlhttprequest_send));
- prototype.setProperty(QLatin1String("abort"), engine->newFunction(qmlxmlhttprequest_abort));
- prototype.setProperty(QLatin1String("getResponseHeader"), engine->newFunction(qmlxmlhttprequest_getResponseHeader, 1));
- prototype.setProperty(QLatin1String("getAllResponseHeaders"), engine->newFunction(qmlxmlhttprequest_getAllResponseHeaders));
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("open"), NEWFUNCTION(qmlxmlhttprequest_open), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("setRequestHeader"), NEWFUNCTION(qmlxmlhttprequest_setRequestHeader), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("send"), NEWFUNCTION(qmlxmlhttprequest_send), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("abort"), NEWFUNCTION(qmlxmlhttprequest_abort), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("getResponseHeader"), NEWFUNCTION(qmlxmlhttprequest_getResponseHeader), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("getAllResponseHeaders"), NEWFUNCTION(qmlxmlhttprequest_getAllResponseHeaders), attributes);
// Read-only properties
- prototype.setProperty(QLatin1String("readyState"), engine->newFunction(qmlxmlhttprequest_readyState), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- prototype.setProperty(QLatin1String("status"), engine->newFunction(qmlxmlhttprequest_status), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- prototype.setProperty(QLatin1String("statusText"), engine->newFunction(qmlxmlhttprequest_statusText), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- prototype.setProperty(QLatin1String("responseText"), engine->newFunction(qmlxmlhttprequest_responseText), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- prototype.setProperty(QLatin1String("responseXML"), engine->newFunction(qmlxmlhttprequest_responseXML), QScriptValue::ReadOnly | QScriptValue::PropertyGetter);
- prototype.setProperty(QLatin1String("onreadystatechange"), engine->newFunction(qmlxmlhttprequest_onreadystatechange), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ xmlhttprequest->PrototypeTemplate()->SetAccessor(v8::String::New("readyState"), qmlxmlhttprequest_readyState, 0, v8::Handle<v8::Value>(), v8::DEFAULT, attributes);
+ xmlhttprequest->PrototypeTemplate()->SetAccessor(v8::String::New("status"),qmlxmlhttprequest_status, 0, v8::Handle<v8::Value>(), v8::DEFAULT, attributes);
+ xmlhttprequest->PrototypeTemplate()->SetAccessor(v8::String::New("statusText"),qmlxmlhttprequest_statusText, 0, v8::Handle<v8::Value>(), v8::DEFAULT, attributes);
+ xmlhttprequest->PrototypeTemplate()->SetAccessor(v8::String::New("responseText"),qmlxmlhttprequest_responseText, 0, v8::Handle<v8::Value>(), v8::DEFAULT, attributes);
+ xmlhttprequest->PrototypeTemplate()->SetAccessor(v8::String::New("responseXML"),qmlxmlhttprequest_responseXML, 0, v8::Handle<v8::Value>(), v8::DEFAULT, attributes);
// State values
- prototype.setProperty(QLatin1String("UNSENT"), 0, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- prototype.setProperty(QLatin1String("OPENED"), 1, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- prototype.setProperty(QLatin1String("HEADERS_RECEIVED"), 2, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- prototype.setProperty(QLatin1String("LOADING"), 3, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- prototype.setProperty(QLatin1String("DONE"), 4, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("UNSENT"), v8::Integer::New(0), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("OPENED"), v8::Integer::New(1), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("HEADERS_RECEIVED"), v8::Integer::New(2), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("LOADING"), v8::Integer::New(3), attributes);
+ xmlhttprequest->PrototypeTemplate()->Set(v8::String::New("DONE"), v8::Integer::New(4), attributes);
// Constructor
- QScriptValue constructor = engine->newFunction(qmlxmlhttprequest_new, prototype);
- constructor.setProperty(QLatin1String("UNSENT"), 0, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- constructor.setProperty(QLatin1String("OPENED"), 1, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- constructor.setProperty(QLatin1String("HEADERS_RECEIVED"), 2, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- constructor.setProperty(QLatin1String("LOADING"), 3, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- constructor.setProperty(QLatin1String("DONE"), 4, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- engine->globalObject().setProperty(QLatin1String("XMLHttpRequest"), constructor);
+ xmlhttprequest->Set(v8::String::New("UNSENT"), v8::Integer::New(0), attributes);
+ xmlhttprequest->Set(v8::String::New("OPENED"), v8::Integer::New(1), attributes);
+ xmlhttprequest->Set(v8::String::New("HEADERS_RECEIVED"), v8::Integer::New(2), attributes);
+ xmlhttprequest->Set(v8::String::New("LOADING"), v8::Integer::New(3), attributes);
+ xmlhttprequest->Set(v8::String::New("DONE"), v8::Integer::New(4), attributes);
+ engine->global()->Set(v8::String::New("XMLHttpRequest"), xmlhttprequest->GetFunction());
// DOM Exception
- QScriptValue domExceptionPrototype = engine->newObject();
- domExceptionPrototype.setProperty(QLatin1String("INDEX_SIZE_ERR"), INDEX_SIZE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("DOMSTRING_SIZE_ERR"), DOMSTRING_SIZE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("HIERARCHY_REQUEST_ERR"), HIERARCHY_REQUEST_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("WRONG_DOCUMENT_ERR"), WRONG_DOCUMENT_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("INVALID_CHARACTER_ERR"), INVALID_CHARACTER_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("NO_DATA_ALLOWED_ERR"), NO_DATA_ALLOWED_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("NO_MODIFICATION_ALLOWED_ERR"), NO_MODIFICATION_ALLOWED_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("NOT_FOUND_ERR"), NOT_FOUND_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("NOT_SUPPORTED_ERR"), NOT_SUPPORTED_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("INUSE_ATTRIBUTE_ERR"), INUSE_ATTRIBUTE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("INVALID_STATE_ERR"), INVALID_STATE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("SYNTAX_ERR"), SYNTAX_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("INVALID_MODIFICATION_ERR"), INVALID_MODIFICATION_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("NAMESPACE_ERR"), NAMESPACE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("INVALID_ACCESS_ERR"), INVALID_ACCESS_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("VALIDATION_ERR"), VALIDATION_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
- domExceptionPrototype.setProperty(QLatin1String("TYPE_MISMATCH_ERR"), TYPE_MISMATCH_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
-
- engine->globalObject().setProperty(QLatin1String("DOMException"), domExceptionPrototype);
+ v8::Local<v8::Object> domexception = v8::Object::New();
+ domexception->Set(v8::String::New("INDEX_SIZE_ERR"), v8::Integer::New(INDEX_SIZE_ERR), attributes);
+ domexception->Set(v8::String::New("DOMSTRING_SIZE_ERR"), v8::Integer::New(DOMSTRING_SIZE_ERR), attributes);
+ domexception->Set(v8::String::New("HIERARCHY_REQUEST_ERR"), v8::Integer::New(HIERARCHY_REQUEST_ERR), attributes);
+ domexception->Set(v8::String::New("WRONG_DOCUMENT_ERR"), v8::Integer::New(WRONG_DOCUMENT_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_CHARACTER_ERR"), v8::Integer::New(INVALID_CHARACTER_ERR), attributes);
+ domexception->Set(v8::String::New("NO_DATA_ALLOWED_ERR"), v8::Integer::New(NO_DATA_ALLOWED_ERR), attributes);
+ domexception->Set(v8::String::New("NO_MODIFICATION_ALLOWED_ERR"), v8::Integer::New(NO_MODIFICATION_ALLOWED_ERR), attributes);
+ domexception->Set(v8::String::New("NOT_FOUND_ERR"), v8::Integer::New(NOT_FOUND_ERR), attributes);
+ domexception->Set(v8::String::New("NOT_SUPPORTED_ERR"), v8::Integer::New(NOT_SUPPORTED_ERR), attributes);
+ domexception->Set(v8::String::New("INUSE_ATTRIBUTE_ERR"), v8::Integer::New(INUSE_ATTRIBUTE_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_STATE_ERR"), v8::Integer::New(INVALID_STATE_ERR), attributes);
+ domexception->Set(v8::String::New("SYNTAX_ERR"), v8::Integer::New(SYNTAX_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_MODIFICATION_ERR"), v8::Integer::New(INVALID_MODIFICATION_ERR), attributes);
+ domexception->Set(v8::String::New("NAMESPACE_ERR"), v8::Integer::New(NAMESPACE_ERR), attributes);
+ domexception->Set(v8::String::New("INVALID_ACCESS_ERR"), v8::Integer::New(INVALID_ACCESS_ERR), attributes);
+ domexception->Set(v8::String::New("VALIDATION_ERR"), v8::Integer::New(VALIDATION_ERR), attributes);
+ domexception->Set(v8::String::New("TYPE_MISMATCH_ERR"), v8::Integer::New(TYPE_MISMATCH_ERR), attributes);
+ engine->global()->Set(v8::String::New("DOMException"), domexception);
+
+ QDeclarativeXMLHttpRequestData *data = new QDeclarativeXMLHttpRequestData;
+ return data;
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest_p.h b/src/declarative/qml/qdeclarativexmlhttprequest_p.h
index 5c09d648dd..a2082db59f 100644
--- a/src/declarative/qml/qdeclarativexmlhttprequest_p.h
+++ b/src/declarative/qml/qdeclarativexmlhttprequest_p.h
@@ -60,8 +60,10 @@
QT_BEGIN_NAMESPACE
-class QScriptEngine;
-void qt_add_qmlxmlhttprequest(QScriptEngine *engine);
+class QV8Engine;
+
+void *qt_add_qmlxmlhttprequest(QV8Engine *engine);
+void qt_rem_qmlxmlhttprequest(QV8Engine *engine, void *);
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qintrusivelist_p.h b/src/declarative/qml/qintrusivelist_p.h
index 218c9ee9db..c1ea80a767 100644
--- a/src/declarative/qml/qintrusivelist_p.h
+++ b/src/declarative/qml/qintrusivelist_p.h
@@ -65,6 +65,7 @@ public:
inline QIntrusiveList();
inline ~QIntrusiveList();
+ inline bool isEmpty() const;
inline void insert(N *n);
inline void remove(N *n);
@@ -176,6 +177,12 @@ QIntrusiveList<N, member>::~QIntrusiveList()
}
template<class N, QIntrusiveListNode N::*member>
+bool QIntrusiveList<N, member>::isEmpty() const
+{
+ return __first == 0;
+}
+
+template<class N, QIntrusiveListNode N::*member>
void QIntrusiveList<N, member>::insert(N *n)
{
QIntrusiveListNode *nnode = &(n->*member);
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index a69d52c8dc..7325cd8340 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -9,7 +9,6 @@ SOURCES += \
$$PWD/qdeclarativeproperty.cpp \
$$PWD/qdeclarativecomponent.cpp \
$$PWD/qdeclarativecontext.cpp \
- $$PWD/qdeclarativeinclude.cpp \
$$PWD/qdeclarativecustomparser.cpp \
$$PWD/qdeclarativepropertyvaluesource.cpp \
$$PWD/qdeclarativepropertyvalueinterceptor.cpp \
@@ -41,13 +40,6 @@ SOURCES += \
$$PWD/qdeclarativetypenotavailable.cpp \
$$PWD/qdeclarativetypenamecache.cpp \
$$PWD/qdeclarativescriptstring.cpp \
- $$PWD/qdeclarativeobjectscriptclass.cpp \
- $$PWD/qdeclarativescarceresourcescriptclass.cpp \
- $$PWD/qdeclarativecontextscriptclass.cpp \
- $$PWD/qdeclarativeglobalscriptclass.cpp \
- $$PWD/qdeclarativevaluetypescriptclass.cpp \
- $$PWD/qdeclarativetypenamescriptclass.cpp \
- $$PWD/qdeclarativelistscriptclass.cpp \
$$PWD/qdeclarativeworkerscript.cpp \
$$PWD/qdeclarativeimageprovider.cpp \
$$PWD/qdeclarativenetworkaccessmanagerfactory.cpp \
@@ -89,7 +81,6 @@ HEADERS += \
$$PWD/qdeclarativeinfo.h \
$$PWD/qdeclarativeproperty_p.h \
$$PWD/qdeclarativecontext_p.h \
- $$PWD/qdeclarativeinclude_p.h \
$$PWD/qdeclarativetypeloader_p.h \
$$PWD/qdeclarativelist.h \
$$PWD/qdeclarativelist_p.h \
@@ -113,13 +104,6 @@ HEADERS += \
$$PWD/qdeclarativetypenotavailable_p.h \
$$PWD/qdeclarativetypenamecache_p.h \
$$PWD/qdeclarativescriptstring.h \
- $$PWD/qdeclarativeobjectscriptclass_p.h \
- $$PWD/qdeclarativescarceresourcescriptclass_p.h \
- $$PWD/qdeclarativecontextscriptclass_p.h \
- $$PWD/qdeclarativeglobalscriptclass_p.h \
- $$PWD/qdeclarativevaluetypescriptclass_p.h \
- $$PWD/qdeclarativetypenamescriptclass_p.h \
- $$PWD/qdeclarativelistscriptclass_p.h \
$$PWD/qdeclarativeworkerscript_p.h \
$$PWD/qdeclarativeguard_p.h \
$$PWD/qdeclarativeimageprovider.h \
@@ -135,3 +119,4 @@ QT += sql
include(parser/parser.pri)
include(rewriter/rewriter.pri)
include(v4/v4.pri)
+include(v8/v8.pri)
diff --git a/src/declarative/qml/v4/qdeclarativev4bindings.cpp b/src/declarative/qml/v4/qdeclarativev4bindings.cpp
index 3f99b269f1..c81f59b0bc 100644
--- a/src/declarative/qml/v4/qdeclarativev4bindings.cpp
+++ b/src/declarative/qml/v4/qdeclarativev4bindings.cpp
@@ -315,6 +315,7 @@ void QDeclarativeV4BindingsPrivate::Binding::destroy()
enabled = false;
removeFromObject();
clear();
+ removeError();
parent->q_func()->release();
}
@@ -1492,7 +1493,8 @@ void QDeclarativeV4BindingsPrivate::run(int instrIndex, quint32 &executedBlocks,
QString str = QString::fromRawData(strdata, len);
- identifiers[instr->initstring.offset] = engine->objectClass->createPersistentIdentifier(str);
+ // XXX not applicable in v8
+ // identifiers[instr->initstring.offset] = engine->objectClass->createPersistentIdentifier(str);
}
QML_V4_END_INSTR(InitString, initstring)
diff --git a/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp b/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
index 8ab0844f5d..795406f006 100644
--- a/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
+++ b/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
@@ -41,7 +41,6 @@
#include "qdeclarativev4irbuilder_p.h"
-#include <private/qdeclarativeglobalscriptclass_p.h> // For illegalNames
#include <private/qdeclarativeanchors_p_p.h> // For AnchorLine
#include <private/qsganchors_p_p.h> // For AnchorLine
#include <private/qdeclarativetypenamecache_p.h>
@@ -437,7 +436,7 @@ bool QDeclarativeV4IRBuilder::visit(AST::IdentifierExpression *ast)
if (name.at(0) == QLatin1Char('u') && name.length() == 9 && name == QLatin1String("undefined")) {
_expr.code = _block->CONST(IR::UndefinedType, 0); // ### undefined value
- } else if(m_engine->globalClass->illegalNames().contains(name) ) {
+ } else if(m_engine->v8engine.illegalNames().contains(name) ) {
if (qmlVerboseCompiler()) qWarning() << "*** illegal symbol:" << name;
return false;
} else if (const QDeclarativeParser::Object *obj = m_expression->ids.value(name)) {
@@ -473,7 +472,7 @@ bool QDeclarativeV4IRBuilder::visit(AST::IdentifierExpression *ast)
return false;
}
- if (data && !(data->flags & QDeclarativePropertyCache::Data::IsFunction)) {
+ if (data && !data->isFunction()) {
IR::Type irType = irTypeFromVariantType(data->propType, m_engine, metaObject);
_expr.code = _block->SYMBOL(irType, name, metaObject, data->coreIndex, IR::Name::ScopeStorage, line, column);
found = true;
@@ -494,7 +493,7 @@ bool QDeclarativeV4IRBuilder::visit(AST::IdentifierExpression *ast)
return false;
}
- if (data && !(data->flags & QDeclarativePropertyCache::Data::IsFunction)) {
+ if (data && !data->isFunction()) {
IR::Type irType = irTypeFromVariantType(data->propType, m_engine, metaObject);
_expr.code = _block->SYMBOL(irType, name, metaObject, data->coreIndex, IR::Name::RootStorage, line, column);
found = true;
@@ -612,10 +611,10 @@ bool QDeclarativeV4IRBuilder::visit(AST::FieldMemberExpression *ast)
QDeclarativePropertyCache *cache = m_engine->cache(attachedMeta);
QDeclarativePropertyCache::Data *data = cache->property(name);
- if (!data || data->flags & QDeclarativePropertyCache::Data::IsFunction)
+ if (!data || data->isFunction())
return false; // Don't support methods (or non-existing properties ;)
- if(!(data->flags & QDeclarativePropertyCache::Data::IsFinal)) {
+ if(!data->isFinal()) {
if (qmlVerboseCompiler())
qWarning() << "*** non-final attached property:"
<< (baseName->id + QLatin1String(".") + ast->name->asString());
@@ -634,7 +633,7 @@ bool QDeclarativeV4IRBuilder::visit(AST::FieldMemberExpression *ast)
QDeclarativePropertyCache::Data *data = cache->property(name);
- if (!data || data->flags & QDeclarativePropertyCache::Data::IsFunction)
+ if (!data || data->isFunction())
return false; // Don't support methods (or non-existing properties ;)
if (data->revision != 0) {
@@ -658,10 +657,10 @@ bool QDeclarativeV4IRBuilder::visit(AST::FieldMemberExpression *ast)
QDeclarativePropertyCache::Data *data = cache->property(name);
- if (!data || data->flags & QDeclarativePropertyCache::Data::IsFunction)
+ if (!data || data->isFunction())
return false; // Don't support methods (or non-existing properties ;)
- if(!(data->flags & QDeclarativePropertyCache::Data::IsFinal)) {
+ if(!data->isFinal()) {
if (qmlVerboseCompiler())
qWarning() << "*** non-final property access:"
<< (baseName->id + QLatin1String(".") + ast->name->asString());
diff --git a/src/declarative/qml/v8/notes.txt b/src/declarative/qml/v8/notes.txt
new file mode 100644
index 0000000000..ff5a289b7c
--- /dev/null
+++ b/src/declarative/qml/v8/notes.txt
@@ -0,0 +1,4 @@
+Removed backwards compatible imports - QTBUG-17518
+
+autotest print() taking objects that don't ToString()
+autotest QDeclarativeV8Function
diff --git a/src/declarative/qml/v8/qhashedstring.cpp b/src/declarative/qml/v8/qhashedstring.cpp
new file mode 100644
index 0000000000..4a23e3b7dd
--- /dev/null
+++ b/src/declarative/qml/v8/qhashedstring.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qhashedstring_p.h"
+
+inline unsigned stringHash(const QChar* data, unsigned length)
+{
+ return v8::String::ComputeHash((uint16_t *)data, length);
+}
+
+void QHashedString::computeHash() const
+{
+ m_hash = stringHash(constData(), length());
+}
+
+void QHashedStringRef::computeHash() const
+{
+ m_hash = stringHash(m_data, m_length);
+}
+
+/*
+ A QHash has initially around pow(2, MinNumBits) buckets. For
+ example, if MinNumBits is 4, it has 17 buckets.
+*/
+const int MinNumBits = 4;
+
+/*
+ The prime_deltas array is a table of selected prime values, even
+ though it doesn't look like one. The primes we are using are 1,
+ 2, 5, 11, 17, 37, 67, 131, 257, ..., i.e. primes in the immediate
+ surrounding of a power of two.
+
+ The primeForNumBits() function returns the prime associated to a
+ power of two. For example, primeForNumBits(8) returns 257.
+*/
+
+static const uchar prime_deltas[] = {
+ 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 9, 25, 3,
+ 1, 21, 3, 21, 7, 15, 9, 5, 3, 29, 15, 0, 0, 0, 0, 0
+};
+
+static inline int primeForNumBits(int numBits)
+{
+ return (1 << numBits) + prime_deltas[numBits];
+}
+
+void QStringHashData::rehash()
+{
+ numBits = qMax(MinNumBits, numBits + 1);
+ numBuckets = primeForNumBits(numBits);
+
+ delete [] buckets;
+ buckets = new QStringHashNode *[numBuckets];
+ ::memset(buckets, 0, sizeof(QStringHashNode *) * numBuckets);
+
+ QStringHashNode *nodeList = nodes;
+ while (nodeList) {
+ int bucket = nodeList->key.hash() % numBuckets;
+ nodeList->next = buckets[bucket];
+ buckets[bucket] = nodeList;
+
+ nodeList = nodeList->nlist;
+ }
+}
+
diff --git a/src/declarative/qml/v8/qhashedstring_p.h b/src/declarative/qml/v8/qhashedstring_p.h
new file mode 100644
index 0000000000..143bd0b995
--- /dev/null
+++ b/src/declarative/qml/v8/qhashedstring_p.h
@@ -0,0 +1,664 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QHASHEDSTRING_P_H
+#define QHASHEDSTRING_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qstring.h>
+#include <private/qv8_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QHashedStringRef;
+class QHashedString : public QString
+{
+public:
+ inline QHashedString();
+ inline QHashedString(const QString &string);
+ inline QHashedString(const QString &string, quint32);
+ inline QHashedString(const QHashedString &string);
+
+ inline QHashedString &operator=(const QHashedString &string);
+ inline bool operator==(const QHashedString &string) const;
+ inline bool operator==(const QHashedStringRef &string) const;
+
+ inline quint32 hash() const;
+ inline quint32 existingHash() const;
+
+ static inline bool isUpper(const QChar &);
+private:
+ friend class QHashedStringRef;
+
+ void computeHash() const;
+ mutable quint32 m_hash;
+};
+
+class QHashedV8String
+{
+public:
+ inline QHashedV8String();
+ explicit inline QHashedV8String(v8::Handle<v8::String>);
+ inline QHashedV8String(const QHashedV8String &string);
+ inline QHashedV8String &operator=(const QHashedV8String &other);
+
+ inline bool operator==(const QHashedV8String &string);
+
+ inline quint32 hash() const;
+ inline int length() const;
+ inline quint32 symbolId() const;
+
+ inline v8::Handle<v8::String> string() const;
+
+private:
+ v8::String::CompleteHashData m_hash;
+ v8::Handle<v8::String> m_string;
+};
+
+class QHashedStringRef
+{
+public:
+ inline QHashedStringRef();
+ inline QHashedStringRef(const QString &);
+ inline QHashedStringRef(const QChar *, int);
+ inline QHashedStringRef(const QChar *, int, quint32);
+ inline QHashedStringRef(const QHashedString &);
+ inline QHashedStringRef(const QHashedStringRef &);
+
+ inline bool operator==(const QHashedString &string) const;
+ inline bool operator==(const QHashedStringRef &string) const;
+
+ inline quint32 hash() const;
+
+ inline const QChar *constData() const;
+ inline quint32 length() const;
+ inline bool startsWithUpper() const;
+
+private:
+ friend class QHashedString;
+
+ void computeHash() const;
+
+ const QChar *m_data;
+ quint32 m_length;
+ mutable quint32 m_hash;
+};
+
+class QStringHashData;
+class QStringHashNode
+{
+public:
+ QStringHashNode(const QHashedString &key)
+ : nlist(0), next(0), key(key), symbolId(0) {
+ }
+
+ QStringHashNode *nlist;
+ QStringHashNode *next;
+ QHashedString key;
+ quint32 symbolId;
+
+ inline bool equals(v8::Handle<v8::String> string) {
+ return string->Equals((uint16_t*)key.constData(), key.length());
+ }
+};
+
+struct QStringHashData
+{
+public:
+ QStringHashData()
+ : nodes(0), buckets(0), numBuckets(0), size(0), numBits(0) {}
+
+ QStringHashNode *nodes;
+ QStringHashNode **buckets;
+ int numBuckets;
+ int size;
+ short numBits;
+
+ void rehash();
+};
+
+template<class T>
+class QStringHash
+{
+private:
+ struct Node : public QStringHashNode {
+ Node(const QHashedString &key, const T &value) : QStringHashNode(key), value(value) {}
+ T value;
+ };
+
+ QStringHashData data;
+
+ inline Node *findNode(const QHashedStringRef &) const;
+ inline Node *findNode(const QHashedV8String &) const;
+ inline Node *findSymbolNode(const QHashedV8String &) const;
+ Node *createNode(const QHashedString &, const T &);
+
+public:
+ inline QStringHash();
+ inline QStringHash(const QStringHash &);
+ inline ~QStringHash();
+
+ QStringHash &operator=(const QStringHash<T> &);
+
+ inline bool isEmpty() const;
+ inline void clear();
+ inline int count() const;
+
+ inline void insert(const QString &, const T &);
+ inline void insert(const QHashedString &, const T &);
+ inline void insert(const QHashedStringRef &, const T &);
+
+ inline T *value(const QString &) const;
+ inline T *value(const QHashedString &) const;
+ inline T *value(const QHashedStringRef &) const;
+ inline T *value(const QHashedV8String &) const;
+
+ inline bool contains(const QString &) const;
+ inline bool contains(const QHashedString &) const;
+ inline bool contains(const QHashedStringRef &) const;
+
+ T &operator[](const QString &);
+ T &operator[](const QHashedString &);
+ T &operator[](const QHashedStringRef &);
+
+ class ConstIterator {
+ public:
+ ConstIterator() : n(0) {}
+ ConstIterator(Node *n) : n(n) {}
+
+ ConstIterator &operator++() { n = (Node *)n->nlist; return *this; }
+ bool operator==(const ConstIterator &o) const { return n == o.n; }
+ bool operator!=(const ConstIterator &o) const { return n != o.n; }
+
+ const QHashedString &key() const { return n->key; }
+ const T &value() const { return n->value; }
+ const T &operator*() const { return n->value; }
+ private:
+ Node *n;
+ };
+
+ ConstIterator begin() const { return ConstIterator((Node *)data.nodes); }
+ ConstIterator end() const { return ConstIterator(); }
+};
+
+template<class T>
+QStringHash<T>::QStringHash()
+{
+}
+
+template<class T>
+QStringHash<T>::QStringHash(const QStringHash<T> &other)
+: data(other.data)
+{
+ data.nodes = 0;
+ data.buckets = 0;
+
+ QStringHashNode *n = other.data.nodes;
+ while (n) {
+ Node *o = (Node *)n;
+ Node *mynode = new Node(o->key, o->value);
+ mynode->nlist = data.nodes;
+ data.nodes = mynode;
+ n = o->nlist;
+ }
+
+ data.rehash();
+}
+
+template<class T>
+QStringHash<T> &QStringHash<T>::operator=(const QStringHash<T> &other)
+{
+ if (&other == this)
+ return *this;
+
+ clear();
+ data = other.data;
+ data.nodes = 0;
+ data.buckets = 0;
+
+ QStringHashNode *n = other.data.nodes;
+ while (n) {
+ Node *o = (Node *)n;
+ Node *mynode = new Node(o->key, o->value);
+ mynode->nlist = data.nodes;
+ data.nodes = mynode;
+ n = o->nlist;
+ }
+
+ data.rehash();
+
+ return *this;
+}
+
+template<class T>
+QStringHash<T>::~QStringHash()
+{
+ clear();
+}
+
+template<class T>
+void QStringHash<T>::clear()
+{
+ QStringHashNode *n = data.nodes;
+ while (n) {
+ Node *o = (Node *)n;
+ n = n->nlist;
+ delete o;
+ }
+
+ delete [] data.buckets;
+
+ data = QStringHashData();
+}
+
+template<class T>
+bool QStringHash<T>::isEmpty() const
+{
+ return data.nodes == 0;
+}
+
+template<class T>
+int QStringHash<T>::count() const
+{
+ return data.size;
+}
+
+template<class T>
+typename QStringHash<T>::Node *QStringHash<T>::createNode(const QHashedString &key, const T &value)
+{
+ if (data.size == data.numBuckets)
+ data.rehash();
+
+ Node *n = new Node(key, value);
+ n->nlist = data.nodes;
+ data.nodes = n;
+
+ int bucket = key.hash() % data.numBuckets;
+ n->next = data.buckets[bucket];
+ data.buckets[bucket] = n;
+
+ data.size++;
+
+ return n;
+}
+
+template<class T>
+void QStringHash<T>::insert(const QString &key, const T &value)
+{
+ QHashedStringRef ch(key);
+ Node *n = findNode(key);
+ if (n) n->value = value;
+ else createNode(QHashedString(key, ch.hash()), value);
+}
+
+template<class T>
+void QStringHash<T>::insert(const QHashedString &key, const T &value)
+{
+ Node *n = findNode(key);
+ if (n) n->value = value;
+ else createNode(key, value);
+}
+
+template<class T>
+void QStringHash<T>::insert(const QHashedStringRef &key, const T &value)
+{
+ Node *n = findNode(key);
+ if (n) n->value = value;
+ else createNode(key, value);
+}
+
+template<class T>
+typename QStringHash<T>::Node *QStringHash<T>::findNode(const QHashedStringRef &string) const
+{
+ QStringHashNode *node = 0;
+ if (data.numBuckets) {
+ node = data.buckets[string.hash() % data.numBuckets];
+ while (node && !(node->key == string))
+ node = node->next;
+ }
+
+ return (Node *)node;
+}
+
+template<class T>
+typename QStringHash<T>::Node *QStringHash<T>::findNode(const QHashedV8String &string) const
+{
+ QStringHashNode *node = 0;
+ if (data.numBuckets) {
+ quint32 hash = string.hash();
+ node = data.buckets[hash % data.numBuckets];
+ int length = string.length();
+ while (node && (length != node->key.length() || hash != node->key.hash() || !node->equals(string.string())))
+ node = node->next;
+ }
+
+ return (Node *)node;
+}
+
+template<class T>
+typename QStringHash<T>::Node *QStringHash<T>::findSymbolNode(const QHashedV8String &string) const
+{
+ Q_ASSERT(string.symbolId() != 0);
+
+ QStringHashNode *node = 0;
+ if (data.numBuckets) {
+ quint32 hash = string.hash();
+ quint32 symbolId = string.symbolId();
+ node = data.buckets[hash % data.numBuckets];
+ int length = string.length();
+ while (node && (length != node->key.length() || hash != node->key.hash() ||
+ !(node->symbolId == symbolId || node->equals(string.string()))))
+ node = node->next;
+ if (node)
+ node->symbolId = symbolId;
+ }
+
+ return (Node *)node;
+}
+
+template<class T>
+T *QStringHash<T>::value(const QString &key) const
+{
+ Node *n = findNode(key);
+ return n?&n->value:0;
+}
+
+template<class T>
+T *QStringHash<T>::value(const QHashedString &key) const
+{
+ Node *n = findNode(key);
+ return n?&n->value:0;
+}
+
+template<class T>
+T *QStringHash<T>::value(const QHashedStringRef &key) const
+{
+ Node *n = findNode(key);
+ return n?&n->value:0;
+}
+
+template<class T>
+T *QStringHash<T>::value(const QHashedV8String &string) const
+{
+ Node *n = string.symbolId()?findSymbolNode(string):findNode(string);
+ return n?&n->value:0;
+}
+
+template<class T>
+bool QStringHash<T>::contains(const QString &s) const
+{
+ return 0 != value(s);
+}
+
+template<class T>
+bool QStringHash<T>::contains(const QHashedString &s) const
+{
+ return 0 != value(s);
+}
+template<class T>
+bool QStringHash<T>::contains(const QHashedStringRef &s) const
+{
+ return 0 != value(s);
+}
+
+template<class T>
+T &QStringHash<T>::operator[](const QString &key)
+{
+ QHashedStringRef cs(key);
+ Node *n = findNode(cs);
+ if (n) return n->value;
+ else return createNode(QHashedString(key, cs.hash()), T())->value;
+}
+
+template<class T>
+T &QStringHash<T>::operator[](const QHashedString &key)
+{
+ Node *n = findNode(key);
+ if (n) return n->value;
+ else return createNode(key, T())->value;
+}
+
+template<class T>
+T &QStringHash<T>::operator[](const QHashedStringRef &key)
+{
+ Node *n = findNode(key);
+ if (n) return n->value;
+ else return createNode(key, T())->value;
+}
+
+inline uint qHash(const QHashedString &string)
+{
+ return uint(string.hash());
+}
+
+inline uint qHash(const QHashedStringRef &string)
+{
+ return uint(string.hash());
+}
+
+QHashedString::QHashedString()
+: QString(), m_hash(0)
+{
+}
+
+QHashedString::QHashedString(const QString &string)
+: QString(string), m_hash(0)
+{
+}
+
+QHashedString::QHashedString(const QString &string, quint32 hash)
+: QString(string), m_hash(hash)
+{
+}
+
+QHashedString::QHashedString(const QHashedString &string)
+: QString(string), m_hash(string.m_hash)
+{
+}
+
+QHashedString &QHashedString::operator=(const QHashedString &string)
+{
+ static_cast<QString &>(*this) = string;
+ m_hash = string.m_hash;
+ return *this;
+}
+
+bool QHashedString::operator==(const QHashedString &string) const
+{
+ return (string.m_hash == m_hash || !string.m_hash || !m_hash) &&
+ static_cast<const QString &>(*this) == static_cast<const QString &>(string);
+}
+
+bool QHashedString::operator==(const QHashedStringRef &string) const
+{
+ return (uint)length() == string.m_length &&
+ (string.m_hash == m_hash || !string.m_hash || !m_hash) &&
+ 0 == ::memcmp(constData(), string.m_data, string.m_length * sizeof(QChar));
+}
+
+quint32 QHashedString::hash() const
+{
+ if (!m_hash) computeHash();
+ return m_hash;
+}
+
+quint32 QHashedString::existingHash() const
+{
+ return m_hash;
+}
+
+bool QHashedString::isUpper(const QChar &qc)
+{
+ ushort c = qc.unicode();
+ // Optimize for _, a-z and A-Z.
+ return ((c != '_' ) && (!(c >= 'a' && c <= 'z')) &&
+ ((c >= 'A' && c <= 'Z') || QChar::category(c) == QChar::Letter_Uppercase));
+}
+
+QHashedV8String::QHashedV8String()
+{
+}
+
+QHashedV8String::QHashedV8String(v8::Handle<v8::String> string)
+: m_hash(string->CompleteHash()), m_string(string)
+{
+ Q_ASSERT(!m_string.IsEmpty());
+}
+
+QHashedV8String::QHashedV8String(const QHashedV8String &string)
+: m_hash(string.m_hash), m_string(string.m_string)
+{
+}
+
+QHashedV8String &QHashedV8String::operator=(const QHashedV8String &other)
+{
+ m_hash = other.m_hash;
+ m_string = other.m_string;
+ return *this;
+}
+
+bool QHashedV8String::operator==(const QHashedV8String &string)
+{
+ return m_hash.hash == string.m_hash.hash && m_hash.length == string.m_hash.length &&
+ m_string.IsEmpty() == m_string.IsEmpty() &&
+ (m_string.IsEmpty() || m_string->StrictEquals(string.m_string));
+}
+
+quint32 QHashedV8String::hash() const
+{
+ return m_hash.hash;
+}
+
+int QHashedV8String::length() const
+{
+ return m_hash.length;
+}
+
+quint32 QHashedV8String::symbolId() const
+{
+ return m_hash.symbol_id;
+}
+
+v8::Handle<v8::String> QHashedV8String::string() const
+{
+ return m_string;
+}
+
+QHashedStringRef::QHashedStringRef()
+: m_data(0), m_length(0), m_hash(0)
+{
+}
+
+QHashedStringRef::QHashedStringRef(const QString &str)
+: m_data(str.constData()), m_length(str.length()), m_hash(0)
+{
+}
+
+QHashedStringRef::QHashedStringRef(const QChar *data, int length)
+: m_data(data), m_length(length), m_hash(0)
+{
+}
+
+QHashedStringRef::QHashedStringRef(const QChar *data, int length, quint32 hash)
+: m_data(data), m_length(length), m_hash(hash)
+{
+}
+
+QHashedStringRef::QHashedStringRef(const QHashedString &string)
+: m_data(string.constData()), m_length(string.length()), m_hash(string.m_hash)
+{
+}
+
+QHashedStringRef::QHashedStringRef(const QHashedStringRef &string)
+: m_data(string.m_data), m_length(string.m_length), m_hash(string.m_hash)
+{
+}
+
+bool QHashedStringRef::operator==(const QHashedString &string) const
+{
+ return m_length == (uint)string.length() &&
+ (m_hash == string.m_hash || !m_hash || !string.m_hash) &&
+ 0 == ::memcmp(string.constData(), m_data, m_length * sizeof(QChar));
+}
+
+bool QHashedStringRef::operator==(const QHashedStringRef &string) const
+{
+ return m_length == string.m_length &&
+ (m_hash == string.m_hash || !m_hash || !string.m_hash) &&
+ 0 == ::memcmp(string.m_data, m_data, m_length * sizeof(QChar));
+}
+
+const QChar *QHashedStringRef::constData() const
+{
+ return m_data;
+}
+
+quint32 QHashedStringRef::length() const
+{
+ return m_length;
+}
+
+bool QHashedStringRef::startsWithUpper() const
+{
+ if (m_length < 1) return false;
+ return QHashedString::isUpper(m_data[0]);
+}
+
+quint32 QHashedStringRef::hash() const
+{
+ if (!m_hash) computeHash();
+ return m_hash;
+}
+
+QT_END_NAMESPACE
+
+#endif // QHASHEDSTRING_P_H
diff --git a/src/declarative/qml/v8/qv8_p.h b/src/declarative/qml/v8/qv8_p.h
new file mode 100644
index 0000000000..6aeb6f6458
--- /dev/null
+++ b/src/declarative/qml/v8/qv8_p.h
@@ -0,0 +1 @@
+#include "../../../3rdparty/v8/include/v8.h"
diff --git a/src/declarative/qml/v8/qv8bindings.cpp b/src/declarative/qml/v8/qv8bindings.cpp
new file mode 100644
index 0000000000..fe881a182e
--- /dev/null
+++ b/src/declarative/qml/v8/qv8bindings.cpp
@@ -0,0 +1,243 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8bindings_p.h"
+
+#include <private/qv8_p.h>
+#include <private/qdeclarativebinding_p.h>
+#include <private/qdeclarativecompiler_p.h>
+#include <private/qdeclarativeproperty_p.h>
+#include <private/qdeclarativebinding_p_p.h>
+#include <private/qdeclarativeexpression_p.h>
+#include <private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8BindingsPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QV8Bindings)
+public:
+ QV8BindingsPrivate();
+
+ struct Binding : public QDeclarativeJavaScriptExpression,
+ public QDeclarativeAbstractBinding {
+ Binding();
+
+ void update() { QDeclarativeAbstractBinding::update(); }
+
+ // Inherited from QDeclarativeAbstractBinding
+ virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags flags);
+ virtual void update(QDeclarativePropertyPrivate::WriteFlags flags);
+ virtual void destroy();
+ virtual void refresh();
+
+ int index:30;
+ bool enabled:1;
+ bool updating:1;
+ int line;
+ QDeclarativeProperty property;
+ QV8BindingsPrivate *parent;
+ };
+
+ QUrl url;
+ int bindingsCount;
+ Binding *bindings;
+ v8::Persistent<v8::Array> functions;
+};
+
+QV8BindingsPrivate::QV8BindingsPrivate()
+: bindingsCount(0), bindings(0)
+{
+}
+
+QV8BindingsPrivate::Binding::Binding()
+: index(-1), enabled(false), updating(false), line(-1), parent(0)
+{
+}
+
+void QV8BindingsPrivate::Binding::setEnabled(bool e, QDeclarativePropertyPrivate::WriteFlags flags)
+{
+ if (enabled != e) {
+ enabled = e;
+
+ if (e) update(flags);
+ }
+}
+
+void QV8BindingsPrivate::Binding::refresh()
+{
+ update();
+}
+
+void QV8BindingsPrivate::Binding::update(QDeclarativePropertyPrivate::WriteFlags flags)
+{
+ if (!enabled)
+ return;
+
+ QDeclarativeContextData *context = QDeclarativeAbstractExpression::context();
+ if (!context || !context->isValid())
+ return;
+
+ if (!updating) {
+ updating = true;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine);
+
+ bool isUndefined = false;
+
+ QDeclarativeDeleteWatcher watcher(this);
+ ep->referenceScarceResources();
+
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(ep->v8engine.context());
+ v8::Local<v8::Value> result = evaluate(v8::Handle<v8::Function>::Cast(parent->functions->Get(index)),
+ &isUndefined);
+
+ bool needsErrorData = false;
+ if (!watcher.wasDeleted() && !error.isValid())
+ needsErrorData = !QDeclarativePropertyPrivate::writeBinding(property, this, result, isUndefined, flags);
+
+ if (!watcher.wasDeleted()) {
+
+ if (needsErrorData) {
+ QUrl url = QUrl(parent->url);
+ if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
+
+ error.setUrl(url);
+ error.setLine(line);
+ error.setColumn(-1);
+ }
+
+ if (error.isValid()) {
+ if (!addError(ep)) ep->warning(error);
+ } else {
+ removeError();
+ }
+
+ updating = false;
+ }
+
+ ep->dereferenceScarceResources();
+
+ } else {
+ QDeclarativeBindingPrivate::printBindingLoopError(property);
+ }
+}
+
+void QV8BindingsPrivate::Binding::destroy()
+{
+ enabled = false;
+ removeFromObject();
+ clear();
+ removeError();
+ parent->q_func()->release();
+}
+
+QV8Bindings::QV8Bindings(const QString &program, int index, int line,
+ QDeclarativeCompiledData *compiled,
+ QDeclarativeContextData *context)
+: QObject(*(new QV8BindingsPrivate))
+{
+ Q_D(QV8Bindings);
+
+ QV8Engine *engine = QDeclarativeEnginePrivate::getV8Engine(context->engine);
+
+ if (compiled->v8bindings[index].IsEmpty()) {
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(engine->context());
+
+ v8::Local<v8::Script> script = engine->qmlModeCompile(program, compiled->name, line);
+ v8::Local<v8::Value> result = script->Run(engine->contextWrapper()->sharedContext());
+
+ if (result->IsArray())
+ compiled->v8bindings[index] = qPersistentNew(v8::Local<v8::Array>::Cast(result));
+ }
+
+ d->url = compiled->url;
+ d->functions = qPersistentNew(compiled->v8bindings[index]);
+ d->bindingsCount = d->functions->Length();
+ d->bindings = new QV8BindingsPrivate::Binding[d->bindingsCount];
+
+ setContext(context);
+}
+
+QV8Bindings::~QV8Bindings()
+{
+ Q_D(QV8Bindings);
+ qPersistentDispose(d->functions);
+
+ delete [] d->bindings;
+ d->bindings = 0;
+ d->bindingsCount = 0;
+}
+
+QDeclarativeAbstractBinding *QV8Bindings::configBinding(int index, QObject *target, QObject *scope,
+ const QDeclarativeProperty &property, int line)
+{
+ Q_D(QV8Bindings);
+ QV8BindingsPrivate::Binding *rv = d->bindings + index;
+
+ rv->line = line;
+ rv->index = index;
+ rv->property = property;
+ rv->setContext(context());
+ rv->setScopeObject(scope);
+ rv->setUseSharedContext(true);
+ rv->setNotifyOnValueChanged(true);
+ rv->setNotifyObject(this, index);
+ rv->parent = d;
+
+ addref(); // This is decremented in Binding::destroy()
+
+ return rv;
+}
+
+int QV8Bindings::qt_metacall(QMetaObject::Call c, int id, void **)
+{
+ Q_D(QV8Bindings);
+
+ if (c == QMetaObject::InvokeMetaMethod) {
+ QV8BindingsPrivate::Binding *binding = d->bindings + id;
+ binding->update(QDeclarativePropertyPrivate::DontRemoveBinding);
+ }
+ return -1;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8bindings_p.h b/src/declarative/qml/v8/qv8bindings_p.h
new file mode 100644
index 0000000000..f8a9407ed8
--- /dev/null
+++ b/src/declarative/qml/v8/qv8bindings_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8BINDINGS_P_H
+#define QV8BINDINGS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qdeclarativeexpression_p.h"
+#include "private/qdeclarativebinding_p.h"
+#include "private/qdeclarativev4instruction_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeCompiledData;
+
+class QV8BindingsPrivate;
+class QV8Bindings : public QObject,
+ public QDeclarativeAbstractExpression,
+ public QDeclarativeRefCount
+{
+public:
+ QV8Bindings(const QString &program, int index, int line,
+ QDeclarativeCompiledData *compiled,
+ QDeclarativeContextData *context);
+ virtual ~QV8Bindings();
+
+ QDeclarativeAbstractBinding *configBinding(int index, QObject *target, QObject *scope,
+ const QDeclarativeProperty &prop, int line);
+
+protected:
+ int qt_metacall(QMetaObject::Call, int, void **);
+
+private:
+ Q_DISABLE_COPY(QV8Bindings)
+ Q_DECLARE_PRIVATE(QV8Bindings)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QV8BINDINGS_P_H
+
+
diff --git a/src/declarative/qml/v8/qv8contextwrapper.cpp b/src/declarative/qml/v8/qv8contextwrapper.cpp
new file mode 100644
index 0000000000..4984102ba2
--- /dev/null
+++ b/src/declarative/qml/v8/qv8contextwrapper.cpp
@@ -0,0 +1,453 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8contextwrapper_p.h"
+#include "qv8engine_p.h"
+
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativecontext_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static QString internal(QLatin1String("You've stumbled onto an internal implementation detail "
+ "that should never have been exposed."));
+
+class QV8ContextResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(ContextType);
+
+public:
+ QV8ContextResource(QV8Engine *engine, QDeclarativeContextData *context, QObject *scopeObject);
+ ~QV8ContextResource();
+
+ inline QDeclarativeContextData *getContext() const;
+ inline QObject *getScopeObject() const;
+
+ quint32 isSharedContext:1;
+ quint32 hasSubContexts:1;
+ quint32 readOnly:1;
+ quint32 dummy:29;
+
+ QObject *secondaryScope;
+
+ // This is a pretty horrible hack, and an abuse of external strings. When we create a
+ // sub-context (a context created by a Qt.include() in an external javascript file),
+ // we pass a specially crafted SubContext external string as the v8::Script::Data() to
+ // the script, which contains a pointer to the context. We can then access the
+ // v8::Script::Data() later on to resolve names and URLs against the sub-context instead
+ // of the main outer context.
+ struct SubContext : public v8::String::ExternalStringResource {
+ SubContext(QDeclarativeContextData *context) : context(context) {}
+ QDeclarativeGuardedContextData context;
+
+ virtual const uint16_t* data() const { return (const uint16_t *)internal.constData(); }
+ virtual size_t length() const { return internal.length(); }
+ };
+
+private:
+ QDeclarativeGuardedContextData context;
+ QDeclarativeGuard<QObject> scopeObject;
+
+};
+
+QV8ContextResource::QV8ContextResource(QV8Engine *engine, QDeclarativeContextData *context, QObject *scopeObject)
+: QV8ObjectResource(engine), isSharedContext(false), hasSubContexts(false), readOnly(true),
+ secondaryScope(0), context(context), scopeObject(scopeObject)
+{
+}
+
+QV8ContextResource::~QV8ContextResource()
+{
+ if (context && context->isJSContext)
+ context->destroy();
+}
+
+// Returns the scope object
+QObject *QV8ContextResource::getScopeObject() const
+{
+ if (isSharedContext)
+ return QDeclarativeEnginePrivate::get(engine->engine())->sharedScope;
+ else
+ return scopeObject;
+}
+
+// Returns the context, including resolving a subcontext
+QDeclarativeContextData *QV8ContextResource::getContext() const
+{
+ if (isSharedContext)
+ return QDeclarativeEnginePrivate::get(engine->engine())->sharedContext;
+
+ if (!hasSubContexts)
+ return context;
+
+ v8::Local<v8::Value> callingdata = v8::Context::GetCallingScriptData();
+ if (callingdata.IsEmpty() || !callingdata->IsString())
+ return context;
+
+ v8::Local<v8::String> callingstring = callingdata->ToString();
+ Q_ASSERT(callingstring->IsExternal());
+ Q_ASSERT(callingstring->GetExternalStringResource());
+
+ SubContext *sc = static_cast<SubContext *>(callingstring->GetExternalStringResource());
+ return sc->context;
+}
+
+QV8ContextWrapper::QV8ContextWrapper()
+: m_engine(0)
+{
+}
+
+QV8ContextWrapper::~QV8ContextWrapper()
+{
+}
+
+void QV8ContextWrapper::destroy()
+{
+ qPersistentDispose(m_sharedContext);
+ qPersistentDispose(m_urlConstructor);
+ qPersistentDispose(m_constructor);
+}
+
+void QV8ContextWrapper::init(QV8Engine *engine)
+{
+ m_engine = engine;
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(NullGetter, NullSetter);
+ m_urlConstructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+ {
+ v8::Local<v8::Object> sharedContext = m_constructor->NewInstance();
+ QV8ContextResource *r = new QV8ContextResource(engine, 0, 0);
+ r->isSharedContext = true;
+ sharedContext->SetExternalResource(r);
+ m_sharedContext = qPersistentNew<v8::Object>(sharedContext);
+ }
+}
+
+v8::Local<v8::Object> QV8ContextWrapper::qmlScope(QDeclarativeContextData *ctxt, QObject *scope)
+{
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8ContextResource *r = new QV8ContextResource(m_engine, ctxt, scope);
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+v8::Local<v8::Object> QV8ContextWrapper::urlScope(const QUrl &url)
+{
+ QDeclarativeContextData *context = new QDeclarativeContextData;
+ context->url = url;
+ context->isInternal = true;
+ context->isJSContext = true;
+
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_urlConstructor->NewInstance();
+ QV8ContextResource *r = new QV8ContextResource(m_engine, context, 0);
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+void QV8ContextWrapper::setReadOnly(v8::Handle<v8::Object> qmlglobal, bool readOnly)
+{
+ QV8ContextResource *resource = v8_resource_cast<QV8ContextResource>(qmlglobal);
+ Q_ASSERT(resource);
+ resource->readOnly = readOnly;
+}
+
+void QV8ContextWrapper::addSubContext(v8::Handle<v8::Object> qmlglobal, v8::Handle<v8::Script> script,
+ QDeclarativeContextData *ctxt)
+{
+ QV8ContextResource *resource = v8_resource_cast<QV8ContextResource>(qmlglobal);
+ Q_ASSERT(resource);
+ resource->hasSubContexts = true;
+ script->SetData(v8::String::NewExternal(new QV8ContextResource::SubContext(ctxt)));
+}
+
+QObject *QV8ContextWrapper::setSecondaryScope(v8::Handle<v8::Object> ctxt, QObject *scope)
+{
+ QV8ContextResource *resource = v8_resource_cast<QV8ContextResource>(ctxt);
+ if (!resource) return 0;
+
+ QObject *rv = resource->secondaryScope;
+ resource->secondaryScope = scope;
+ return rv;
+}
+
+QDeclarativeContextData *QV8ContextWrapper::callingContext()
+{
+ v8::Local<v8::Object> qmlglobal = v8::Context::GetCallingQmlGlobal();
+ if (qmlglobal.IsEmpty()) return 0;
+
+ QV8ContextResource *r = v8_resource_cast<QV8ContextResource>(qmlglobal);
+ return r?r->getContext():0;
+}
+
+QDeclarativeContextData *QV8ContextWrapper::context(v8::Handle<v8::Value> value)
+{
+ if (!value->IsObject())
+ return 0;
+
+ v8::Handle<v8::Object> qmlglobal = v8::Handle<v8::Object>::Cast(value);
+ QV8ContextResource *r = v8_resource_cast<QV8ContextResource>(qmlglobal);
+ return r?r->getContext():0;
+}
+
+v8::Handle<v8::Value> QV8ContextWrapper::NullGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ QV8ContextResource *resource = v8_resource_check<QV8ContextResource>(info.This());
+
+ QV8Engine *engine = resource->engine;
+
+ QString error = QLatin1String("Can't find variable: ") + engine->toString(property);
+ v8::ThrowException(v8::Exception::ReferenceError(engine->toString(error)));
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8ContextWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ QV8ContextResource *resource = v8_resource_check<QV8ContextResource>(info.This());
+
+ // Its possible we could delay the calculation of the "actual" context (in the case
+ // of sub contexts) until it is definately needed.
+ QDeclarativeContextData *context = resource->getContext();
+
+ if (!context)
+ return v8::Undefined();
+
+ if (v8::Context::GetCallingQmlGlobal() != info.This())
+ return v8::Handle<v8::Value>();
+
+ // Search type (attached property/enum/imported scripts) names
+ // Secondary scope object
+ // while (context) {
+ // Search context properties
+ // Search scope object
+ // Search context object
+ // context = context->parent
+ // }
+
+ QV8Engine *engine = resource->engine;
+
+ QObject *scopeObject = resource->getScopeObject();
+
+ QHashedV8String propertystring(property);
+
+ if (context->imports && QV8Engine::startsWithUpper(property)) {
+ // Search for attached properties, enums and imported scripts
+ QDeclarativeTypeNameCache::Data *data = context->imports->data(propertystring);
+
+ if (data) {
+ if (data->importedScriptIndex != -1) {
+ int index = data->importedScriptIndex;
+ if (index < context->importedScripts.count())
+ return context->importedScripts.at(index);
+ else
+ return v8::Undefined();
+ } else if (data->type) {
+ return engine->typeWrapper()->newObject(scopeObject, data->type);
+ } else if (data->typeNamespace) {
+ return engine->typeWrapper()->newObject(scopeObject, data->typeNamespace);
+ }
+ Q_ASSERT(!"Unreachable");
+ }
+
+ // Fall through
+ }
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
+ QV8QObjectWrapper *qobjectWrapper = engine->qobjectWrapper();
+
+ if (resource->secondaryScope) {
+ v8::Handle<v8::Value> result = qobjectWrapper->getProperty(resource->secondaryScope, propertystring,
+ QV8QObjectWrapper::IgnoreRevision);
+ if (!result.IsEmpty()) return result;
+ }
+
+ while (context) {
+ // Search context properties
+ if (context->propertyNames) {
+ int propertyIdx = context->propertyNames->value(propertystring);
+
+ if (propertyIdx != -1) {
+ typedef QDeclarativeEnginePrivate::CapturedProperty CapturedProperty;
+
+ if (propertyIdx < context->idValueCount) {
+
+ if (ep->captureProperties)
+ ep->capturedProperties << CapturedProperty(&context->idValues[propertyIdx].bindings);
+
+ return engine->newQObject(context->idValues[propertyIdx]);
+ } else {
+
+ QDeclarativeContextPrivate *cp = context->asQDeclarativeContextPrivate();
+
+ if (ep->captureProperties)
+ ep->capturedProperties << CapturedProperty(context->asQDeclarativeContext(), -1,
+ propertyIdx + cp->notifyIndex);
+
+ const QVariant &value = cp->propertyValues.at(propertyIdx);
+ if (value.userType() == qMetaTypeId<QList<QObject*> >()) {
+ QDeclarativeListProperty<QObject> prop(context->asQDeclarativeContext(), (void*)propertyIdx,
+ 0,
+ QDeclarativeContextPrivate::context_count,
+ QDeclarativeContextPrivate::context_at);
+ return engine->listWrapper()->newList(prop, qMetaTypeId<QDeclarativeListProperty<QObject> >());
+ } else {
+ return engine->fromVariant(cp->propertyValues.at(propertyIdx));
+ }
+ }
+ }
+ }
+
+ // Search scope object
+ if (scopeObject) {
+ v8::Handle<v8::Value> result = qobjectWrapper->getProperty(scopeObject, propertystring,
+ QV8QObjectWrapper::CheckRevision);
+ if (!result.IsEmpty()) return result;
+ }
+ scopeObject = 0;
+
+
+ // Search context object
+ if (context->contextObject) {
+ v8::Handle<v8::Value> result = qobjectWrapper->getProperty(context->contextObject, propertystring,
+ QV8QObjectWrapper::CheckRevision);
+ if (!result.IsEmpty()) return result;
+ }
+
+ context = context->parent;
+ }
+
+ QString error = QLatin1String("Can't find variable: ") + engine->toString(property);
+ v8::ThrowException(v8::Exception::ReferenceError(engine->toString(error)));
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8ContextWrapper::NullSetter(v8::Local<v8::String> property,
+ v8::Local<v8::Value>,
+ const v8::AccessorInfo &info)
+{
+ QV8ContextResource *resource = v8_resource_check<QV8ContextResource>(info.This());
+
+ QV8Engine *engine = resource->engine;
+
+ if (!resource->readOnly) {
+ return v8::Handle<v8::Value>();
+ } else {
+ QString error = QLatin1String("Invalid write to global property \"") + engine->toString(property) +
+ QLatin1String("\"");
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ return v8::Handle<v8::Value>();
+ }
+}
+
+v8::Handle<v8::Value> QV8ContextWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ QV8ContextResource *resource = v8_resource_check<QV8ContextResource>(info.This());
+
+ // Its possible we could delay the calculation of the "actual" context (in the case
+ // of sub contexts) until it is definately needed.
+ QDeclarativeContextData *context = resource->getContext();
+
+ if (!context)
+ return v8::Undefined();
+
+ if (v8::Context::GetCallingQmlGlobal() != info.This())
+ return v8::Handle<v8::Value>();
+
+ // See QV8ContextWrapper::Getter for resolution order
+
+ QV8Engine *engine = resource->engine;
+ QObject *scopeObject = resource->getScopeObject();
+
+ QHashedV8String propertystring(property);
+
+ QV8QObjectWrapper *qobjectWrapper = engine->qobjectWrapper();
+
+ // Search scope object
+ if (resource->secondaryScope &&
+ qobjectWrapper->setProperty(resource->secondaryScope, propertystring, value,
+ QV8QObjectWrapper::IgnoreRevision))
+ return value;
+
+ while (context) {
+ // Search context properties
+ if (context->propertyNames && -1 != context->propertyNames->value(propertystring))
+ return value;
+
+ // Search scope object
+ if (scopeObject &&
+ qobjectWrapper->setProperty(scopeObject, propertystring, value, QV8QObjectWrapper::CheckRevision))
+ return value;
+ scopeObject = 0;
+
+ // Search context object
+ if (context->contextObject &&
+ qobjectWrapper->setProperty(context->contextObject, propertystring, value,
+ QV8QObjectWrapper::CheckRevision))
+ return value;
+
+ context = context->parent;
+ }
+
+ if (!resource->readOnly) {
+ return v8::Handle<v8::Value>();
+ } else {
+ QString error = QLatin1String("Invalid write to global property \"") + engine->toString(property) +
+ QLatin1String("\"");
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ return v8::Undefined();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8contextwrapper_p.h b/src/declarative/qml/v8/qv8contextwrapper_p.h
new file mode 100644
index 0000000000..7a7e745166
--- /dev/null
+++ b/src/declarative/qml/v8/qv8contextwrapper_p.h
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module 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$
+**
+****************************************************************************/
+
+#ifndef QV8CONTEXTWRAPPER_P_H
+#define QV8CONTEXTWRAPPER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <private/qv8_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QUrl;
+class QObject;
+class QV8Engine;
+class QDeclarativeContextData;
+class QV8ContextWrapper
+{
+public:
+ QV8ContextWrapper();
+ ~QV8ContextWrapper();
+
+ void init(QV8Engine *);
+ void destroy();
+
+ v8::Local<v8::Object> qmlScope(QDeclarativeContextData *ctxt, QObject *scope);
+ v8::Local<v8::Object> urlScope(const QUrl &);
+
+ void setReadOnly(v8::Handle<v8::Object>, bool);
+
+ void addSubContext(v8::Handle<v8::Object> qmlglobal, v8::Handle<v8::Script>,
+ QDeclarativeContextData *ctxt);
+
+ // XXX We only use the secondary scope to pass the "arguments" of the signal to
+ // on<SignalName> properties. Instead of doing this we should rewrite the
+ // JavaScript closure function to accept these arguments as named parameters.
+ // To keep backwards compatibility we have to check that the argument names are
+ // not members of the QV8Engine::illegalNames() set.
+ QObject *setSecondaryScope(v8::Handle<v8::Object>, QObject *);
+
+ QDeclarativeContextData *callingContext();
+ QDeclarativeContextData *context(v8::Handle<v8::Value>);
+
+ inline v8::Handle<v8::Object> sharedContext() const;
+
+private:
+ static v8::Handle<v8::Value> NullGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> NullSetter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+
+ QV8Engine *m_engine;
+ v8::Persistent<v8::Function> m_constructor;
+ v8::Persistent<v8::Function> m_urlConstructor;
+ v8::Persistent<v8::Object> m_sharedContext;
+};
+
+v8::Handle<v8::Object> QV8ContextWrapper::sharedContext() const
+{
+ return m_sharedContext;
+}
+
+QT_END_NAMESPACE
+
+#endif // QV8CONTEXTWRAPPER_P_H
+
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
new file mode 100644
index 0000000000..a6af68d392
--- /dev/null
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -0,0 +1,1634 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8engine_p.h"
+
+#include "qv8contextwrapper_p.h"
+#include "qv8include_p.h"
+#include "../../../3rdparty/javascriptcore/DateMath.h"
+
+#include <private/qdeclarativelist_p.h>
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativecomponent_p.h>
+#include <private/qdeclarativestringconverters_p.h>
+
+#include <QtDeclarative/qdeclarativecomponent.h>
+
+#include <QtCore/qstring.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qcryptographichash.h>
+#include <QtCore/qnumeric.h>
+#include <QtGui/qdesktopservices.h>
+#include <QtGui/qfontdatabase.h>
+#include <private/qdeclarativeapplication_p.h>
+#include <private/qdeclarativexmlhttprequest_p.h>
+#include <private/qdeclarativesqldatabase_p.h>
+
+// XXX TODO: Need to check all the global functions will also work in a worker script where the
+// QDeclarativeEngine is not available
+QT_BEGIN_NAMESPACE
+
+static bool ObjectComparisonCallback(v8::Local<v8::Object> lhs, v8::Local<v8::Object> rhs)
+{
+ if (lhs == rhs)
+ return true;
+
+ QV8ObjectResource *lhsr = static_cast<QV8ObjectResource*>(lhs->GetExternalResource());
+ QV8ObjectResource *rhsr = static_cast<QV8ObjectResource*>(rhs->GetExternalResource());
+
+ Q_ASSERT(lhsr->engine == rhsr->engine);
+
+ if (lhsr && rhsr) {
+ QV8ObjectResource::ResourceType lhst = lhsr->resourceType();
+ QV8ObjectResource::ResourceType rhst = rhsr->resourceType();
+
+ switch (lhst) {
+ case QV8ObjectResource::VariantType:
+ if (rhst == QV8ObjectResource::VariantType)
+ return lhsr->engine->variantWrapper()->toVariant(lhsr) ==
+ lhsr->engine->variantWrapper()->toVariant(rhsr);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return false;
+}
+
+QV8Engine::QV8Engine()
+: m_xmlHttpRequestData(0), m_sqlDatabaseData(0), m_listModelData(0)
+{
+}
+
+QV8Engine::~QV8Engine()
+{
+ for (int ii = 0; ii < m_extensionData.count(); ++ii)
+ delete m_extensionData[ii];
+ m_extensionData.clear();
+
+ qt_rem_qmlsqldatabase(this, m_sqlDatabaseData);
+ m_sqlDatabaseData = 0;
+ qt_rem_qmlxmlhttprequest(this, m_xmlHttpRequestData);
+ m_xmlHttpRequestData = 0;
+ delete m_listModelData;
+ m_listModelData = 0;
+
+ qPersistentDispose(m_freezeObject);
+ qPersistentDispose(m_getOwnPropertyNames);
+ m_valueTypeWrapper.destroy();
+ m_variantWrapper.destroy();
+ m_listWrapper.destroy();
+ m_typeWrapper.destroy();
+ m_qobjectWrapper.destroy();
+ m_contextWrapper.destroy();
+ m_stringWrapper.destroy();
+ qPersistentDispose(m_context);
+}
+
+void QV8Engine::init(QDeclarativeEngine *engine)
+{
+ m_engine = engine;
+
+ QByteArray v8args = qgetenv("V8ARGS");
+ if (!v8args.isEmpty())
+ v8::V8::SetFlagsFromString(v8args.constData(), v8args.length());
+
+ v8::HandleScope handle_scope;
+ m_context = v8::Context::New();
+ qPersistentRegister(m_context);
+ v8::Context::Scope context_scope(m_context);
+
+ v8::V8::SetUserObjectComparisonCallbackFunction(ObjectComparisonCallback);
+
+ m_stringWrapper.init();
+ m_contextWrapper.init(this);
+ m_qobjectWrapper.init(this);
+ m_typeWrapper.init(this);
+ m_listWrapper.init(this);
+ m_variantWrapper.init(this);
+ m_valueTypeWrapper.init(this);
+
+ {
+ v8::Handle<v8::Value> v = global()->Get(v8::String::New("Object"))->ToObject()->Get(v8::String::New("getOwnPropertyNames"));
+ m_getOwnPropertyNames = qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(v));
+ }
+
+ initializeGlobal(m_context->Global());
+ freezeObject(m_context->Global());
+}
+
+QString QV8Engine::toStringStatic(v8::Handle<v8::Value> jsstr)
+{
+ return toStringStatic(jsstr->ToString());
+}
+
+QString QV8Engine::toStringStatic(v8::Handle<v8::String> jsstr)
+{
+ QString qstr;
+ qstr.resize(jsstr->Length());
+ jsstr->Write((uint16_t*)qstr.data());
+ return qstr;
+}
+
+QVariant QV8Engine::toVariant(v8::Handle<v8::Value> value, int typeHint)
+{
+ if (value.IsEmpty())
+ return QVariant();
+
+ if (value->IsObject()) {
+ QV8ObjectResource *r = (QV8ObjectResource *)value->ToObject()->GetExternalResource();
+ if (r) {
+ switch (r->resourceType()) {
+ case QV8ObjectResource::ContextType:
+ case QV8ObjectResource::TypeType:
+ case QV8ObjectResource::XMLHttpRequestType:
+ case QV8ObjectResource::DOMNodeType:
+ case QV8ObjectResource::SQLDatabaseType:
+ case QV8ObjectResource::ListModelType:
+ case QV8ObjectResource::Context2DType:
+ return QVariant();
+ case QV8ObjectResource::QObjectType:
+ return qVariantFromValue<QObject *>(m_qobjectWrapper.toQObject(r));
+ case QV8ObjectResource::ListType:
+ return m_listWrapper.toVariant(r);
+ case QV8ObjectResource::VariantType:
+ return m_variantWrapper.toVariant(r);
+ case QV8ObjectResource::ValueTypeType:
+ return m_valueTypeWrapper.toVariant(r);
+ }
+ }
+ }
+
+ if (typeHint == qMetaTypeId<QList<QObject *> >() && value->IsArray()) {
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
+
+ QList<QObject *> list;
+ uint32_t length = array->Length();
+ for (uint32_t ii = 0; ii < length; ++ii) {
+ v8::Local<v8::Value> arrayItem = array->Get(ii);
+ if (arrayItem->IsObject()) {
+ list << toQObject(arrayItem->ToObject());
+ } else {
+ list << 0;
+ }
+ }
+
+ return qVariantFromValue<QList<QObject*> >(list);
+ }
+
+ return toBasicVariant(value);
+}
+
+static v8::Handle<v8::Array> arrayFromStringList(QV8Engine *engine, const QStringList &list)
+{
+ v8::Context::Scope scope(engine->context());
+ v8::Local<v8::Array> result = v8::Array::New(list.count());
+ for (int ii = 0; ii < list.count(); ++ii)
+ result->Set(ii, engine->toString(list.at(ii)));
+ return result;
+}
+
+static v8::Handle<v8::Array> arrayFromVariantList(QV8Engine *engine, const QVariantList &list)
+{
+ v8::Context::Scope scope(engine->context());
+ v8::Local<v8::Array> result = v8::Array::New(list.count());
+ for (int ii = 0; ii < list.count(); ++ii)
+ result->Set(ii, engine->fromVariant(list.at(ii)));
+ return result;
+}
+
+static v8::Handle<v8::Object> objectFromVariantMap(QV8Engine *engine, const QVariantMap &map)
+{
+ v8::Context::Scope scope(engine->context());
+ v8::Local<v8::Object> object = v8::Object::New();
+ for (QVariantMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter)
+ object->Set(engine->toString(iter.key()), engine->fromVariant(iter.value()));
+ return object;
+}
+
+Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax);
+
+// Converts a QRegExp to a JS RegExp.
+// The conversion is not 100% exact since ECMA regexp and QRegExp
+// have different semantics/flags, but we try to do our best.
+static v8::Handle<v8::RegExp> regexpFromQRegExp(QV8Engine *engine, const QRegExp &re)
+{
+ // Convert the pattern to a ECMAScript pattern.
+ QString pattern = qt_regexp_toCanonical(re.pattern(), re.patternSyntax());
+ if (re.isMinimal()) {
+ QString ecmaPattern;
+ int len = pattern.length();
+ ecmaPattern.reserve(len);
+ int i = 0;
+ const QChar *wc = pattern.unicode();
+ bool inBracket = false;
+ while (i < len) {
+ QChar c = wc[i++];
+ ecmaPattern += c;
+ switch (c.unicode()) {
+ case '?':
+ case '+':
+ case '*':
+ case '}':
+ if (!inBracket)
+ ecmaPattern += QLatin1Char('?');
+ break;
+ case '\\':
+ if (i < len)
+ ecmaPattern += wc[i++];
+ break;
+ case '[':
+ inBracket = true;
+ break;
+ case ']':
+ inBracket = false;
+ break;
+ default:
+ break;
+ }
+ }
+ pattern = ecmaPattern;
+ }
+
+ int flags = v8::RegExp::kNone;
+ if (re.caseSensitivity() == Qt::CaseInsensitive)
+ flags |= v8::RegExp::kIgnoreCase;
+
+ return v8::RegExp::New(engine->toString(pattern), static_cast<v8::RegExp::Flags>(flags));
+}
+
+v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
+{
+ int type = variant.userType();
+ const void *ptr = variant.constData();
+
+ if (type < QMetaType::User) {
+ switch (QMetaType::Type(type)) {
+ case QMetaType::Void:
+ return v8::Undefined();
+ case QMetaType::Bool:
+ return v8::Boolean::New(*reinterpret_cast<const bool*>(ptr));
+ case QMetaType::Int:
+ return v8::Integer::New(*reinterpret_cast<const int*>(ptr));
+ case QMetaType::UInt:
+ return v8::Integer::NewFromUnsigned(*reinterpret_cast<const uint*>(ptr));
+ case QMetaType::LongLong:
+ return v8::Number::New(*reinterpret_cast<const qlonglong*>(ptr));
+ case QMetaType::ULongLong:
+ return v8::Number::New(*reinterpret_cast<const qulonglong*>(ptr));
+ case QMetaType::Double:
+ return v8::Number::New(*reinterpret_cast<const double*>(ptr));
+ case QMetaType::QString:
+ return m_stringWrapper.toString(*reinterpret_cast<const QString*>(ptr));
+ case QMetaType::Float:
+ return v8::Number::New(*reinterpret_cast<const float*>(ptr));
+ case QMetaType::Short:
+ return v8::Integer::New(*reinterpret_cast<const short*>(ptr));
+ case QMetaType::UShort:
+ return v8::Integer::NewFromUnsigned(*reinterpret_cast<const unsigned short*>(ptr));
+ case QMetaType::Char:
+ return v8::Integer::New(*reinterpret_cast<const char*>(ptr));
+ case QMetaType::UChar:
+ return v8::Integer::NewFromUnsigned(*reinterpret_cast<const unsigned char*>(ptr));
+ case QMetaType::QChar:
+ return v8::Integer::New((*reinterpret_cast<const QChar*>(ptr)).unicode());
+ case QMetaType::QDateTime:
+ return v8::Date::New(qtDateTimeToJsDate(*reinterpret_cast<const QDateTime *>(ptr)));
+ case QMetaType::QDate:
+ return v8::Date::New(qtDateTimeToJsDate(QDateTime(*reinterpret_cast<const QDate *>(ptr))));
+ case QMetaType::QTime:
+ return v8::Date::New(qtDateTimeToJsDate(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr))));
+ case QMetaType::QRegExp:
+ return regexpFromQRegExp(this, *reinterpret_cast<const QRegExp *>(ptr));
+ case QMetaType::QObjectStar:
+ case QMetaType::QWidgetStar:
+ return newQObject(*reinterpret_cast<QObject* const *>(ptr));
+ case QMetaType::QStringList:
+ return arrayFromStringList(this, *reinterpret_cast<const QStringList *>(ptr));
+ case QMetaType::QVariantList:
+ return arrayFromVariantList(this, *reinterpret_cast<const QVariantList *>(ptr));
+ case QMetaType::QVariantMap:
+ return objectFromVariantMap(this, *reinterpret_cast<const QVariantMap *>(ptr));
+
+ default:
+ break;
+ }
+
+ if (QDeclarativeValueType *vt = QDeclarativeEnginePrivate::get(m_engine)->valueTypes[type])
+ return m_valueTypeWrapper.newValueType(variant, vt);
+
+ } else {
+ if (type == qMetaTypeId<QDeclarativeListReference>()) {
+ typedef QDeclarativeListReferencePrivate QDLRP;
+ QDLRP *p = QDLRP::get((QDeclarativeListReference*)ptr);
+ if (p->object) {
+ return m_listWrapper.newList(p->property, p->propertyType);
+ } else {
+ return v8::Null();
+ }
+ } else if (type == qMetaTypeId<QList<QObject *> >()) {
+ // XXX Can this be made more by using Array as a prototype and implementing
+ // directly against QList<QObject*>?
+ const QList<QObject *> &list = *(QList<QObject *>*)ptr;
+ v8::Local<v8::Array> array = v8::Array::New(list.count());
+ for (int ii = 0; ii < list.count(); ++ii)
+ array->Set(ii, newQObject(list.at(ii)));
+ return array;
+ }
+
+ bool objOk;
+ QObject *obj = QDeclarativeMetaType::toQObject(variant, &objOk);
+ if (objOk)
+ return newQObject(obj);
+ }
+
+ // XXX TODO: To be compatible, we still need to handle:
+ // + QScriptValue
+ // + QObjectList
+ // + QList<int>
+
+ return m_variantWrapper.newVariant(variant);
+}
+
+// A handle scope and context must be entered
+v8::Local<v8::Script> QV8Engine::qmlModeCompile(const QString &source, const QString &fileName, int lineNumber)
+{
+ v8::Local<v8::String> v8source = m_stringWrapper.toString(source);
+ v8::Local<v8::String> v8fileName = m_stringWrapper.toString(fileName);
+
+ v8::ScriptOrigin origin(v8fileName, v8::Integer::New(lineNumber - 1));
+
+ v8::Local<v8::Script> script = v8::Script::Compile(v8source, &origin, 0, v8::Handle<v8::String>(),
+ v8::Script::QmlMode);
+
+ return script;
+}
+
+QNetworkAccessManager *QV8Engine::networkAccessManager()
+{
+ return QDeclarativeEnginePrivate::get(m_engine)->getNetworkAccessManager();
+}
+
+const QSet<QString> &QV8Engine::illegalNames() const
+{
+ return m_illegalNames;
+}
+
+// Requires a handle scope
+v8::Local<v8::Array> QV8Engine::getOwnPropertyNames(v8::Handle<v8::Object> o)
+{
+ v8::TryCatch tc;
+ v8::Handle<v8::Value> args[] = { o };
+ v8::Local<v8::Value> r = m_getOwnPropertyNames->Call(global(), 1, args);
+ if (tc.HasCaught())
+ return v8::Array::New();
+ else
+ return v8::Local<v8::Array>::Cast(r);
+}
+
+QDeclarativeContextData *QV8Engine::callingContext()
+{
+ return m_contextWrapper.callingContext();
+}
+
+// Converts a JS value to a QVariant.
+// Null, Undefined -> QVariant() (invalid)
+// Boolean -> QVariant(bool)
+// Number -> QVariant(double)
+// String -> QVariant(QString)
+// Array -> QVariantList(...)
+// Date -> QVariant(QDateTime)
+// RegExp -> QVariant(QRegExp)
+// [Any other object] -> QVariantMap(...)
+QVariant QV8Engine::toBasicVariant(v8::Handle<v8::Value> value)
+{
+ if (value->IsNull() || value->IsUndefined())
+ return QVariant();
+ else if (value->IsBoolean())
+ return value->ToBoolean()->Value();
+ else if (value->IsInt32())
+ return value->ToInt32()->Value();
+ else if (value->IsNumber())
+ return value->ToNumber()->Value();
+ else if (value->IsString())
+ return m_stringWrapper.toString(value->ToString());
+ if (value->IsDate())
+ return qtDateTimeFromJsDate(v8::Handle<v8::Date>::Cast(value)->NumberValue());
+ // NOTE: since we convert QTime to JS Date, round trip will change the variant type (to QDateTime)!
+
+ Q_ASSERT(value->IsObject());
+
+ if (value->IsRegExp()) {
+ v8::Context::Scope scope(context());
+ v8::Handle<v8::RegExp> jsRegExp = v8::Handle<v8::RegExp>::Cast(value);
+ // Copied from QtScript
+ // Converts a JS RegExp to a QRegExp.
+ // The conversion is not 100% exact since ECMA regexp and QRegExp
+ // have different semantics/flags, but we try to do our best.
+ QString pattern = toString(jsRegExp->GetSource());
+ Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
+ if (jsRegExp->GetFlags() & v8::RegExp::kIgnoreCase)
+ caseSensitivity = Qt::CaseInsensitive;
+ return QRegExp(pattern, caseSensitivity, QRegExp::RegExp2);
+ } else if (value->IsArray()) {
+ v8::Context::Scope scope(context());
+ QVariantList rv;
+
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
+ int length = array->Length();
+ for (int ii = 0; ii < length; ++ii)
+ rv << toVariant(array->Get(ii), -1);
+
+ return rv;
+ } else if (!value->IsFunction()) {
+ v8::Context::Scope scope(context());
+ v8::Handle<v8::Object> object = value->ToObject();
+ v8::Local<v8::Array> properties = object->GetPropertyNames();
+ int length = properties->Length();
+ if (length == 0)
+ return QVariant();
+
+ QVariantMap map;
+ for (int ii = 0; ii < length; ++ii) {
+ v8::Handle<v8::Value> property = properties->Get(ii);
+ map.insert(toString(property), toVariant(object->Get(property), -1));
+ }
+ return map;
+ }
+
+ return QVariant();
+}
+
+
+
+#include <QtGui/qvector3d.h>
+
+struct StaticQtMetaObject : public QObject
+{
+ static const QMetaObject *get()
+ { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
+};
+
+void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
+{
+ v8::Local<v8::Function> printFn = V8FUNCTION(print, this);
+
+ v8::Local<v8::Object> console = v8::Object::New();
+ console->Set(v8::String::New("log"), printFn);
+ console->Set(v8::String::New("debug"), printFn);
+
+ v8::Local<v8::Object> qt = v8::Object::New();
+
+ // Set all the enums from the "Qt" namespace
+ const QMetaObject *qtMetaObject = StaticQtMetaObject::get();
+ for (int ii = 0; ii < qtMetaObject->enumeratorCount(); ++ii) {
+ QMetaEnum enumerator = qtMetaObject->enumerator(ii);
+ for (int jj = 0; jj < enumerator.keyCount(); ++jj) {
+ qt->Set(v8::String::New(enumerator.key(jj)), v8::Integer::New(enumerator.value(jj)));
+ }
+ }
+
+ if (m_engine)
+ qt->Set(v8::String::New("application"), newQObject(new QDeclarativeApplication(m_engine)));
+
+ qt->Set(v8::String::New("include"), V8FUNCTION(QV8Include::include, this));
+ qt->Set(v8::String::New("isQtObject"), V8FUNCTION(isQtObject, this));
+ qt->Set(v8::String::New("rgba"), V8FUNCTION(rgba, this));
+ qt->Set(v8::String::New("hsla"), V8FUNCTION(hsla, this));
+ qt->Set(v8::String::New("rect"), V8FUNCTION(rect, this));
+ qt->Set(v8::String::New("point"), V8FUNCTION(point, this));
+ qt->Set(v8::String::New("size"), V8FUNCTION(size, this));
+ qt->Set(v8::String::New("vector3d"), V8FUNCTION(vector3d, this));
+
+ if (m_engine) {
+ qt->Set(v8::String::New("lighter"), V8FUNCTION(lighter, this));
+ qt->Set(v8::String::New("darker"), V8FUNCTION(darker, this));
+ qt->Set(v8::String::New("tint"), V8FUNCTION(tint, this));
+ }
+
+ qt->Set(v8::String::New("formatDate"), V8FUNCTION(formatDate, this));
+ qt->Set(v8::String::New("formatTime"), V8FUNCTION(formatTime, this));
+ qt->Set(v8::String::New("formatDateTime"), V8FUNCTION(formatDateTime, this));
+
+ qt->Set(v8::String::New("openUrlExternally"), V8FUNCTION(openUrlExternally, this));
+ qt->Set(v8::String::New("fontFamilies"), V8FUNCTION(fontFamilies, this));
+ qt->Set(v8::String::New("md5"), V8FUNCTION(md5, this));
+ qt->Set(v8::String::New("btoa"), V8FUNCTION(btoa, this));
+ qt->Set(v8::String::New("atob"), V8FUNCTION(atob, this));
+ qt->Set(v8::String::New("resolvedUrl"), V8FUNCTION(resolvedUrl, this));
+
+ if (m_engine) {
+ qt->Set(v8::String::New("quit"), V8FUNCTION(quit, this));
+ qt->Set(v8::String::New("createQmlObject"), V8FUNCTION(createQmlObject, this));
+ qt->Set(v8::String::New("createComponent"), V8FUNCTION(createComponent, this));
+ }
+
+ global->Set(v8::String::New("qsTranslate"), V8FUNCTION(qsTranslate, this));
+ global->Set(v8::String::New("QT_TRANSLATE_NOOP"), V8FUNCTION(qsTranslateNoOp, this));
+ global->Set(v8::String::New("qsTr"), V8FUNCTION(qsTr, this));
+ global->Set(v8::String::New("QT_TR_NOOP"), V8FUNCTION(qsTrNoOp, this));
+ global->Set(v8::String::New("qsTrId"), V8FUNCTION(qsTrId, this));
+ global->Set(v8::String::New("QT_TRID_NOOP"), V8FUNCTION(qsTrIdNoOp, this));
+
+ global->Set(v8::String::New("print"), printFn);
+ global->Set(v8::String::New("console"), console);
+ global->Set(v8::String::New("Qt"), qt);
+ global->Set(v8::String::New("gc"), V8FUNCTION(gc, this));
+
+ m_xmlHttpRequestData = qt_add_qmlxmlhttprequest(this);
+ m_sqlDatabaseData = qt_add_qmlsqldatabase(this);
+
+ {
+ v8::Handle<v8::Value> args[] = { global };
+ v8::Local<v8::Value> names = m_getOwnPropertyNames->Call(global, 1, args);
+ v8::Local<v8::Array> namesArray = v8::Local<v8::Array>::Cast(names);
+ for (quint32 ii = 0; ii < namesArray->Length(); ++ii)
+ m_illegalNames.insert(toString(namesArray->Get(ii)));
+ }
+
+ {
+#define FREEZE_SOURCE "(function freeze_recur(obj) { "\
+ " if (Qt.isQtObject(obj)) return;"\
+ " if (obj != Function.connect && obj != Function.disconnect && "\
+ " obj instanceof Object) {"\
+ " var properties = Object.getOwnPropertyNames(obj);"\
+ " for (var prop in properties) { "\
+ " if (prop == \"connect\" || prop == \"disconnect\") {"\
+ " Object.freeze(obj[prop]); "\
+ " continue;"\
+ " }"\
+ " freeze_recur(obj[prop]);"\
+ " }"\
+ " }"\
+ " if (obj instanceof Object) {"\
+ " Object.freeze(obj);"\
+ " }"\
+ "})"
+
+ v8::Local<v8::Script> freeze = v8::Script::New(v8::String::New(FREEZE_SOURCE));
+ v8::Local<v8::Value> result = freeze->Run();
+ Q_ASSERT(result->IsFunction());
+ m_freezeObject = qPersistentNew(v8::Local<v8::Function>::Cast(result));
+#undef FREEZE_SOURCE
+ }
+}
+
+void QV8Engine::freezeObject(v8::Handle<v8::Value> value)
+{
+ v8::Handle<v8::Value> args[] = { value };
+ m_freezeObject->Call(global(), 1, args);
+}
+
+void QV8Engine::gc()
+{
+ v8::V8::LowMemoryNotification();
+ while (!v8::V8::IdleNotification()) {}
+}
+
+#ifdef QML_GLOBAL_HANDLE_DEBUGGING
+#include <QtCore/qthreadstorage.h>
+static QThreadStorage<QSet<void *> *> QV8Engine_activeHandles;
+
+void QV8Engine::registerHandle(void *handle)
+{
+ if (!handle) {
+ qWarning("Attempting to register a null handle");
+ return;
+ }
+
+ if (!QV8Engine_activeHandles.hasLocalData())
+ QV8Engine_activeHandles.setLocalData(new QSet<void *>);
+
+ if (QV8Engine_activeHandles.localData()->contains(handle)) {
+ qFatal("Handle %p already alive", handle);
+ } else {
+ QV8Engine_activeHandles.localData()->insert(handle);
+ }
+}
+
+void QV8Engine::releaseHandle(void *handle)
+{
+ if (!handle)
+ return;
+
+ if (!QV8Engine_activeHandles.hasLocalData())
+ QV8Engine_activeHandles.setLocalData(new QSet<void *>);
+
+ if (QV8Engine_activeHandles.localData()->contains(handle)) {
+ QV8Engine_activeHandles.localData()->remove(handle);
+ } else {
+ qFatal("Handle %p already dead", handle);
+ }
+}
+#endif
+
+struct QV8EngineRegistrationData
+{
+ QV8EngineRegistrationData() : extensionCount(0) {}
+
+ QMutex mutex;
+ int extensionCount;
+};
+Q_GLOBAL_STATIC(QV8EngineRegistrationData, registrationData);
+
+QMutex *QV8Engine::registrationMutex()
+{
+ return &registrationData()->mutex;
+}
+
+int QV8Engine::registerExtension()
+{
+ return registrationData()->extensionCount++;
+}
+
+void QV8Engine::setExtensionData(int index, Deletable *data)
+{
+ if (m_extensionData.count() <= index)
+ m_extensionData.resize(index + 1);
+
+ if (m_extensionData.at(index))
+ delete m_extensionData.at(index);
+
+ m_extensionData[index] = data;
+}
+
+v8::Handle<v8::Value> QV8Engine::gc(const v8::Arguments &args)
+{
+ Q_UNUSED(args);
+ gc();
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8Engine::print(const v8::Arguments &args)
+{
+ QString result;
+ for (int i = 0; i < args.Length(); ++i) {
+ if (i != 0)
+ result.append(QLatin1Char(' '));
+
+ v8::Local<v8::String> jsstr = args[i]->ToString();
+ if (!jsstr.IsEmpty()) {
+ QString qstr;
+ qstr.resize(jsstr->Length());
+ jsstr->Write((uint16_t*)qstr.data());
+ result.append(qstr);
+ }
+ }
+ qDebug("%s", qPrintable(result));
+ return v8::Undefined();
+}
+
+/*!
+\qmlmethod bool Qt::isQtObject(object)
+Returns true if \c object is a valid reference to a Qt or QML object, otherwise false.
+*/
+v8::Handle<v8::Value> QV8Engine::isQtObject(const v8::Arguments &args)
+{
+ if (args.Length() == 0)
+ return v8::Boolean::New(false);
+
+ return v8::Boolean::New(0 != V8ENGINE()->toQObject(args[0]));
+}
+
+/*!
+\qmlmethod color Qt::rgba(real red, real green, real blue, real alpha)
+
+Returns a color with the specified \c red, \c green, \c blue and \c alpha components.
+All components should be in the range 0-1 inclusive.
+*/
+v8::Handle<v8::Value> QV8Engine::rgba(const v8::Arguments &args)
+{
+ int argCount = args.Length();
+ if (argCount < 3 || argCount > 4)
+ V8THROW_ERROR("Qt.rgba(): Invalid arguments");
+
+ double r = args[0]->NumberValue();
+ double g = args[1]->NumberValue();
+ double b = args[2]->NumberValue();
+ double a = (argCount == 4) ? args[3]->NumberValue() : 1;
+
+ if (r < 0.0) r=0.0;
+ if (r > 1.0) r=1.0;
+ if (g < 0.0) g=0.0;
+ if (g > 1.0) g=1.0;
+ if (b < 0.0) b=0.0;
+ if (b > 1.0) b=1.0;
+ if (a < 0.0) a=0.0;
+ if (a > 1.0) a=1.0;
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QColor::fromRgbF(r, g, b, a)));
+}
+
+/*!
+\qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha)
+
+Returns a color with the specified \c hue, \c saturation, \c lightness and \c alpha components.
+All components should be in the range 0-1 inclusive.
+*/
+v8::Handle<v8::Value> QV8Engine::hsla(const v8::Arguments &args)
+{
+ int argCount = args.Length();
+ if (argCount < 3 || argCount > 4)
+ V8THROW_ERROR("Qt.hsla(): Invalid arguments");
+
+ double h = args[0]->NumberValue();
+ double s = args[1]->NumberValue();
+ double l = args[2]->NumberValue();
+ double a = (argCount == 4) ? args[3]->NumberValue() : 1;
+
+ if (h < 0.0) h=0.0;
+ if (h > 1.0) h=1.0;
+ if (s < 0.0) s=0.0;
+ if (s > 1.0) s=1.0;
+ if (l < 0.0) l=0.0;
+ if (l > 1.0) l=1.0;
+ if (a < 0.0) a=0.0;
+ if (a > 1.0) a=1.0;
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QColor::fromHslF(h, s, l, a)));
+}
+
+/*!
+\qmlmethod rect Qt::rect(int x, int y, int width, int height)
+
+Returns a \c rect with the top-left corner at \c x, \c y and the specified \c width and \c height.
+
+The returned object has \c x, \c y, \c width and \c height attributes with the given values.
+*/
+v8::Handle<v8::Value> QV8Engine::rect(const v8::Arguments &args)
+{
+ if (args.Length() != 4)
+ V8THROW_ERROR("Qt.rect(): Invalid arguments");
+
+ double x = args[0]->NumberValue();
+ double y = args[1]->NumberValue();
+ double w = args[2]->NumberValue();
+ double h = args[3]->NumberValue();
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QRectF(x, y, w, h)));
+}
+
+/*!
+\qmlmethod point Qt::point(int x, int y)
+Returns a Point with the specified \c x and \c y coordinates.
+*/
+v8::Handle<v8::Value> QV8Engine::point(const v8::Arguments &args)
+{
+ if (args.Length() != 2)
+ V8THROW_ERROR("Qt.point(): Invalid arguments");
+
+ double x = args[0]->ToNumber()->Value();
+ double y = args[1]->ToNumber()->Value();
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QPointF(x, y)));
+}
+
+/*!
+\qmlmethod Qt::size(int width, int height)
+Returns a Size with the specified \c width and \c height.
+*/
+v8::Handle<v8::Value> QV8Engine::size(const v8::Arguments &args)
+{
+ if (args.Length() != 2)
+ V8THROW_ERROR("Qt.size(): Invalid arguments");
+
+ double w = args[0]->ToNumber()->Value();
+ double h = args[1]->ToNumber()->Value();
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QSizeF(w, h)));
+}
+
+/*!
+\qmlmethod Qt::vector3d(real x, real y, real z)
+Returns a Vector3D with the specified \c x, \c y and \c z.
+*/
+v8::Handle<v8::Value> QV8Engine::vector3d(const v8::Arguments &args)
+{
+ if (args.Length() != 3)
+ V8THROW_ERROR("Qt.vector(): Invalid arguments");
+
+ double x = args[0]->ToNumber()->Value();
+ double y = args[1]->ToNumber()->Value();
+ double z = args[2]->ToNumber()->Value();
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(QVector3D(x, y, z)));
+}
+
+/*!
+\qmlmethod color Qt::lighter(color baseColor, real factor)
+Returns a color lighter than \c baseColor by the \c factor provided.
+
+If the factor is greater than 1.0, this functions returns a lighter color.
+Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0,
+the return color is darker, but we recommend using the Qt.darker() function for this purpose.
+If the factor is 0 or negative, the return value is unspecified.
+
+The function converts the current RGB color to HSV, multiplies the value (V) component
+by factor and converts the color back to RGB.
+
+If \c factor is not supplied, returns a color 50% lighter than \c baseColor (factor 1.5).
+*/
+v8::Handle<v8::Value> QV8Engine::lighter(const v8::Arguments &args)
+{
+ if (args.Length() != 1 && args.Length() != 2)
+ V8THROW_ERROR("Qt.lighter(): Invalid arguments");
+
+ QColor color;
+ QVariant v = V8ENGINE()->toVariant(args[0], -1);
+ if (v.userType() == QVariant::Color) {
+ color = v.value<QColor>();
+ } else if (v.userType() == QVariant::String) {
+ bool ok = false;
+ color = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok) {
+ return v8::Null();
+ }
+ } else {
+ return v8::Null();
+ }
+
+ qreal factor = 1.5;
+ if (args.Length() == 2)
+ factor = args[1]->ToNumber()->Value();
+
+ color = color.lighter(int(qRound(factor*100.)));
+ return V8ENGINE()->fromVariant(QVariant::fromValue(color));
+}
+
+/*!
+\qmlmethod color Qt::darker(color baseColor, real factor)
+Returns a color darker than \c baseColor by the \c factor provided.
+
+If the factor is greater than 1.0, this function returns a darker color.
+Setting factor to 3.0 returns a color that has one-third the brightness.
+If the factor is less than 1.0, the return color is lighter, but we recommend using
+the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return
+value is unspecified.
+
+The function converts the current RGB color to HSV, divides the value (V) component
+by factor and converts the color back to RGB.
+
+If \c factor is not supplied, returns a color 50% darker than \c baseColor (factor 2.0).
+*/
+v8::Handle<v8::Value> QV8Engine::darker(const v8::Arguments &args)
+{
+ if (args.Length() != 1 && args.Length() != 2)
+ V8THROW_ERROR("Qt.darker(): Invalid arguments");
+
+ QColor color;
+ QVariant v = V8ENGINE()->toVariant(args[0], -1);
+ if (v.userType() == QVariant::Color) {
+ color = v.value<QColor>();
+ } else if (v.userType() == QVariant::String) {
+ bool ok = false;
+ color = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok) {
+ return v8::Null();
+ }
+ } else {
+ return v8::Null();
+ }
+
+ qreal factor = 2.0;
+ if (args.Length() == 2)
+ factor = args[1]->ToNumber()->Value();
+
+ color = color.darker(int(qRound(factor*100.)));
+ return V8ENGINE()->fromVariant(QVariant::fromValue(color));
+}
+
+/*!
+ \qmlmethod color Qt::tint(color baseColor, color tintColor)
+ This function allows tinting one color with another.
+
+ The tint color should usually be mostly transparent, or you will not be
+ able to see the underlying color. The below example provides a slight red
+ tint by having the tint color be pure red which is only 1/16th opaque.
+
+ \qml
+ Item {
+ Rectangle {
+ x: 0; width: 80; height: 80
+ color: "lightsteelblue"
+ }
+ Rectangle {
+ x: 100; width: 80; height: 80
+ color: Qt.tint("lightsteelblue", "#10FF0000")
+ }
+ }
+ \endqml
+ \image declarative-rect_tint.png
+
+ Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color.
+*/
+v8::Handle<v8::Value> QV8Engine::tint(const v8::Arguments &args)
+{
+ if (args.Length() != 2)
+ V8THROW_ERROR("Qt.tint(): Invalid arguments");
+
+ // base color
+ QColor color;
+ QVariant v = V8ENGINE()->toVariant(args[0], -1);
+ if (v.userType() == QVariant::Color) {
+ color = v.value<QColor>();
+ } else if (v.userType() == QVariant::String) {
+ bool ok = false;
+ color = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok) {
+ return v8::Null();
+ }
+ } else {
+ return v8::Null();
+ }
+
+ // tint color
+ QColor tintColor;
+ v = V8ENGINE()->toVariant(args[1], -1);
+ if (v.userType() == QVariant::Color) {
+ tintColor = v.value<QColor>();
+ } else if (v.userType() == QVariant::String) {
+ bool ok = false;
+ tintColor = QDeclarativeStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok) {
+ return v8::Null();
+ }
+ } else {
+ return v8::Null();
+ }
+
+ // tint the base color and return the final color
+ QColor finalColor;
+ int a = tintColor.alpha();
+ if (a == 0xFF)
+ finalColor = tintColor;
+ else if (a == 0x00)
+ finalColor = color;
+ else {
+ qreal a = tintColor.alphaF();
+ qreal inv_a = 1.0 - a;
+
+ finalColor.setRgbF(tintColor.redF() * a + color.redF() * inv_a,
+ tintColor.greenF() * a + color.greenF() * inv_a,
+ tintColor.blueF() * a + color.blueF() * inv_a,
+ a + inv_a * color.alphaF());
+ }
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(finalColor));
+}
+
+/*!
+\qmlmethod string Qt::formatDate(datetime date, variant format)
+
+Returns a string representation of \c date, optionally formatted according
+to \c format.
+
+The \a date parameter may be a JavaScript \c Date object, a \l{date}{date}
+property, a QDate, or QDateTime value. The \a format parameter may be any of
+the possible format values as described for
+\l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
+
+If \a format is not specified, \a date is formatted using
+\l {Qt::DefaultLocaleShortDate}{Qt.DefaultLocaleShortDate}.
+*/
+v8::Handle<v8::Value> QV8Engine::formatDate(const v8::Arguments &args)
+{
+ if (args.Length() < 1 || args.Length() > 2)
+ V8THROW_ERROR("Qt.formatDate(): Invalid arguments");
+
+ Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
+ QDate date = V8ENGINE()->toVariant(args[0], -1).toDateTime().date();
+ QString formattedDate;
+ if (args.Length() == 2) {
+ if (args[1]->IsString()) {
+ QString format = V8ENGINE()->toVariant(args[1], -1).toString();
+ formattedDate = date.toString(format);
+ } else if (args[1]->IsNumber()) {
+ quint32 intFormat = args[1]->ToNumber()->Value();
+ Qt::DateFormat format = Qt::DateFormat(intFormat);
+ formattedDate = date.toString(format);
+ } else {
+ V8THROW_ERROR("Qt.formatDate(): Invalid date format");
+ }
+ } else {
+ formattedDate = date.toString(enumFormat);
+ }
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(formattedDate));
+}
+
+/*!
+\qmlmethod string Qt::formatTime(datetime time, variant format)
+
+Returns a string representation of \c time, optionally formatted according to
+\c format.
+
+The \a time parameter may be a JavaScript \c Date object, a QTime, or QDateTime
+value. The \a format parameter may be any of the possible format values as
+described for \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.
+
+If \a format is not specified, \a time is formatted using
+\l {Qt::DefaultLocaleShortDate}{Qt.DefaultLocaleShortDate}.
+*/
+v8::Handle<v8::Value> QV8Engine::formatTime(const v8::Arguments &args)
+{
+ if (args.Length() < 1 || args.Length() > 2)
+ V8THROW_ERROR("Qt.formatTime(): Invalid arguments");
+
+ QVariant argVariant = V8ENGINE()->toVariant(args[0], -1);
+ QTime time;
+ if (args[0]->IsDate() || (argVariant.type() == QVariant::String))
+ time = argVariant.toDateTime().time();
+ else // if (argVariant.type() == QVariant::Time), or invalid.
+ time = argVariant.toTime();
+
+ Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
+ QString formattedTime;
+ if (args.Length() == 2) {
+ if (args[1]->IsString()) {
+ QString format = V8ENGINE()->toVariant(args[1], -1).toString();
+ formattedTime = time.toString(format);
+ } else if (args[1]->IsNumber()) {
+ quint32 intFormat = args[1]->ToNumber()->Value();
+ Qt::DateFormat format = Qt::DateFormat(intFormat);
+ formattedTime = time.toString(format);
+ } else {
+ V8THROW_ERROR("Qt.formatTime(): Invalid time format");
+ }
+ } else {
+ formattedTime = time.toString(enumFormat);
+ }
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(formattedTime));
+}
+
+/*!
+\qmlmethod string Qt::formatDateTime(datetime dateTime, variant format)
+
+Returns a string representation of \c datetime, optionally formatted according to
+\c format.
+
+The \a date parameter may be a JavaScript \c Date object, a \l{date}{date}
+property, a QDate, QTime, or QDateTime value.
+
+If \a format is not provided, \a dateTime is formatted using
+\l {Qt::DefaultLocaleShortDate}{Qt.DefaultLocaleShortDate}. Otherwise,
+\a format should be either:
+
+\list
+\o One of the Qt::DateFormat enumeration values, such as
+ \c Qt.DefaultLocaleShortDate or \c Qt.ISODate
+\o A string that specifies the format of the returned string, as detailed below.
+\endlist
+
+If \a format specifies a format string, it should use the following expressions
+to specify the date:
+
+ \table
+ \header \i Expression \i Output
+ \row \i d \i the day as number without a leading zero (1 to 31)
+ \row \i dd \i the day as number with a leading zero (01 to 31)
+ \row \i ddd
+ \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
+ Uses QDate::shortDayName().
+ \row \i dddd
+ \i the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
+ Uses QDate::longDayName().
+ \row \i M \i the month as number without a leading zero (1-12)
+ \row \i MM \i the month as number with a leading zero (01-12)
+ \row \i MMM
+ \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
+ Uses QDate::shortMonthName().
+ \row \i MMMM
+ \i the long localized month name (e.g. 'January' to 'December').
+ Uses QDate::longMonthName().
+ \row \i yy \i the year as two digit number (00-99)
+ \row \i yyyy \i the year as four digit number
+ \endtable
+
+In addition the following expressions can be used to specify the time:
+
+ \table
+ \header \i Expression \i Output
+ \row \i h
+ \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
+ \row \i hh
+ \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
+ \row \i m \i the minute without a leading zero (0 to 59)
+ \row \i mm \i the minute with a leading zero (00 to 59)
+ \row \i s \i the second without a leading zero (0 to 59)
+ \row \i ss \i the second with a leading zero (00 to 59)
+ \row \i z \i the milliseconds without leading zeroes (0 to 999)
+ \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
+ \row \i AP
+ \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
+ \row \i ap
+ \i use am/pm display. \e ap will be replaced by either "am" or "pm".
+ \endtable
+
+ All other input characters will be ignored. Any sequence of characters that
+ are enclosed in single quotes will be treated as text and not be used as an
+ expression. Two consecutive single quotes ("''") are replaced by a single quote
+ in the output.
+
+For example, if the following date/time value was specified:
+
+ \code
+ // 21 May 2001 14:13:09
+ var dateTime = new Date(2001, 5, 21, 14, 13, 09)
+ \endcode
+
+This \a dateTime value could be passed to \c Qt.formatDateTime(),
+\l {QML:Qt::formatDate()}{Qt.formatDate()} or \l {QML:Qt::formatTime()}{Qt.formatTime()}
+with the \a format values below to produce the following results:
+
+ \table
+ \header \i Format \i Result
+ \row \i "dd.MM.yyyy" \i 21.05.2001
+ \row \i "ddd MMMM d yy" \i Tue May 21 01
+ \row \i "hh:mm:ss.zzz" \i 14:13:09.042
+ \row \i "h:m:s ap" \i 2:13:9 pm
+ \endtable
+*/
+v8::Handle<v8::Value> QV8Engine::formatDateTime(const v8::Arguments &args)
+{
+ if (args.Length() < 1 || args.Length() > 2)
+ V8THROW_ERROR("Qt.formatDateTime(): Invalid arguments");
+
+ Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
+ QDateTime dt = V8ENGINE()->toVariant(args[0], -1).toDateTime();
+ QString formattedDt;
+ if (args.Length() == 2) {
+ if (args[1]->IsString()) {
+ QString format = V8ENGINE()->toVariant(args[1], -1).toString();
+ formattedDt = dt.toString(format);
+ } else if (args[1]->IsNumber()) {
+ quint32 intFormat = args[1]->ToNumber()->Value();
+ Qt::DateFormat format = Qt::DateFormat(intFormat);
+ formattedDt = dt.toString(format);
+ } else {
+ V8THROW_ERROR("Qt.formatDateTime(): Invalid datetime format");
+ }
+ } else {
+ formattedDt = dt.toString(enumFormat);
+ }
+
+ return V8ENGINE()->fromVariant(QVariant::fromValue(formattedDt));
+}
+
+double QV8Engine::qtDateTimeToJsDate(const QDateTime &dt)
+{
+ // from QScriptEngine::DateTimeToMs()
+ if (!dt.isValid()) {
+ return qSNaN();
+ }
+ QDateTime utc = dt.toUTC();
+ QDate date = utc.date();
+ QTime time = utc.time();
+ QV8DateConverter::JSC::GregorianDateTime tm;
+ tm.year = date.year() - 1900;
+ tm.month = date.month() - 1;
+ tm.monthDay = date.day();
+ tm.weekDay = date.dayOfWeek();
+ tm.yearDay = date.dayOfYear();
+ tm.hour = time.hour();
+ tm.minute = time.minute();
+ tm.second = time.second();
+ return QV8DateConverter::JSC::gregorianDateTimeToMS(tm, time.msec());
+}
+
+QDateTime QV8Engine::qtDateTimeFromJsDate(double jsDate)
+{
+ // from QScriptEngine::MsToDateTime()
+ if (qIsNaN(jsDate))
+ return QDateTime();
+ QV8DateConverter::JSC::GregorianDateTime tm;
+ QV8DateConverter::JSC::msToGregorianDateTime(jsDate, tm);
+
+ // from QScriptEngine::MsFromTime()
+ int ms = int(::fmod(jsDate, 1000.0));
+ if (ms < 0)
+ ms += int(1000.0);
+
+ QDateTime convertedUTC = QDateTime(QDate(tm.year + 1900, tm.month + 1, tm.monthDay),
+ QTime(tm.hour, tm.minute, tm.second, ms), Qt::UTC);
+ return convertedUTC.toLocalTime();
+}
+
+/*!
+\qmlmethod bool Qt::openUrlExternally(url target)
+Attempts to open the specified \c target url in an external application, based on the user's desktop preferences. Returns true if it succeeds, and false otherwise.
+*/
+v8::Handle<v8::Value> QV8Engine::openUrlExternally(const v8::Arguments &args)
+{
+ if (args.Length() != 1)
+ return V8ENGINE()->fromVariant(false);
+
+ bool ret = false;
+#ifndef QT_NO_DESKTOPSERVICES
+ ret = QDesktopServices::openUrl(V8ENGINE()->toVariant(resolvedUrl(args), -1).toUrl());
+#endif
+ return V8ENGINE()->fromVariant(ret);
+}
+
+/*!
+ \qmlmethod url Qt::resolvedUrl(url url)
+ Returns \a url resolved relative to the URL of the caller.
+*/
+v8::Handle<v8::Value> QV8Engine::resolvedUrl(const v8::Arguments &args)
+{
+ QUrl url = V8ENGINE()->toVariant(args[0], -1).toUrl();
+ QDeclarativeEngine *e = V8ENGINE()->engine();
+ QDeclarativeEnginePrivate *p = 0;
+ if (e) p = QDeclarativeEnginePrivate::get(e);
+ if (p) {
+ QDeclarativeContextData *ctxt = V8ENGINE()->callingContext();
+ if (ctxt)
+ return V8ENGINE()->fromVariant(ctxt->resolvedUrl(url));
+ else
+ return V8ENGINE()->fromVariant(url);
+ }
+
+ return V8ENGINE()->fromVariant(e->baseUrl().resolved(url));
+}
+
+/*!
+\qmlmethod list<string> Qt::fontFamilies()
+Returns a list of the font families available to the application.
+*/
+v8::Handle<v8::Value> QV8Engine::fontFamilies(const v8::Arguments &args)
+{
+ if (args.Length() != 0)
+ V8THROW_ERROR("Qt.fontFamilies(): Invalid arguments");
+
+ QFontDatabase database;
+ return V8ENGINE()->fromVariant(database.families());
+}
+
+/*!
+\qmlmethod string Qt::md5(data)
+Returns a hex string of the md5 hash of \c data.
+*/
+v8::Handle<v8::Value> QV8Engine::md5(const v8::Arguments &args)
+{
+ if (args.Length() != 1)
+ V8THROW_ERROR("Qt.md5(): Invalid arguments");
+
+ QByteArray data = V8ENGINE()->toString(args[0]->ToString()).toUtf8();
+ QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5);
+ return V8ENGINE()->toString(QLatin1String(result.toHex()));
+}
+
+/*!
+\qmlmethod string Qt::btoa(data)
+Binary to ASCII - this function returns a base64 encoding of \c data.
+*/
+v8::Handle<v8::Value> QV8Engine::btoa(const v8::Arguments &args)
+{
+ if (args.Length() != 1)
+ V8THROW_ERROR("Qt.btoa(): Invalid arguments");
+
+ QByteArray data = V8ENGINE()->toString(args[0]->ToString()).toUtf8();
+
+ return V8ENGINE()->toString(QLatin1String(data.toBase64()));
+}
+
+/*!
+\qmlmethod string Qt::atob(data)
+ASCII to binary - this function returns a base64 decoding of \c data.
+*/
+v8::Handle<v8::Value> QV8Engine::atob(const v8::Arguments &args)
+{
+ if (args.Length() != 1)
+ V8THROW_ERROR("Qt.atob(): Invalid arguments");
+
+ QByteArray data = V8ENGINE()->toString(args[0]->ToString()).toUtf8();
+
+ return V8ENGINE()->toString(QLatin1String(QByteArray::fromBase64(data)));
+}
+
+/*!
+\qmlmethod Qt::quit()
+This function causes the QDeclarativeEngine::quit() signal to be emitted.
+Within the \l {QML Viewer}, this causes the launcher application to exit;
+to quit a C++ application when this method is called, connect the
+QDeclarativeEngine::quit() signal to the QCoreApplication::quit() slot.
+*/
+v8::Handle<v8::Value> QV8Engine::quit(const v8::Arguments &args)
+{
+ QDeclarativeEnginePrivate::get(V8ENGINE()->engine())->sendQuit();
+ return v8::Undefined();
+}
+
+/*!
+\qmlmethod object Qt::createQmlObject(string qml, object parent, string filepath)
+
+Returns a new object created from the given \a string of QML which will have the specified \a parent,
+or \c null if there was an error in creating the object.
+
+If \a filepath is specified, it will be used for error reporting for the created object.
+
+Example (where \c parentItem is the id of an existing QML item):
+
+\snippet doc/src/snippets/declarative/createQmlObject.qml 0
+
+In the case of an error, a QtScript Error object is thrown. This object has an additional property,
+\c qmlErrors, which is an array of the errors encountered.
+Each object in this array has the members \c lineNumber, \c columnNumber, \c fileName and \c message.
+For example, if the above snippet had misspelled color as 'colro' then the array would contain an object like the following:
+{ "lineNumber" : 1, "columnNumber" : 32, "fileName" : "dynamicSnippet1", "message" : "Cannot assign to non-existent property \"colro\""}.
+
+Note that this function returns immediately, and therefore may not work if
+the \a qml string loads new components (that is, external QML files that have not yet been loaded).
+If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead.
+
+See \l {Dynamic Object Management in QML} for more information on using this function.
+*/
+v8::Handle<v8::Value> QV8Engine::createQmlObject(const v8::Arguments &args)
+{
+ if (args.Length() < 2 || args.Length() > 3)
+ V8THROW_ERROR("Qt.createQmlObject(): Invalid arguments");
+
+ struct Error {
+ static v8::Local<v8::Value> create(QV8Engine *engine, const QList<QDeclarativeError> &errors) {
+ QString errorstr = QLatin1String("Qt.createQmlObject(): failed to create object: ");
+
+ v8::Local<v8::Array> qmlerrors = v8::Array::New(errors.count());
+ for (int ii = 0; ii < errors.count(); ++ii) {
+ const QDeclarativeError &error = errors.at(ii);
+ errorstr += QLatin1String("\n ") + error.toString();
+ v8::Local<v8::Object> qmlerror = v8::Object::New();
+ qmlerror->Set(v8::String::New("lineNumber"), v8::Integer::New(error.line()));
+ qmlerror->Set(v8::String::New("columnNumber"), v8::Integer::New(error.line()));
+ qmlerror->Set(v8::String::New("fileName"), engine->toString(error.url().toString()));
+ qmlerror->Set(v8::String::New("message"), engine->toString(error.description()));
+ qmlerrors->Set(ii, qmlerror);
+ }
+
+ v8::Local<v8::Value> error = v8::Exception::Error(engine->toString(errorstr));
+ v8::Local<v8::Object> errorObject = error->ToObject();
+ errorObject->Set(v8::String::New("qmlErrors"), qmlerrors);
+ return error;
+ }
+ };
+
+ QV8Engine *v8engine = V8ENGINE();
+ QDeclarativeEngine *engine = v8engine->engine();
+
+ QDeclarativeContextData *context = v8engine->callingContext();
+ QDeclarativeContext *effectiveContext = 0;
+ if (context->isPragmaLibraryContext)
+ effectiveContext = engine->rootContext();
+ else
+ effectiveContext = context->asQDeclarativeContext();
+ Q_ASSERT(context && effectiveContext);
+
+ QString qml = v8engine->toString(args[0]->ToString());
+ if (qml.isEmpty())
+ return v8::Null();
+
+ QUrl url;
+ if(args.Length() > 2)
+ url = QUrl(v8engine->toString(args[2]->ToString()));
+ else
+ url = QUrl(QLatin1String("inline"));
+
+ if (url.isValid() && url.isRelative())
+ url = context->resolvedUrl(url);
+
+ QObject *parentArg = v8engine->toQObject(args[1]);
+ if(!parentArg)
+ V8THROW_ERROR("Qt.createQmlObject(): Missing parent object");
+
+ QDeclarativeComponent component(engine);
+ component.setData(qml.toUtf8(), url);
+
+ if(component.isError()) {
+ v8::ThrowException(Error::create(v8engine, component.errors()));
+ return v8::Undefined();
+ }
+
+ if (!component.isReady())
+ V8THROW_ERROR("Qt.createQmlObject(): Component is not ready");
+
+ QObject *obj = component.beginCreate(effectiveContext);
+ if(obj)
+ QDeclarativeData::get(obj, true)->setImplicitDestructible();
+ component.completeCreate();
+
+ if(component.isError()) {
+ v8::ThrowException(Error::create(v8engine, component.errors()));
+ return v8::Undefined();
+ }
+
+ Q_ASSERT(obj);
+
+ obj->setParent(parentArg);
+
+ QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();
+ for (int ii = 0; ii < functions.count(); ++ii) {
+ if (QDeclarativePrivate::Parented == functions.at(ii)(obj, parentArg))
+ break;
+ }
+
+ return v8engine->newQObject(obj);
+}
+
+/*!
+\qmlmethod object Qt::createComponent(url)
+
+Returns a \l Component object created using the QML file at the specified \a url,
+or \c null if an empty string was given.
+
+The returned component's \l Component::status property indicates whether the
+component was successfully created. If the status is \c Component.Error,
+see \l Component::errorString() for an error description.
+
+Call \l {Component::createObject()}{Component.createObject()} on the returned
+component to create an object instance of the component.
+
+For example:
+
+\snippet doc/src/snippets/declarative/createComponent-simple.qml 0
+
+See \l {Dynamic Object Management in QML} for more information on using this function.
+
+To create a QML object from an arbitrary string of QML (instead of a file),
+use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
+*/
+v8::Handle<v8::Value> QV8Engine::createComponent(const v8::Arguments &args)
+{
+ if (args.Length() != 1)
+ V8THROW_ERROR("Qt.createComponent(): Invalid arguments");
+
+ QV8Engine *v8engine = V8ENGINE();
+ QDeclarativeEngine *engine = v8engine->engine();
+
+ QDeclarativeContextData *context = v8engine->callingContext();
+ QDeclarativeContextData *effectiveContext = context;
+ if (context->isPragmaLibraryContext)
+ effectiveContext = 0;
+ Q_ASSERT(context);
+
+ QString arg = v8engine->toString(args[0]->ToString());
+ if (arg.isEmpty())
+ return v8::Null();
+
+ QUrl url = context->resolvedUrl(QUrl(arg));
+ QDeclarativeComponent *c = new QDeclarativeComponent(engine, url, engine);
+ QDeclarativeComponentPrivate::get(c)->creationContext = effectiveContext;
+ QDeclarativeData::get(c, true)->setImplicitDestructible();
+ return v8engine->newQObject(c);
+}
+
+v8::Handle<v8::Value> QV8Engine::qsTranslate(const v8::Arguments &args)
+{
+ if (args.Length() < 2)
+ V8THROW_ERROR("qsTranslate() requires at least two arguments");
+ if (!args[0]->IsString())
+ V8THROW_ERROR("qsTranslate(): first argument (context) must be a string");
+ if (!args[1]->IsString())
+ V8THROW_ERROR("qsTranslate(): second argument (text) must be a string");
+ if ((args.Length() > 2) && !args[2]->IsString())
+ V8THROW_ERROR("qsTranslate(): third argument (comment) must be a string");
+ if ((args.Length() > 3) && !args[3]->IsString())
+ V8THROW_ERROR("qsTranslate(): fourth argument (encoding) must be a string");
+
+ QV8Engine *v8engine = V8ENGINE();
+ QString context = v8engine->toString(args[0]);
+ QString text = v8engine->toString(args[1]);
+ QString comment;
+ if (args.Length() > 2) comment = v8engine->toString(args[2]);
+
+ QCoreApplication::Encoding encoding = QCoreApplication::UnicodeUTF8;
+ if (args.Length() > 3) {
+ QString encStr = v8engine->toString(args[3]);
+ if (encStr == QLatin1String("CodecForTr")) {
+ encoding = QCoreApplication::CodecForTr;
+ } else if (encStr == QLatin1String("UnicodeUTF8")) {
+ encoding = QCoreApplication::UnicodeUTF8;
+ } else {
+ QString msg = QString::fromLatin1("qsTranslate(): invalid encoding '%0'").arg(encStr);
+ V8THROW_ERROR((uint16_t *)msg.constData());
+ }
+ }
+
+ int n = -1;
+ if (args.Length() > 4)
+ n = args[4]->Int32Value();
+
+ QString result = QCoreApplication::translate(context.toUtf8().constData(),
+ text.toUtf8().constData(),
+ comment.toUtf8().constData(),
+ encoding, n);
+
+ return v8engine->toString(result);
+}
+
+v8::Handle<v8::Value> QV8Engine::qsTranslateNoOp(const v8::Arguments &args)
+{
+ if (args.Length() < 2)
+ return v8::Undefined();
+ return args[1];
+}
+
+v8::Handle<v8::Value> QV8Engine::qsTr(const v8::Arguments &args)
+{
+ if (args.Length() < 1)
+ V8THROW_ERROR("qsTr() requires at least one argument");
+ if (!args[0]->IsString())
+ V8THROW_ERROR("qsTr(): first argument (text) must be a string");
+ if ((args.Length() > 1) && !args[1]->IsString())
+ V8THROW_ERROR("qsTr(): second argument (comment) must be a string");
+ if ((args.Length() > 2) && !args[2]->IsNumber())
+ V8THROW_ERROR("qsTr(): third argument (n) must be a number");
+
+ QV8Engine *v8engine = V8ENGINE();
+ QDeclarativeContextData *ctxt = v8engine->callingContext();
+
+ QString context = ctxt->url.toString();
+ QString text = v8engine->toString(args[0]);
+ QString comment;
+ if (args.Length() > 1)
+ comment = v8engine->toString(args[1]);
+ int n = -1;
+ if (args.Length() > 2)
+ n = args[2]->Int32Value();
+
+ QString result = QCoreApplication::translate(context.toUtf8().constData(), text.toUtf8().constData(),
+ comment.toUtf8().constData(), QCoreApplication::UnicodeUTF8, n);
+
+ return v8engine->toString(result);
+}
+
+v8::Handle<v8::Value> QV8Engine::qsTrNoOp(const v8::Arguments &args)
+{
+ if (args.Length() < 1)
+ return v8::Undefined();
+ return args[0];
+}
+
+v8::Handle<v8::Value> QV8Engine::qsTrId(const v8::Arguments &args)
+{
+ if (args.Length() < 1)
+ V8THROW_ERROR("qsTrId() requires at least one argument");
+ if (!args[0]->IsString())
+ V8THROW_TYPE("qsTrId(): first argument (id) must be a string");
+ if (args.Length() > 1 && !args[1]->IsNumber())
+ V8THROW_TYPE("qsTrId(): second argument (n) must be a number");
+
+ int n = -1;
+ if (args.Length() > 1)
+ n = args[1]->Int32Value();
+
+ QV8Engine *v8engine = V8ENGINE();
+ return v8engine->toString(qtTrId(v8engine->toString(args[0]).toUtf8().constData(), n));
+}
+
+v8::Handle<v8::Value> QV8Engine::qsTrIdNoOp(const v8::Arguments &args)
+{
+ if (args.Length() < 1)
+ return v8::Undefined();
+ return args[0];
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h
new file mode 100644
index 0000000000..ef8f16013d
--- /dev/null
+++ b/src/declarative/qml/v8/qv8engine_p.h
@@ -0,0 +1,464 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEV8ENGINE_P_H
+#define QDECLARATIVEV8ENGINE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qvariant.h>
+#include <QtCore/qset.h>
+#include <QtCore/qmutex.h>
+#include <private/qv8_p.h>
+
+#include <private/qdeclarativepropertycache_p.h>
+
+#include "qv8contextwrapper_p.h"
+#include "qv8qobjectwrapper_p.h"
+#include "qv8stringwrapper_p.h"
+#include "qv8typewrapper_p.h"
+#include "qv8listwrapper_p.h"
+#include "qv8variantwrapper_p.h"
+#include "qv8valuetypewrapper_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+// Uncomment the following line to enable global handle debugging. When enabled, all the persistent
+// handles allocated using qPersistentNew() (or registered with qPersistentRegsiter()) and disposed
+// with qPersistentDispose() are tracked. If you try and do something illegal, like double disposing
+// a handle, qFatal() is called.
+// #define QML_GLOBAL_HANDLE_DEBUGGING
+
+#define V8_RESOURCE_TYPE(resourcetype) \
+public: \
+ enum { V8ResourceType = QV8ObjectResource:: resourcetype }; \
+ virtual QV8ObjectResource::ResourceType resourceType() const { return QV8ObjectResource:: resourcetype; } \
+private:
+
+#define V8ENGINE() ((QV8Engine *)v8::External::Unwrap(args.Data()))
+#define V8FUNCTION(function, engine) v8::FunctionTemplate::New(function, v8::External::Wrap((QV8Engine*)engine))->GetFunction()
+#define V8THROW_ERROR(string) { \
+ v8::ThrowException(v8::Exception::Error(v8::String::New(string))); \
+ return v8::Handle<v8::Value>(); \
+}
+#define V8THROW_TYPE(string) { \
+ v8::ThrowException(v8::Exception::TypeError(v8::String::New(string))); \
+ return v8::Handle<v8::Value>(); \
+}
+#define V8ENGINE_ACCESSOR() ((QV8Engine *)v8::External::Unwrap(info.Data()));
+#define V8THROW_ERROR_SETTER(string) { \
+ v8::ThrowException(v8::Exception::Error(v8::String::New(string))); \
+ return; \
+}
+
+#define V8_DEFINE_EXTENSION(dataclass, datafunction) \
+ inline dataclass *datafunction(QV8Engine *engine) \
+ { \
+ static int extensionId = -1; \
+ if (extensionId == -1) { \
+ QV8Engine::registrationMutex()->lock(); \
+ if (extensionId == -1) \
+ extensionId = QV8Engine::registerExtension(); \
+ QV8Engine::registrationMutex()->unlock(); \
+ } \
+ dataclass *rv = (dataclass *)engine->extensionData(extensionId); \
+ if (!rv) { \
+ rv = new dataclass(engine); \
+ engine->setExtensionData(extensionId, rv); \
+ } \
+ return rv; \
+ } \
+
+class QV8Engine;
+class QV8ObjectResource : public v8::Object::ExternalResource
+{
+public:
+ QV8ObjectResource(QV8Engine *engine) : engine(engine) { Q_ASSERT(engine); }
+ enum ResourceType { ContextType, QObjectType, TypeType, ListType, VariantType,
+ ValueTypeType, XMLHttpRequestType, DOMNodeType, SQLDatabaseType,
+ ListModelType, Context2DType };
+ virtual ResourceType resourceType() const = 0;
+
+ QV8Engine *engine;
+};
+
+template<class T>
+inline T *v8_resource_cast(v8::Handle<v8::Object> object) {
+ QV8ObjectResource *resource = static_cast<QV8ObjectResource *>(object->GetExternalResource());
+ return (resource && (quint32)resource->resourceType() == (quint32)T::V8ResourceType)?static_cast<T *>(resource):0;
+}
+
+template<class T>
+inline T *v8_resource_check(v8::Handle<v8::Object> object) {
+ T *resource = static_cast<T *>(object->GetExternalResource());
+ Q_ASSERT(resource && resource->resourceType() == (quint32)T::V8ResourceType);
+ return resource;
+}
+
+// Used to allow a QObject method take and return raw V8 handles without having to expose
+// v8 in the public API.
+// Use like this:
+// class MyClass : public QObject {
+// Q_OBJECT
+// ...
+// Q_INVOKABLE void myMethod(QDeclarativeV8Function*);
+// };
+// The QDeclarativeV8Function - and consequently the arguments and return value - only remains
+// valid during the call. If the return value isn't set within myMethod(), the will return
+// undefined.
+class QV8Engine;
+class QDeclarativeV8Function
+{
+public:
+ int Length() const { return _ac; }
+ v8::Local<v8::Value> operator[](int idx) { return (*_a)->Get(idx); }
+ QDeclarativeContextData *context() { return _c; }
+ v8::Handle<v8::Object> qmlGlobal() { return *_g; }
+ void returnValue(v8::Handle<v8::Value> rv) { *_r = rv; }
+ QV8Engine *engine() const { return _e; }
+private:
+ friend class QV8QObjectWrapper;
+ QDeclarativeV8Function();
+ QDeclarativeV8Function(const QDeclarativeV8Function &);
+ QDeclarativeV8Function &operator=(const QDeclarativeV8Function &);
+
+ QDeclarativeV8Function(int length, v8::Handle<v8::Object> &args,
+ v8::Handle<v8::Value> &rv, v8::Handle<v8::Object> &global,
+ QDeclarativeContextData *c, QV8Engine *e)
+ : _ac(length), _a(&args), _r(&rv), _g(&global), _c(c), _e(e) {}
+
+ int _ac;
+ v8::Handle<v8::Object> *_a;
+ v8::Handle<v8::Value> *_r;
+ v8::Handle<v8::Object> *_g;
+ QDeclarativeContextData *_c;
+ QV8Engine *_e;
+};
+
+class QDeclarativeV8Handle
+{
+public:
+ QDeclarativeV8Handle() : d(0) {}
+ QDeclarativeV8Handle(const QDeclarativeV8Handle &other) : d(other.d) {}
+ QDeclarativeV8Handle &operator=(const QDeclarativeV8Handle &other) { d = other.d; return *this; }
+
+ static QDeclarativeV8Handle fromHandle(v8::Handle<v8::Value> h) {
+ return reinterpret_cast<QDeclarativeV8Handle &>(h);
+ }
+ v8::Handle<v8::Value> toHandle() const {
+ return reinterpret_cast<const v8::Handle<v8::Value> &>(*this);
+ }
+private:
+ void *d;
+};
+
+class QObject;
+class QDeclarativeEngine;
+class QDeclarativeValueType;
+class QNetworkAccessManager;
+class QDeclarativeContextData;
+class Q_AUTOTEST_EXPORT QV8Engine
+{
+public:
+ QV8Engine();
+ ~QV8Engine();
+
+ struct Deletable {
+ ~Deletable() {}
+ };
+
+ void init(QDeclarativeEngine *);
+
+ QDeclarativeEngine *engine() { return m_engine; }
+ v8::Local<v8::Object> global() { return m_context->Global(); }
+ v8::Handle<v8::Context> context() { return m_context; }
+ QV8ContextWrapper *contextWrapper() { return &m_contextWrapper; }
+ QV8QObjectWrapper *qobjectWrapper() { return &m_qobjectWrapper; }
+ QV8TypeWrapper *typeWrapper() { return &m_typeWrapper; }
+ QV8ListWrapper *listWrapper() { return &m_listWrapper; }
+ QV8VariantWrapper *variantWrapper() { return &m_variantWrapper; }
+
+ void *xmlHttpRequestData() { return m_xmlHttpRequestData; }
+ void *sqlDatabaseData() { return m_sqlDatabaseData; }
+
+ Deletable *listModelData() { return m_listModelData; }
+ void setListModelData(Deletable *d) { if (m_listModelData) delete m_listModelData; m_listModelData = d; }
+
+ QDeclarativeContextData *callingContext();
+
+ v8::Local<v8::Array> getOwnPropertyNames(v8::Handle<v8::Object>);
+ void freezeObject(v8::Handle<v8::Value>);
+
+ inline QString toString(v8::Handle<v8::Value> string);
+ inline QString toString(v8::Handle<v8::String> string);
+ static QString toStringStatic(v8::Handle<v8::Value>);
+ static QString toStringStatic(v8::Handle<v8::String>);
+ static inline bool startsWithUpper(v8::Handle<v8::String>);
+
+ QVariant toVariant(v8::Handle<v8::Value>, int typeHint);
+ v8::Handle<v8::Value> fromVariant(const QVariant &);
+ inline bool isVariant(v8::Handle<v8::Value>);
+
+ // Compile \a source (from \a fileName at \a lineNumber) in QML mode
+ v8::Local<v8::Script> qmlModeCompile(const QString &source,
+ const QString &fileName = QString(),
+ int lineNumber = 1);
+
+ // Return the QML global "scope" object for the \a ctxt context and \a scope object.
+ inline v8::Local<v8::Object> qmlScope(QDeclarativeContextData *ctxt, QObject *scope);
+
+ // Return a JS wrapper for the given QObject \a object
+ inline v8::Handle<v8::Value> newQObject(QObject *object);
+ inline bool isQObject(v8::Handle<v8::Value>);
+ inline QObject *toQObject(v8::Handle<v8::Value>);
+
+ // Return a JS string for the given QString \a string
+ inline v8::Local<v8::String> toString(const QString &string);
+
+ // Create a new value type object
+ inline v8::Handle<v8::Value> newValueType(QObject *, int coreIndex, QDeclarativeValueType *);
+ inline v8::Handle<v8::Value> newValueType(const QVariant &, QDeclarativeValueType *);
+
+ // Create a new QVariant object. This doesn't examine the type of the variant, but always returns
+ // a QVariant wrapper
+ inline v8::Handle<v8::Value> newQVariant(const QVariant &);
+
+ // Return the network access manager for this engine. By default this returns the network
+ // access manager of the QDeclarativeEngine. It is overridden in the case of a threaded v8
+ // instance (like in WorkerScript).
+ virtual QNetworkAccessManager *networkAccessManager();
+
+ // Return the list of illegal id names (the names of the properties on the global object)
+ const QSet<QString> &illegalNames() const;
+
+ static void gc();
+
+#ifdef QML_GLOBAL_HANDLE_DEBUGGING
+ // Used for handle debugging
+ static void registerHandle(void *);
+ static void releaseHandle(void *);
+#endif
+
+ static QMutex *registrationMutex();
+ static int registerExtension();
+
+ inline Deletable *extensionData(int) const;
+ void setExtensionData(int, Deletable *);
+
+private:
+ QDeclarativeEngine *m_engine;
+ v8::Persistent<v8::Context> m_context;
+
+ QV8StringWrapper m_stringWrapper;
+ QV8ContextWrapper m_contextWrapper;
+ QV8QObjectWrapper m_qobjectWrapper;
+ QV8TypeWrapper m_typeWrapper;
+ QV8ListWrapper m_listWrapper;
+ QV8VariantWrapper m_variantWrapper;
+ QV8ValueTypeWrapper m_valueTypeWrapper;
+
+ v8::Persistent<v8::Function> m_getOwnPropertyNames;
+ v8::Persistent<v8::Function> m_freezeObject;
+
+ void *m_xmlHttpRequestData;
+ void *m_sqlDatabaseData;
+
+ QVector<Deletable *> m_extensionData;
+ Deletable *m_listModelData;
+
+ QSet<QString> m_illegalNames;
+
+ QVariant toBasicVariant(v8::Handle<v8::Value>);
+
+ void initializeGlobal(v8::Handle<v8::Object>);
+
+ static v8::Handle<v8::Value> gc(const v8::Arguments &args);
+ static v8::Handle<v8::Value> print(const v8::Arguments &args);
+ static v8::Handle<v8::Value> isQtObject(const v8::Arguments &args);
+ static v8::Handle<v8::Value> rgba(const v8::Arguments &args);
+ static v8::Handle<v8::Value> hsla(const v8::Arguments &args);
+ static v8::Handle<v8::Value> rect(const v8::Arguments &args);
+ static v8::Handle<v8::Value> point(const v8::Arguments &args);
+ static v8::Handle<v8::Value> size(const v8::Arguments &args);
+ static v8::Handle<v8::Value> vector3d(const v8::Arguments &args);
+ static v8::Handle<v8::Value> lighter(const v8::Arguments &args);
+ static v8::Handle<v8::Value> darker(const v8::Arguments &args);
+ static v8::Handle<v8::Value> tint(const v8::Arguments &args);
+ static v8::Handle<v8::Value> formatDate(const v8::Arguments &args);
+ static v8::Handle<v8::Value> formatTime(const v8::Arguments &args);
+ static v8::Handle<v8::Value> formatDateTime(const v8::Arguments &args);
+ static v8::Handle<v8::Value> openUrlExternally(const v8::Arguments &args);
+ static v8::Handle<v8::Value> fontFamilies(const v8::Arguments &args);
+ static v8::Handle<v8::Value> md5(const v8::Arguments &args);
+ static v8::Handle<v8::Value> btoa(const v8::Arguments &args);
+ static v8::Handle<v8::Value> atob(const v8::Arguments &args);
+ static v8::Handle<v8::Value> quit(const v8::Arguments &args);
+ static v8::Handle<v8::Value> resolvedUrl(const v8::Arguments &args);
+ static v8::Handle<v8::Value> createQmlObject(const v8::Arguments &args);
+ static v8::Handle<v8::Value> createComponent(const v8::Arguments &args);
+ static v8::Handle<v8::Value> qsTranslate(const v8::Arguments &args);
+ static v8::Handle<v8::Value> qsTranslateNoOp(const v8::Arguments &args);
+ static v8::Handle<v8::Value> qsTr(const v8::Arguments &args);
+ static v8::Handle<v8::Value> qsTrNoOp(const v8::Arguments &args);
+ static v8::Handle<v8::Value> qsTrId(const v8::Arguments &args);
+ static v8::Handle<v8::Value> qsTrIdNoOp(const v8::Arguments &args);
+
+ double qtDateTimeToJsDate(const QDateTime &dt);
+ QDateTime qtDateTimeFromJsDate(double jsDate);
+};
+
+// Allocate a new Persistent handle. *ALL* persistent handles in QML must be allocated
+// using this method.
+template<class T>
+v8::Persistent<T> qPersistentNew(v8::Handle<T> that)
+{
+ v8::Persistent<T> rv = v8::Persistent<T>::New(that);
+#ifdef QML_GLOBAL_HANDLE_DEBUGGING
+ QV8Engine::registerHandle(*rv);
+#endif
+ return rv;
+}
+
+// Register a Persistent handle that was returned to you by V8 (such as by
+// v8::Context::New). This allows us to do handle tracking on these handles too.
+template<class T>
+void qPersistentRegister(v8::Persistent<T> handle)
+{
+#ifdef QML_GLOBAL_HANDLE_DEBUGGING
+ QV8Engine::registerHandle(*handle);
+#else
+ Q_UNUSED(handle);
+#endif
+}
+
+// Dispose and clear a persistent handle. *ALL* persistent handles in QML must be
+// disposed using this method.
+template<class T>
+void qPersistentDispose(v8::Persistent<T> &that)
+{
+#ifdef QML_GLOBAL_HANDLE_DEBUGGING
+ QV8Engine::releaseHandle(*that);
+#endif
+ that.Dispose();
+ that.Clear();
+}
+
+QString QV8Engine::toString(v8::Handle<v8::Value> string)
+{
+ return m_stringWrapper.toString(string->ToString());
+}
+
+QString QV8Engine::toString(v8::Handle<v8::String> string)
+{
+ return m_stringWrapper.toString(string);
+}
+
+bool QV8Engine::isVariant(v8::Handle<v8::Value> value)
+{
+ return m_variantWrapper.isVariant(value);
+}
+
+v8::Local<v8::Object> QV8Engine::qmlScope(QDeclarativeContextData *ctxt, QObject *scope)
+{
+ return m_contextWrapper.qmlScope(ctxt, scope);
+}
+
+bool QV8Engine::isQObject(v8::Handle<v8::Value> obj)
+{
+ return obj->IsObject()?m_qobjectWrapper.isQObject(v8::Handle<v8::Object>::Cast(obj)):false;
+}
+
+QObject *QV8Engine::toQObject(v8::Handle<v8::Value> obj)
+{
+ return obj->IsObject()?m_qobjectWrapper.toQObject(v8::Handle<v8::Object>::Cast(obj)):0;
+}
+
+v8::Handle<v8::Value> QV8Engine::newQObject(QObject *object)
+{
+ return m_qobjectWrapper.newQObject(object);
+}
+
+v8::Local<v8::String> QV8Engine::toString(const QString &string)
+{
+ return m_stringWrapper.toString(string);
+}
+
+v8::Handle<v8::Value> QV8Engine::newValueType(QObject *object, int property, QDeclarativeValueType *type)
+{
+ return m_valueTypeWrapper.newValueType(object, property, type);
+}
+
+v8::Handle<v8::Value> QV8Engine::newValueType(const QVariant &value, QDeclarativeValueType *type)
+{
+ return m_valueTypeWrapper.newValueType(value, type);
+}
+
+// XXX Can this be made more optimal? It is called prior to resolving each and every
+// unqualified name in QV8ContextWrapper.
+bool QV8Engine::startsWithUpper(v8::Handle<v8::String> string)
+{
+ uint16_t c = string->GetCharacter(0);
+ return (c >= 'A' && c <= 'Z') ||
+ (c > 127 && QChar::category(c) == QChar::Letter_Uppercase);
+}
+
+QV8Engine::Deletable *QV8Engine::extensionData(int index) const
+{
+ if (index < m_extensionData.count())
+ return m_extensionData[index];
+ else
+ return 0;
+}
+
+QT_END_NAMESPACE
+
+#endif // QDECLARATIVEV8ENGINE_P_H
diff --git a/src/declarative/qml/v8/qv8include.cpp b/src/declarative/qml/v8/qv8include.cpp
new file mode 100644
index 0000000000..e2161a9001
--- /dev/null
+++ b/src/declarative/qml/v8/qv8include.cpp
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8include_p.h"
+
+#include <QtScript/qscriptengine.h>
+#include <QtNetwork/qnetworkrequest.h>
+#include <QtNetwork/qnetworkreply.h>
+#include <QtCore/qfile.h>
+
+#include <private/qdeclarativeengine_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QV8Include::QV8Include(const QUrl &url, QV8Engine *engine, QDeclarativeContextData *context,
+ v8::Handle<v8::Object> qmlglobal, v8::Handle<v8::Function> callback)
+: m_engine(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0), m_context(context)
+{
+ m_qmlglobal = qPersistentNew<v8::Object>(qmlglobal);
+ if (!callback.IsEmpty())
+ m_callbackFunction = qPersistentNew<v8::Function>(callback);
+
+ m_resultObject = qPersistentNew<v8::Object>(resultValue());
+
+ m_network = engine->networkAccessManager();
+
+ QNetworkRequest request;
+ request.setUrl(url);
+
+ m_reply = m_network->get(request);
+ QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
+}
+
+QV8Include::~QV8Include()
+{
+ delete m_reply; m_reply = 0;
+ qPersistentDispose(m_callbackFunction);
+ qPersistentDispose(m_resultObject);
+}
+
+v8::Local<v8::Object> QV8Include::resultValue(Status status)
+{
+ // XXX It seems inefficient to create this object from scratch each time.
+ v8::Local<v8::Object> result = v8::Object::New();
+ result->Set(v8::String::New("OK"), v8::Integer::New(Ok));
+ result->Set(v8::String::New("LOADING"), v8::Integer::New(Loading));
+ result->Set(v8::String::New("NETWORK_ERROR"), v8::Integer::New(NetworkError));
+ result->Set(v8::String::New("EXCEPTION"), v8::Integer::New(Exception));
+
+ result->Set(v8::String::New("status"), v8::Integer::New(status));
+
+ return result;
+}
+
+void QV8Include::callback(QV8Engine *engine, v8::Handle<v8::Function> callback, v8::Handle<v8::Object> status)
+{
+ if (!callback.IsEmpty()) {
+ v8::Handle<v8::Value> args[] = { status };
+ v8::TryCatch tc;
+ callback->Call(engine->global(), 1, args);
+ }
+}
+
+v8::Handle<v8::Object> QV8Include::result()
+{
+ return m_resultObject;
+}
+
+#define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15
+void QV8Include::finished()
+{
+ m_redirectCount++;
+
+ if (m_redirectCount < INCLUDE_MAXIMUM_REDIRECT_RECURSION) {
+ QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ m_url = m_url.resolved(redirect.toUrl());
+ delete m_reply;
+
+ QNetworkRequest request;
+ request.setUrl(m_url);
+
+ m_reply = m_network->get(request);
+ QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
+ return;
+ }
+ }
+
+ v8::HandleScope handle_scope;
+
+ if (m_reply->error() == QNetworkReply::NoError) {
+ QByteArray data = m_reply->readAll();
+
+ QString code = QString::fromUtf8(data);
+ QDeclarativeScriptParser::extractPragmas(code);
+
+ QDeclarativeContextData *importContext = new QDeclarativeContextData;
+ importContext->isInternal = true;
+ importContext->isJSContext = true;
+ importContext->url = m_url;
+ importContext->isPragmaLibraryContext = m_context->isPragmaLibraryContext;
+ importContext->setParent(m_context, true);
+
+ v8::Context::Scope ctxtscope(m_engine->context());
+ v8::TryCatch try_catch;
+
+ v8::Local<v8::Script> script = m_engine->qmlModeCompile(code, m_url.toString());
+
+ if (!try_catch.HasCaught()) {
+ m_engine->contextWrapper()->addSubContext(m_qmlglobal, script, importContext);
+ script->Run(m_qmlglobal);
+ }
+
+ if (try_catch.HasCaught()) {
+ m_resultObject->Set(v8::String::New("status"), v8::Integer::New(Exception));
+ m_resultObject->Set(v8::String::New("exception"), try_catch.Exception());
+ } else {
+ m_resultObject->Set(v8::String::New("status"), v8::Integer::New(Ok));
+ }
+ } else {
+ m_resultObject->Set(v8::String::New("status"), v8::Integer::New(NetworkError));
+ }
+
+ callback(m_engine, m_callbackFunction, m_resultObject);
+
+ disconnect();
+ deleteLater();
+}
+
+/*
+ Documented in qv8engine.cpp
+*/
+v8::Handle<v8::Value> QV8Include::include(const v8::Arguments &args)
+{
+ if (args.Length() == 0)
+ return v8::Undefined();
+
+ QV8Engine *engine = V8ENGINE();
+ QDeclarativeContextData *context = engine->callingContext();
+
+ if (!context || !context->isJSContext)
+ V8THROW_ERROR("Qt.include(): Can only be called from JavaScript files");
+
+ QUrl url(context->resolvedUrl(QUrl(engine->toString(args[0]->ToString()))));
+
+ v8::Local<v8::Function> callbackFunction;
+ if (args.Length() >= 2 && args[1]->IsFunction())
+ callbackFunction = v8::Local<v8::Function>::Cast(args[1]);
+
+ QString localFile = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
+
+ v8::Local<v8::Object> result;
+
+ if (localFile.isEmpty()) {
+
+ QV8Include *i = new QV8Include(url, engine, context,
+ v8::Context::GetCallingQmlGlobal(),
+ callbackFunction);
+ result = v8::Local<v8::Object>::New(i->result());
+
+ } else {
+
+ QFile f(localFile);
+
+ if (f.open(QIODevice::ReadOnly)) {
+ QByteArray data = f.readAll();
+ QString code = QString::fromUtf8(data);
+ QDeclarativeScriptParser::extractPragmas(code);
+
+ QDeclarativeContextData *importContext = new QDeclarativeContextData;
+ importContext->isInternal = true;
+ importContext->isJSContext = true;
+ importContext->url = url;
+ importContext->setParent(context, true);
+
+ v8::TryCatch try_catch;
+
+ v8::Local<v8::Script> script = engine->qmlModeCompile(code, url.toString());
+
+ if (!try_catch.HasCaught()) {
+ v8::Local<v8::Object> qmlglobal = v8::Context::GetCallingQmlGlobal();
+ engine->contextWrapper()->addSubContext(qmlglobal, script, importContext);
+ script->Run(qmlglobal);
+ }
+
+ if (try_catch.HasCaught()) {
+ result = resultValue(Exception);
+ result->Set(v8::String::New("exception"), try_catch.Exception());
+ } else {
+ result = resultValue(Ok);
+ }
+
+ } else {
+ result = resultValue(NetworkError);
+ }
+
+ callback(engine, callbackFunction, result);
+ }
+
+ if (result.IsEmpty())
+ return v8::Undefined();
+ else
+ return result;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeinclude_p.h b/src/declarative/qml/v8/qv8include_p.h
index e923d39d43..eb5c2a0103 100644
--- a/src/declarative/qml/qdeclarativeinclude_p.h
+++ b/src/declarative/qml/v8/qv8include_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QDECLARATIVEINCLUDE_P_H
-#define QDECLARATIVEINCLUDE_P_H
+#ifndef QV8INCLUDE_P_H
+#define QV8INCLUDE_P_H
//
// W A R N I N G
@@ -55,19 +55,19 @@
#include <QtCore/qobject.h>
#include <QtCore/qurl.h>
-#include <QtScript/qscriptvalue.h>
#include <private/qdeclarativecontext_p.h>
#include <private/qdeclarativeguard_p.h>
+#include <private/qv8_p.h>
+
QT_BEGIN_NAMESPACE
class QDeclarativeEngine;
-class QScriptContext;
-class QScriptEngine;
class QNetworkAccessManager;
class QNetworkReply;
-class QDeclarativeInclude : public QObject
+class QV8Engine;
+class QV8Include : public QObject
{
Q_OBJECT
public:
@@ -78,38 +78,36 @@ public:
Exception = 3
};
- QDeclarativeInclude(const QUrl &, QDeclarativeEngine *, QScriptContext *ctxt);
- ~QDeclarativeInclude();
-
- void setCallback(const QScriptValue &);
- QScriptValue callback() const;
+ static v8::Handle<v8::Value> include(const v8::Arguments &args);
- QScriptValue result() const;
+private slots:
+ void finished();
- static QScriptValue resultValue(QScriptEngine *, Status status = Loading);
- static void callback(QScriptEngine *, QScriptValue &callback, QScriptValue &status);
+private:
+ QV8Include(const QUrl &, QV8Engine *, QDeclarativeContextData *,
+ v8::Handle<v8::Object>, v8::Handle<v8::Function>);
+ ~QV8Include();
- static QScriptValue include(QScriptContext *ctxt, QScriptEngine *engine);
- static QScriptValue worker_include(QScriptContext *ctxt, QScriptEngine *engine);
+ v8::Handle<v8::Object> result();
-public slots:
- void finished();
+ static v8::Local<v8::Object> resultValue(Status status = Loading);
+ static void callback(QV8Engine *engine, v8::Handle<v8::Function> callback, v8::Handle<v8::Object> status);
-private:
- QDeclarativeEngine *m_engine;
- QScriptEngine *m_scriptEngine;
+ QV8Engine *m_engine;
QNetworkAccessManager *m_network;
QDeclarativeGuard<QNetworkReply> m_reply;
QUrl m_url;
int m_redirectCount;
- QScriptValue m_callback;
- QScriptValue m_result;
+
+ v8::Persistent<v8::Function> m_callbackFunction;
+ v8::Persistent<v8::Object> m_resultObject;
+
QDeclarativeGuardedContextData m_context;
- QScriptValue m_scope[2];
+ v8::Persistent<v8::Object> m_qmlglobal;
};
QT_END_NAMESPACE
-#endif // QDECLARATIVEINCLUDE_P_H
+#endif // QV8INCLUDE_P_H
diff --git a/src/declarative/qml/v8/qv8listwrapper.cpp b/src/declarative/qml/v8/qv8listwrapper.cpp
new file mode 100644
index 0000000000..5f2d9fb91e
--- /dev/null
+++ b/src/declarative/qml/v8/qv8listwrapper.cpp
@@ -0,0 +1,178 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8listwrapper_p.h"
+#include "qv8engine_p.h"
+#include <private/qdeclarativelist_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8ListResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(ListType);
+public:
+ QV8ListResource(QV8Engine *engine) : QV8ObjectResource(engine) {}
+
+ QDeclarativeGuard<QObject> object;
+ QDeclarativeListProperty<QObject> property;
+ int propertyType;
+};
+
+QV8ListWrapper::QV8ListWrapper()
+: m_engine(0)
+{
+}
+
+QV8ListWrapper::~QV8ListWrapper()
+{
+}
+
+void QV8ListWrapper::init(QV8Engine *engine)
+{
+ m_engine = engine;
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetIndexedPropertyHandler(IndexedGetter);
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("length"), LengthGetter, 0,
+ v8::Handle<v8::Value>(), v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+}
+
+void QV8ListWrapper::destroy()
+{
+ qPersistentDispose(m_constructor);
+}
+
+v8::Handle<v8::Value> QV8ListWrapper::newList(QObject *object, int propId, int propType)
+{
+ if (!object || propId == -1)
+ return v8::Null();
+
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8ListResource *r = new QV8ListResource(m_engine);
+ r->object = object;
+ r->propertyType = propType;
+ void *args[] = { &r->property, 0 };
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args);
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+v8::Handle<v8::Value> QV8ListWrapper::newList(const QDeclarativeListProperty<QObject> &prop, int propType)
+{
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8ListResource *r = new QV8ListResource(m_engine);
+ r->object = prop.object;
+ r->property = prop;
+ r->propertyType = propType;
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+QVariant QV8ListWrapper::toVariant(v8::Handle<v8::Object> obj)
+{
+ QV8ListResource *resource = v8_resource_cast<QV8ListResource>(obj);
+ if (resource) return toVariant(resource);
+ else return QVariant();
+}
+
+QVariant QV8ListWrapper::toVariant(QV8ObjectResource *r)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::ListType);
+ QV8ListResource *resource = static_cast<QV8ListResource *>(r);
+
+ if (!resource->object)
+ return QVariant();
+
+ return QVariant::fromValue(QDeclarativeListReferencePrivate::init(resource->property, resource->propertyType,
+ m_engine->engine()));
+}
+
+v8::Handle<v8::Value> QV8ListWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ Q_UNUSED(info);
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8ListWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ Q_UNUSED(info);
+ return value;
+}
+
+v8::Handle<v8::Value> QV8ListWrapper::IndexedGetter(uint32_t index, const v8::AccessorInfo &info)
+{
+ QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This());
+
+ if (!resource || resource->object.isNull()) return v8::Undefined();
+
+ quint32 count = resource->property.count?resource->property.count(&resource->property):0;
+ if (index < count && resource->property.at) {
+ return resource->engine->newQObject(resource->property.at(&resource->property, index));
+ } else {
+ return v8::Undefined();
+ }
+}
+
+v8::Handle<v8::Value> QV8ListWrapper::LengthGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+
+ QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This());
+
+ if (!resource || resource->object.isNull()) return v8::Undefined();
+
+ quint32 count = resource->property.count?resource->property.count(&resource->property):0;
+
+ return v8::Integer::NewFromUnsigned(count);
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8listwrapper_p.h b/src/declarative/qml/v8/qv8listwrapper_p.h
new file mode 100644
index 0000000000..82fdaa7271
--- /dev/null
+++ b/src/declarative/qml/v8/qv8listwrapper_p.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8LISTWRAPPER_P_H
+#define QV8LISTWRAPPER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtDeclarative/qdeclarativelist.h>
+#include <private/qv8_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8Engine;
+class QV8ObjectResource;
+class QV8ListWrapper
+{
+public:
+ QV8ListWrapper();
+ ~QV8ListWrapper();
+
+ void init(QV8Engine *);
+ void destroy();
+
+ v8::Handle<v8::Value> newList(QObject *, int, int);
+ v8::Handle<v8::Value> newList(const QDeclarativeListProperty<QObject> &, int);
+ QVariant toVariant(v8::Handle<v8::Object>);
+ QVariant toVariant(QV8ObjectResource *);
+
+private:
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> IndexedGetter(uint32_t index,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> LengthGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+
+ QV8Engine *m_engine;
+ v8::Persistent<v8::Function> m_constructor;
+};
+
+QT_END_NAMESPACE
+
+#endif // QV8LISTWRAPPER_P_H
+
diff --git a/src/declarative/qml/v8/qv8qobjectwrapper.cpp b/src/declarative/qml/v8/qv8qobjectwrapper.cpp
new file mode 100644
index 0000000000..e59df8dc53
--- /dev/null
+++ b/src/declarative/qml/v8/qv8qobjectwrapper.cpp
@@ -0,0 +1,1989 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8qobjectwrapper_p.h"
+#include "qv8contextwrapper_p.h"
+#include "qv8engine_p.h"
+
+#include <private/qdeclarativeguard_p.h>
+#include <private/qdeclarativepropertycache_p.h>
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativevmemetaobject_p.h>
+#include <private/qdeclarativebinding_p.h>
+
+#include <QtScript/qscriptvalue.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qatomic.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_METATYPE(QScriptValue);
+Q_DECLARE_METATYPE(QDeclarativeV8Handle);
+
+#if defined(__GNUC__)
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
+// The code in this file does not violate strict aliasing, but GCC thinks it does
+// so turn off the warnings for us to have a clean build
+# pragma GCC diagnostic ignored "-Wstrict-aliasing"
+# endif
+#endif
+
+#define QOBJECT_TOSTRING_INDEX -2
+#define QOBJECT_DESTROY_INDEX -3
+
+// XXX TODO: Need to review all calls to QDeclarativeEngine *engine() to confirm QObjects work
+// correctly in a worker thread
+
+class QV8QObjectResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(QObjectType);
+
+public:
+ QV8QObjectResource(QV8Engine *engine, QObject *object);
+
+ QDeclarativeGuard<QObject> object;
+};
+
+class QV8QObjectInstance : public QDeclarativeGuard<QObject>
+{
+public:
+ QV8QObjectInstance(QObject *o, QV8QObjectWrapper *w)
+ : QDeclarativeGuard<QObject>(o), wrapper(w)
+ {
+ }
+
+ ~QV8QObjectInstance()
+ {
+ qPersistentDispose(v8object);
+ }
+
+ virtual void objectDestroyed(QObject *o)
+ {
+ if (wrapper)
+ wrapper->m_taintedObjects.remove(o);
+ delete this;
+ }
+
+ v8::Persistent<v8::Object> v8object;
+ QV8QObjectWrapper *wrapper;
+};
+
+namespace {
+struct MetaCallArgument {
+ inline MetaCallArgument();
+ inline ~MetaCallArgument();
+ inline void *dataPtr();
+
+ inline void initAsType(int type);
+ inline void fromValue(int type, QV8Engine *, v8::Handle<v8::Value>);
+ inline v8::Handle<v8::Value> toValue(QV8Engine *);
+
+private:
+ MetaCallArgument(const MetaCallArgument &);
+
+ inline void cleanup();
+
+ char data[4 * sizeof(void *)];
+ int type;
+ bool isObjectType;
+};
+}
+
+QV8QObjectResource::QV8QObjectResource(QV8Engine *engine, QObject *object)
+: QV8ObjectResource(engine), object(object)
+{
+}
+
+static QAtomicInt objectIdCounter(1);
+
+QV8QObjectWrapper::QV8QObjectWrapper()
+: m_engine(0), m_id(objectIdCounter.fetchAndAddOrdered(1))
+{
+}
+
+QV8QObjectWrapper::~QV8QObjectWrapper()
+{
+ for (TaintedHash::Iterator iter = m_taintedObjects.begin();
+ iter != m_taintedObjects.end();
+ ++iter) {
+ (*iter)->wrapper = 0;
+ }
+ m_taintedObjects.clear();
+}
+
+void QV8QObjectWrapper::destroy()
+{
+ qDeleteAll(m_connections);
+ m_connections.clear();
+
+ qPersistentDispose(m_hiddenObject);
+ qPersistentDispose(m_destroySymbol);
+ qPersistentDispose(m_toStringSymbol);
+ qPersistentDispose(m_methodConstructor);
+ qPersistentDispose(m_constructor);
+}
+
+#define FAST_VALUE_GETTER(name, cpptype, defaultvalue, constructor) \
+static v8::Handle<v8::Value> name ## ValueGetter(v8::Local<v8::String>, const v8::AccessorInfo &info) \
+{ \
+ v8::Handle<v8::Object> This = info.This(); \
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(This); \
+ \
+ if (resource->object.isNull()) return v8::Undefined(); \
+ \
+ QObject *object = resource->object; \
+ \
+ uint32_t data = info.Data()->Uint32Value(); \
+ int index = data & 0x7FFF; \
+ int notify = (data & 0x0FFF0000) >> 16; \
+ if (notify == 0x0FFF) notify = -1; \
+ \
+ QDeclarativeEnginePrivate *ep = resource->engine->engine()?QDeclarativeEnginePrivate::get(resource->engine->engine()):0; \
+ if (ep && notify /* 0 means constant */ && ep->captureProperties) { \
+ typedef QDeclarativeEnginePrivate::CapturedProperty CapturedProperty; \
+ ep->capturedProperties << CapturedProperty(object, index, notify); \
+ } \
+ \
+ cpptype value = defaultvalue; \
+ void *args[] = { &value, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, index, args); \
+ \
+ return constructor(value); \
+} \
+static v8::Handle<v8::Value> name ## ValueGetterDirect(v8::Local<v8::String>, const v8::AccessorInfo &info) \
+{ \
+ v8::Handle<v8::Object> This = info.This(); \
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(This); \
+ \
+ if (resource->object.isNull()) return v8::Undefined(); \
+ \
+ QObject *object = resource->object; \
+ \
+ uint32_t data = info.Data()->Uint32Value(); \
+ int index = data & 0x7FFF; \
+ int notify = (data & 0x0FFF0000) >> 16; \
+ if (notify == 0x0FFF) notify = -1; \
+ \
+ QDeclarativeEnginePrivate *ep = resource->engine->engine()?QDeclarativeEnginePrivate::get(resource->engine->engine()):0; \
+ if (ep && notify /* 0 means constant */ && ep->captureProperties) { \
+ typedef QDeclarativeEnginePrivate::CapturedProperty CapturedProperty; \
+ ep->capturedProperties << CapturedProperty(object, index, notify); \
+ } \
+ \
+ cpptype value = defaultvalue; \
+ void *args[] = { &value, 0 }; \
+ object->qt_metacall(QMetaObject::ReadProperty, index, args); \
+ \
+ return constructor(value); \
+}
+
+#define CREATE_FUNCTION \
+ "(function(method) { "\
+ "return (function(object, data, qmlglobal) { "\
+ "return (function() { "\
+ "return method(object, data, qmlglobal, arguments.length, arguments); "\
+ "});"\
+ "});"\
+ "})"
+
+
+static quint32 toStringHash = -1;
+static quint32 destroyHash = -1;
+
+void QV8QObjectWrapper::init(QV8Engine *engine)
+{
+ m_engine = engine;
+
+ m_toStringSymbol = qPersistentNew<v8::String>(v8::String::NewSymbol("toString"));
+ m_destroySymbol = qPersistentNew<v8::String>(v8::String::NewSymbol("destroy"));
+ m_hiddenObject = qPersistentNew<v8::Object>(v8::Object::New());
+
+ m_toStringString = QHashedV8String(m_toStringSymbol);
+ m_destroyString = QHashedV8String(m_destroySymbol);
+
+ toStringHash = m_toStringString.hash();
+ destroyHash = m_destroyString.hash();
+
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter, Query, 0, Enumerator);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+ {
+ v8::ScriptOrigin origin(m_hiddenObject); // Hack to allow us to identify these functions
+ v8::Local<v8::Script> script = v8::Script::New(v8::String::New(CREATE_FUNCTION), &origin);
+ v8::Local<v8::Function> fn = v8::Local<v8::Function>::Cast(script->Run());
+ v8::Handle<v8::Value> invokeFn = v8::FunctionTemplate::New(Invoke)->GetFunction();
+ v8::Handle<v8::Value> args[] = { invokeFn };
+ v8::Local<v8::Function> createFn = v8::Local<v8::Function>::Cast(fn->Call(engine->global(), 1, args));
+ m_methodConstructor = qPersistentNew<v8::Function>(createFn);
+ }
+
+ {
+ v8::Local<v8::Object> prototype = engine->global()->Get(v8::String::New("Function"))->ToObject()->Get(v8::String::New("prototype"))->ToObject();
+ prototype->Set(v8::String::New("connect"), V8FUNCTION(Connect, engine));
+ prototype->Set(v8::String::New("disconnect"), V8FUNCTION(Disconnect, engine));
+ }
+}
+
+bool QV8QObjectWrapper::isQObject(v8::Handle<v8::Object> obj)
+{
+ return v8_resource_cast<QV8QObjectResource>(obj) != 0;
+}
+
+QObject *QV8QObjectWrapper::toQObject(v8::Handle<v8::Object> obj)
+{
+ QV8QObjectResource *r = v8_resource_cast<QV8QObjectResource>(obj);
+ return r?r->object:0;
+}
+
+// r *MUST* be a QV8ObjectResource (r->type() == QV8ObjectResource::QObjectType)
+QObject *QV8QObjectWrapper::QV8QObjectWrapper::toQObject(QV8ObjectResource *r)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::QObjectType);
+ return static_cast<QV8QObjectResource *>(r)->object;
+}
+
+// Load value properties
+static v8::Handle<v8::Value> LoadProperty(QV8Engine *engine, QObject *object,
+ const QDeclarativePropertyCache::Data &property)
+{
+ Q_ASSERT(!property.isFunction());
+
+#define PROPERTY_LOAD(metatype, cpptype, constructor) \
+ if (property.propType == QMetaType:: metatype) { \
+ cpptype type = cpptype(); \
+ void *args[] = { &type, 0 }; \
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, property.coreIndex, args); \
+ return constructor(type); \
+ }
+
+ if (property.isQObject()) {
+ QObject *rv = 0;
+ void *args[] = { &rv, 0 };
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, property.coreIndex, args);
+ return engine->newQObject(rv);
+ } else if (property.isQList()) {
+ return engine->listWrapper()->newList(object, property.coreIndex, property.propType);
+ } else PROPERTY_LOAD(QReal, qreal, v8::Number::New)
+ else PROPERTY_LOAD(Int || property.isEnum(), int, v8::Integer::New)
+ else PROPERTY_LOAD(Bool, bool, v8::Boolean::New)
+ else PROPERTY_LOAD(QString, QString, engine->toString)
+ else PROPERTY_LOAD(UInt, uint, v8::Integer::NewFromUnsigned)
+ else PROPERTY_LOAD(Float, float, v8::Number::New)
+ else PROPERTY_LOAD(Double, double, v8::Number::New)
+ else if(property.isV8Handle()) {
+ QDeclarativeV8Handle handle;
+ void *args[] = { &handle, 0 };
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, property.coreIndex, args);
+ return reinterpret_cast<v8::Handle<v8::Value> &>(handle);
+ } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) {
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
+ QDeclarativeValueType *valueType = ep->valueTypes[property.propType];
+ if (valueType)
+ return engine->newValueType(object, property.coreIndex, valueType);
+ }
+
+ QVariant var = object->metaObject()->property(property.coreIndex).read(object);
+ return engine->fromVariant(var);
+
+#undef PROPERTY_LOAD
+}
+
+static v8::Handle<v8::Value> LoadPropertyDirect(QV8Engine *engine, QObject *object,
+ const QDeclarativePropertyCache::Data &property)
+{
+ Q_ASSERT(!property.isFunction());
+
+#define PROPERTY_LOAD(metatype, cpptype, constructor) \
+ if (property.propType == QMetaType:: metatype) { \
+ cpptype type = cpptype(); \
+ void *args[] = { &type, 0 }; \
+ object->qt_metacall(QMetaObject::ReadProperty, property.coreIndex, args); \
+ return constructor(type); \
+ }
+
+ if (property.isQObject()) {
+ QObject *rv = 0;
+ void *args[] = { &rv, 0 };
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, property.coreIndex, args);
+ return engine->newQObject(rv);
+ } else if (property.isQList()) {
+ return engine->listWrapper()->newList(object, property.coreIndex, property.propType);
+ } else PROPERTY_LOAD(QReal, qreal, v8::Number::New)
+ else PROPERTY_LOAD(Int || property.isEnum(), int, v8::Integer::New)
+ else PROPERTY_LOAD(Bool, bool, v8::Boolean::New)
+ else PROPERTY_LOAD(QString, QString, engine->toString)
+ else PROPERTY_LOAD(UInt, uint, v8::Integer::NewFromUnsigned)
+ else PROPERTY_LOAD(Float, float, v8::Number::New)
+ else PROPERTY_LOAD(Double, double, v8::Number::New)
+ else if(property.isV8Handle()) {
+ QDeclarativeV8Handle handle;
+ void *args[] = { &handle, 0 };
+ object->qt_metacall(QMetaObject::ReadProperty, property.coreIndex, args);
+ return reinterpret_cast<v8::Handle<v8::Value> &>(handle);
+ } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) {
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
+ QDeclarativeValueType *valueType = ep->valueTypes[property.propType];
+ if (valueType)
+ return engine->newValueType(object, property.coreIndex, valueType);
+ }
+
+ QVariant var = object->metaObject()->property(property.coreIndex).read(object);
+ return engine->fromVariant(var);
+
+#undef PROPERTY_LOAD
+}
+
+v8::Handle<v8::Value> QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject *object,
+ v8::Handle<v8::Value> *objectHandle,
+ const QHashedV8String &property,
+ QV8QObjectWrapper::RevisionMode revisionMode)
+{
+ // XXX More recent versions of V8 introduced "Callable" objects. It is possible that these
+ // will be a faster way of creating QObject method objects.
+ struct MethodClosure {
+ static v8::Handle<v8::Value> create(QV8Engine *engine, QObject *object,
+ v8::Handle<v8::Value> *objectHandle,
+ int index) {
+ v8::Handle<v8::Value> argv[] = {
+ objectHandle?*objectHandle:engine->newQObject(object),
+ v8::Integer::New(index)
+ };
+ return engine->qobjectWrapper()->m_methodConstructor->Call(engine->global(), 2, argv);
+ }
+ static v8::Handle<v8::Value> createWithGlobal(QV8Engine *engine, QObject *object,
+ v8::Handle<v8::Value> *objectHandle,
+ int index) {
+ v8::Handle<v8::Value> argv[] = {
+ objectHandle?*objectHandle:engine->newQObject(object),
+ v8::Integer::New(index),
+ v8::Context::GetCallingQmlGlobal()
+ };
+ return engine->qobjectWrapper()->m_methodConstructor->Call(engine->global(), 3, argv);
+ }
+ };
+
+ {
+ // Comparing the hash first actually makes a measurable difference here, at least on x86
+ quint32 hash = property.hash();
+ if (hash == toStringHash && engine->qobjectWrapper()->m_toStringString == property) {
+ return MethodClosure::create(engine, object, objectHandle, QOBJECT_TOSTRING_INDEX);
+ } else if (hash == destroyHash && engine->qobjectWrapper()->m_destroyString == property) {
+ return MethodClosure::create(engine, object, objectHandle, QOBJECT_DESTROY_INDEX);
+ }
+ }
+
+ QDeclarativePropertyCache::Data local;
+ QDeclarativePropertyCache::Data *result = 0;
+ {
+ QDeclarativeData *ddata = QDeclarativeData::get(object, false);
+ if (ddata && ddata->propertyCache)
+ result = ddata->propertyCache->property(property);
+ else
+ result = QDeclarativePropertyCache::property(engine->engine(), object, property, local);
+ }
+
+ if (!result)
+ return v8::Handle<v8::Value>();
+
+ if (revisionMode == QV8QObjectWrapper::CheckRevision && result->revision != 0) {
+ QDeclarativeData *ddata = QDeclarativeData::get(object);
+ if (ddata && ddata->propertyCache && !ddata->propertyCache->isAllowedInRevision(result))
+ return v8::Handle<v8::Value>();
+ }
+
+ typedef QDeclarativeEnginePrivate::CapturedProperty CapturedProperty;
+
+ if (result->isFunction()) {
+ if (result->isVMEFunction()) {
+ return ((QDeclarativeVMEMetaObject *)(object->metaObject()))->vmeMethod(result->coreIndex);
+ } else if (result->isV8Function()) {
+ return MethodClosure::createWithGlobal(engine, object, objectHandle, result->coreIndex);
+ } else {
+ return MethodClosure::create(engine, object, objectHandle, result->coreIndex);
+ }
+ }
+
+ QDeclarativeEnginePrivate *ep = engine->engine()?QDeclarativeEnginePrivate::get(engine->engine()):0;
+ if (ep && ep->captureProperties && !result->isConstant()) {
+ if (result->coreIndex == 0)
+ ep->capturedProperties << CapturedProperty(QDeclarativeData::get(object, true)->objectNameNotifier());
+ else
+ ep->capturedProperties << CapturedProperty(object, result->coreIndex, result->notifyIndex);
+ }
+
+ if (result->isDirect()) {
+ return LoadPropertyDirect(engine, object, *result);
+ } else {
+ return LoadProperty(engine, object, *result);
+ }
+}
+
+// Setter for writable properties. Shared between the interceptor and fast property accessor
+static inline void StoreProperty(QV8Engine *engine, QObject *object, QDeclarativePropertyCache::Data *property,
+ v8::Handle<v8::Value> value)
+{
+ QDeclarativeBinding *newBinding = 0;
+
+ if (value->IsFunction()) {
+ QDeclarativeContextData *context = engine->callingContext();
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value);
+
+ v8::Local<v8::StackTrace> trace =
+ v8::StackTrace::CurrentStackTrace(1, (v8::StackTrace::StackTraceOptions)(v8::StackTrace::kLineNumber |
+ v8::StackTrace::kScriptName));
+ v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
+ int lineNumber = frame->GetLineNumber();
+ QString url = engine->toString(frame->GetScriptName());
+
+ QDeclarativePropertyCache::ValueTypeData valueTypeData;
+ newBinding = new QDeclarativeBinding(&function, object, context);
+ newBinding->setSourceLocation(url, lineNumber);
+ newBinding->setTarget(QDeclarativePropertyPrivate::restore(*property, valueTypeData, object, context));
+ newBinding->setEvaluateFlags(newBinding->evaluateFlags() | QDeclarativeBinding::RequiresThisObject);
+ }
+
+ QDeclarativeAbstractBinding *oldBinding =
+ QDeclarativePropertyPrivate::setBinding(object, property->coreIndex, -1, newBinding);
+ if (oldBinding)
+ oldBinding->destroy();
+
+#define PROPERTY_STORE(cpptype, value) \
+ cpptype o = value; \
+ int status = -1; \
+ int flags = 0; \
+ void *argv[] = { &o, 0, &status, &flags }; \
+ QMetaObject::metacall(object, QMetaObject::WriteProperty, property->coreIndex, argv);
+
+
+ if (value->IsNull() && property->isQObject()) {
+ PROPERTY_STORE(QObject*, 0);
+ } else if (value->IsUndefined() && property->isResettable()) {
+ void *a[] = { 0 };
+ QMetaObject::metacall(object, QMetaObject::ResetProperty, property->coreIndex, a);
+ } else if (value->IsUndefined() && property->propType == qMetaTypeId<QVariant>()) {
+ PROPERTY_STORE(QVariant, QVariant());
+ } else if (value->IsUndefined()) {
+ QString error = QLatin1String("Cannot assign [undefined] to ") +
+ QLatin1String(QMetaType::typeName(property->propType));
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ } else if (value->IsFunction()) {
+ // this is handled by the binding creation above
+ } else if (property->propType == QMetaType::Int && value->IsNumber()) {
+ PROPERTY_STORE(int, qRound(value->ToNumber()->Value()));
+ } else if (property->propType == QMetaType::QReal && value->IsNumber()) {
+ PROPERTY_STORE(qreal, qreal(value->ToNumber()->Value()));
+ } else if (property->propType == QMetaType::Float && value->IsNumber()) {
+ PROPERTY_STORE(float, float(value->ToNumber()->Value()));
+ } else if (property->propType == QMetaType::Double && value->IsNumber()) {
+ PROPERTY_STORE(double, double(value->ToNumber()->Value()));
+ } else if (property->propType == QMetaType::QString && value->IsString()) {
+ PROPERTY_STORE(QString, engine->toString(value->ToString()));
+ } else {
+ QVariant v;
+ if (property->isQList())
+ v = engine->toVariant(value, qMetaTypeId<QList<QObject *> >());
+ else
+ v = engine->toVariant(value, property->propType);
+
+ QDeclarativeContextData *context = engine->callingContext();
+
+ if (!QDeclarativePropertyPrivate::write(object, *property, v, context)) {
+ const char *valueType = 0;
+ if (v.userType() == QVariant::Invalid) valueType = "null";
+ else valueType = QMetaType::typeName(v.userType());
+
+ QString error = QLatin1String("Cannot assign ") +
+ QLatin1String(valueType) +
+ QLatin1String(" to ") +
+ QLatin1String(QMetaType::typeName(property->propType));
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ }
+ }
+}
+
+bool QV8QObjectWrapper::SetProperty(QV8Engine *engine, QObject *object, const QHashedV8String &property,
+ v8::Handle<v8::Value> value, QV8QObjectWrapper::RevisionMode revisionMode)
+{
+ if (engine->qobjectWrapper()->m_toStringString == property ||
+ engine->qobjectWrapper()->m_destroyString == property)
+ return true;
+
+ QDeclarativePropertyCache::Data local;
+ QDeclarativePropertyCache::Data *result = 0;
+ result = QDeclarativePropertyCache::property(engine->engine(), object, property, local);
+
+ if (!result)
+ return false;
+
+ if (revisionMode == QV8QObjectWrapper::CheckRevision && result->revision != 0) {
+ QDeclarativeData *ddata = QDeclarativeData::get(object);
+ if (ddata && ddata->propertyCache && !ddata->propertyCache->isAllowedInRevision(result))
+ return false;
+ }
+
+ if (!result->isWritable() && !result->isQList()) {
+ QString error = QLatin1String("Cannot assign to read-only property \"") +
+ engine->toString(property.string()) + QLatin1Char('\"');
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ return true;
+ }
+
+ StoreProperty(engine, object, result, value);
+
+ return true;
+}
+
+v8::Handle<v8::Value> QV8QObjectWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
+
+ if (resource->object.isNull())
+ return v8::Undefined();
+
+ QObject *object = resource->object;
+
+ QHashedV8String propertystring(property);
+
+ QV8Engine *v8engine = resource->engine;
+ v8::Handle<v8::Value> This = info.This();
+ v8::Handle<v8::Value> result = GetProperty(v8engine, object, &This, propertystring,
+ QV8QObjectWrapper::IgnoreRevision);
+ if (!result.IsEmpty())
+ return result;
+
+ if (QV8Engine::startsWithUpper(property)) {
+ // Check for attached properties
+ QDeclarativeContextData *context = v8engine->callingContext();
+ QDeclarativeTypeNameCache::Data *data =
+ context && (context->imports)?context->imports->data(propertystring):0;
+
+ if (data) {
+ if (data->type) {
+ return v8engine->typeWrapper()->newObject(object, data->type, QV8TypeWrapper::ExcludeEnums);
+ } else if (data->typeNamespace) {
+ return v8engine->typeWrapper()->newObject(object, data->typeNamespace, QV8TypeWrapper::ExcludeEnums);
+ }
+ }
+ }
+
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8QObjectWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
+
+ if (resource->object.isNull())
+ return value;
+
+ QObject *object = resource->object;
+
+ QHashedV8String propertystring(property);
+
+ QV8Engine *v8engine = resource->engine;
+ bool result = SetProperty(v8engine, object, propertystring, value, QV8QObjectWrapper::IgnoreRevision);
+
+ if (!result) {
+ QString error = QLatin1String("Cannot assign to non-existent property \"") +
+ v8engine->toString(property) + QLatin1Char('\"');
+ v8::ThrowException(v8::Exception::Error(v8engine->toString(error)));
+ return value;
+ }
+
+ return value;
+}
+
+v8::Handle<v8::Integer> QV8QObjectWrapper::Query(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
+
+ if (resource->object.isNull())
+ return v8::Handle<v8::Integer>();
+
+ QV8Engine *engine = resource->engine;
+ QObject *object = resource->object;
+
+ QHashedV8String propertystring(property);
+
+ QDeclarativePropertyCache::Data local;
+ QDeclarativePropertyCache::Data *result = 0;
+ result = QDeclarativePropertyCache::property(engine->engine(), object, propertystring, local);
+
+ if (!result)
+ return v8::Handle<v8::Integer>();
+ else if (!result->isWritable() && !result->isQList())
+ return v8::Integer::New(v8::ReadOnly | v8::DontDelete);
+ else
+ return v8::Integer::New(v8::DontDelete);
+}
+
+v8::Handle<v8::Array> QV8QObjectWrapper::Enumerator(const v8::AccessorInfo &info)
+{
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
+
+ if (resource->object.isNull())
+ return v8::Array::New();
+
+ QObject *object = resource->object;
+
+ QStringList result;
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(resource->engine->engine());
+
+ QDeclarativePropertyCache *cache = 0;
+ QDeclarativeData *ddata = QDeclarativeData::get(object);
+ if (ddata)
+ cache = ddata->propertyCache;
+
+ if (!cache) {
+ cache = ep->cache(object);
+ if (cache) {
+ if (ddata) { cache->addref(); ddata->propertyCache = cache; }
+ } else {
+ // Not cachable - fall back to QMetaObject (eg. dynamic meta object)
+ const QMetaObject *mo = object->metaObject();
+ int pc = mo->propertyCount();
+ int po = mo->propertyOffset();
+ for (int i=po; i<pc; ++i)
+ result << QString::fromUtf8(mo->property(i).name());
+ }
+ } else {
+ result = cache->propertyNames();
+ }
+
+ v8::Local<v8::Array> rv = v8::Array::New(result.count());
+
+ for (int ii = 0; ii < result.count(); ++ii)
+ rv->Set(ii, resource->engine->toString(result.at(ii)));
+
+ return rv;
+}
+
+FAST_VALUE_GETTER(QObject, QObject*, 0, resource->engine->newQObject);
+FAST_VALUE_GETTER(Int, int, 0, v8::Integer::New);
+FAST_VALUE_GETTER(Bool, bool, false, v8::Boolean::New);
+FAST_VALUE_GETTER(QString, QString, QString(), resource->engine->toString);
+FAST_VALUE_GETTER(UInt, uint, 0, v8::Integer::NewFromUnsigned);
+FAST_VALUE_GETTER(Float, float, 0, v8::Number::New);
+FAST_VALUE_GETTER(Double, double, 0, v8::Number::New);
+
+static void FastValueSetter(v8::Local<v8::String>, v8::Local<v8::Value> value,
+ const v8::AccessorInfo& info)
+{
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
+
+ if (resource->object.isNull())
+ return;
+
+ QObject *object = resource->object;
+
+ uint32_t data = info.Data()->Uint32Value();
+ int index = data & 0x7FFF; // So that we can use the same data for Setter and Getter
+
+ QDeclarativeData *ddata = QDeclarativeData::get(object, false);
+ Q_ASSERT(ddata);
+ Q_ASSERT(ddata->propertyCache);
+
+ QDeclarativePropertyCache::Data *pdata = ddata->propertyCache->property(index);
+ Q_ASSERT(pdata);
+
+ Q_ASSERT(pdata->isWritable() || pdata->isQList());
+
+ StoreProperty(resource->engine, object, pdata, value);
+}
+
+static void FastValueSetterReadOnly(v8::Local<v8::String> property, v8::Local<v8::Value>,
+ const v8::AccessorInfo& info)
+{
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(info.This());
+
+ if (resource->object.isNull())
+ return;
+
+ QV8Engine *v8engine = resource->engine;
+
+ QString error = QLatin1String("Cannot assign to read-only property \"") +
+ v8engine->toString(property) + QLatin1Char('\"');
+ v8::ThrowException(v8::Exception::Error(v8engine->toString(error)));
+}
+
+static void WeakQObjectReferenceCallback(v8::Persistent<v8::Value> handle, void *)
+{
+ Q_ASSERT(handle->IsObject());
+
+ QV8QObjectResource *resource = v8_resource_check<QV8QObjectResource>(handle->ToObject());
+
+ Q_ASSERT(resource);
+
+ QObject *object = resource->object;
+ if (object) {
+ QDeclarativeData *ddata = QDeclarativeData::get(object, false);
+ if (ddata) {
+ ddata->v8object.Clear();
+ if (!object->parent() && !ddata->indestructible)
+ object->deleteLater();
+ }
+ }
+
+ qPersistentDispose(handle);
+}
+
+static void WeakQObjectInstanceCallback(v8::Persistent<v8::Value> handle, void *data)
+{
+ QV8QObjectInstance *instance = (QV8QObjectInstance *)data;
+ instance->v8object.Clear();
+ qPersistentDispose(handle);
+}
+
+v8::Local<v8::Object> QDeclarativePropertyCache::newQObject(QObject *object, QV8Engine *engine)
+{
+ Q_ASSERT(object);
+
+ Q_ASSERT(QDeclarativeData::get(object, false));
+ Q_ASSERT(QDeclarativeData::get(object, false)->propertyCache == this);
+
+ // Setup constructor
+ if (constructor.IsEmpty()) {
+ v8::Local<v8::FunctionTemplate> ft;
+
+ QString toString = QLatin1String("toString");
+ QString destroy = QLatin1String("destroy");
+
+ // XXX TODO: Enables fast property accessors. These more than double the property access
+ // performance, but the cost of setting up this structure hasn't been measured so
+ // its not guarenteed that this is a win overall. We need to try and measure the cost.
+ for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter) {
+ Data *property = *iter;
+ if (property->isFunction() ||
+ property->coreIndex >= 0x7FFF || property->notifyIndex >= 0x0FFF ||
+ property->coreIndex == 0)
+ continue;
+
+ v8::AccessorGetter fastgetter = 0;
+ v8::AccessorSetter fastsetter = FastValueSetter;
+ if (!property->isWritable())
+ fastsetter = FastValueSetterReadOnly;
+
+ if (property->isQObject())
+ fastgetter = property->isDirect()?QObjectValueGetterDirect:QObjectValueGetter;
+ else if (property->propType == QMetaType::Int || property->isEnum())
+ fastgetter = property->isDirect()?IntValueGetterDirect:IntValueGetter;
+ else if (property->propType == QMetaType::Bool)
+ fastgetter = property->isDirect()?BoolValueGetterDirect:BoolValueGetter;
+ else if (property->propType == QMetaType::QString)
+ fastgetter = property->isDirect()?QStringValueGetterDirect:QStringValueGetter;
+ else if (property->propType == QMetaType::UInt)
+ fastgetter = property->isDirect()?UIntValueGetterDirect:UIntValueGetter;
+ else if (property->propType == QMetaType::Float)
+ fastgetter = property->isDirect()?FloatValueGetterDirect:FloatValueGetter;
+ else if (property->propType == QMetaType::Double)
+ fastgetter = property->isDirect()?DoubleValueGetterDirect:DoubleValueGetter;
+
+ if (fastgetter) {
+ int notifyIndex = property->notifyIndex;
+ if (property->isConstant()) notifyIndex = 0;
+ else if (notifyIndex == -1) notifyIndex = 0x0FFF;
+ uint32_t data = (notifyIndex & 0x0FFF) << 16 | property->coreIndex;
+
+ QString name = iter.key();
+ if (name == toString || name == destroy)
+ continue;
+
+ if (ft.IsEmpty()) {
+ ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(QV8QObjectWrapper::Getter,
+ QV8QObjectWrapper::Setter,
+ QV8QObjectWrapper::Query,
+ 0,
+ QV8QObjectWrapper::Enumerator);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ }
+
+ ft->InstanceTemplate()->SetAccessor(engine->toString(name), fastgetter, fastsetter,
+ v8::Integer::NewFromUnsigned(data));
+ }
+ }
+
+ if (ft.IsEmpty()) {
+ constructor = qPersistentNew<v8::Function>(engine->qobjectWrapper()->m_constructor);
+ } else {
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(QV8QObjectWrapper::Getter,
+ QV8QObjectWrapper::Setter,
+ QV8QObjectWrapper::Query,
+ 0,
+ QV8QObjectWrapper::Enumerator);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+ }
+
+ v8::Local<v8::Object> result = constructor->NewInstance();
+ QV8QObjectResource *r = new QV8QObjectResource(engine, object);
+ result->SetExternalResource(r);
+ return result;
+}
+
+v8::Local<v8::Object> QV8QObjectWrapper::newQObject(QObject *object, QDeclarativeData *ddata, QV8Engine *engine)
+{
+ v8::Local<v8::Object> rv;
+
+ if (!ddata->propertyCache && engine->engine()) {
+ ddata->propertyCache = QDeclarativeEnginePrivate::get(engine->engine())->cache(object);
+ if (ddata->propertyCache) ddata->propertyCache->addref();
+ }
+
+ if (ddata->propertyCache) {
+ rv = ddata->propertyCache->newQObject(object, engine);
+ } else {
+ // XXX NewInstance() should be optimized
+ rv = m_constructor->NewInstance();
+ QV8QObjectResource *r = new QV8QObjectResource(engine, object);
+ rv->SetExternalResource(r);
+ }
+
+ return rv;
+}
+
+/*
+As V8 doesn't support an equality callback, for QObject's we have to return exactly the same
+V8 handle for subsequent calls to newQObject for the same QObject. To do this we have a two
+pronged strategy:
+ 1. If there is no current outstanding V8 handle to the QObject, we create one and store a
+ persistent handle in QDeclarativeData::v8object. We mark the QV8QObjectWrapper that
+ "owns" this handle by setting the QDeclarativeData::v8objectid to the id of this
+ QV8QObjectWrapper.
+ 2. If another QV8QObjectWrapper has create the handle in QDeclarativeData::v8object we create
+ an entry in the m_taintedObject hash where we store the handle and mark the object as
+ "tainted" in the QDeclarativeData::hasTaintedV8Object flag.
+We have to mark the object as tainted to ensure that we search our m_taintedObject hash even
+in the case that the original QV8QObjectWrapper owner of QDeclarativeData::v8object has
+released the handle.
+*/
+v8::Handle<v8::Value> QV8QObjectWrapper::newQObject(QObject *object)
+{
+ if (!object)
+ return v8::Null();
+
+ if (QObjectPrivate::get(object)->wasDeleted)
+ return v8::Undefined();
+
+ QDeclarativeData *ddata = QDeclarativeData::get(object, true);
+
+ if (!ddata)
+ return v8::Undefined();
+
+ if (ddata->v8objectid == m_id && !ddata->v8object.IsEmpty()) {
+ // We own the v8object
+ return v8::Local<v8::Object>::New(ddata->v8object);
+ } else if (ddata->v8object.IsEmpty() &&
+ (ddata->v8objectid == m_id || // We own the QObject
+ ddata->v8objectid == 0 || // No one owns the QObject
+ !ddata->hasTaintedV8Object)) { // Someone else has used the QObject, but it isn't tainted
+
+ v8::Local<v8::Object> rv = newQObject(object, ddata, m_engine);
+ ddata->v8object = qPersistentNew<v8::Object>(rv);
+ ddata->v8object.MakeWeak(0, WeakQObjectReferenceCallback);
+ ddata->v8objectid = m_id;
+ return rv;
+
+ } else {
+ // If this object is tainted, we have to check to see if it is in our
+ // tainted object list
+ TaintedHash::Iterator iter =
+ ddata->hasTaintedV8Object?m_taintedObjects.find(object):m_taintedObjects.end();
+ bool found = iter != m_taintedObjects.end();
+
+ // If our tainted handle doesn't exist or has been collected, and there isn't
+ // a handle in the ddata, we can assume ownership of the ddata->v8object
+ if ((!found || (*iter)->v8object.IsEmpty()) && ddata->v8object.IsEmpty()) {
+ v8::Local<v8::Object> rv = newQObject(object, ddata, m_engine);
+ ddata->v8object = qPersistentNew<v8::Object>(rv);
+ ddata->v8object.MakeWeak(0, WeakQObjectReferenceCallback);
+ ddata->v8objectid = m_id;
+
+ if (found) {
+ delete (*iter);
+ m_taintedObjects.erase(iter);
+ }
+
+ return rv;
+ } else if (!found) {
+ QV8QObjectInstance *instance = new QV8QObjectInstance(object, this);
+ iter = m_taintedObjects.insert(object, instance);
+ ddata->hasTaintedV8Object = true;
+ }
+
+ if ((*iter)->v8object.IsEmpty()) {
+ v8::Local<v8::Object> rv = newQObject(object, ddata, m_engine);
+ (*iter)->v8object = qPersistentNew<v8::Object>(rv);
+ (*iter)->v8object.MakeWeak((*iter), WeakQObjectInstanceCallback);
+ }
+
+ return v8::Local<v8::Object>::New((*iter)->v8object);
+ }
+}
+
+QPair<QObject *, int> QV8QObjectWrapper::ExtractQtMethod(QV8Engine *engine, v8::Handle<v8::Function> function)
+{
+ v8::ScriptOrigin origin = function->GetScriptOrigin();
+ if (origin.ResourceName()->StrictEquals(engine->qobjectWrapper()->m_hiddenObject)) {
+
+ // This is one of our special QObject method wrappers
+ v8::Handle<v8::Value> args[] = { engine->qobjectWrapper()->m_hiddenObject };
+ v8::Local<v8::Value> data = function->Call(engine->global(), 1, args);
+
+ if (data->IsArray()) {
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(data);
+ return qMakePair(engine->toQObject(array->Get(0)), array->Get(1)->Int32Value());
+ }
+
+ // In theory this can't fall through, but I suppose V8 might run out of memory or something
+ }
+
+ return qMakePair((QObject *)0, -1);
+}
+
+struct QV8QObjectConnectionList : public QObject, public QDeclarativeGuard<QObject>
+{
+ QV8QObjectConnectionList(QObject *object, QV8Engine *engine);
+ ~QV8QObjectConnectionList();
+
+ struct Connection {
+ Connection()
+ : needsDestroy(false) {}
+ Connection(const Connection &other)
+ : thisObject(other.thisObject), function(other.function), needsDestroy(false) {}
+ Connection &operator=(const Connection &other) {
+ thisObject = other.thisObject;
+ function = other.function;
+ needsDestroy = other.needsDestroy;
+ return *this;
+ }
+
+ v8::Persistent<v8::Object> thisObject;
+ v8::Persistent<v8::Function> function;
+
+ void dispose() {
+ qPersistentDispose(thisObject);
+ qPersistentDispose(function);
+ }
+
+ bool needsDestroy;
+ };
+
+ struct ConnectionList : public QList<Connection> {
+ ConnectionList() : connectionsInUse(0), connectionsNeedClean(false) {}
+ int connectionsInUse;
+ bool connectionsNeedClean;
+ };
+
+ QV8Engine *engine;
+
+ typedef QHash<int, ConnectionList> SlotHash;
+ SlotHash slotHash;
+ bool needsDestroy;
+ int inUse;
+
+ virtual void objectDestroyed(QObject *);
+ virtual int qt_metacall(QMetaObject::Call, int, void **);
+};
+
+QV8QObjectConnectionList::QV8QObjectConnectionList(QObject *object, QV8Engine *engine)
+: QDeclarativeGuard<QObject>(object), engine(engine), needsDestroy(false), inUse(0)
+{
+}
+
+QV8QObjectConnectionList::~QV8QObjectConnectionList()
+{
+ for (SlotHash::Iterator iter = slotHash.begin(); iter != slotHash.end(); ++iter) {
+ QList<Connection> &connections = *iter;
+ for (int ii = 0; ii < connections.count(); ++ii) {
+ qPersistentDispose(connections[ii].thisObject);
+ qPersistentDispose(connections[ii].function);
+ }
+ }
+ slotHash.clear();
+}
+
+void QV8QObjectConnectionList::objectDestroyed(QObject *object)
+{
+ engine->qobjectWrapper()->m_connections.remove(object);
+
+ if (inUse)
+ needsDestroy = true;
+ else
+ delete this;
+}
+
+int QV8QObjectConnectionList::qt_metacall(QMetaObject::Call method, int index, void **metaArgs)
+{
+ if (method == QMetaObject::InvokeMetaMethod) {
+ SlotHash::Iterator iter = slotHash.find(index);
+ if (iter == slotHash.end())
+ return -1;
+ ConnectionList &connectionList = *iter;
+ if (connectionList.isEmpty())
+ return -1;
+
+ inUse++;
+
+ connectionList.connectionsInUse++;
+
+ QList<Connection> connections = connectionList;
+
+ QMetaMethod method = data()->metaObject()->method(index);
+ Q_ASSERT(method.methodType() == QMetaMethod::Signal);
+ // XXX TODO: We should figure out a way to cache the parameter types to avoid resolving
+ // them each time.
+ QList<QByteArray> params = method.parameterTypes();
+
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(engine->context());
+
+ QVarLengthArray<v8::Handle<v8::Value> > args(params.count());
+ int argCount = params.count();
+
+ for (int ii = 0; ii < argCount; ++ii) {
+ int type = QMetaType::type(params.at(ii).constData());
+ if (type == qMetaTypeId<QVariant>()) {
+ args[ii] = engine->fromVariant(*((QVariant *)metaArgs[ii + 1]));
+ } else {
+ args[ii] = engine->fromVariant(QVariant(type, metaArgs[ii + 1]));
+ }
+ }
+
+ for (int ii = 0; ii < connections.count(); ++ii) {
+ Connection &connection = connections[ii];
+ if (connection.needsDestroy)
+ continue;
+ if (connection.thisObject.IsEmpty()) {
+ connection.function->Call(engine->global(), argCount, args.data());
+ } else {
+ connection.function->Call(connection.thisObject, argCount, args.data());
+ }
+ }
+
+ connectionList.connectionsInUse--;
+ if (connectionList.connectionsInUse == 0 && connectionList.connectionsNeedClean) {
+ for (QList<Connection>::Iterator iter = connectionList.begin();
+ iter != connectionList.end(); ) {
+ if (iter->needsDestroy) {
+ iter->dispose();
+ iter = connectionList.erase(iter);
+ } else {
+ ++iter;
+ }
+ }
+ }
+
+ inUse--;
+ if (inUse == 0 && needsDestroy)
+ delete this;
+ }
+
+ return -1;
+}
+
+v8::Handle<v8::Value> QV8QObjectWrapper::Connect(const v8::Arguments &args)
+{
+ if (args.Length() == 0)
+ V8THROW_ERROR("Function.prototype.connect: no arguments given");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (!args.This()->IsFunction())
+ V8THROW_ERROR("Function.prototype.connect: this object is not a signal");
+
+ QPair<QObject *, int> signalInfo = ExtractQtMethod(engine, v8::Handle<v8::Function>::Cast(args.This()));
+ QObject *signalObject = signalInfo.first;
+ int signalIndex = signalInfo.second;
+
+ if (signalIndex == -1)
+ V8THROW_ERROR("Function.prototype.connect: this object is not a signal");
+
+ if (!signalObject)
+ V8THROW_ERROR("Function.prototype.connect: cannot connect to deleted QObject");
+
+ if (signalIndex < 0 || signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal)
+ V8THROW_ERROR("Function.prototype.connect: this object is not a signal");
+
+ v8::Local<v8::Value> functionValue;
+ v8::Local<v8::Value> functionThisValue;
+
+ if (args.Length() == 1) {
+ functionValue = args[0];
+ } else {
+ functionThisValue = args[0];
+ functionValue = args[1];
+ }
+
+ if (!functionValue->IsFunction())
+ V8THROW_ERROR("Function.prototype.connect: target is not a function");
+
+ if (!functionThisValue.IsEmpty() && !functionThisValue->IsObject())
+ V8THROW_ERROR("Function.prototype.connect: target this is not an object");
+
+ QV8QObjectWrapper *qobjectWrapper = engine->qobjectWrapper();
+ QHash<QObject *, QV8QObjectConnectionList *> &connections = qobjectWrapper->m_connections;
+ QHash<QObject *, QV8QObjectConnectionList *>::Iterator iter = connections.find(signalObject);
+ if (iter == connections.end())
+ iter = connections.insert(signalObject, new QV8QObjectConnectionList(signalObject, engine));
+
+ QV8QObjectConnectionList *connectionList = *iter;
+ QV8QObjectConnectionList::SlotHash::Iterator slotIter = connectionList->slotHash.find(signalIndex);
+ if (slotIter == connectionList->slotHash.end()) {
+ slotIter = connectionList->slotHash.insert(signalIndex, QV8QObjectConnectionList::ConnectionList());
+ QMetaObject::connect(signalObject, signalIndex, connectionList, signalIndex);
+ }
+
+ QV8QObjectConnectionList::Connection connection;
+ if (!functionThisValue.IsEmpty())
+ connection.thisObject = qPersistentNew<v8::Object>(functionThisValue->ToObject());
+ connection.function = qPersistentNew<v8::Function>(v8::Handle<v8::Function>::Cast(functionValue));
+
+ slotIter->append(connection);
+
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8QObjectWrapper::Disconnect(const v8::Arguments &args)
+{
+ if (args.Length() == 0)
+ V8THROW_ERROR("Function.prototype.disconnect: no arguments given");
+
+ QV8Engine *engine = V8ENGINE();
+
+ if (!args.This()->IsFunction())
+ V8THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
+
+ QPair<QObject *, int> signalInfo = ExtractQtMethod(engine, v8::Handle<v8::Function>::Cast(args.This()));
+ QObject *signalObject = signalInfo.first;
+ int signalIndex = signalInfo.second;
+
+ if (signalIndex == -1)
+ V8THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
+
+ if (!signalObject)
+ V8THROW_ERROR("Function.prototype.disconnect: cannot disconnect from deleted QObject");
+
+ if (signalIndex < 0 || signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal)
+ V8THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
+
+ v8::Local<v8::Value> functionValue;
+ v8::Local<v8::Value> functionThisValue;
+
+ if (args.Length() == 1) {
+ functionValue = args[0];
+ } else {
+ functionThisValue = args[0];
+ functionValue = args[1];
+ }
+
+ if (!functionValue->IsFunction())
+ V8THROW_ERROR("Function.prototype.disconnect: target is not a function");
+
+ if (!functionThisValue.IsEmpty() && !functionThisValue->IsObject())
+ V8THROW_ERROR("Function.prototype.disconnect: target this is not an object");
+
+ QV8QObjectWrapper *qobjectWrapper = engine->qobjectWrapper();
+ QHash<QObject *, QV8QObjectConnectionList *> &connectionsList = qobjectWrapper->m_connections;
+ QHash<QObject *, QV8QObjectConnectionList *>::Iterator iter = connectionsList.find(signalObject);
+ if (iter == connectionsList.end())
+ return v8::Undefined(); // Nothing to disconnect from
+
+ QV8QObjectConnectionList *connectionList = *iter;
+ QV8QObjectConnectionList::SlotHash::Iterator slotIter = connectionList->slotHash.find(signalIndex);
+ if (slotIter == connectionList->slotHash.end())
+ return v8::Undefined(); // Nothing to disconnect from
+
+ QV8QObjectConnectionList::ConnectionList &connections = *slotIter;
+
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(functionValue);
+ QPair<QObject *, int> functionData = ExtractQtMethod(engine, function);
+
+ if (functionData.second != -1) {
+ // This is a QObject function wrapper
+ for (int ii = 0; ii < connections.count(); ++ii) {
+ QV8QObjectConnectionList::Connection &connection = connections[ii];
+
+ if (connection.thisObject.IsEmpty() == functionThisValue.IsEmpty() &&
+ (connection.thisObject.IsEmpty() || connection.thisObject->StrictEquals(functionThisValue))) {
+
+ QPair<QObject *, int> connectedFunctionData = ExtractQtMethod(engine, connection.function);
+ if (connectedFunctionData == functionData) {
+ // Match!
+ if (connections.connectionsInUse) {
+ connection.needsDestroy = true;
+ } else {
+ connection.dispose();
+ connections.removeAt(ii);
+ }
+ return v8::Undefined();
+ }
+ }
+ }
+
+ } else {
+ // This is a normal JS function
+ for (int ii = 0; ii < connections.count(); ++ii) {
+ QV8QObjectConnectionList::Connection &connection = connections[ii];
+ if (connection.function->StrictEquals(function) &&
+ connection.thisObject.IsEmpty() == functionThisValue.IsEmpty() &&
+ (connection.thisObject.IsEmpty() || connection.thisObject->StrictEquals(functionThisValue))) {
+ // Match!
+ if (connections.connectionsInUse) {
+ connection.needsDestroy = true;
+ } else {
+ connection.dispose();
+ connections.removeAt(ii);
+ }
+ return v8::Undefined();
+ }
+ }
+ }
+
+ return v8::Undefined();
+}
+
+/*!
+ \fn v8::Handle<v8::Value> QV8QObjectWrapper::getProperty(QObject *object, const QHashedV8String &property, QV8QObjectWrapper::RevisionMode revisionMode)
+
+ Get the \a property of \a object. Returns an empty handle if the property doesn't exist.
+
+ Only searches for real properties of \a object (including methods), not attached properties etc.
+*/
+
+/*
+ \fn bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV8String &property, v8::Handle<v8::Value> value, RevisionMode revisionMode)
+
+ Set the \a property of \a object to \a value.
+
+ Returns true if the property was "set" - even if this results in an exception being thrown -
+ and false if the object has no such property.
+
+ Only searches for real properties of \a object (including methods), not attached properties etc.
+*/
+
+namespace {
+struct CallArgs
+{
+ CallArgs(int length, v8::Handle<v8::Object> *args) : _length(length), _args(args) {}
+ int Length() const { return _length; }
+ v8::Local<v8::Value> operator[](int idx) { return (*_args)->Get(idx); }
+
+private:
+ int _length;
+ v8::Handle<v8::Object> *_args;
+};
+}
+
+static v8::Handle<v8::Value> CallMethod(QObject *object, int index, int returnType, int argCount,
+ int *argTypes, QV8Engine *engine, CallArgs &callArgs)
+{
+ if (argCount > 0) {
+
+ QVarLengthArray<MetaCallArgument, 9> args(argCount + 1);
+ args[0].initAsType(returnType);
+
+ for (int ii = 0; ii < argCount; ++ii)
+ args[ii + 1].fromValue(argTypes[ii], engine, callArgs[ii]);
+
+ QVarLengthArray<void *, 9> argData(args.count());
+ for (int ii = 0; ii < args.count(); ++ii)
+ argData[ii] = args[ii].dataPtr();
+
+ QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, argData.data());
+
+ return args[0].toValue(engine);
+
+ } else if (returnType != 0) {
+
+ MetaCallArgument arg;
+ arg.initAsType(returnType);
+
+ void *args[] = { arg.dataPtr() };
+
+ QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, args);
+
+ return arg.toValue(engine);
+
+ } else {
+
+ void *args[] = { 0 };
+ QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, index, args);
+ return v8::Undefined();
+
+ }
+}
+
+static int EnumType(const QMetaObject *meta, const QString &strname)
+{
+ QByteArray str = strname.toUtf8();
+ QByteArray scope;
+ QByteArray name;
+ int scopeIdx = str.lastIndexOf("::");
+ if (scopeIdx != -1) {
+ scope = str.left(scopeIdx);
+ name = str.mid(scopeIdx + 2);
+ } else {
+ name = str;
+ }
+ for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
+ QMetaEnum m = meta->enumerator(i);
+ if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
+ return QVariant::Int;
+ }
+ return QVariant::Invalid;
+}
+
+/*!
+ Returns the match score for converting \a actual to be of type \a conversionType. A
+ zero score means "perfect match" whereas a higher score is worse.
+
+ The conversion table is copied out of the QtScript callQtMethod() function.
+*/
+static int MatchScore(v8::Handle<v8::Value> actual, int conversionType,
+ const QByteArray &conversionTypeName)
+{
+ if (actual->IsNumber()) {
+ switch (conversionType) {
+ case QMetaType::Double:
+ return 0;
+ case QMetaType::Float:
+ return 1;
+ case QMetaType::LongLong:
+ case QMetaType::ULongLong:
+ return 2;
+ case QMetaType::Long:
+ case QMetaType::ULong:
+ return 3;
+ case QMetaType::Int:
+ case QMetaType::UInt:
+ return 4;
+ case QMetaType::Short:
+ case QMetaType::UShort:
+ return 5;
+ break;
+ case QMetaType::Char:
+ case QMetaType::UChar:
+ return 6;
+ default:
+ return 10;
+ }
+ } else if (actual->IsString()) {
+ switch (conversionType) {
+ case QMetaType::QString:
+ return 0;
+ default:
+ return 10;
+ }
+ } else if (actual->IsBoolean()) {
+ switch (conversionType) {
+ case QMetaType::Bool:
+ return 0;
+ default:
+ return 10;
+ }
+ } else if (actual->IsDate()) {
+ switch (conversionType) {
+ case QMetaType::QDateTime:
+ return 0;
+ case QMetaType::QDate:
+ return 1;
+ case QMetaType::QTime:
+ return 2;
+ default:
+ return 10;
+ }
+ } else if (actual->IsRegExp()) {
+ switch (conversionType) {
+ case QMetaType::QRegExp:
+ return 0;
+ default:
+ return 10;
+ }
+ } else if (actual->IsArray()) {
+ switch (conversionType) {
+ case QMetaType::QStringList:
+ case QMetaType::QVariantList:
+ return 5;
+ default:
+ return 10;
+ }
+ } else if (actual->IsNull()) {
+ switch (conversionType) {
+ case QMetaType::VoidStar:
+ case QMetaType::QObjectStar:
+ return 0;
+ default:
+ if (!conversionTypeName.endsWith('*'))
+ return 10;
+ else
+ return 0;
+ }
+ } else if (actual->IsObject()) {
+ v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(actual);
+
+ QV8ObjectResource *r = static_cast<QV8ObjectResource *>(obj->GetExternalResource());
+ if (r && r->resourceType() == QV8ObjectResource::QObjectType) {
+ switch (conversionType) {
+ case QMetaType::QObjectStar:
+ return 0;
+ default:
+ return 10;
+ }
+ } else if (r && r->resourceType() == QV8ObjectResource::VariantType) {
+ if (conversionType == qMetaTypeId<QVariant>())
+ return 0;
+ else if (r->engine->toVariant(actual, -1).userType() == conversionType)
+ return 0;
+ else
+ return 10;
+ } else {
+ return 10;
+ }
+
+ } else {
+ return 10;
+ }
+}
+
+static inline int QMetaObject_methods(const QMetaObject *metaObject)
+{
+ struct Private
+ {
+ int revision;
+ int className;
+ int classInfoCount, classInfoData;
+ int methodCount, methodData;
+ };
+
+ return reinterpret_cast<const Private *>(metaObject->d.data)->methodCount;
+}
+
+static QByteArray QMetaMethod_name(const QMetaMethod &m)
+{
+ QByteArray sig = m.signature();
+ int paren = sig.indexOf('(');
+ if (paren == -1)
+ return sig;
+ else
+ return sig.left(paren);
+}
+
+/*!
+Returns the next related method, if one, or 0.
+*/
+static const QDeclarativePropertyCache::Data * RelatedMethod(QObject *object,
+ const QDeclarativePropertyCache::Data *current,
+ QDeclarativePropertyCache::Data &dummy)
+{
+ QDeclarativePropertyCache *cache = QDeclarativeData::get(object)->propertyCache;
+ if (current->relatedIndex == -1)
+ return 0;
+
+ if (cache) {
+ return cache->method(current->relatedIndex);
+ } else {
+ const QMetaObject *mo = object->metaObject();
+ int methodOffset = mo->methodCount() - QMetaObject_methods(mo);
+
+ while (methodOffset > current->relatedIndex) {
+ mo = mo->superClass();
+ methodOffset -= QMetaObject_methods(mo);
+ }
+
+ QMetaMethod method = mo->method(current->relatedIndex);
+ dummy.load(method);
+
+ // Look for overloaded methods
+ QByteArray methodName = QMetaMethod_name(method);
+ for (int ii = current->relatedIndex - 1; ii >= methodOffset; --ii) {
+ if (methodName == QMetaMethod_name(mo->method(ii))) {
+ dummy.relatedIndex = ii;
+ return &dummy;
+ }
+ }
+
+ return &dummy;
+ }
+}
+
+static v8::Handle<v8::Value> CallPrecise(QObject *object, const QDeclarativePropertyCache::Data &data,
+ QV8Engine *engine, CallArgs &callArgs)
+{
+ if (data.hasArguments()) {
+
+ QMetaMethod m = object->metaObject()->method(data.coreIndex);
+ QList<QByteArray> argTypeNames = m.parameterTypes();
+ QVarLengthArray<int, 9> argTypes(argTypeNames.count());
+
+ // ### Cache
+ for (int ii = 0; ii < argTypeNames.count(); ++ii) {
+ argTypes[ii] = QMetaType::type(argTypeNames.at(ii));
+ if (argTypes[ii] == QVariant::Invalid)
+ argTypes[ii] = EnumType(object->metaObject(), QString::fromLatin1(argTypeNames.at(ii)));
+ if (argTypes[ii] == QVariant::Invalid) {
+ QString error = QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii)));
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ return v8::Handle<v8::Value>();
+ }
+ }
+
+ if (argTypes.count() > callArgs.Length()) {
+ QString error = QLatin1String("Insufficient arguments");
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ return v8::Handle<v8::Value>();
+ }
+
+ return CallMethod(object, data.coreIndex, data.propType, argTypes.count(),
+ argTypes.data(), engine, callArgs);
+
+ } else {
+
+ return CallMethod(object, data.coreIndex, data.propType, 0, 0, engine, callArgs);
+
+ }
+}
+
+/*!
+Resolve the overloaded method to call. The algorithm works conceptually like this:
+ 1. Resolve the set of overloads it is *possible* to call.
+ Impossible overloads include those that have too many parameters or have parameters
+ of unknown type.
+ 2. Filter the set of overloads to only contain those with the closest number of
+ parameters.
+ For example, if we are called with 3 parameters and there are 2 overloads that
+ take 2 parameters and one that takes 3, eliminate the 2 parameter overloads.
+ 3. Find the best remaining overload based on its match score.
+ If two or more overloads have the same match score, call the last one. The match
+ score is constructed by adding the matchScore() result for each of the parameters.
+*/
+static v8::Handle<v8::Value> CallOverloaded(QObject *object, const QDeclarativePropertyCache::Data &data,
+ QV8Engine *engine, CallArgs &callArgs)
+{
+ int argumentCount = callArgs.Length();
+
+ const QDeclarativePropertyCache::Data *best = 0;
+ int bestParameterScore = INT_MAX;
+ int bestMatchScore = INT_MAX;
+
+ QDeclarativePropertyCache::Data dummy;
+ const QDeclarativePropertyCache::Data *attempt = &data;
+
+ do {
+ QList<QByteArray> methodArgTypeNames;
+
+ if (attempt->hasArguments())
+ methodArgTypeNames = object->metaObject()->method(attempt->coreIndex).parameterTypes();
+
+ int methodArgumentCount = methodArgTypeNames.count();
+
+ if (methodArgumentCount > argumentCount)
+ continue; // We don't have sufficient arguments to call this method
+
+ int methodParameterScore = argumentCount - methodArgumentCount;
+ if (methodParameterScore > bestParameterScore)
+ continue; // We already have a better option
+
+ int methodMatchScore = 0;
+ QVarLengthArray<int, 9> methodArgTypes(methodArgumentCount);
+
+ bool unknownArgument = false;
+ for (int ii = 0; ii < methodArgumentCount; ++ii) {
+ methodArgTypes[ii] = QMetaType::type(methodArgTypeNames.at(ii));
+ if (methodArgTypes[ii] == QVariant::Invalid)
+ methodArgTypes[ii] = EnumType(object->metaObject(),
+ QString::fromLatin1(methodArgTypeNames.at(ii)));
+ if (methodArgTypes[ii] == QVariant::Invalid) {
+ unknownArgument = true;
+ break;
+ }
+ methodMatchScore += MatchScore(callArgs[ii], methodArgTypes[ii], methodArgTypeNames.at(ii));
+ }
+ if (unknownArgument)
+ continue; // We don't understand all the parameters
+
+ if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) {
+ best = attempt;
+ bestParameterScore = methodParameterScore;
+ bestMatchScore = methodMatchScore;
+ }
+
+ if (bestParameterScore == 0 && bestMatchScore == 0)
+ break; // We can't get better than that
+
+ } while((attempt = RelatedMethod(object, attempt, dummy)) != 0);
+
+ if (best) {
+ return CallPrecise(object, *best, engine, callArgs);
+ } else {
+ QString error = QLatin1String("Unable to determine callable overload. Candidates are:");
+ const QDeclarativePropertyCache::Data *candidate = &data;
+ while (candidate) {
+ error += QLatin1String("\n ") +
+ QString::fromUtf8(object->metaObject()->method(candidate->coreIndex).signature());
+ candidate = RelatedMethod(object, candidate, dummy);
+ }
+
+ v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ return v8::Handle<v8::Value>();
+ }
+}
+
+static v8::Handle<v8::Value> ToString(QV8Engine *engine, QObject *object, int, v8::Handle<v8::Object>)
+{
+ QString result;
+ if (object) {
+ QString objectName = object->objectName();
+
+ result += QString::fromUtf8(object->metaObject()->className());
+ result += QLatin1String("(0x");
+ result += QString::number((quintptr)object,16);
+
+ if (!objectName.isEmpty()) {
+ result += QLatin1String(", \"");
+ result += objectName;
+ result += QLatin1Char('\"');
+ }
+
+ result += QLatin1Char(')');
+ } else {
+ result = QLatin1String("null");
+ }
+
+ return engine->toString(result);
+}
+
+static v8::Handle<v8::Value> Destroy(QV8Engine *, QObject *object, int argCount, v8::Handle<v8::Object> args)
+{
+ QDeclarativeData *ddata = QDeclarativeData::get(object, false);
+ if (!ddata || ddata->indestructible) {
+ const char *error = "Invalid attempt to destroy() an indestructible object";
+ v8::ThrowException(v8::Exception::Error(v8::String::New(error)));
+ return v8::Undefined();
+ }
+
+ int delay = 0;
+ if (argCount > 0)
+ delay = args->Get(0)->Uint32Value();
+
+ if (delay > 0)
+ QTimer::singleShot(delay, object, SLOT(deleteLater()));
+ else
+ object->deleteLater();
+
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8QObjectWrapper::Invoke(const v8::Arguments &args)
+{
+ // object, index, qmlglobal, argCount, args
+ Q_ASSERT(args.Length() == 5);
+ Q_ASSERT(args[0]->IsObject());
+
+ QV8QObjectResource *resource = v8_resource_cast<QV8QObjectResource>(args[0]->ToObject());
+
+ if (!resource)
+ return v8::Undefined();
+
+ int argCount = args[3]->Int32Value();
+ v8::Handle<v8::Object> arguments = v8::Handle<v8::Object>::Cast(args[4]);
+
+ // Special hack to return info about this closure.
+ if (argCount == 1 && arguments->Get(0)->StrictEquals(resource->engine->qobjectWrapper()->m_hiddenObject)) {
+ v8::Local<v8::Array> data = v8::Array::New(2);
+ data->Set(0, args[0]);
+ data->Set(1, args[1]);
+ return data;
+ }
+
+ QObject *object = resource->object;
+ int index = args[1]->Int32Value();
+
+ if (!object)
+ return v8::Undefined();
+
+ if (index < 0) {
+ // Builtin functions
+ if (index == QOBJECT_TOSTRING_INDEX) {
+ return ToString(resource->engine, object, argCount, arguments);
+ } else if (index == QOBJECT_DESTROY_INDEX) {
+ return Destroy(resource->engine, object, argCount, arguments);
+ } else {
+ return v8::Undefined();
+ }
+ }
+
+ QDeclarativePropertyCache::Data method;
+
+ if (QDeclarativeData *ddata = static_cast<QDeclarativeData *>(QObjectPrivate::get(object)->declarativeData)) {
+ if (ddata->propertyCache) {
+ QDeclarativePropertyCache::Data *d = ddata->propertyCache->method(index);
+ if (!d)
+ return v8::Undefined();
+ method = *d;
+ }
+ }
+
+ if (method.coreIndex == -1) {
+ QMetaMethod mm = object->metaObject()->method(index);
+ method.load(object->metaObject()->method(index));
+
+ if (method.coreIndex == -1)
+ return v8::Undefined();
+ }
+
+ if (method.isV8Function()) {
+ v8::Handle<v8::Value> rv;
+ v8::Handle<v8::Object> qmlglobal = args[2]->ToObject();
+
+ QDeclarativeV8Function func(argCount, arguments, rv, qmlglobal,
+ resource->engine->contextWrapper()->context(qmlglobal),
+ resource->engine);
+ QDeclarativeV8Function *funcptr = &func;
+
+ void *args[] = { 0, &funcptr };
+ QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, method.coreIndex, args);
+
+ if (rv.IsEmpty()) return v8::Undefined();
+ return rv;
+ }
+
+ CallArgs callArgs(argCount, &arguments);
+ if (method.relatedIndex == -1) {
+ return CallPrecise(object, method, resource->engine, callArgs);
+ } else {
+ return CallOverloaded(object, method, resource->engine, callArgs);
+ }
+}
+
+MetaCallArgument::MetaCallArgument()
+: type(QVariant::Invalid), isObjectType(false)
+{
+}
+
+MetaCallArgument::~MetaCallArgument()
+{
+ cleanup();
+}
+
+void MetaCallArgument::cleanup()
+{
+ if (type == QMetaType::QString) {
+ ((QString *)&data)->~QString();
+ } else if (type == -1 || type == qMetaTypeId<QVariant>()) {
+ ((QVariant *)&data)->~QVariant();
+ } else if (type == qMetaTypeId<QScriptValue>()) {
+ ((QScriptValue *)&data)->~QScriptValue();
+ } else if (type == qMetaTypeId<QList<QObject *> >()) {
+ ((QList<QObject *> *)&data)->~QList<QObject *>();
+ }
+}
+
+void *MetaCallArgument::dataPtr()
+{
+ if (type == -1)
+ return ((QVariant *)data)->data();
+ else
+ return (void *)&data;
+}
+
+void MetaCallArgument::initAsType(int callType)
+{
+ if (type != 0) { cleanup(); type = 0; }
+ if (callType == 0) return;
+
+ if (callType == qMetaTypeId<QScriptValue>()) {
+ new (&data) QScriptValue();
+ type = callType;
+ } else if (callType == QMetaType::Int ||
+ callType == QMetaType::UInt ||
+ callType == QMetaType::Bool ||
+ callType == QMetaType::Double ||
+ callType == QMetaType::Float) {
+ type = callType;
+ } else if (callType == QMetaType::QObjectStar) {
+ *((QObject **)&data) = 0;
+ type = callType;
+ } else if (callType == QMetaType::QString) {
+ new (&data) QString();
+ type = callType;
+ } else if (callType == qMetaTypeId<QVariant>()) {
+ type = callType;
+ new (&data) QVariant();
+ } else if (callType == qMetaTypeId<QList<QObject *> >()) {
+ type = callType;
+ new (&data) QList<QObject *>();
+ } else if (callType == qMetaTypeId<QDeclarativeV8Handle>()) {
+ type = callType;
+ new (&data) v8::Handle<v8::Value>();
+ } else {
+ type = -1;
+ new (&data) QVariant(callType, (void *)0);
+ }
+}
+
+void MetaCallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle<v8::Value> value)
+{
+ if (type != 0) { cleanup(); type = 0; }
+
+ if (callType == qMetaTypeId<QScriptValue>()) {
+ new (&data) QScriptValue();
+ type = qMetaTypeId<QScriptValue>();
+ } else if (callType == QMetaType::Int) {
+ *((int *)&data) = int(value->Int32Value());
+ type = callType;
+ } else if (callType == QMetaType::UInt) {
+ *((uint *)&data) = uint(value->Uint32Value());
+ type = callType;
+ } else if (callType == QMetaType::Bool) {
+ *((bool *)&data) = value->BooleanValue();
+ type = callType;
+ } else if (callType == QMetaType::Double) {
+ *((double *)&data) = double(value->NumberValue());
+ type = callType;
+ } else if (callType == QMetaType::Float) {
+ *((float *)&data) = float(value->NumberValue());
+ type = callType;
+ } else if (callType == QMetaType::QString) {
+ if (value->IsNull() || value->IsUndefined())
+ new (&data) QString();
+ else
+ new (&data) QString(engine->toString(value->ToString()));
+ type = callType;
+ } else if (callType == QMetaType::QObjectStar) {
+ *((QObject **)&data) = engine->toQObject(value);
+ type = callType;
+ } else if (callType == qMetaTypeId<QVariant>()) {
+ new (&data) QVariant(engine->toVariant(value, -1));
+ type = callType;
+ } else if (callType == qMetaTypeId<QList<QObject*> >()) {
+ QList<QObject *> *list = new (&data) QList<QObject *>();
+ if (value->IsArray()) {
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
+ uint32_t length = array->Length();
+ for (uint32_t ii = 0; ii < length; ++ii)
+ list->append(engine->toQObject(array->Get(ii)));
+ } else {
+ list->append(engine->toQObject(value));
+ }
+ type = callType;
+ } else if (callType == qMetaTypeId<QDeclarativeV8Handle>()) {
+ new (&data) v8::Handle<v8::Value>(value);
+ type = callType;
+ } else {
+ new (&data) QVariant();
+ type = -1;
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine());
+ QVariant v = engine->toVariant(value, -1);
+
+ if (v.userType() == callType) {
+ *((QVariant *)&data) = v;
+ } else if (v.canConvert((QVariant::Type)callType)) {
+ *((QVariant *)&data) = v;
+ ((QVariant *)&data)->convert((QVariant::Type)callType);
+ } else if (const QMetaObject *mo = ep->rawMetaObjectForType(callType)) {
+ QObject *obj = ep->toQObject(v);
+
+ if (obj) {
+ const QMetaObject *objMo = obj->metaObject();
+ while (objMo && objMo != mo) objMo = objMo->superClass();
+ if (!objMo) obj = 0;
+ }
+
+ *((QVariant *)&data) = QVariant(callType, &obj);
+ } else {
+ *((QVariant *)&data) = QVariant(callType, (void *)0);
+ }
+ }
+}
+
+v8::Handle<v8::Value> MetaCallArgument::toValue(QV8Engine *engine)
+{
+ if (type == qMetaTypeId<QScriptValue>()) {
+ return v8::Undefined();
+ } else if (type == QMetaType::Int) {
+ return v8::Integer::New(*((int *)&data));
+ } else if (type == QMetaType::UInt) {
+ return v8::Integer::NewFromUnsigned(*((uint *)&data));
+ } else if (type == QMetaType::Bool) {
+ return v8::Boolean::New(*((bool *)&data));
+ } else if (type == QMetaType::Double) {
+ return v8::Number::New(*((double *)&data));
+ } else if (type == QMetaType::Float) {
+ return v8::Number::New(*((float *)&data));
+ } else if (type == QMetaType::QString) {
+ return engine->toString(*((QString *)&data));
+ } else if (type == QMetaType::QObjectStar) {
+ QObject *object = *((QObject **)&data);
+ if (object)
+ QDeclarativeData::get(object, true)->setImplicitDestructible();
+ return engine->newQObject(object);
+ } else if (type == qMetaTypeId<QList<QObject *> >()) {
+ // XXX Can this be made more by using Array as a prototype and implementing
+ // directly against QList<QObject*>?
+ QList<QObject *> &list = *(QList<QObject *>*)&data;
+ v8::Local<v8::Array> array = v8::Array::New(list.count());
+ for (int ii = 0; ii < list.count(); ++ii)
+ array->Set(ii, engine->newQObject(list.at(ii)));
+ return array;
+ } else if (type == qMetaTypeId<QDeclarativeV8Handle>()) {
+ return *(v8::Handle<v8::Value>*)&data;
+ } else if (type == -1 || type == qMetaTypeId<QVariant>()) {
+ QVariant value = *((QVariant *)&data);
+ v8::Handle<v8::Value> rv = engine->fromVariant(value);
+ if (QObject *object = engine->toQObject(rv))
+ QDeclarativeData::get(object, true)->setImplicitDestructible();
+ return rv;
+ } else {
+ return v8::Undefined();
+ }
+}
diff --git a/src/declarative/qml/v8/qv8qobjectwrapper_p.h b/src/declarative/qml/v8/qv8qobjectwrapper_p.h
new file mode 100644
index 0000000000..bc4eb443dc
--- /dev/null
+++ b/src/declarative/qml/v8/qv8qobjectwrapper_p.h
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8QOBJECTWRAPPER_P_H
+#define QV8QOBJECTWRAPPER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qmetatype.h>
+#include <QtCore/qpair.h>
+#include <QtCore/qhash.h>
+#include <private/qv8_p.h>
+#include <private/qhashedstring_p.h>
+#include <private/qdeclarativedata_p.h>
+#include <private/qdeclarativepropertycache_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QObject;
+class QV8Engine;
+class QDeclarativeData;
+class QV8ObjectResource;
+class QV8QObjectInstance;
+class QV8QObjectConnectionList;
+class QDeclarativePropertyCache;
+class Q_AUTOTEST_EXPORT QV8QObjectWrapper
+{
+public:
+ QV8QObjectWrapper();
+ ~QV8QObjectWrapper();
+
+ void init(QV8Engine *);
+ void destroy();
+
+ v8::Handle<v8::Value> newQObject(QObject *object);
+ bool isQObject(v8::Handle<v8::Object>);
+ QObject *toQObject(v8::Handle<v8::Object>);
+ QObject *toQObject(QV8ObjectResource *);
+
+ enum RevisionMode { IgnoreRevision, CheckRevision };
+ inline v8::Handle<v8::Value> getProperty(QObject *, const QHashedV8String &, RevisionMode);
+ inline bool setProperty(QObject *, const QHashedV8String &, v8::Handle<v8::Value>, RevisionMode);
+
+private:
+ friend class QDeclarativePropertyCache;
+ friend class QV8QObjectConnectionList;
+ friend class QV8QObjectInstance;
+
+ v8::Local<v8::Object> newQObject(QObject *, QDeclarativeData *, QV8Engine *);
+ static v8::Handle<v8::Value> GetProperty(QV8Engine *, QObject *, v8::Handle<v8::Value> *,
+ const QHashedV8String &, QV8QObjectWrapper::RevisionMode);
+ static bool SetProperty(QV8Engine *, QObject *, const QHashedV8String &,
+ v8::Handle<v8::Value>, QV8QObjectWrapper::RevisionMode);
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Integer> Query(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Connect(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Disconnect(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Invoke(const v8::Arguments &args);
+ static QPair<QObject *, int> ExtractQtMethod(QV8Engine *, v8::Handle<v8::Function>);
+
+ QV8Engine *m_engine;
+ quint32 m_id;
+ v8::Persistent<v8::Function> m_constructor;
+ v8::Persistent<v8::Function> m_methodConstructor;
+ v8::Persistent<v8::String> m_toStringSymbol;
+ v8::Persistent<v8::String> m_destroySymbol;
+ QHashedV8String m_toStringString;
+ QHashedV8String m_destroyString;
+ v8::Persistent<v8::Object> m_hiddenObject;
+ QHash<QObject *, QV8QObjectConnectionList *> m_connections;
+ typedef QHash<QObject *, QV8QObjectInstance *> TaintedHash;
+ TaintedHash m_taintedObjects;
+};
+
+v8::Handle<v8::Value> QV8QObjectWrapper::getProperty(QObject *object, const QHashedV8String &string,
+ RevisionMode mode)
+{
+ QDeclarativeData *dd = QDeclarativeData::get(object, false);
+ if (!dd || !dd->propertyCache || m_toStringString == string || m_destroyString == string ||
+ dd->propertyCache->property(string)) {
+ return GetProperty(m_engine, object, 0, string, mode);
+ } else {
+ return v8::Handle<v8::Value>();
+ }
+}
+
+bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV8String &string,
+ v8::Handle<v8::Value> value, RevisionMode mode)
+{
+ QDeclarativeData *dd = QDeclarativeData::get(object, false);
+ if (!dd || !dd->propertyCache || m_toStringString == string || m_destroyString == string ||
+ dd->propertyCache->property(string)) {
+ return SetProperty(m_engine, object, string, value, mode);
+ } else {
+ return false;
+ }
+}
+
+QT_END_NAMESPACE
+
+#endif // QV8QOBJECTWRAPPER_P_H
+
+
diff --git a/src/declarative/qml/v8/qv8stringwrapper.cpp b/src/declarative/qml/v8/qv8stringwrapper.cpp
new file mode 100644
index 0000000000..883c4826c5
--- /dev/null
+++ b/src/declarative/qml/v8/qv8stringwrapper.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8stringwrapper_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QV8StringResource : public v8::String::ExternalStringResource
+{
+public:
+ QV8StringResource(const QString &str) : str(str) {}
+ virtual const uint16_t* data() const { return (uint16_t*)str.constData(); }
+ virtual size_t length() const { return str.length(); }
+ virtual void Dispose() { delete this; }
+
+ QString str;
+};
+
+QV8StringWrapper::QV8StringWrapper()
+{
+}
+
+QV8StringWrapper::~QV8StringWrapper()
+{
+}
+
+void QV8StringWrapper::init()
+{
+}
+
+void QV8StringWrapper::destroy()
+{
+}
+
+v8::Local<v8::String> QV8StringWrapper::toString(const QString &qstr)
+{
+// return v8::String::NewExternal(new QV8StringResource(qstr));
+ return v8::String::New((uint16_t*)qstr.constData(), qstr.length());
+}
+
+QString QV8StringWrapper::toString(v8::Handle<v8::String> jsstr)
+{
+ if (jsstr.IsEmpty()) {
+ return QString();
+ } else if (jsstr->IsExternal()) {
+ QV8StringResource *r = (QV8StringResource *)jsstr->GetExternalStringResource();
+ return r->str;
+ } else {
+ QString qstr;
+ qstr.resize(jsstr->Length());
+ jsstr->Write((uint16_t*)qstr.data());
+ return qstr;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8stringwrapper_p.h b/src/declarative/qml/v8/qv8stringwrapper_p.h
new file mode 100644
index 0000000000..8dde5c8c44
--- /dev/null
+++ b/src/declarative/qml/v8/qv8stringwrapper_p.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEV8STRINGWRAPPER_P_H
+#define QDECLARATIVEV8STRINGWRAPPER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qstring.h>
+#include <private/qv8_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_AUTOTEST_EXPORT QV8StringWrapper
+{
+public:
+ QV8StringWrapper();
+ ~QV8StringWrapper();
+
+ void init();
+ void destroy();
+
+ v8::Local<v8::String> toString(const QString &);
+ QString toString(v8::Handle<v8::String>);
+};
+
+QT_END_NAMESPACE
+
+#endif // QDECLARATIVEV8STRINGWRAPPER_P_H
diff --git a/src/declarative/qml/v8/qv8typewrapper.cpp b/src/declarative/qml/v8/qv8typewrapper.cpp
new file mode 100644
index 0000000000..9aac7a30d7
--- /dev/null
+++ b/src/declarative/qml/v8/qv8typewrapper.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8contextwrapper_p.h"
+#include "qv8engine_p.h"
+
+#include <private/qdeclarativeengine_p.h>
+#include <private/qdeclarativecontext_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8TypeResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(TypeType);
+
+public:
+ QV8TypeResource(QV8Engine *engine);
+ virtual ~QV8TypeResource();
+
+ QV8TypeWrapper::TypeNameMode mode;
+
+ QDeclarativeGuard<QObject> object;
+ QDeclarativeType *type;
+ QDeclarativeTypeNameCache *typeNamespace;
+};
+
+QV8TypeResource::QV8TypeResource(QV8Engine *engine)
+: QV8ObjectResource(engine), mode(QV8TypeWrapper::IncludeEnums), type(0), typeNamespace(0)
+{
+}
+
+QV8TypeResource::~QV8TypeResource()
+{
+ if (typeNamespace) typeNamespace->release();
+}
+
+QV8TypeWrapper::QV8TypeWrapper()
+: m_engine(0)
+{
+}
+
+QV8TypeWrapper::~QV8TypeWrapper()
+{
+}
+
+void QV8TypeWrapper::destroy()
+{
+ qPersistentDispose(m_constructor);
+}
+
+void QV8TypeWrapper::init(QV8Engine *engine)
+{
+ m_engine = engine;
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetNamedPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+}
+
+v8::Local<v8::Object> QV8TypeWrapper::newObject(QObject *o, QDeclarativeType *t, TypeNameMode mode)
+{
+ Q_ASSERT(t);
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8TypeResource *r = new QV8TypeResource(m_engine);
+ r->mode = mode; r->object = o; r->type = t;
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+v8::Local<v8::Object> QV8TypeWrapper::newObject(QObject *o, QDeclarativeTypeNameCache *t, TypeNameMode mode)
+{
+ Q_ASSERT(t);
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8TypeResource *r = new QV8TypeResource(m_engine);
+ t->addref();
+ r->mode = mode; r->object = o; r->typeNamespace = t;
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+v8::Handle<v8::Value> QV8TypeWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ v8::Object::ExternalResource *r = info.This()->GetExternalResource();
+ QV8TypeResource *resource = v8_resource_cast<QV8TypeResource>(info.This());
+
+ if (!resource)
+ return v8::Undefined();
+
+ QV8Engine *v8engine = resource->engine;
+ QObject *object = resource->object;
+
+ QHashedV8String propertystring(property);
+
+ if (resource->type) {
+ QDeclarativeType *type = resource->type;
+
+ if (QV8Engine::startsWithUpper(property)) {
+ if (resource->mode == IncludeEnums) {
+ QString name = v8engine->toString(property);
+
+ // ### Optimize
+ QByteArray enumName = name.toUtf8();
+ const QMetaObject *metaObject = type->baseMetaObject();
+ for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) {
+ QMetaEnum e = metaObject->enumerator(ii);
+ int value = e.keyToValue(enumName.constData());
+ if (value != -1)
+ return v8::Integer::New(value);
+ }
+ }
+
+ // Fall through to undefined
+
+ } else if (resource->object) {
+ QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
+ if (ao)
+ return v8engine->qobjectWrapper()->getProperty(ao, propertystring,
+ QV8QObjectWrapper::IgnoreRevision);
+
+ // Fall through to undefined
+ }
+
+ // Fall through to undefined
+
+ } else if (resource->typeNamespace) {
+
+ QDeclarativeTypeNameCache *typeNamespace = resource->typeNamespace;
+ QDeclarativeTypeNameCache::Data *d = typeNamespace->data(propertystring);
+ Q_ASSERT(!d || !d->typeNamespace); // Nested namespaces not supported
+
+ if (d && d->type) {
+ return v8engine->typeWrapper()->newObject(object, d->type, resource->mode);
+ } else if (QDeclarativeMetaType::ModuleApiInstance *moduleApi = typeNamespace->moduleApi()) {
+ // XXX TODO: Currently module APIs are implemented against QScriptValues. Consequently we
+ // can't do anything here until the QtScript/V8 binding is complete.
+ return v8::Undefined();
+
+ }
+
+ // Fall through to undefined
+
+ } else {
+ Q_ASSERT(!"Unreachable");
+ }
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8TypeWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ v8::Object::ExternalResource *r = info.This()->GetExternalResource();
+ QV8TypeResource *resource = v8_resource_cast<QV8TypeResource>(info.This());
+
+ if (!resource)
+ return value;
+
+ QV8Engine *v8engine = resource->engine;
+
+ // XXX TODO: Implement writes to module API objects
+
+ QHashedV8String propertystring(property);
+
+ if (resource->type && resource->object) {
+ QDeclarativeType *type = resource->type;
+ QObject *object = resource->object;
+ QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
+ if (ao)
+ v8engine->qobjectWrapper()->setProperty(ao, propertystring, value,
+ QV8QObjectWrapper::IgnoreRevision);
+ }
+
+ return value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass_p.h b/src/declarative/qml/v8/qv8typewrapper_p.h
index 9f386ba3a2..e7403dfa40 100644
--- a/src/declarative/qml/qdeclarativetypenamescriptclass_p.h
+++ b/src/declarative/qml/v8/qv8typewrapper_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QDECLARATIVETYPENAMESCRIPTCLASS_P_H
-#define QDECLARATIVETYPENAMESCRIPTCLASS_P_H
+#ifndef QV8TYPEWRAPPER_P_H
+#define QV8TYPEWRAPPER_P_H
//
// W A R N I N G
@@ -52,42 +52,41 @@
//
// We mean it.
//
-#include "private/qdeclarativeengine_p.h"
-#include <private/qscriptdeclarativeclass_p.h>
-#include <QtScript/qscriptclass.h>
+#include <QtCore/qglobal.h>
+#include <private/qv8_p.h>
QT_BEGIN_NAMESPACE
-class QDeclarativeEngine;
+class QObject;
+class QV8Engine;
class QDeclarativeType;
class QDeclarativeTypeNameCache;
-class QDeclarativeTypeNameScriptClass : public QScriptDeclarativeClass
+class QV8TypeWrapper
{
public:
- QDeclarativeTypeNameScriptClass(QDeclarativeEngine *);
- ~QDeclarativeTypeNameScriptClass();
+ QV8TypeWrapper();
+ ~QV8TypeWrapper();
- enum TypeNameMode { IncludeEnums, ExcludeEnums };
- QScriptValue newObject(QObject *, QDeclarativeType *, TypeNameMode = IncludeEnums);
- QScriptValue newObject(QObject *, QDeclarativeTypeNameCache *, TypeNameMode = IncludeEnums);
-
-protected:
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
- QScriptClass::QueryFlags flags);
+ void init(QV8Engine *);
+ void destroy();
- virtual Value property(Object *, const Identifier &);
- virtual void setProperty(Object *, const Identifier &name, const QScriptValue &);
+ enum TypeNameMode { IncludeEnums, ExcludeEnums };
+ v8::Local<v8::Object> newObject(QObject *, QDeclarativeType *, TypeNameMode = IncludeEnums);
+ v8::Local<v8::Object> newObject(QObject *, QDeclarativeTypeNameCache *, TypeNameMode = IncludeEnums);
private:
- QDeclarativeEngine *engine;
- QObject *object;
- QDeclarativeType *type;
- QDeclarativeMetaType::ModuleApiInstance *api;
- quint32 enumValue;
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+
+ QV8Engine *m_engine;
+ v8::Persistent<v8::Function> m_constructor;
};
QT_END_NAMESPACE
-#endif // QDECLARATIVETYPENAMESCRIPTCLASS_P_H
+#endif // QV8TYPEWRAPPER_P_H
diff --git a/src/declarative/qml/v8/qv8valuetypewrapper.cpp b/src/declarative/qml/v8/qv8valuetypewrapper.cpp
new file mode 100644
index 0000000000..f3100cf7b5
--- /dev/null
+++ b/src/declarative/qml/v8/qv8valuetypewrapper.cpp
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8valuetypewrapper_p.h"
+#include "qv8engine_p.h"
+
+#include <private/qdeclarativevaluetype_p.h>
+#include <private/qdeclarativebinding_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QV8ValueTypeResource : public QV8ObjectResource
+{
+ V8_RESOURCE_TYPE(ValueTypeType);
+
+public:
+ enum ObjectType { Reference, Copy };
+
+ QV8ValueTypeResource(QV8Engine *engine, ObjectType objectType);
+
+ ObjectType objectType;
+ QDeclarativeValueType *type;
+};
+
+class QV8ValueTypeReferenceResource : public QV8ValueTypeResource
+{
+public:
+ QV8ValueTypeReferenceResource(QV8Engine *engine);
+
+ QDeclarativeGuard<QObject> object;
+ int property;
+};
+
+class QV8ValueTypeCopyResource : public QV8ValueTypeResource
+{
+public:
+ QV8ValueTypeCopyResource(QV8Engine *engine);
+
+ QVariant value;
+};
+
+QV8ValueTypeResource::QV8ValueTypeResource(QV8Engine *engine, ObjectType objectType)
+: QV8ObjectResource(engine), objectType(objectType)
+{
+}
+
+QV8ValueTypeReferenceResource::QV8ValueTypeReferenceResource(QV8Engine *engine)
+: QV8ValueTypeResource(engine, Reference)
+{
+}
+
+QV8ValueTypeCopyResource::QV8ValueTypeCopyResource(QV8Engine *engine)
+: QV8ValueTypeResource(engine, Copy)
+{
+}
+
+QV8ValueTypeWrapper::QV8ValueTypeWrapper()
+: m_engine(0)
+{
+}
+
+QV8ValueTypeWrapper::~QV8ValueTypeWrapper()
+{
+}
+
+void QV8ValueTypeWrapper::destroy()
+{
+ qPersistentDispose(m_constructor);
+}
+
+void QV8ValueTypeWrapper::init(QV8Engine *engine)
+{
+ m_engine = engine;
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetNamedPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+}
+
+v8::Local<v8::Object> QV8ValueTypeWrapper::newValueType(QObject *object, int property, QDeclarativeValueType *type)
+{
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8ValueTypeReferenceResource *r = new QV8ValueTypeReferenceResource(m_engine);
+ r->type = type; r->object = object; r->property = property;
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+v8::Local<v8::Object> QV8ValueTypeWrapper::newValueType(const QVariant &value, QDeclarativeValueType *type)
+{
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv = m_constructor->NewInstance();
+ QV8ValueTypeCopyResource *r = new QV8ValueTypeCopyResource(m_engine);
+ r->type = type; r->value = value;
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+QVariant QV8ValueTypeWrapper::toVariant(v8::Handle<v8::Object> obj)
+{
+ QV8ValueTypeResource *r = v8_resource_cast<QV8ValueTypeResource>(obj);
+ if (r) return toVariant(r);
+ else return QVariant();
+}
+
+QVariant QV8ValueTypeWrapper::toVariant(QV8ObjectResource *r)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::ValueTypeType);
+ QV8ValueTypeResource *resource = static_cast<QV8ValueTypeResource *>(r);
+
+ if (resource->objectType == QV8ValueTypeResource::Reference) {
+ QV8ValueTypeReferenceResource *reference = static_cast<QV8ValueTypeReferenceResource *>(resource);
+
+ if (reference->object) {
+ reference->type->read(reference->object, reference->property);
+ return reference->type->value();
+ } else {
+ return QVariant();
+ }
+
+ } else {
+ Q_ASSERT(resource->objectType == QV8ValueTypeResource::Copy);
+
+ QV8ValueTypeCopyResource *copy = static_cast<QV8ValueTypeCopyResource *>(resource);
+
+ return copy->value;
+ }
+}
+
+v8::Handle<v8::Value> QV8ValueTypeWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ QV8ValueTypeResource *r = v8_resource_cast<QV8ValueTypeResource>(info.This());
+ if (!r) return v8::Undefined();
+
+ // XXX This is horribly inefficient. Sadly people seem to have taken a liking to
+ // value type properties, so we should probably try and optimize it a little.
+ // We should probably just replace all value properties with dedicated accessors.
+
+ QByteArray propName = r->engine->toString(property).toUtf8();
+ int index = r->type->metaObject()->indexOfProperty(propName.constData());
+ if (index == -1)
+ return v8::Undefined();
+
+ if (r->objectType == QV8ValueTypeResource::Reference) {
+ QV8ValueTypeReferenceResource *reference = static_cast<QV8ValueTypeReferenceResource *>(r);
+
+ if (!reference->object)
+ return v8::Undefined();
+
+ r->type->read(reference->object, reference->property);
+ } else {
+ Q_ASSERT(r->objectType == QV8ValueTypeResource::Copy);
+
+ QV8ValueTypeCopyResource *copy = static_cast<QV8ValueTypeCopyResource *>(r);
+
+ r->type->setValue(copy->value);
+ }
+
+ QMetaProperty prop = r->type->metaObject()->property(index);
+ QVariant result = prop.read(r->type);
+
+ return r->engine->fromVariant(result);
+}
+
+v8::Handle<v8::Value> QV8ValueTypeWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ QV8ValueTypeResource *r = v8_resource_cast<QV8ValueTypeResource>(info.This());
+ if (!r) return value;
+
+ QByteArray propName = r->engine->toString(property).toUtf8();
+ int index = r->type->metaObject()->indexOfProperty(propName.constData());
+ if (index == -1)
+ return value;
+
+ if (r->objectType == QV8ValueTypeResource::Reference) {
+ QV8ValueTypeReferenceResource *reference = static_cast<QV8ValueTypeReferenceResource *>(r);
+
+ if (!reference->object ||
+ !reference->object->metaObject()->property(reference->property).isWritable())
+ return value;
+
+ r->type->read(reference->object, reference->property);
+ QMetaProperty p = r->type->metaObject()->property(index);
+
+ QDeclarativeBinding *newBinding = 0;
+
+ if (value->IsFunction()) {
+ QDeclarativeContextData *context = r->engine->callingContext();
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value);
+
+ QDeclarativePropertyCache::Data cacheData;
+ cacheData.setFlags(QDeclarativePropertyCache::Data::IsWritable);
+ cacheData.propType = reference->object->metaObject()->property(reference->property).userType();
+ cacheData.coreIndex = reference->property;
+
+ QDeclarativePropertyCache::ValueTypeData valueTypeData;
+ valueTypeData.valueTypeCoreIdx = index;
+ valueTypeData.valueTypePropType = p.userType();
+
+ v8::Local<v8::StackTrace> trace =
+ v8::StackTrace::CurrentStackTrace(1,
+ (v8::StackTrace::StackTraceOptions)(v8::StackTrace::kLineNumber |
+ v8::StackTrace::kScriptName));
+ v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
+ int lineNumber = frame->GetLineNumber();
+ QString url = r->engine->toString(frame->GetScriptName());
+
+ newBinding = new QDeclarativeBinding(&function, reference->object, context);
+ newBinding->setSourceLocation(url, lineNumber);
+ newBinding->setTarget(QDeclarativePropertyPrivate::restore(cacheData, valueTypeData,
+ reference->object, context));
+ newBinding->setEvaluateFlags(newBinding->evaluateFlags() | QDeclarativeBinding::RequiresThisObject);
+ }
+
+ QDeclarativeAbstractBinding *oldBinding =
+ QDeclarativePropertyPrivate::setBinding(reference->object, reference->property, index, newBinding);
+ if (oldBinding)
+ oldBinding->destroy();
+
+ if (!value->IsFunction()) {
+ QVariant v = r->engine->toVariant(value, -1);
+
+ if (p.isEnumType() && (QMetaType::Type)v.type() == QMetaType::Double)
+ v = v.toInt();
+
+ p.write(reference->type, v);
+
+ reference->type->write(reference->object, reference->property, 0);
+ }
+
+ } else {
+ Q_ASSERT(r->objectType == QV8ValueTypeResource::Copy);
+
+ QV8ValueTypeCopyResource *copy = static_cast<QV8ValueTypeCopyResource *>(r);
+
+ QVariant v = r->engine->toVariant(value, -1);
+
+ r->type->setValue(copy->value);
+ QMetaProperty p = r->type->metaObject()->property(index);
+ p.write(r->type, v);
+ copy->value = r->type->value();
+ }
+
+ return value;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativevaluetypescriptclass_p.h b/src/declarative/qml/v8/qv8valuetypewrapper_p.h
index bafcff4ac2..d08d89392c 100644
--- a/src/declarative/qml/qdeclarativevaluetypescriptclass_p.h
+++ b/src/declarative/qml/v8/qv8valuetypewrapper_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QDECLARATIVEVALUETYPESCRIPTCLASS_P_H
-#define QDECLARATIVEVALUETYPESCRIPTCLASS_P_H
+#ifndef QV8VALUETYPEWRAPPER_P_H
+#define QV8VALUETYPEWRAPPER_P_H
//
// W A R N I N G
@@ -53,35 +53,43 @@
// We mean it.
//
-
-#include <private/qscriptdeclarativeclass_p.h>
+#include <QtCore/qglobal.h>
+#include <QtDeclarative/qdeclarativelist.h>
+#include <private/qv8_p.h>
QT_BEGIN_NAMESPACE
-class QDeclarativeEngine;
+class QV8Engine;
+class QV8ObjectResource;
class QDeclarativeValueType;
-class QDeclarativeValueTypeScriptClass : public QScriptDeclarativeClass
+class QV8ValueTypeWrapper
{
public:
- QDeclarativeValueTypeScriptClass(QDeclarativeEngine *);
- ~QDeclarativeValueTypeScriptClass();
+ QV8ValueTypeWrapper();
+ ~QV8ValueTypeWrapper();
+
+ void init(QV8Engine *);
+ void destroy();
- QScriptValue newObject(QObject *object, int coreIndex, QDeclarativeValueType *);
- QScriptValue newObject(const QVariant &, QDeclarativeValueType *);
+ v8::Local<v8::Object> newValueType(QObject *, int, QDeclarativeValueType *);
+ v8::Local<v8::Object> newValueType(const QVariant &, QDeclarativeValueType *);
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
- QScriptClass::QueryFlags flags);
- virtual Value property(Object *, const Identifier &);
- virtual void setProperty(Object *, const Identifier &name, const QScriptValue &);
+ QVariant toVariant(v8::Handle<v8::Object>);
+ QVariant toVariant(QV8ObjectResource *);
- virtual QVariant toVariant(Object *, bool *ok = 0);
- QVariant toVariant(const QScriptValue &);
private:
- QDeclarativeEngine *engine;
- int m_lastIndex;
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+
+ QV8Engine *m_engine;
+ v8::Persistent<v8::Function> m_constructor;
};
QT_END_NAMESPACE
-#endif // QDECLARATIVEVALUETYPESCRIPTCLASS_P_H
+#endif // QV8VALUETYPEWRAPPER_P_H
+
diff --git a/src/declarative/qml/v8/qv8variantwrapper.cpp b/src/declarative/qml/v8/qv8variantwrapper.cpp
new file mode 100644
index 0000000000..a5602fbbad
--- /dev/null
+++ b/src/declarative/qml/v8/qv8variantwrapper.cpp
@@ -0,0 +1,220 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8variantwrapper_p.h"
+#include "qv8engine_p.h"
+#include "qdeclarativeengine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QV8VariantResource : public QV8ObjectResource,
+ public QDeclarativeEnginePrivate::ScarceResourceData
+{
+ V8_RESOURCE_TYPE(VariantType);
+public:
+ QV8VariantResource(QV8Engine *engine, const QVariant &data);
+};
+
+QV8VariantResource::QV8VariantResource(QV8Engine *engine, const QVariant &data)
+: QV8ObjectResource(engine), QDeclarativeEnginePrivate::ScarceResourceData(data)
+{
+}
+
+QV8VariantWrapper::QV8VariantWrapper()
+: m_engine(0)
+{
+}
+
+QV8VariantWrapper::~QV8VariantWrapper()
+{
+}
+
+void QV8VariantWrapper::init(QV8Engine *engine)
+{
+ m_engine = engine;
+ m_toString = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(ToString)->GetFunction());
+
+ {
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->InstanceTemplate()->MarkAsUseUserObjectComparison();
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("toString"), ToStringGetter, 0,
+ m_toString, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
+ m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+ {
+ m_preserve = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(Preserve)->GetFunction());
+ m_destroy = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(Destroy)->GetFunction());
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ ft->InstanceTemplate()->MarkAsUseUserObjectComparison();
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("preserve"), PreserveGetter, 0,
+ m_preserve, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("destroy"), DestroyGetter, 0,
+ m_destroy, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
+ ft->InstanceTemplate()->SetAccessor(v8::String::New("toString"), ToStringGetter, 0,
+ m_toString, v8::DEFAULT,
+ v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
+ m_scarceConstructor = qPersistentNew<v8::Function>(ft->GetFunction());
+ }
+
+}
+
+void QV8VariantWrapper::destroy()
+{
+ qPersistentDispose(m_toString);
+ qPersistentDispose(m_destroy);
+ qPersistentDispose(m_preserve);
+ qPersistentDispose(m_scarceConstructor);
+ qPersistentDispose(m_constructor);
+}
+
+v8::Local<v8::Object> QV8VariantWrapper::newVariant(const QVariant &value)
+{
+ bool scarceResource = value.type() == QVariant::Pixmap ||
+ value.type() == QVariant::Image;
+
+ // XXX NewInstance() should be optimized
+ v8::Local<v8::Object> rv;
+ QV8VariantResource *r = new QV8VariantResource(m_engine, value);
+
+ if (scarceResource) {
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(m_engine->engine());
+ Q_ASSERT(ep->scarceResourcesRefCount);
+ rv = m_scarceConstructor->NewInstance();
+ ep->scarceResources.insert(r);
+ } else {
+ rv = m_constructor->NewInstance();
+ }
+
+ rv->SetExternalResource(r);
+ return rv;
+}
+
+bool QV8VariantWrapper::isVariant(v8::Handle<v8::Value> value)
+{
+ return value->IsObject() && v8_resource_cast<QV8VariantResource>(value->ToObject());
+}
+
+QVariant QV8VariantWrapper::toVariant(v8::Handle<v8::Object> obj)
+{
+ QV8VariantResource *r = v8_resource_cast<QV8VariantResource>(obj);
+ return r?r->data:QVariant();
+}
+
+QVariant QV8VariantWrapper::toVariant(QV8ObjectResource *r)
+{
+ Q_ASSERT(r->resourceType() == QV8ObjectResource::VariantType);
+ return static_cast<QV8VariantResource *>(r)->data;
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::PreserveGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ return info.Data();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::DestroyGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ return info.Data();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::ToStringGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ Q_UNUSED(property);
+ return info.Data();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::Preserve(const v8::Arguments &args)
+{
+ QV8VariantResource *resource = v8_resource_cast<QV8VariantResource>(args.This());
+ if (resource) {
+ resource->node.remove();
+ }
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::Destroy(const v8::Arguments &args)
+{
+ QV8VariantResource *resource = v8_resource_cast<QV8VariantResource>(args.This());
+ if (resource) {
+ resource->data = QVariant();
+ resource->node.remove();
+ }
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QV8VariantWrapper::ToString(const v8::Arguments &args)
+{
+ QV8VariantResource *resource = v8_resource_cast<QV8VariantResource>(args.This());
+ if (resource) {
+ QString result = resource->data.toString();
+ if (result.isEmpty() && !resource->data.canConvert(QVariant::String))
+ result = QString::fromLatin1("QVariant(%0)").arg(QString::fromLatin1(resource->data.typeName()));
+ return resource->engine->toString(result);
+ } else {
+ return v8::Undefined();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/v8/qv8variantwrapper_p.h
index 04d3e9a4d5..9e165f37f4 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h
+++ b/src/declarative/qml/v8/qv8variantwrapper_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QDECLARATIVECONTEXTSCRIPTCLASS_P_H
-#define QDECLARATIVECONTEXTSCRIPTCLASS_P_H
+#ifndef QV8VARIANTWRAPPER_P_H
+#define QV8VARIANTWRAPPER_P_H
//
// W A R N I N G
@@ -53,54 +53,53 @@
// We mean it.
//
-#include "private/qdeclarativetypenamecache_p.h"
-#include <private/qscriptdeclarativeclass_p.h>
+#include <QtCore/qglobal.h>
+#include <QtDeclarative/qdeclarativelist.h>
+#include <private/qv8_p.h>
QT_BEGIN_NAMESPACE
-class QDeclarativeEngine;
-class QDeclarativeContext;
-class QDeclarativeContextData;
-class QDeclarativeContextScriptClass : public QScriptDeclarativeClass
+class QV8Engine;
+class QV8ObjectResource;
+class QV8VariantWrapper
{
public:
- QDeclarativeContextScriptClass(QDeclarativeEngine *);
- ~QDeclarativeContextScriptClass();
+ QV8VariantWrapper();
+ ~QV8VariantWrapper();
- QScriptValue newContext(QDeclarativeContextData *, QObject * = 0);
- QScriptValue newUrlContext(QDeclarativeContextData *, QObject *, const QString &);
- QScriptValue newUrlContext(const QString &);
- QScriptValue newSharedContext();
+ void init(QV8Engine *);
+ void destroy();
- QDeclarativeContextData *contextFromValue(const QScriptValue &);
- QUrl urlFromValue(const QScriptValue &);
-
- QObject *setOverrideObject(QScriptValue &, QObject *);
-
-protected:
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
- QScriptClass::QueryFlags flags);
- virtual Value property(Object *, const Identifier &);
- virtual void setProperty(Object *, const Identifier &name, const QScriptValue &);
+ v8::Local<v8::Object> newVariant(const QVariant &);
+ bool isVariant(v8::Handle<v8::Value>);
+ QVariant toVariant(v8::Handle<v8::Object>);
+ QVariant toVariant(QV8ObjectResource *);
private:
- QScriptClass::QueryFlags queryProperty(QDeclarativeContextData *, QObject *scopeObject,
- const Identifier &,
- QScriptClass::QueryFlags flags,
- bool includeTypes);
-
- QDeclarativeEngine *engine;
-
- QObject *lastScopeObject;
- QDeclarativeContextData *lastContext;
- QDeclarativeTypeNameCache::Data *lastData;
- int lastPropertyIndex;
- QScriptValue lastFunction;
-
- uint m_id;
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> PreserveGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> DestroyGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> ToStringGetter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Preserve(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Destroy(const v8::Arguments &args);
+ static v8::Handle<v8::Value> ToString(const v8::Arguments &args);
+
+ QV8Engine *m_engine;
+ v8::Persistent<v8::Function> m_constructor;
+ v8::Persistent<v8::Function> m_scarceConstructor;
+ v8::Persistent<v8::Function> m_preserve;
+ v8::Persistent<v8::Function> m_destroy;
+ v8::Persistent<v8::Function> m_toString;
};
QT_END_NAMESPACE
-#endif // QDECLARATIVECONTEXTSCRIPTCLASS_P_H
+#endif // QV8VARIANTWRAPPER_P_H
diff --git a/src/declarative/qml/v8/qv8worker.cpp b/src/declarative/qml/v8/qv8worker.cpp
new file mode 100644
index 0000000000..0d396d3304
--- /dev/null
+++ b/src/declarative/qml/v8/qv8worker.cpp
@@ -0,0 +1,352 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8worker_p.h"
+
+#include <private/qdeclarativelistmodel_p.h>
+#include <private/qdeclarativelistmodelworkeragent_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// We allow the following JavaScript types to be passed between the main and
+// the secondary thread:
+// + undefined
+// + null
+// + Boolean
+// + String
+// + Function
+// + Array
+// + "Simple" Objects
+// + Number
+// + Date
+// + RegExp
+// <quint8 type><quint24 size><data>
+
+enum Type {
+ WorkerUndefined,
+ WorkerNull,
+ WorkerTrue,
+ WorkerFalse,
+ WorkerString,
+ WorkerFunction,
+ WorkerArray,
+ WorkerObject,
+ WorkerInt32,
+ WorkerUint32,
+ WorkerNumber,
+ WorkerDate,
+ WorkerRegexp,
+ WorkerListModel
+};
+
+static inline quint32 valueheader(Type type, quint32 size = 0)
+{
+ return quint8(type) << 24 | (size & 0xFFFFFF);
+}
+
+static inline Type headertype(quint32 header)
+{
+ return (Type)(header >> 24);
+}
+
+static inline quint32 headersize(quint32 header)
+{
+ return header & 0xFFFFFF;
+}
+
+static inline void push(QByteArray &data, quint32 value)
+{
+ data.append((const char *)&value, sizeof(quint32));
+}
+
+static inline void push(QByteArray &data, double value)
+{
+ data.append((const char *)&value, sizeof(double));
+}
+
+static inline void push(QByteArray &data, void *ptr)
+{
+ data.append((const char *)&ptr, sizeof(void *));
+}
+
+static inline void reserve(QByteArray &data, int extra)
+{
+ data.reserve(data.size() + extra);
+}
+
+static inline quint32 popUint32(const char *&data)
+{
+ quint32 rv = *((quint32 *)data);
+ data += sizeof(quint32);
+ return rv;
+}
+
+static inline double popDouble(const char *&data)
+{
+ double rv = *((double *)data);
+ data += sizeof(double);
+ return rv;
+}
+
+static inline void *popPtr(const char *&data)
+{
+ void *rv = *((void **)data);
+ data += sizeof(void *);
+ return rv;
+}
+
+// XXX TODO: Check that worker script is exception safe in the case of
+// serialization/deserialization failures
+
+#define ALIGN(size) (((size) + 3) & ~3)
+void QV8Worker::serialize(QByteArray &data, v8::Handle<v8::Value> v, QV8Engine *engine)
+{
+ if (v.IsEmpty()) {
+ } else if (v->IsUndefined()) {
+ push(data, valueheader(WorkerUndefined));
+ } else if (v->IsNull()) {
+ push(data, valueheader(WorkerNull));
+ } else if (v->IsTrue()) {
+ push(data, valueheader(WorkerTrue));
+ } else if (v->IsFalse()) {
+ push(data, valueheader(WorkerFalse));
+ } else if (v->IsString()) {
+ v8::Handle<v8::String> string = v->ToString();
+ int length = string->Length() + 1;
+ if (length > 0xFFFFFF) {
+ push(data, valueheader(WorkerUndefined));
+ return;
+ }
+ int utf16size = ALIGN(length * sizeof(uint16_t));
+
+ reserve(data, utf16size + sizeof(quint32));
+ push(data, valueheader(WorkerString, length));
+
+ int offset = data.size();
+ data.resize(data.size() + utf16size);
+ char *buffer = data.data() + offset;
+
+ string->Write((uint16_t*)buffer);
+ } else if (v->IsFunction()) {
+ // XXX TODO: Implement passing function objects between the main and
+ // worker scripts
+ push(data, valueheader(WorkerUndefined));
+ } else if (v->IsArray()) {
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(v);
+ uint32_t length = array->Length();
+ if (length > 0xFFFFFF) {
+ push(data, valueheader(WorkerUndefined));
+ return;
+ }
+ reserve(data, sizeof(quint32) + length * sizeof(quint32));
+ push(data, valueheader(WorkerArray, length));
+ for (uint32_t ii = 0; ii < length; ++ii)
+ serialize(data, array->Get(ii), engine);
+ } else if (v->IsInt32()) {
+ reserve(data, 2 * sizeof(quint32));
+ push(data, valueheader(WorkerInt32));
+ push(data, (quint32)v->Int32Value());
+ } else if (v->IsUint32()) {
+ reserve(data, 2 * sizeof(quint32));
+ push(data, valueheader(WorkerUint32));
+ push(data, v->Uint32Value());
+ } else if (v->IsNumber()) {
+ reserve(data, sizeof(quint32) + sizeof(double));
+ push(data, valueheader(WorkerNumber));
+ push(data, v->NumberValue());
+ } else if (v->IsDate()) {
+ reserve(data, sizeof(quint32) + sizeof(double));
+ push(data, valueheader(WorkerDate));
+ push(data, v8::Handle<v8::Date>::Cast(v)->NumberValue());
+ } else if (v->IsRegExp()) {
+ v8::Handle<v8::RegExp> regexp = v8::Handle<v8::RegExp>::Cast(v);
+ quint32 flags = regexp->GetFlags();
+ v8::Local<v8::String> source = regexp->GetSource();
+
+ int length = source->Length() + 1;
+ if (length > 0xFFFFFF) {
+ push(data, valueheader(WorkerUndefined));
+ return;
+ }
+ int utf16size = ALIGN(length * sizeof(uint16_t));
+
+ reserve(data, sizeof(quint32) + utf16size);
+ push(data, valueheader(WorkerRegexp, flags));
+ push(data, (quint32)length);
+ int offset = data.size();
+ data.resize(data.size() + utf16size);
+ char *buffer = data.data() + offset;
+
+ source->Write((uint16_t*)buffer);
+ } else if (v->IsObject() && !v->ToObject()->GetExternalResource()) {
+ v8::Handle<v8::Object> object = v->ToObject();
+ v8::Local<v8::Array> properties = engine->getOwnPropertyNames(object);
+ quint32 length = properties->Length();
+ if (length > 0xFFFFFF) {
+ push(data, valueheader(WorkerUndefined));
+ return;
+ }
+ push(data, valueheader(WorkerObject, length));
+ v8::TryCatch tc;
+ for (quint32 ii = 0; ii < length; ++ii) {
+ v8::Local<v8::String> str = properties->Get(ii)->ToString();
+ serialize(data, str, engine);
+
+ v8::Local<v8::Value> val = object->Get(str);
+ if (tc.HasCaught()) {
+ serialize(data, v8::Undefined(), engine);
+ tc.Reset();
+ } else {
+ serialize(data, val, engine);
+ }
+ }
+ } else if (engine->isQObject(v)) {
+ // XXX TODO: Generalize passing objects between the main thread and worker scripts so
+ // that others can trivially plug in their elements.
+ QDeclarativeListModel *lm = qobject_cast<QDeclarativeListModel *>(engine->toQObject(v));
+ if (lm && lm->agent()) {
+ QDeclarativeListModelWorkerAgent *agent = lm->agent();
+ agent->addref();
+ push(data, valueheader(WorkerListModel));
+ push(data, (void *)agent);
+ return;
+ }
+ // No other QObject's are allowed to be sent
+ push(data, valueheader(WorkerUndefined));
+ } else {
+ push(data, valueheader(WorkerUndefined));
+ }
+}
+
+v8::Handle<v8::Value> QV8Worker::deserialize(const char *&data, QV8Engine *engine)
+{
+ quint32 header = popUint32(data);
+ Type type = headertype(header);
+
+ switch (type) {
+ case WorkerUndefined:
+ return v8::Undefined();
+ case WorkerNull:
+ return v8::Null();
+ case WorkerTrue:
+ return v8::True();
+ case WorkerFalse:
+ return v8::False();
+ case WorkerString:
+ {
+ quint32 size = headersize(header);
+ v8::Local<v8::String> string = v8::String::New((uint16_t*)data, size - 1);
+ data += ALIGN(size * sizeof(uint16_t));
+ return string;
+ }
+ case WorkerFunction:
+ Q_ASSERT(!"Unreachable");
+ break;
+ case WorkerArray:
+ {
+ quint32 size = headersize(header);
+ v8::Local<v8::Array> array = v8::Array::New(size);
+ for (quint32 ii = 0; ii < size; ++ii) {
+ array->Set(ii, deserialize(data, engine));
+ }
+ return array;
+ }
+ case WorkerObject:
+ {
+ quint32 size = headersize(header);
+ v8::Local<v8::Object> o = v8::Object::New();
+ for (quint32 ii = 0; ii < size; ++ii) {
+ v8::Handle<v8::Value> name = deserialize(data, engine);
+ v8::Handle<v8::Value> value = deserialize(data, engine);
+ o->Set(name, value);
+ }
+ return o;
+ }
+ case WorkerInt32:
+ return v8::Integer::New((qint32)popUint32(data));
+ case WorkerUint32:
+ return v8::Integer::NewFromUnsigned(popUint32(data));
+ case WorkerNumber:
+ return v8::Number::New(popDouble(data));
+ case WorkerDate:
+ return v8::Date::New(popDouble(data));
+ case WorkerRegexp:
+ {
+ quint32 flags = headersize(header);
+ quint32 length = popUint32(data);
+ v8::Local<v8::String> source = v8::String::New((uint16_t*)data, length - 1);
+ data += ALIGN(length * sizeof(uint16_t));
+ return v8::RegExp::New(source, (v8::RegExp::Flags)flags);
+ }
+ case WorkerListModel:
+ {
+ void *ptr = popPtr(data);
+ QDeclarativeListModelWorkerAgent *agent = (QDeclarativeListModelWorkerAgent *)ptr;
+ v8::Handle<v8::Value> rv = engine->newQObject(agent);
+ if (rv->IsObject()) {
+ QDeclarativeListModelWorkerAgent::VariantRef ref(agent);
+ QVariant var = qVariantFromValue(ref);
+ rv->ToObject()->SetHiddenValue(v8::String::New("qml::ref"), engine->fromVariant(var));
+ }
+ agent->release();
+ agent->setV8Engine(engine);
+ return rv;
+ }
+ }
+ Q_ASSERT(!"Unreachable");
+ return v8::Undefined();
+}
+
+QByteArray QV8Worker::serialize(v8::Handle<v8::Value> value, QV8Engine *engine)
+{
+ QByteArray rv;
+ serialize(rv, value, engine);
+ return rv;
+}
+
+v8::Handle<v8::Value> QV8Worker::deserialize(const QByteArray &data, QV8Engine *engine)
+{
+ const char *stream = data.constData();
+ return deserialize(stream, engine);
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/declarative/qml/v8/qv8worker_p.h b/src/declarative/qml/v8/qv8worker_p.h
new file mode 100644
index 0000000000..086e18e7e0
--- /dev/null
+++ b/src/declarative/qml/v8/qv8worker_p.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8WORKER_P_H
+#define QV8WORKER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qv8engine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QV8Worker {
+public:
+ struct SavedData {
+ };
+
+ static QByteArray serialize(v8::Handle<v8::Value>, QV8Engine *);
+ static v8::Handle<v8::Value> deserialize(const QByteArray &, QV8Engine *);
+
+private:
+ static void serialize(QByteArray &, v8::Handle<v8::Value>, QV8Engine *);
+ static v8::Handle<v8::Value> deserialize(const char *&, QV8Engine *);
+};
+
+QT_END_NAMESPACE
+
+#endif // QV8WORKER_P_H
diff --git a/src/declarative/qml/v8/v8.pri b/src/declarative/qml/v8/v8.pri
new file mode 100644
index 0000000000..61e0184884
--- /dev/null
+++ b/src/declarative/qml/v8/v8.pri
@@ -0,0 +1,34 @@
+INCLUDEPATH += $$PWD/../../../3rdparty/javascriptcore
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/qv8_p.h \
+ $$PWD/qv8stringwrapper_p.h \
+ $$PWD/qv8engine_p.h \
+ $$PWD/qhashedstring_p.h \
+ $$PWD/qv8contextwrapper_p.h \
+ $$PWD/qv8qobjectwrapper_p.h \
+ $$PWD/qv8typewrapper_p.h \
+ $$PWD/qv8listwrapper_p.h \
+ $$PWD/qv8variantwrapper_p.h \
+ $$PWD/qv8valuetypewrapper_p.h \
+ $$PWD/qv8include_p.h \
+ $$PWD/qv8worker_p.h \
+ $$PWD/qv8bindings_p.h \
+ $$PWD/../../../3rdparty/javascriptcore/DateMath.h \
+
+SOURCES += \
+ $$PWD/qv8stringwrapper.cpp \
+ $$PWD/qv8engine.cpp \
+ $$PWD/qhashedstring.cpp \
+ $$PWD/qv8contextwrapper.cpp \
+ $$PWD/qv8qobjectwrapper.cpp \
+ $$PWD/qv8typewrapper.cpp \
+ $$PWD/qv8listwrapper.cpp \
+ $$PWD/qv8variantwrapper.cpp \
+ $$PWD/qv8valuetypewrapper.cpp \
+ $$PWD/qv8include.cpp \
+ $$PWD/qv8worker.cpp \
+ $$PWD/qv8bindings.cpp \
+ $$PWD/../../../3rdparty/javascriptcore/DateMath.cpp \
+
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 28c2df6d79..8659c5b7aa 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -52,12 +52,127 @@
#include <QtCore/qdebug.h>
#include <QtCore/qstack.h>
#include <QXmlStreamReader>
-#include <QtScript/qscriptvalueiterator.h>
Q_DECLARE_METATYPE(QListModelInterface *)
QT_BEGIN_NAMESPACE
+QV8ListModelResource::QV8ListModelResource(FlatListModel *model, FlatNodeData *data, QV8Engine *engine)
+: QV8ObjectResource(engine), model(model), nodeData(data)
+{
+ if (nodeData) nodeData->addData(this);
+}
+
+QV8ListModelResource::~QV8ListModelResource()
+{
+ if (nodeData) nodeData->removeData(this);
+}
+
+class QDeclarativeListModelV8Data : public QV8Engine::Deletable
+{
+public:
+ QDeclarativeListModelV8Data();
+ ~QDeclarativeListModelV8Data();
+
+ v8::Persistent<v8::Function> constructor;
+
+ static v8::Local<v8::Object> create(QV8Engine *);
+
+ static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info);
+ static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info);
+};
+
+v8::Local<v8::Object> QDeclarativeListModelV8Data::create(QV8Engine *engine)
+{
+ if (!engine->listModelData()) {
+ QDeclarativeListModelV8Data *d = new QDeclarativeListModelV8Data;
+ engine->setListModelData(d);
+ }
+
+ QDeclarativeListModelV8Data *d = (QDeclarativeListModelV8Data *)engine->listModelData();
+ return d->constructor->NewInstance();
+}
+
+QDeclarativeListModelV8Data::QDeclarativeListModelV8Data()
+{
+ v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
+ ft->InstanceTemplate()->SetNamedPropertyHandler(Getter, Setter);
+ ft->InstanceTemplate()->SetHasExternalResource(true);
+ constructor = qPersistentNew<v8::Function>(ft->GetFunction());
+}
+
+QDeclarativeListModelV8Data::~QDeclarativeListModelV8Data()
+{
+ qPersistentDispose(constructor);
+}
+
+v8::Handle<v8::Value> QDeclarativeListModelV8Data::Getter(v8::Local<v8::String> property,
+ const v8::AccessorInfo &info)
+{
+ QV8ListModelResource *r = v8_resource_cast<QV8ListModelResource>(info.This());
+ if (!r)
+ return v8::Undefined();
+
+ if (!r->nodeData) // Item at this index has been deleted
+ return v8::Undefined();
+
+
+ int index = r->nodeData->index;
+ QString propName = r->engine->toString(property);
+
+ int role = r->model->m_strings.value(propName, -1);
+
+ if (role >= 0 && index >=0 ) {
+ const QHash<int, QVariant> &row = r->model->m_values[index];
+ return r->engine->fromVariant(row[role]);
+ }
+
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> QDeclarativeListModelV8Data::Setter(v8::Local<v8::String> property,
+ v8::Local<v8::Value> value,
+ const v8::AccessorInfo &info)
+{
+ QV8ListModelResource *r = v8_resource_cast<QV8ListModelResource>(info.This());
+ if (!r)
+ return v8::Undefined();
+
+ if (!r->nodeData) // item at this index has been deleted
+ return value;
+
+
+ if (!value->IsRegExp() && !value->IsDate() && value->IsObject() && !r->engine->isVariant(value)) {
+ qmlInfo(r->model->m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
+ return value;
+ }
+
+ int index = r->nodeData->index;
+ QString propName = r->engine->toString(property);
+
+ int role = r->model->m_strings.value(propName, -1);
+ if (role >= 0 && index >= 0) {
+ QHash<int, QVariant> &row = r->model->m_values[index];
+ row[role] = r->engine->toVariant(value, -1);
+
+ QList<int> roles;
+ roles << role;
+ if (r->model->m_parentAgent) {
+ // This is the list in the worker thread, so tell the agent to
+ // emit itemsChanged() later
+ r->model->m_parentAgent->changedData(index, 1, roles);
+ } else {
+ // This is the list in the main thread, so emit itemsChanged()
+ emit r->model->m_listModel->itemsChanged(index, 1, roles);
+ }
+ }
+
+ return value;
+}
+
template<typename T>
void qdeclarativelistmodel_move(int from, int to, int n, T *items)
{
@@ -367,13 +482,14 @@ QDeclarativeListModel *ModelNode::model(const NestedListModel *model)
ModelObject *ModelNode::object(const NestedListModel *model)
{
if (!objectCache) {
- objectCache = new ModelObject(this,
- const_cast<NestedListModel*>(model),
- QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(model->m_listModel)));
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(qmlEngine(model->m_listModel));
+ objectCache = new ModelObject(this, const_cast<NestedListModel*>(model), &ep->v8engine);
+
QHash<QString, ModelNode *>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) {
objectCache->setValue(it.key().toUtf8(), model->valueForNode(*it));
}
+
objectCache->setNodeUpdatesEnabled(true);
}
return objectCache;
@@ -419,9 +535,11 @@ void QDeclarativeListModel::remove(int index)
\sa set() append()
*/
-void QDeclarativeListModel::insert(int index, const QScriptValue& valuemap)
+void QDeclarativeListModel::insert(int index, const QDeclarativeV8Handle &handle)
{
- if (!valuemap.isObject() || valuemap.isArray()) {
+ v8::Handle<v8::Value> valuemap = handle.toHandle();
+
+ if (!valuemap->IsObject() || valuemap->IsArray()) {
qmlInfo(this) << tr("insert: value is not an object");
return;
}
@@ -432,6 +550,7 @@ void QDeclarativeListModel::insert(int index, const QScriptValue& valuemap)
}
bool ok = m_flat ? m_flat->insert(index, valuemap) : m_nested->insert(index, valuemap);
+
if (ok && !inWorkerThread()) {
emit itemsInserted(index, 1);
emit countChanged();
@@ -494,14 +613,16 @@ void QDeclarativeListModel::move(int from, int to, int n)
\sa set() remove()
*/
-void QDeclarativeListModel::append(const QScriptValue& valuemap)
+void QDeclarativeListModel::append(const QDeclarativeV8Handle &handle)
{
- if (!valuemap.isObject() || valuemap.isArray()) {
+ v8::Handle<v8::Value> valuemap = handle.toHandle();
+
+ if (!valuemap->IsObject() || valuemap->IsArray()) {
qmlInfo(this) << tr("append: value is not an object");
return;
}
- insert(count(), valuemap);
+ insert(count(), handle);
}
/*!
@@ -535,10 +656,10 @@ void QDeclarativeListModel::append(const QScriptValue& valuemap)
\sa append()
*/
-QScriptValue QDeclarativeListModel::get(int index) const
+QDeclarativeV8Handle QDeclarativeListModel::get(int index) const
{
// the internal flat/nested class checks for bad index
- return m_flat ? m_flat->get(index) : m_nested->get(index);
+ return QDeclarativeV8Handle::fromHandle(m_flat ? m_flat->get(index) : m_nested->get(index));
}
/*!
@@ -557,7 +678,7 @@ QScriptValue QDeclarativeListModel::get(int index) const
\sa append()
*/
-void QDeclarativeListModel::set(int index, const QScriptValue& valuemap)
+void QDeclarativeListModel::set(int index, const QDeclarativeV8Handle &valuemap)
{
QList<int> roles;
set(index, valuemap, &roles);
@@ -565,9 +686,11 @@ void QDeclarativeListModel::set(int index, const QScriptValue& valuemap)
emit itemsChanged(index, 1, roles);
}
-void QDeclarativeListModel::set(int index, const QScriptValue& valuemap, QList<int> *roles)
+void QDeclarativeListModel::set(int index, const QDeclarativeV8Handle &handle, QList<int> *roles)
{
- if (!valuemap.isObject() || valuemap.isArray()) {
+ v8::Handle<v8::Value> valuemap = handle.toHandle();
+
+ if (!valuemap->IsObject() || valuemap->IsArray()) {
qmlInfo(this) << tr("set: value is not an object");
return;
}
@@ -577,7 +700,7 @@ void QDeclarativeListModel::set(int index, const QScriptValue& valuemap, QList<i
}
if (index == count()) {
- append(valuemap);
+ append(handle);
} else {
if (m_flat)
m_flat->set(index, valuemap, roles);
@@ -912,7 +1035,7 @@ bool QDeclarativeListModelParser::definesEmptyList(const QString &s)
*/
FlatListModel::FlatListModel(QDeclarativeListModel *base)
- : m_scriptEngine(0), m_listModel(base), m_scriptClass(0), m_parentAgent(0)
+: m_engine(0), m_listModel(base), m_parentAgent(0)
{
}
@@ -960,7 +1083,7 @@ void FlatListModel::remove(int index)
removedNode(index);
}
-bool FlatListModel::insert(int index, const QScriptValue &value)
+bool FlatListModel::insert(int index, v8::Handle<v8::Value> value)
{
Q_ASSERT(index >= 0 && index <= m_values.count());
@@ -974,19 +1097,27 @@ bool FlatListModel::insert(int index, const QScriptValue &value)
return true;
}
-QScriptValue FlatListModel::get(int index) const
+QV8Engine *FlatListModel::engine() const
{
- QScriptEngine *scriptEngine = m_scriptEngine ? m_scriptEngine : QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(m_listModel));
+ return m_engine?m_engine:QDeclarativeEnginePrivate::getV8Engine(qmlEngine(m_listModel));
+}
- if (!scriptEngine)
- return 0;
+QV8Engine *NestedListModel::engine() const
+{
+ return QDeclarativeEnginePrivate::getV8Engine(qmlEngine(m_listModel));
+}
+
+v8::Handle<v8::Value> FlatListModel::get(int index) const
+{
+ QV8Engine *v8engine = engine();
+
+ if (!v8engine)
+ return v8::Undefined();
if (index < 0 || index >= m_values.count())
- return scriptEngine->undefinedValue();
+ return v8::Undefined();
FlatListModel *that = const_cast<FlatListModel*>(this);
- if (!m_scriptClass)
- that->m_scriptClass = new FlatListScriptClass(that, scriptEngine);
FlatNodeData *data = m_nodeData.value(index);
if (!data) {
@@ -994,10 +1125,13 @@ QScriptValue FlatListModel::get(int index) const
that->m_nodeData.replace(index, data);
}
- return QScriptDeclarativeClass::newObject(scriptEngine, m_scriptClass, new FlatNodeObjectData(data));
+ v8::Local<v8::Object> rv = QDeclarativeListModelV8Data::create(v8engine);
+ QV8ListModelResource *r = new QV8ListModelResource(that, data, v8engine);
+ rv->SetExternalResource(r);
+ return rv;
}
-void FlatListModel::set(int index, const QScriptValue &value, QList<int> *roles)
+void FlatListModel::set(int index, v8::Handle<v8::Value> value, QList<int> *roles)
{
Q_ASSERT(index >= 0 && index < m_values.count());
@@ -1032,19 +1166,25 @@ void FlatListModel::move(int from, int to, int n)
moveNodes(from, to, n);
}
-bool FlatListModel::addValue(const QScriptValue &value, QHash<int, QVariant> *row, QList<int> *roles)
+bool FlatListModel::addValue(v8::Handle<v8::Value> value, QHash<int, QVariant> *row, QList<int> *roles)
{
- QScriptValueIterator it(value);
- while (it.hasNext()) {
- it.next();
- QScriptValue value = it.value();
- if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
+ if (!value->IsObject())
+ return false;
+
+ v8::Local<v8::Array> properties = engine()->getOwnPropertyNames(value->ToObject());
+ uint32_t length = properties->Length();
+ for (uint32_t ii = 0; ii < length; ++ii) {
+ // XXX TryCatch?
+ v8::Handle<v8::Value> property = properties->Get(ii);
+ v8::Handle<v8::Value> jsv = value->ToObject()->Get(property);
+
+ if (!jsv->IsRegExp() && !jsv->IsDate() && jsv->IsObject() && !engine()->isVariant(jsv)) {
qmlInfo(m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
return false;
}
- QString name = it.name();
- QVariant v = it.value().toVariant();
+ QString name = engine()->toString(property);
+ QVariant v = engine()->toVariant(jsv, -1);
QHash<QString, int>::Iterator iter = m_strings.find(name);
if (iter == m_strings.end()) {
@@ -1100,104 +1240,26 @@ void FlatListModel::moveNodes(int from, int to, int n)
}
}
-
-
FlatNodeData::~FlatNodeData()
{
- for (QSet<FlatNodeObjectData *>::Iterator iter = objects.begin(); iter != objects.end(); ++iter) {
- FlatNodeObjectData *data = *iter;
+ for (QSet<QV8ListModelResource *>::Iterator iter = objects.begin(); iter != objects.end(); ++iter) {
+ QV8ListModelResource *data = *iter;
data->nodeData = 0;
}
}
-void FlatNodeData::addData(FlatNodeObjectData *data)
+void FlatNodeData::addData(QV8ListModelResource *data)
{
objects.insert(data);
}
-void FlatNodeData::removeData(FlatNodeObjectData *data)
+void FlatNodeData::removeData(QV8ListModelResource *data)
{
objects.remove(data);
}
-
-FlatListScriptClass::FlatListScriptClass(FlatListModel *model, QScriptEngine *seng)
- : QScriptDeclarativeClass(seng),
- m_model(model)
-{
-}
-
-QScriptDeclarativeClass::Value FlatListScriptClass::property(Object *obj, const Identifier &name)
-{
- FlatNodeObjectData *objData = static_cast<FlatNodeObjectData*>(obj);
- if (!objData->nodeData) // item at this index has been deleted
- return QScriptDeclarativeClass::Value(engine(), engine()->undefinedValue());
-
- int index = objData->nodeData->index;
- QString propName = toString(name);
- int role = m_model->m_strings.value(propName, -1);
-
- if (role >= 0 && index >=0 ) {
- const QHash<int, QVariant> &row = m_model->m_values[index];
- QScriptValue sv = engine()->toScriptValue<QVariant>(row[role]);
- return QScriptDeclarativeClass::Value(engine(), sv);
- }
-
- return QScriptDeclarativeClass::Value(engine(), engine()->undefinedValue());
-}
-
-void FlatListScriptClass::setProperty(Object *obj, const Identifier &name, const QScriptValue &value)
-{
- if (!value.isVariant() && !value.isRegExp() && !value.isDate() && value.isObject()) {
- qmlInfo(m_model->m_listModel) << "Cannot add list-type data when modifying or after modification from a worker script";
- return;
- }
-
- FlatNodeObjectData *objData = static_cast<FlatNodeObjectData*>(obj);
- if (!objData->nodeData) // item at this index has been deleted
- return;
-
- int index = objData->nodeData->index;
- QString propName = toString(name);
-
- int role = m_model->m_strings.value(propName, -1);
- if (role >= 0 && index >= 0) {
- QHash<int, QVariant> &row = m_model->m_values[index];
- row[role] = value.toVariant();
-
- QList<int> roles;
- roles << role;
- if (m_model->m_parentAgent) {
- // This is the list in the worker thread, so tell the agent to
- // emit itemsChanged() later
- m_model->m_parentAgent->changedData(index, 1, roles);
- } else {
- // This is the list in the main thread, so emit itemsChanged()
- emit m_model->m_listModel->itemsChanged(index, 1, roles);
- }
- }
-}
-
-QScriptClass::QueryFlags FlatListScriptClass::queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags)
-{
- return (QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess);
-}
-
-bool FlatListScriptClass::compare(Object *obj1, Object *obj2)
-{
- FlatNodeObjectData *data1 = static_cast<FlatNodeObjectData*>(obj1);
- FlatNodeObjectData *data2 = static_cast<FlatNodeObjectData*>(obj2);
-
- if (!data1->nodeData || !data2->nodeData)
- return false;
-
- return data1->nodeData->index == data2->nodeData->index;
-}
-
-
-
NestedListModel::NestedListModel(QDeclarativeListModel *base)
- : _root(0), m_ownsRoot(false), m_listModel(base), _rolesOk(false)
+: _root(0), m_ownsRoot(false), m_listModel(base), _rolesOk(false)
{
}
@@ -1315,7 +1377,7 @@ void NestedListModel::remove(int index)
delete node;
}
-bool NestedListModel::insert(int index, const QScriptValue& valuemap)
+bool NestedListModel::insert(int index, v8::Handle<v8::Value> valuemap)
{
if (!_root) {
_root = new ModelNode(this);
@@ -1336,42 +1398,47 @@ void NestedListModel::move(int from, int to, int n)
qdeclarativelistmodel_move<QVariantList>(from, to, n, &_root->values);
}
-QScriptValue NestedListModel::get(int index) const
+v8::Handle<v8::Value> NestedListModel::get(int index) const
{
QDeclarativeEngine *eng = qmlEngine(m_listModel);
if (!eng)
- return 0;
+ return v8::Undefined();;
- if (index < 0 || index >= count()) {
- QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(eng);
- if (seng)
- return seng->undefinedValue();
- return 0;
- }
+ if (index < 0 || index >= count())
+ return v8::Undefined();
ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index));
if (!node)
- return 0;
-
- return QDeclarativeEnginePrivate::qmlScriptObject(node->object(this), eng);
+ return v8::Undefined();;
+
+ return QDeclarativeEnginePrivate::get(eng)->v8engine.newQObject(node->object(this));
}
-void NestedListModel::set(int index, const QScriptValue& valuemap, QList<int> *roles)
+void NestedListModel::set(int index, v8::Handle<v8::Value> valuemap, QList<int> *roles)
{
Q_ASSERT(index >=0 && index < count());
+ if (!valuemap->IsObject())
+ return;
+
ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index));
bool emitItemsChanged = node->setObjectValue(valuemap);
if (!emitItemsChanged)
return;
- QScriptValueIterator it(valuemap);
- while (it.hasNext()) {
- it.next();
- int r = roleStrings.indexOf(it.name());
+ QV8Engine *v8engine = engine();
+
+ v8::Local<v8::Array> properties = v8engine->getOwnPropertyNames(valuemap->ToObject());
+ uint32_t length = properties->Length();
+ for (uint32_t ii = 0; ii < length; ++ii) {
+ // XXX TryCatch?
+ v8::Handle<v8::Value> property = properties->Get(ii);
+ QString name = v8engine->toString(property);
+
+ int r = roleStrings.indexOf(name);
if (r < 0) {
r = roleStrings.count();
- roleStrings << it.name();
+ roleStrings << name;
}
roles->append(r);
}
@@ -1456,55 +1523,75 @@ void ModelNode::clear()
properties.clear();
}
-bool ModelNode::setObjectValue(const QScriptValue& valuemap, bool writeToCache)
+bool ModelNode::setObjectValue(v8::Handle<v8::Value> valuemap, bool writeToCache)
{
+ if (!valuemap->IsObject())
+ return false;
+
bool emitItemsChanged = false;
- QScriptValueIterator it(valuemap);
- while (it.hasNext()) {
- it.next();
- ModelNode *prev = properties.value(it.name());
+ QV8Engine *v8engine = m_model->engine();
+
+ v8::Local<v8::Array> propertyNames = v8engine->getOwnPropertyNames(valuemap->ToObject());
+ uint32_t length = propertyNames->Length();
+
+ for (uint32_t ii = 0; ii < length; ++ii) {
+ // XXX TryCatch?
+ v8::Handle<v8::Value> property = propertyNames->Get(ii);
+ v8::Handle<v8::Value> v = valuemap->ToObject()->Get(property);
+
+ QString name = v8engine->toString(property);
+ ModelNode *prev = properties.value(name);
ModelNode *value = new ModelNode(m_model);
- QScriptValue v = it.value();
- if (v.isArray()) {
+ if (v->IsArray()) {
value->isArray = true;
value->setListValue(v);
if (writeToCache && objectCache)
- objectCache->setValue(it.name().toUtf8(), QVariant::fromValue(value->model(m_model)));
+ objectCache->setValue(name.toUtf8(), QVariant::fromValue(value->model(m_model)));
emitItemsChanged = true; // for now, too inefficient to check whether list and sublists have changed
} else {
- value->values << v.toVariant();
+ value->values << v8engine->toVariant(v, -1);
if (writeToCache && objectCache)
- objectCache->setValue(it.name().toUtf8(), value->values.last());
+ objectCache->setValue(name.toUtf8(), value->values.last());
if (!emitItemsChanged && prev && prev->values.count() == 1
&& prev->values[0] != value->values.last()) {
emitItemsChanged = true;
}
}
- if (properties.contains(it.name()))
- delete properties[it.name()];
- properties.insert(it.name(), value);
+ if (properties.contains(name))
+ delete properties[name];
+ properties.insert(name, value);
}
return emitItemsChanged;
}
-void ModelNode::setListValue(const QScriptValue& valuelist) {
+void ModelNode::setListValue(v8::Handle<v8::Value> valuelist)
+{
+ Q_ASSERT(valuelist->IsArray());
values.clear();
- int size = valuelist.property(QLatin1String("length")).toInt32();
- for (int i=0; i<size; i++) {
+
+ QV8Engine *engine = m_model->engine();
+
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(valuelist);
+ uint32_t length = array->Length();
+ for (uint32_t ii = 0; ii < length; ++ii) {
ModelNode *value = new ModelNode(m_model);
- QScriptValue v = valuelist.property(i);
- if (v.isArray()) {
+
+ // XXX TryCatch?
+ v8::Handle<v8::Value> v = array->Get(ii);
+
+ if (v->IsArray()) {
value->isArray = true;
value->setListValue(v);
- } else if (v.isObject()) {
- value->listIndex = i;
+ } else if (v->IsObject()) {
+ value->listIndex = ii;
value->setObjectValue(v);
} else {
- value->listIndex = i;
- value->values << v.toVariant();
+ value->listIndex = ii;
+ value->values << engine->toVariant(v, -1);
}
+
values.append(QVariant::fromValue(value));
}
}
@@ -1581,10 +1668,8 @@ void ModelNode::dump(ModelNode *node, int ind)
}
}
-ModelObject::ModelObject(ModelNode *node, NestedListModel *model, QScriptEngine *seng)
- : m_model(model),
- m_node(node),
- m_meta(new ModelNodeMetaObject(seng, this))
+ModelObject::ModelObject(ModelNode *node, NestedListModel *model, QV8Engine *eng)
+: m_model(model), m_node(node), m_meta(new ModelNodeMetaObject(eng, this))
{
}
@@ -1599,12 +1684,8 @@ void ModelObject::setNodeUpdatesEnabled(bool enable)
m_meta->m_enabled = enable;
}
-
-ModelNodeMetaObject::ModelNodeMetaObject(QScriptEngine *seng, ModelObject *object)
- : QDeclarativeOpenMetaObject(object),
- m_enabled(false),
- m_seng(seng),
- m_obj(object)
+ModelNodeMetaObject::ModelNodeMetaObject(QV8Engine *eng, ModelObject *object)
+: QDeclarativeOpenMetaObject(object), m_enabled(false), m_engine(eng), m_obj(object)
{
}
@@ -1616,12 +1697,13 @@ void ModelNodeMetaObject::propertyWritten(int index)
QString propName = QString::fromUtf8(name(index));
QVariant value = operator[](index);
- QScriptValue sv = m_seng->newObject();
- sv.setProperty(propName, m_seng->newVariant(value));
- bool changed = m_obj->m_node->setObjectValue(sv, false);
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(m_engine->context());
+ v8::Local<v8::Object> object = v8::Object::New();
+ object->Set(m_engine->toString(propName), m_engine->variantWrapper()->newVariant(value));
+ bool changed = m_obj->m_node->setObjectValue(object, false);
if (changed)
m_obj->m_node->changedProperty(propName);
}
-
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h
index 93a31834d6..94a7e65bfb 100644
--- a/src/declarative/util/qdeclarativelistmodel_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p.h
@@ -51,7 +51,8 @@
#include <QtCore/QList>
#include <QtCore/QVariant>
#include <private/qlistmodelinterface_p.h>
-#include <QtScript/qscriptvalue.h>
+
+#include <private/qv8engine_p.h>
QT_BEGIN_HEADER
@@ -63,7 +64,6 @@ class FlatListModel;
class NestedListModel;
class QDeclarativeListModelWorkerAgent;
struct ModelNode;
-class FlatListScriptClass;
class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeListModel : public QListModelInterface
{
Q_OBJECT
@@ -80,10 +80,10 @@ public:
Q_INVOKABLE void clear();
Q_INVOKABLE void remove(int index);
- Q_INVOKABLE void append(const QScriptValue&);
- Q_INVOKABLE void insert(int index, const QScriptValue&);
- Q_INVOKABLE QScriptValue get(int index) const;
- Q_INVOKABLE void set(int index, const QScriptValue&);
+ Q_INVOKABLE void append(const QDeclarativeV8Handle &);
+ Q_INVOKABLE void insert(int index, const QDeclarativeV8Handle &);
+ Q_INVOKABLE QDeclarativeV8Handle get(int index) const;
+ Q_INVOKABLE void set(int index, const QDeclarativeV8Handle &);
Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
Q_INVOKABLE void move(int from, int to, int count);
Q_INVOKABLE void sync();
@@ -97,13 +97,13 @@ private:
friend class QDeclarativeListModelParser;
friend class QDeclarativeListModelWorkerAgent;
friend class FlatListModel;
- friend class FlatListScriptClass;
+ friend class QDeclarativeListModelV8Data;
friend struct ModelNode;
// Constructs a flat list model for a worker agent
QDeclarativeListModel(const QDeclarativeListModel *orig, QDeclarativeListModelWorkerAgent *parent);
- void set(int index, const QScriptValue&, QList<int> *roles);
+ void set(int index, const QDeclarativeV8Handle &, QList<int> *roles);
void setProperty(int index, const QString& property, const QVariant& value, QList<int> *roles);
bool flatten();
diff --git a/src/declarative/util/qdeclarativelistmodel_p_p.h b/src/declarative/util/qdeclarativelistmodel_p_p.h
index 84a6e90c24..971f0d8d82 100644
--- a/src/declarative/util/qdeclarativelistmodel_p_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p_p.h
@@ -58,8 +58,6 @@
#include "private/qdeclarativeopenmetaobject_p.h"
#include "qdeclarative.h"
-#include <private/qscriptdeclarativeclass_p.h>
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -67,10 +65,8 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeOpenMetaObject;
-class QScriptEngine;
class QDeclarativeListModelWorkerAgent;
struct ModelNode;
-class FlatListScriptClass;
class FlatNodeData;
class FlatListModel
@@ -87,58 +83,39 @@ public:
int count() const;
void clear();
void remove(int index);
- bool insert(int index, const QScriptValue&);
- QScriptValue get(int index) const;
- void set(int index, const QScriptValue&, QList<int> *roles);
+ bool insert(int index, v8::Handle<v8::Value>);
+ v8::Handle<v8::Value> get(int index) const;
+ void set(int index, v8::Handle<v8::Value>, QList<int> *roles);
void setProperty(int index, const QString& property, const QVariant& value, QList<int> *roles);
void move(int from, int to, int count);
private:
friend class QDeclarativeListModelWorkerAgent;
friend class QDeclarativeListModel;
- friend class FlatListScriptClass;
+ friend class QDeclarativeListModelV8Data;
friend class FlatNodeData;
- bool addValue(const QScriptValue &value, QHash<int, QVariant> *row, QList<int> *roles);
+ bool addValue(v8::Handle<v8::Value> value, QHash<int, QVariant> *row, QList<int> *roles);
void insertedNode(int index);
void removedNode(int index);
void moveNodes(int from, int to, int n);
- QScriptEngine *m_scriptEngine;
+ QV8Engine *engine() const;
+ QV8Engine *m_engine;
QHash<int, QString> m_roles;
QHash<QString, int> m_strings;
QList<QHash<int, QVariant> > m_values;
QDeclarativeListModel *m_listModel;
- FlatListScriptClass *m_scriptClass;
QList<FlatNodeData *> m_nodeData;
QDeclarativeListModelWorkerAgent *m_parentAgent;
};
-
-/*
- Created when get() is called on a FlatListModel. This allows changes to the
- object returned by get() to be tracked, and passed onto the model.
-*/
-class FlatListScriptClass : public QScriptDeclarativeClass
-{
-public:
- FlatListScriptClass(FlatListModel *model, QScriptEngine *seng);
-
- Value property(Object *, const Identifier &);
- void setProperty(Object *, const Identifier &name, const QScriptValue &);
- QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags);
- bool compare(Object *, Object *);
-
-private:
- FlatListModel *m_model;
-};
-
/*
FlatNodeData and FlatNodeObjectData allow objects returned by get() to still
point to the correct list index if move(), insert() or remove() are called.
*/
-struct FlatNodeObjectData;
+class QV8ListModelResource;
class FlatNodeData
{
public:
@@ -147,31 +124,26 @@ public:
~FlatNodeData();
- void addData(FlatNodeObjectData *data);
- void removeData(FlatNodeObjectData *data);
+ void addData(QV8ListModelResource *data);
+ void removeData(QV8ListModelResource *data);
int index;
private:
- QSet<FlatNodeObjectData*> objects;
+ QSet<QV8ListModelResource*> objects;
};
-struct FlatNodeObjectData : public QScriptDeclarativeClass::Object
+class QV8ListModelResource : public QV8ObjectResource
{
- FlatNodeObjectData(FlatNodeData *data) : nodeData(data) {
- nodeData->addData(this);
- }
-
- ~FlatNodeObjectData() {
- if (nodeData)
- nodeData->removeData(this);
- }
+ V8_RESOURCE_TYPE(ListModelType);
+public:
+ QV8ListModelResource(FlatListModel *model, FlatNodeData *data, QV8Engine *engine);
+ ~QV8ListModelResource();
+ FlatListModel *model;
FlatNodeData *nodeData;
};
-
-
class NestedListModel
{
public:
@@ -187,9 +159,9 @@ public:
int count() const;
void clear();
void remove(int index);
- bool insert(int index, const QScriptValue&);
- QScriptValue get(int index) const;
- void set(int index, const QScriptValue&, QList<int> *roles);
+ bool insert(int index, v8::Handle<v8::Value>);
+ v8::Handle<v8::Value> get(int index) const;
+ void set(int index, v8::Handle<v8::Value>, QList<int> *roles);
void setProperty(int index, const QString& property, const QVariant& value, QList<int> *roles);
void move(int from, int to, int count);
@@ -200,6 +172,7 @@ public:
bool m_ownsRoot;
QDeclarativeListModel *m_listModel;
+ QV8Engine *engine() const;
private:
friend struct ModelNode;
mutable QStringList roleStrings;
@@ -212,7 +185,7 @@ class ModelObject : public QObject
{
Q_OBJECT
public:
- ModelObject(ModelNode *node, NestedListModel *model, QScriptEngine *seng);
+ ModelObject(ModelNode *node, NestedListModel *model, QV8Engine *eng);
void setValue(const QByteArray &name, const QVariant &val);
void setNodeUpdatesEnabled(bool enable);
@@ -226,7 +199,7 @@ private:
class ModelNodeMetaObject : public QDeclarativeOpenMetaObject
{
public:
- ModelNodeMetaObject(QScriptEngine *seng, ModelObject *object);
+ ModelNodeMetaObject(QV8Engine *eng, ModelObject *object);
bool m_enabled;
@@ -234,11 +207,10 @@ protected:
void propertyWritten(int index);
private:
- QScriptEngine *m_seng;
+ QV8Engine *m_engine;
ModelObject *m_obj;
};
-
/*
A ModelNode is created for each item in a NestedListModel.
*/
@@ -255,8 +227,8 @@ struct ModelNode
QDeclarativeListModel *model(const NestedListModel *model);
ModelObject *object(const NestedListModel *model);
- bool setObjectValue(const QScriptValue& valuemap, bool writeToCache = true);
- void setListValue(const QScriptValue& valuelist);
+ bool setObjectValue(v8::Handle<v8::Value> valuemap, bool writeToCache = true);
+ void setListValue(v8::Handle<v8::Value> valuelist);
bool setProperty(const QString& prop, const QVariant& val);
void changedProperty(const QString &name) const;
void updateListIndexes();
diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
index efc83a523b..c6855d354b 100644
--- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
+++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
@@ -83,10 +83,7 @@ void QDeclarativeListModelWorkerAgent::Data::changedChange(int index, int count,
}
QDeclarativeListModelWorkerAgent::QDeclarativeListModelWorkerAgent(QDeclarativeListModel *model)
- : m_engine(0),
- m_ref(1),
- m_orig(model),
- m_copy(new QDeclarativeListModel(model, this))
+: m_engine(0), m_ref(1), m_orig(model), m_copy(new QDeclarativeListModel(model, this))
{
}
@@ -94,14 +91,14 @@ QDeclarativeListModelWorkerAgent::~QDeclarativeListModelWorkerAgent()
{
}
-void QDeclarativeListModelWorkerAgent::setScriptEngine(QScriptEngine *eng)
+void QDeclarativeListModelWorkerAgent::setV8Engine(QV8Engine *eng)
{
m_engine = eng;
if (m_copy->m_flat)
- m_copy->m_flat->m_scriptEngine = eng;
+ m_copy->m_flat->m_engine = eng;
}
-QScriptEngine *QDeclarativeListModelWorkerAgent::scriptEngine() const
+QV8Engine *QDeclarativeListModelWorkerAgent::v8engine() const
{
return m_engine;
}
@@ -140,7 +137,7 @@ void QDeclarativeListModelWorkerAgent::remove(int index)
data.removeChange(index, 1);
}
-void QDeclarativeListModelWorkerAgent::append(const QScriptValue &value)
+void QDeclarativeListModelWorkerAgent::append(const QDeclarativeV8Handle &value)
{
int count = m_copy->count();
m_copy->append(value);
@@ -149,7 +146,7 @@ void QDeclarativeListModelWorkerAgent::append(const QScriptValue &value)
data.insertChange(m_copy->count() - 1, 1);
}
-void QDeclarativeListModelWorkerAgent::insert(int index, const QScriptValue &value)
+void QDeclarativeListModelWorkerAgent::insert(int index, const QDeclarativeV8Handle &value)
{
int count = m_copy->count();
m_copy->insert(index, value);
@@ -158,12 +155,12 @@ void QDeclarativeListModelWorkerAgent::insert(int index, const QScriptValue &val
data.insertChange(index, 1);
}
-QScriptValue QDeclarativeListModelWorkerAgent::get(int index) const
+QDeclarativeV8Handle QDeclarativeListModelWorkerAgent::get(int index) const
{
return m_copy->get(index);
}
-void QDeclarativeListModelWorkerAgent::set(int index, const QScriptValue &value)
+void QDeclarativeListModelWorkerAgent::set(int index, const QDeclarativeV8Handle &value)
{
QList<int> roles;
m_copy->set(index, value, &roles);
diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent_p.h b/src/declarative/util/qdeclarativelistmodelworkeragent_p.h
index fa8c773f8e..d814029334 100644
--- a/src/declarative/util/qdeclarativelistmodelworkeragent_p.h
+++ b/src/declarative/util/qdeclarativelistmodelworkeragent_p.h
@@ -55,11 +55,12 @@
#include "qdeclarative.h"
-#include <QtScript/qscriptvalue.h>
#include <QtGui/qevent.h>
#include <QMutex>
#include <QWaitCondition>
+#include <private/qv8engine_p.h>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -67,7 +68,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeListModel;
-class FlatListScriptClass;
class QDeclarativeListModelWorkerAgent : public QObject
{
@@ -78,8 +78,8 @@ public:
QDeclarativeListModelWorkerAgent(QDeclarativeListModel *);
~QDeclarativeListModelWorkerAgent();
- void setScriptEngine(QScriptEngine *eng);
- QScriptEngine *scriptEngine() const;
+ void setV8Engine(QV8Engine *eng);
+ QV8Engine *v8engine() const;
void addref();
void release();
@@ -88,10 +88,10 @@ public:
Q_INVOKABLE void clear();
Q_INVOKABLE void remove(int index);
- Q_INVOKABLE void append(const QScriptValue &);
- Q_INVOKABLE void insert(int index, const QScriptValue&);
- Q_INVOKABLE QScriptValue get(int index) const;
- Q_INVOKABLE void set(int index, const QScriptValue &);
+ Q_INVOKABLE void append(const QDeclarativeV8Handle &);
+ Q_INVOKABLE void insert(int index, const QDeclarativeV8Handle &);
+ Q_INVOKABLE QDeclarativeV8Handle get(int index) const;
+ Q_INVOKABLE void set(int index, const QDeclarativeV8Handle &);
Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
Q_INVOKABLE void move(int from, int to, int count);
Q_INVOKABLE void sync();
@@ -116,8 +116,8 @@ protected:
private:
friend class QDeclarativeWorkerScriptEnginePrivate;
- friend class FlatListScriptClass;
- QScriptEngine *m_engine;
+ friend class QDeclarativeListModelV8Data;
+ QV8Engine *m_engine;
struct Change {
enum { Inserted, Removed, Moved, Changed } type;
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 6f9245be65..e12959620b 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -780,18 +780,22 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati
var title = model.get(0).title;
\endjs
*/
-QScriptValue QDeclarativeXmlListModel::get(int index) const
+QDeclarativeV8Handle QDeclarativeXmlListModel::get(int index) const
{
+ // Must be called with a context and handle scope
Q_D(const QDeclarativeXmlListModel);
- QScriptEngine *sengine = QDeclarativeEnginePrivate::getScriptEngine(qmlContext(this)->engine());
if (index < 0 || index >= count())
- return sengine->undefinedValue();
+ return QDeclarativeV8Handle::fromHandle(v8::Undefined());
- QScriptValue sv = sengine->newObject();
- for (int i=0; i<d->roleObjects.count(); i++)
- sv.setProperty(d->roleObjects[i]->name(), sengine->toScriptValue(d->data.value(i).value(index)));
- return sv;
+ QDeclarativeEngine *engine = qmlContext(this)->engine();
+ QV8Engine *v8engine = QDeclarativeEnginePrivate::getV8Engine(engine);
+ v8::Local<v8::Object> rv = v8::Object::New();
+ for (int ii = 0; ii < d->roleObjects.count(); ++ii)
+ rv->Set(v8engine->toString(d->roleObjects[ii]->name()),
+ v8engine->fromVariant(d->data.value(ii).value(index)));
+
+ return QDeclarativeV8Handle::fromHandle(rv);
}
/*!
diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h
index 4600f4f358..3d8617f929 100644
--- a/src/declarative/util/qdeclarativexmllistmodel_p.h
+++ b/src/declarative/util/qdeclarativexmllistmodel_p.h
@@ -47,9 +47,9 @@
#include <QtCore/qurl.h>
#include <QtCore/qstringlist.h>
-#include <QtScript/qscriptvalue.h>
#include <private/qlistmodelinterface_p.h>
+#include <private/qv8engine_p.h>
QT_BEGIN_HEADER
@@ -110,7 +110,7 @@ public:
QString namespaceDeclarations() const;
void setNamespaceDeclarations(const QString&);
- Q_INVOKABLE QScriptValue get(int index) const;
+ Q_INVOKABLE QDeclarativeV8Handle get(int index) const;
enum Status { Null, Ready, Loading, Error };
Status status() const;
diff --git a/src/imports/testlib/SignalSpy.qml b/src/imports/testlib/SignalSpy.qml
index ba51c5a33f..f32a9c6129 100644
--- a/src/imports/testlib/SignalSpy.qml
+++ b/src/imports/testlib/SignalSpy.qml
@@ -66,7 +66,7 @@ Item {
i += 50
}
var success = (count >= expected)
- if (!qtest_results.verify(success, "wait for signal " + signalName, Qt.qtest_caller_file(), Qt.qtest_caller_line()))
+ if (!qtest_results.verify(success, "wait for signal " + signalName, QtTest.qtest_caller_file(), QtTest.qtest_caller_line()))
throw new Error("QtQuickTest::fail")
}
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 5418fe6d8e..22fd5b66bb 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -46,6 +46,9 @@ import "testlogger.js" as TestLogger
Item {
id: testCase
visible: false
+ TestUtil {
+ id:util
+ }
// Name of the test case to prefix the function name in messages.
property string name
@@ -66,7 +69,7 @@ Item {
// Property that is set to true when the main window is shown.
// We need to set the property value in an odd way to handle
// both qmlviewer and the QtQuickTest module test wrapper.
- property bool windowShown: Qt.qtest_wrapper ? qtest.windowShown : false
+ property bool windowShown: util.wrapper ? qtest.windowShown : false
// Internal private state. Identifiers prefixed with qtest are reserved.
property bool qtest_prevWhen: true
@@ -80,21 +83,21 @@ Item {
function fail(msg) {
if (msg === undefined)
msg = "";
- qtest_results.fail(msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())
+ qtest_results.fail(msg, util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::fail")
}
function qtest_fail(msg, frame) {
if (msg === undefined)
msg = "";
- qtest_results.fail(msg, Qt.qtest_caller_file(frame), Qt.qtest_caller_line(frame))
+ qtest_results.fail(msg, util.callerFile(frame), util.callerLine(frame))
throw new Error("QtQuickTest::fail")
}
function verify(cond, msg) {
if (msg === undefined)
msg = "";
- if (!qtest_results.verify(cond, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line()))
+ if (!qtest_results.verify(cond, msg, util.callerFile(), util.callerLine()))
throw new Error("QtQuickTest::fail")
}
@@ -279,7 +282,7 @@ Item {
else
msg = "Compared values are not the same"
}
- if (!qtest_results.compare(success, msg, act, exp, Qt.qtest_caller_file(), Qt.qtest_caller_line()))
+ if (!qtest_results.compare(success, msg, act, exp, util.callerFile(), util.callerLine()))
throw new Error("QtQuickTest::fail")
}
@@ -297,21 +300,21 @@ Item {
var act = qtest_formatValue(actual)
var exp = qtest_formatValue(value)
var success = qtest_compareInternal(actual, value)
- if (!qtest_results.compare(success, "property " + prop, act, exp, Qt.qtest_caller_file(), Qt.qtest_caller_line()))
+ if (!qtest_results.compare(success, "property " + prop, act, exp, util.callerFile(), util.callerLine()))
throw new Error("QtQuickTest::fail")
}
function skip(msg) {
if (msg === undefined)
msg = ""
- qtest_results.skipSingle(msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())
+ qtest_results.skipSingle(msg, util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::skip")
}
function skipAll(msg) {
if (msg === undefined)
msg = ""
- qtest_results.skipAll(msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())
+ qtest_results.skipAll(msg, util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::skip")
}
@@ -324,7 +327,7 @@ Item {
warn("message argument missing from expectFail()")
msg = ""
}
- if (!qtest_results.expectFail(tag, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line()))
+ if (!qtest_results.expectFail(tag, msg, util.callerFile(), util.callerLine()))
throw new Error("QtQuickTest::expectFail")
}
@@ -337,7 +340,7 @@ Item {
warn("message argument missing from expectFailContinue()")
msg = ""
}
- if (!qtest_results.expectFailContinue(tag, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line()))
+ if (!qtest_results.expectFailContinue(tag, msg, util.callerFile(), util.callerLine()))
throw new Error("QtQuickTest::expectFail")
}
@@ -505,7 +508,7 @@ Item {
}
function qtest_run() {
- if (Qt.qtest_printAvailableFunctions) {
+ if (util.printAvailableFunctions) {
completed = true
return
}
@@ -650,7 +653,7 @@ Item {
}
}
- // The test framework will set qtest.windowShown when the
+ // The test framework will set util.windowShown when the
// window is actually shown. If we are running with qmlviewer,
// then this won't happen. So we use a timer instead.
Timer {
@@ -661,7 +664,7 @@ Item {
}
Component.onCompleted: {
- if (Qt.qtest_printAvailableFunctions) {
+ if (util.printAvailableFunctions) {
var testList = []
for (var prop in testCase) {
if (prop.indexOf("test_") != 0 && prop.indexOf("benchmark_") != 0)
@@ -683,7 +686,7 @@ Item {
if (optional)
TestLogger.log_optional_test(qtest_testId)
qtest_prevWhen = when
- var isQmlViewer = Qt.qtest_wrapper ? false : true
+ var isQmlViewer = util.wrapper ? false : true
if (isQmlViewer)
qtest_windowShowTimer.running = true
if (when && !completed && !running)
diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp
index c35db2d312..0f27102764 100644
--- a/src/imports/testlib/main.cpp
+++ b/src/imports/testlib/main.cpp
@@ -47,56 +47,63 @@
#include <QtScript/qscriptengine.h>
#include "QtQuickTest/private/quicktestresult_p.h"
#include "QtQuickTest/private/quicktestevent_p.h"
+#include "private/qtestoptions_p.h"
+#include "QtDeclarative/qsgitem.h"
+#include <QtDeclarative/private/qdeclarativeengine_p.h>
QT_BEGIN_NAMESPACE
QML_DECLARE_TYPE(QuickTestResult)
QML_DECLARE_TYPE(QuickTestEvent)
-// Copied from qdeclarativedebughelper_p.h in Qt, to avoid a dependency
-// on a private header from Qt.
-class Q_DECLARATIVE_EXPORT QDeclarativeDebugHelper
+#include <QtDebug>
+
+class QuickTestUtil : public QObject
{
+ Q_OBJECT
+ Q_PROPERTY(bool printAvailableFunctions READ printAvailableFunctions)
+ Q_PROPERTY(bool wrapper READ wrapper)
public:
- static QScriptEngine *getScriptEngine(QDeclarativeEngine *engine);
- static void setAnimationSlowDownFactor(qreal factor);
- static void enableDebugging();
-};
+ QuickTestUtil(QObject *parent = 0)
+ :QObject(parent)
+ {}
-static QScriptContext *qtest_find_frame(QScriptContext *ctx)
-{
- qint32 frame = 1;
- if (ctx->argumentCount() > 0)
- frame = ctx->argument(0).toInt32();
- ++frame; // Exclude the native function; start at its caller.
- while (ctx) {
- if (frame-- <= 0)
- break;
- ctx = ctx->parentContext();
+ ~QuickTestUtil()
+ {}
+ bool printAvailableFunctions() const
+ {
+ return QTest::printAvailableFunctions;
}
- return ctx;
-}
-
-static QScriptValue qtest_caller_file
- (QScriptContext *ctx, QScriptEngine *engine)
-{
- ctx = qtest_find_frame(ctx);
- if (ctx) {
- QScriptContextInfo info(ctx);
- return engine->newVariant(info.fileName());
+ bool wrapper() const
+ {
+ return true;
}
- return engine->newVariant(QLatin1String(""));
-}
-static QScriptValue qtest_caller_line
- (QScriptContext *ctx, QScriptEngine *engine)
-{
- ctx = qtest_find_frame(ctx);
- if (ctx) {
- QScriptContextInfo info(ctx);
- return engine->newVariant(info.lineNumber());
+public Q_SLOTS:
+ QDeclarativeV8Handle callerFile(int frameIndex = 0) const
+ {
+ v8::HandleScope scope;
+
+ v8::Local<v8::StackTrace> stacks = v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
+ int count = stacks->GetFrameCount();
+ if (count >= frameIndex + 2) {
+ v8::Local<v8::StackFrame> frame = stacks->GetFrame(frameIndex + 2);
+ return QDeclarativeV8Handle::fromHandle(frame->GetScriptNameOrSourceURL());
+ }
+ return QDeclarativeV8Handle();
}
- return engine->newVariant(qint32(0));
-}
+ int callerLine(int frameIndex = 0) const
+ {
+ v8::HandleScope scope;
+ v8::Local<v8::StackTrace> stacks = v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
+ int count = stacks->GetFrameCount();
+ if (count >= frameIndex + 2) {
+ v8::Local<v8::StackFrame> frame = stacks->GetFrame(frameIndex + 2);
+ return frame->GetLineNumber();
+ }
+ return -1;
+ }
+};
+QML_DECLARE_TYPE(QuickTestUtil)
class QTestQmlModule : public QDeclarativeExtensionPlugin
{
@@ -107,22 +114,11 @@ public:
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtTest"));
qmlRegisterType<QuickTestResult>(uri,1,0,"TestResult");
qmlRegisterType<QuickTestEvent>(uri,1,0,"TestEvent");
+ qmlRegisterType<QuickTestUtil>(uri,1,0,"TestUtil");
}
+
void initializeEngine(QDeclarativeEngine *engine, const char *)
{
- // Install some helper functions in the global "Qt" object
- // for walking the stack and finding a caller's location.
- // Normally we would use an exception's backtrace, but JSC
- // only provides the top-most frame in the backtrace.
- QScriptEngine *eng = QDeclarativeDebugHelper::getScriptEngine(engine);
- QScriptValue qtObject
- = eng->globalObject().property(QLatin1String("Qt"));
- qtObject.setProperty
- (QLatin1String("qtest_caller_file"),
- eng->newFunction(qtest_caller_file));
- qtObject.setProperty
- (QLatin1String("qtest_caller_line"),
- eng->newFunction(qtest_caller_line));
}
};
diff --git a/src/imports/testlib/testlib.pro b/src/imports/testlib/testlib.pro
index 80bd5c534c..92c5a097cd 100644
--- a/src/imports/testlib/testlib.pro
+++ b/src/imports/testlib/testlib.pro
@@ -21,7 +21,7 @@ symbian {
}
-QT += declarative script qmltest qmltest-private
+QT += declarative script qmltest qmltest-private declarative-private script-private core-private
SOURCES += main.cpp
HEADERS +=
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index d8451be341..4dfad1867b 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -189,15 +189,6 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
&eventLoop, SLOT(quit()));
view.rootContext()->setContextProperty
(QLatin1String("qtest"), &rootobj);
- QScriptEngine *engine;
- engine = QDeclarativeDebugHelper::getScriptEngine(view.engine());
- QScriptValue qtObject
- = engine->globalObject().property(QLatin1String("Qt"));
- qtObject.setProperty
- (QLatin1String("qtest_wrapper"), QScriptValue(true));
- qtObject.setProperty
- (QLatin1String("qtest_printAvailableFunctions"),
- QScriptValue(QTest::printAvailableFunctions));
foreach (QString path, imports)
view.engine()->addImportPath(path);
QString path = fi.absoluteFilePath();
@@ -254,15 +245,6 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
view.setViewport((*createViewport)());
view.rootContext()->setContextProperty
(QLatin1String("qtest"), &rootobj);
- QScriptEngine *engine;
- engine = QDeclarativeDebugHelper::getScriptEngine(view.engine());
- QScriptValue qtObject
- = engine->globalObject().property(QLatin1String("Qt"));
- qtObject.setProperty
- (QLatin1String("qtest_wrapper"), QScriptValue(true));
- qtObject.setProperty
- (QLatin1String("qtest_printAvailableFunctions"),
- QScriptValue(QTest::printAvailableFunctions));
foreach (QString path, imports)
view.engine()->addImportPath(path);
QString path = fi.absoluteFilePath();
diff --git a/src/src.pro b/src/src.pro
index 1f47672180..e825502451 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -1,5 +1,5 @@
TEMPLATE = subdirs
CONFIG += ordered
-SUBDIRS += declarative plugins
+SUBDIRS += v8 declarative plugins
contains(QT_CONFIG, qmltest): SUBDIRS += qmltest
SUBDIRS += imports
diff --git a/src/v8/0001-Add-hashing-and-comparison-methods-to-v8-String.patch b/src/v8/0001-Add-hashing-and-comparison-methods-to-v8-String.patch
new file mode 100644
index 0000000000..e18e5bc69e
--- /dev/null
+++ b/src/v8/0001-Add-hashing-and-comparison-methods-to-v8-String.patch
@@ -0,0 +1,338 @@
+From 9a956953836844f1342ac012f4c2408405224fcd Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Mon, 23 May 2011 15:47:20 +1000
+Subject: [PATCH 1/8] Add hashing and comparison methods to v8::String
+
+This allows us to more rapidly search for a v8::String inside
+a hash of QStrings.
+---
+ include/v8.h | 43 +++++++++++++++++++++++++++++
+ src/api.cc | 39 +++++++++++++++++++++++++++
+ src/heap-inl.h | 2 +
+ src/heap.cc | 3 ++
+ src/objects-inl.h | 1 +
+ src/objects.cc | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
+ src/objects.h | 15 +++++++++-
+ 7 files changed, 177 insertions(+), 3 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index d15d024..626f34c 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -994,6 +994,47 @@ class String : public Primitive {
+ V8EXPORT int Utf8Length() const;
+
+ /**
++ * Returns the hash of this string.
++ */
++ V8EXPORT uint32_t Hash() const;
++
++ struct CompleteHashData {
++ CompleteHashData() : length(0), hash(0), symbol_id(0) {}
++ int length;
++ uint32_t hash;
++ uint32_t symbol_id;
++ };
++
++ /**
++ * Returns the "complete" hash of the string. This is
++ * all the information about the string needed to implement
++ * a very efficient hash keyed on the string.
++ *
++ * The members of CompleteHashData are:
++ * length: The length of the string. Equivalent to Length()
++ * hash: The hash of the string. Equivalent to Hash()
++ * symbol_id: If the string is a sequential symbol, the symbol
++ * id, otherwise 0. If the symbol ids of two strings are
++ * the same (and non-zero) the two strings are identical.
++ * If the symbol ids are different the strings may still be
++ * identical, but an Equals() check must be performed.
++ */
++ V8EXPORT CompleteHashData CompleteHash() const;
++
++ /**
++ * Compute a hash value for the passed UTF16 string
++ * data.
++ */
++ V8EXPORT static uint32_t ComputeHash(uint16_t *string, int length);
++
++ /**
++ * Returns true if this string is equal to the external
++ * string data provided.
++ */
++ V8EXPORT bool Equals(uint16_t *string, int length);
++ V8EXPORT bool Equals(char *string, int length);
++
++ /**
+ * Write the contents of the string to an external buffer.
+ * If no arguments are given, expects the buffer to be large
+ * enough to hold the entire string and NULL terminator. Copies
+@@ -1023,6 +1064,8 @@ class String : public Primitive {
+ HINT_MANY_WRITES_EXPECTED = 1
+ };
+
++ V8EXPORT uint16_t GetCharacter(int index);
++
+ V8EXPORT int Write(uint16_t* buffer,
+ int start = 0,
+ int length = -1,
+diff --git a/src/api.cc b/src/api.cc
+index a2373cd..0d860bd 100644
+--- a/src/api.cc
++++ b/src/api.cc
+@@ -3284,6 +3284,45 @@ int String::Utf8Length() const {
+ return str->Utf8Length();
+ }
+
++uint32_t String::Hash() const {
++ i::Handle<i::String> str = Utils::OpenHandle(this);
++ if (IsDeadCheck(str->GetIsolate(), "v8::String::Hash()")) return 0;
++ return str->Hash();
++}
++
++String::CompleteHashData String::CompleteHash() const {
++ i::Handle<i::String> str = Utils::OpenHandle(this);
++ if (IsDeadCheck(str->GetIsolate(), "v8::String::CompleteHash()")) return CompleteHashData();
++ CompleteHashData result;
++ result.length = str->length();
++ result.hash = str->Hash();
++ if (str->IsSeqString())
++ result.symbol_id = i::SeqString::cast(*str)->symbol_id();
++ return result;
++}
++
++uint32_t String::ComputeHash(uint16_t *string, int length) {
++ return i::HashSequentialString<i::uc16>(string, length) >> i::String::kHashShift;
++}
++
++uint16_t String::GetCharacter(int index)
++{
++ i::Handle<i::String> str = Utils::OpenHandle(this);
++ return str->Get(index);
++}
++
++bool String::Equals(uint16_t *string, int length) {
++ i::Handle<i::String> str = Utils::OpenHandle(this);
++ if (IsDeadCheck(str->GetIsolate(), "v8::String::Equals()")) return 0;
++ return str->SlowEqualsExternal(string, length);
++}
++
++bool String::Equals(char *string, int length)
++{
++ i::Handle<i::String> str = Utils::OpenHandle(this);
++ if (IsDeadCheck(str->GetIsolate(), "v8::String::Equals()")) return 0;
++ return str->SlowEqualsExternal(string, length);
++}
+
+ int String::WriteUtf8(char* buffer,
+ int capacity,
+diff --git a/src/heap-inl.h b/src/heap-inl.h
+index 99737ed..f4fce7b 100644
+--- a/src/heap-inl.h
++++ b/src/heap-inl.h
+@@ -93,6 +93,7 @@ MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str,
+ String* answer = String::cast(result);
+ answer->set_length(str.length());
+ answer->set_hash_field(hash_field);
++ SeqString::cast(answer)->set_symbol_id(0);
+
+ ASSERT_EQ(size, answer->Size());
+
+@@ -126,6 +127,7 @@ MaybeObject* Heap::AllocateTwoByteSymbol(Vector<const uc16> str,
+ String* answer = String::cast(result);
+ answer->set_length(str.length());
+ answer->set_hash_field(hash_field);
++ SeqString::cast(answer)->set_symbol_id(0);
+
+ ASSERT_EQ(size, answer->Size());
+
+diff --git a/src/heap.cc b/src/heap.cc
+index 2b6c11f..930c97b 100644
+--- a/src/heap.cc
++++ b/src/heap.cc
+@@ -3519,6 +3519,7 @@ MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer,
+ String* answer = String::cast(result);
+ answer->set_length(chars);
+ answer->set_hash_field(hash_field);
++ SeqString::cast(result)->set_symbol_id(0);
+
+ ASSERT_EQ(size, answer->Size());
+
+@@ -3561,6 +3562,7 @@ MaybeObject* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) {
+ HeapObject::cast(result)->set_map(ascii_string_map());
+ String::cast(result)->set_length(length);
+ String::cast(result)->set_hash_field(String::kEmptyHashField);
++ SeqString::cast(result)->set_symbol_id(0);
+ ASSERT_EQ(size, HeapObject::cast(result)->Size());
+ return result;
+ }
+@@ -3596,6 +3598,7 @@ MaybeObject* Heap::AllocateRawTwoByteString(int length,
+ HeapObject::cast(result)->set_map(string_map());
+ String::cast(result)->set_length(length);
+ String::cast(result)->set_hash_field(String::kEmptyHashField);
++ SeqString::cast(result)->set_symbol_id(0);
+ ASSERT_EQ(size, HeapObject::cast(result)->Size());
+ return result;
+ }
+diff --git a/src/objects-inl.h b/src/objects-inl.h
+index 65aec5d..c82080d 100644
+--- a/src/objects-inl.h
++++ b/src/objects-inl.h
+@@ -1924,6 +1924,7 @@ INT_ACCESSORS(ExternalArray, length, kLengthOffset)
+
+
+ SMI_ACCESSORS(String, length, kLengthOffset)
++SMI_ACCESSORS(SeqString, symbol_id, kSymbolIdOffset)
+
+
+ uint32_t String::hash_field() {
+diff --git a/src/objects.cc b/src/objects.cc
+index df61956..877da3d 100644
+--- a/src/objects.cc
++++ b/src/objects.cc
+@@ -5346,6 +5346,66 @@ static inline bool CompareStringContentsPartial(Isolate* isolate,
+ }
+ }
+
++bool String::SlowEqualsExternal(uc16 *string, int length) {
++ int len = this->length();
++ if (len != length) return false;
++ if (len == 0) return true;
++
++ // We know the strings are both non-empty. Compare the first chars
++ // before we try to flatten the strings.
++ if (this->Get(0) != string[0]) return false;
++
++ String* lhs = this->TryFlattenGetString();
++
++ if (lhs->IsFlat()) {
++ if (lhs->IsAsciiRepresentation()) {
++ Vector<const char> vec1 = lhs->ToAsciiVector();
++ VectorIterator<char> buf1(vec1);
++ VectorIterator<uc16> ib(string, length);
++ return CompareStringContents(&buf1, &ib);
++ } else {
++ Vector<const uc16> vec1 = lhs->ToUC16Vector();
++ Vector<const uc16> vec2(string, length);
++ return CompareRawStringContents(vec1, vec2);
++ }
++ } else {
++ Isolate* isolate = GetIsolate();
++ isolate->objects_string_compare_buffer_a()->Reset(0, lhs);
++ VectorIterator<uc16> ib(string, length);
++ return CompareStringContents(isolate->objects_string_compare_buffer_a(), &ib);
++ }
++}
++
++bool String::SlowEqualsExternal(char *string, int length)
++{
++ int len = this->length();
++ if (len != length) return false;
++ if (len == 0) return true;
++
++ // We know the strings are both non-empty. Compare the first chars
++ // before we try to flatten the strings.
++ if (this->Get(0) != string[0]) return false;
++
++ String* lhs = this->TryFlattenGetString();
++
++ if (StringShape(lhs).IsSequentialAscii()) {
++ const char* str1 = SeqAsciiString::cast(lhs)->GetChars();
++ return CompareRawStringContents(Vector<const char>(str1, len),
++ Vector<const char>(string, len));
++ }
++
++ if (lhs->IsFlat()) {
++ Vector<const uc16> vec1 = lhs->ToUC16Vector();
++ VectorIterator<const uc16> buf1(vec1);
++ VectorIterator<char> buf2(string, length);
++ return CompareStringContents(&buf1, &buf2);
++ } else {
++ Isolate* isolate = GetIsolate();
++ isolate->objects_string_compare_buffer_a()->Reset(0, lhs);
++ VectorIterator<char> ib(string, length);
++ return CompareStringContents(isolate->objects_string_compare_buffer_a(), &ib);
++ }
++}
+
+ bool String::SlowEquals(String* other) {
+ // Fast check: negative check with lengths.
+@@ -8655,9 +8715,24 @@ class AsciiSymbolKey : public SequentialSymbolKey<char> {
+
+ MaybeObject* AsObject() {
+ if (hash_field_ == 0) Hash();
+- return HEAP->AllocateAsciiSymbol(string_, hash_field_);
++ MaybeObject *result = HEAP->AllocateAsciiSymbol(string_, hash_field_);
++ if (!result->IsFailure() && result->ToObjectUnchecked()->IsSeqString()) {
++ while (true) {
++ Atomic32 my_symbol_id = next_symbol_id;
++ if (my_symbol_id > Smi::kMaxValue)
++ break;
++ if (my_symbol_id ==NoBarrier_CompareAndSwap(&next_symbol_id, my_symbol_id, my_symbol_id + 1)) {
++ SeqString::cast(result->ToObjectUnchecked())->set_symbol_id(next_symbol_id++);
++ break;
++ }
++ }
++ }
++ return result;
+ }
++
++ static Atomic32 next_symbol_id;
+ };
++Atomic32 AsciiSymbolKey::next_symbol_id = 1;
+
+
+ class TwoByteSymbolKey : public SequentialSymbolKey<uc16> {
+diff --git a/src/objects.h b/src/objects.h
+index e966b3d..6e26f57 100644
+--- a/src/objects.h
++++ b/src/objects.h
+@@ -5359,6 +5359,9 @@ class String: public HeapObject {
+ bool IsAsciiEqualTo(Vector<const char> str);
+ bool IsTwoByteEqualTo(Vector<const uc16> str);
+
++ bool SlowEqualsExternal(uc16 *string, int length);
++ bool SlowEqualsExternal(char *string, int length);
++
+ // Return a UTF8 representation of the string. The string is null
+ // terminated but may optionally contain nulls. Length is returned
+ // in length_output if length_output is not a null pointer The string
+@@ -5610,9 +5613,17 @@ class String: public HeapObject {
+ class SeqString: public String {
+ public:
+
++ // Get and set the symbol id of the string
++ inline int symbol_id();
++ inline void set_symbol_id(int value);
++
+ // Casting.
+ static inline SeqString* cast(Object* obj);
+
++ // Layout description.
++ static const int kSymbolIdOffset = String::kSize;
++ static const int kSize = kSymbolIdOffset + kPointerSize;
++
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
+ };
+@@ -5647,7 +5658,7 @@ class SeqAsciiString: public SeqString {
+ }
+
+ // Layout description.
+- static const int kHeaderSize = String::kSize;
++ static const int kHeaderSize = SeqString::kSize;
+ static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
+
+ // Maximal memory usage for a single sequential ASCII string.
+@@ -5701,7 +5712,7 @@ class SeqTwoByteString: public SeqString {
+ }
+
+ // Layout description.
+- static const int kHeaderSize = String::kSize;
++ static const int kHeaderSize = SeqString::kSize;
+ static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
+
+ // Maximal memory usage for a single sequential two-byte string.
+--
+1.7.2.3
+
diff --git a/src/v8/0002-Add-a-bit-field-3-to-Map.patch b/src/v8/0002-Add-a-bit-field-3-to-Map.patch
new file mode 100644
index 0000000000..98cc017883
--- /dev/null
+++ b/src/v8/0002-Add-a-bit-field-3-to-Map.patch
@@ -0,0 +1,118 @@
+From 4ce6693b28f0a699acd91c0ae88ae917cc273e9a Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Mon, 23 May 2011 15:55:26 +1000
+Subject: [PATCH 2/8] Add a bit field 3 to Map
+
+Bit field 3 will be used to add QML specific map flags.
+---
+ src/heap.cc | 2 ++
+ src/objects-inl.h | 10 ++++++++++
+ src/objects.cc | 2 ++
+ src/objects.h | 9 ++++++++-
+ 4 files changed, 22 insertions(+), 1 deletions(-)
+
+diff --git a/src/heap.cc b/src/heap.cc
+index 930c97b..900f462 100644
+--- a/src/heap.cc
++++ b/src/heap.cc
+@@ -1573,6 +1573,7 @@ MaybeObject* Heap::AllocatePartialMap(InstanceType instance_type,
+ reinterpret_cast<Map*>(result)->set_unused_property_fields(0);
+ reinterpret_cast<Map*>(result)->set_bit_field(0);
+ reinterpret_cast<Map*>(result)->set_bit_field2(0);
++ reinterpret_cast<Map*>(result)->set_bit_field3(0);
+ return result;
+ }
+
+@@ -1599,6 +1600,7 @@ MaybeObject* Heap::AllocateMap(InstanceType instance_type, int instance_size) {
+ map->set_unused_property_fields(0);
+ map->set_bit_field(0);
+ map->set_bit_field2((1 << Map::kIsExtensible) | (1 << Map::kHasFastElements));
++ map->set_bit_field3(0);
+
+ // If the map object is aligned fill the padding area with Smi 0 objects.
+ if (Map::kPadStart < Map::kSize) {
+diff --git a/src/objects-inl.h b/src/objects-inl.h
+index c82080d..cce3edd 100644
+--- a/src/objects-inl.h
++++ b/src/objects-inl.h
+@@ -2430,6 +2430,16 @@ void Map::set_bit_field2(byte value) {
+ }
+
+
++byte Map::bit_field3() {
++ return READ_BYTE_FIELD(this, kBitField3Offset);
++}
++
++
++void Map::set_bit_field3(byte value) {
++ WRITE_BYTE_FIELD(this, kBitField3Offset, value);
++}
++
++
+ void Map::set_non_instance_prototype(bool value) {
+ if (value) {
+ set_bit_field(bit_field() | (1 << kHasNonInstancePrototype));
+diff --git a/src/objects.cc b/src/objects.cc
+index 877da3d..2409ea3 100644
+--- a/src/objects.cc
++++ b/src/objects.cc
+@@ -3614,6 +3614,7 @@ MaybeObject* Map::CopyDropDescriptors() {
+ }
+ Map::cast(result)->set_bit_field(bit_field());
+ Map::cast(result)->set_bit_field2(bit_field2());
++ Map::cast(result)->set_bit_field3(bit_field3());
+ Map::cast(result)->set_is_shared(false);
+ Map::cast(result)->ClearCodeCache(heap);
+ return result;
+@@ -3642,6 +3643,7 @@ MaybeObject* Map::CopyNormalized(PropertyNormalizationMode mode,
+
+ Map::cast(result)->set_bit_field(bit_field());
+ Map::cast(result)->set_bit_field2(bit_field2());
++ Map::cast(result)->set_bit_field3(bit_field3());
+
+ Map::cast(result)->set_is_shared(sharing == SHARED_NORMALIZED_MAP);
+
+diff --git a/src/objects.h b/src/objects.h
+index 6e26f57..07e1089 100644
+--- a/src/objects.h
++++ b/src/objects.h
+@@ -3597,6 +3597,10 @@ class Map: public HeapObject {
+ inline byte bit_field2();
+ inline void set_bit_field2(byte value);
+
++ // Bit field 3.
++ inline byte bit_field3();
++ inline void set_bit_field3(byte value);
++
+ // Tells whether the object in the prototype property will be used
+ // for instances created from this function. If the prototype
+ // property is set to a value that is not a JSObject, the prototype
+@@ -3844,7 +3848,7 @@ class Map: public HeapObject {
+ // Layout description.
+ static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
+ static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
+- static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
++ static const int kPrototypeOffset = POINTER_SIZE_ALIGN(kInstanceAttributesOffset + 2 * kIntSize);
+ static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
+ static const int kInstanceDescriptorsOffset =
+ kConstructorOffset + kPointerSize;
+@@ -3876,6 +3880,7 @@ class Map: public HeapObject {
+ static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
+ static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
+ static const int kBitField2Offset = kInstanceAttributesOffset + 3;
++ static const int kBitField3Offset = kInstanceAttributesOffset + 4;
+
+ STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
+
+@@ -3898,6 +3903,8 @@ class Map: public HeapObject {
+ static const int kIsShared = 5;
+ static const int kHasExternalArrayElements = 6;
+
++ // Bit positions for bit field 3
++
+ // Layout of the default cache. It holds alternating name and code objects.
+ static const int kCodeCacheEntrySize = 2;
+ static const int kCodeCacheEntryNameOffset = 0;
+--
+1.7.2.3
+
diff --git a/src/v8/0003-Add-a-fallback-mode-for-named-property-interceptors.patch b/src/v8/0003-Add-a-fallback-mode-for-named-property-interceptors.patch
new file mode 100644
index 0000000000..6af02cfa0c
--- /dev/null
+++ b/src/v8/0003-Add-a-fallback-mode-for-named-property-interceptors.patch
@@ -0,0 +1,364 @@
+From 5adbbff4a7f09a02d5c2d9b4e15dde89080e2405 Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Mon, 23 May 2011 16:21:02 +1000
+Subject: [PATCH 3/8] Add a "fallback" mode for named property interceptors
+
+By default interceptors are called before the normal property
+resolution on objects. When an interceptor is installed as a
+"fallback" interceptor, it is only called if the object doesn't
+already have the property.
+
+In the case of a global object having an fallback interceptor,
+the interceptor is not invoked at all for var or function
+declarations.
+---
+ include/v8.h | 8 ++++++++
+ src/api.cc | 29 +++++++++++++++++++++++++++++
+ src/factory.cc | 4 ++++
+ src/handles.cc | 6 ++++--
+ src/handles.h | 3 ++-
+ src/objects-inl.h | 16 ++++++++++++++++
+ src/objects.cc | 22 ++++++++++++++++------
+ src/objects.h | 18 ++++++++++++++----
+ src/runtime.cc | 11 ++++++-----
+ 9 files changed, 99 insertions(+), 18 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index 626f34c..06085ec 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -2168,6 +2168,7 @@ class V8EXPORT FunctionTemplate : public Template {
+ NamedPropertyQuery query,
+ NamedPropertyDeleter remover,
+ NamedPropertyEnumerator enumerator,
++ bool is_fallback,
+ Handle<Value> data);
+ void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
+ IndexedPropertySetter setter,
+@@ -2252,6 +2253,13 @@ class V8EXPORT ObjectTemplate : public Template {
+ NamedPropertyEnumerator enumerator = 0,
+ Handle<Value> data = Handle<Value>());
+
++ void SetFallbackPropertyHandler(NamedPropertyGetter getter,
++ NamedPropertySetter setter = 0,
++ NamedPropertyQuery query = 0,
++ NamedPropertyDeleter deleter = 0,
++ NamedPropertyEnumerator enumerator = 0,
++ Handle<Value> data = Handle<Value>());
++
+ /**
+ * Sets an indexed property handler on the object template.
+ *
+diff --git a/src/api.cc b/src/api.cc
+index 0d860bd..c20b062 100644
+--- a/src/api.cc
++++ b/src/api.cc
+@@ -981,6 +981,7 @@ void FunctionTemplate::SetNamedInstancePropertyHandler(
+ NamedPropertyQuery query,
+ NamedPropertyDeleter remover,
+ NamedPropertyEnumerator enumerator,
++ bool is_fallback,
+ Handle<Value> data) {
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ if (IsDeadCheck(isolate,
+@@ -999,6 +1000,7 @@ void FunctionTemplate::SetNamedInstancePropertyHandler(
+ if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
+ if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
+ if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
++ obj->set_is_fallback(i::Smi::FromInt(is_fallback));
+
+ if (data.IsEmpty()) data = v8::Undefined();
+ obj->set_data(*Utils::OpenHandle(*data));
+@@ -1143,6 +1145,33 @@ void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter,
+ query,
+ remover,
+ enumerator,
++ false,
++ data);
++}
++
++
++void ObjectTemplate::SetFallbackPropertyHandler(NamedPropertyGetter getter,
++ NamedPropertySetter setter,
++ NamedPropertyQuery query,
++ NamedPropertyDeleter remover,
++ NamedPropertyEnumerator enumerator,
++ Handle<Value> data) {
++ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
++ if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetFallbackPropertyHandler()")) {
++ return;
++ }
++ ENTER_V8(isolate);
++ i::HandleScope scope(isolate);
++ EnsureConstructor(this);
++ i::FunctionTemplateInfo* constructor =
++ i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
++ i::Handle<i::FunctionTemplateInfo> cons(constructor);
++ Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter,
++ setter,
++ query,
++ remover,
++ enumerator,
++ true,
+ data);
+ }
+
+diff --git a/src/factory.cc b/src/factory.cc
+index 7dee66f..dcdc645 100644
+--- a/src/factory.cc
++++ b/src/factory.cc
+@@ -1058,6 +1058,10 @@ Handle<JSFunction> Factory::CreateApiFunction(
+ // Set interceptor information in the map.
+ if (!obj->named_property_handler()->IsUndefined()) {
+ map->set_has_named_interceptor();
++
++ InterceptorInfo *nph = InterceptorInfo::cast(obj->named_property_handler());
++ bool is_fallback = nph->is_fallback()->IsUndefined()?false:nph->is_fallback()->value();
++ map->set_named_interceptor_is_fallback(is_fallback);
+ }
+ if (!obj->indexed_property_handler()->IsUndefined()) {
+ map->set_has_indexed_interceptor();
+diff --git a/src/handles.cc b/src/handles.cc
+index 326de86..dd3a86c 100644
+--- a/src/handles.cc
++++ b/src/handles.cc
+@@ -262,9 +262,11 @@ Handle<Object> SetProperty(Handle<JSObject> object,
+ Handle<String> key,
+ Handle<Object> value,
+ PropertyAttributes attributes,
+- StrictModeFlag strict_mode) {
++ StrictModeFlag strict_mode,
++ bool skip_fallback_interceptor) {
+ CALL_HEAP_FUNCTION(object->GetIsolate(),
+- object->SetProperty(*key, *value, attributes, strict_mode),
++ object->SetProperty(*key, *value, attributes, strict_mode,
++ skip_fallback_interceptor),
+ Object);
+ }
+
+diff --git a/src/handles.h b/src/handles.h
+index 3839f37..4b42506 100644
+--- a/src/handles.h
++++ b/src/handles.h
+@@ -188,7 +188,8 @@ Handle<Object> SetProperty(Handle<JSObject> object,
+ Handle<String> key,
+ Handle<Object> value,
+ PropertyAttributes attributes,
+- StrictModeFlag strict_mode);
++ StrictModeFlag strict_mode,
++ bool skip_fallback_interceptor = false);
+
+ Handle<Object> SetProperty(Handle<Object> object,
+ Handle<Object> key,
+diff --git a/src/objects-inl.h b/src/objects-inl.h
+index cce3edd..6aaca2f 100644
+--- a/src/objects-inl.h
++++ b/src/objects-inl.h
+@@ -2521,6 +2521,21 @@ bool Map::is_shared() {
+ }
+
+
++void Map::set_named_interceptor_is_fallback(bool value)
++{
++ if (value) {
++ set_bit_field3(bit_field3() | (1 << kNamedInterceptorIsFallback));
++ } else {
++ set_bit_field3(bit_field3() & ~(1 << kNamedInterceptorIsFallback));
++ }
++}
++
++bool Map::named_interceptor_is_fallback()
++{
++ return ((1 << kNamedInterceptorIsFallback) & bit_field3()) != 0;
++}
++
++
+ JSFunction* Map::unchecked_constructor() {
+ return reinterpret_cast<JSFunction*>(READ_FIELD(this, kConstructorOffset));
+ }
+@@ -2970,6 +2985,7 @@ ACCESSORS(InterceptorInfo, query, Object, kQueryOffset)
+ ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset)
+ ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset)
+ ACCESSORS(InterceptorInfo, data, Object, kDataOffset)
++ACCESSORS(InterceptorInfo, is_fallback, Smi, kFallbackOffset)
+
+ ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset)
+ ACCESSORS(CallHandlerInfo, data, Object, kDataOffset)
+diff --git a/src/objects.cc b/src/objects.cc
+index 2409ea3..f1e4c8c 100644
+--- a/src/objects.cc
++++ b/src/objects.cc
+@@ -1712,9 +1712,10 @@ MaybeObject* JSObject::SetPropertyWithInterceptor(
+ MaybeObject* JSObject::SetProperty(String* name,
+ Object* value,
+ PropertyAttributes attributes,
+- StrictModeFlag strict_mode) {
++ StrictModeFlag strict_mode,
++ bool skip_fallback_interceptor) {
+ LookupResult result;
+- LocalLookup(name, &result);
++ LocalLookup(name, &result, skip_fallback_interceptor);
+ return SetProperty(&result, name, value, attributes, strict_mode);
+ }
+
+@@ -3148,7 +3149,8 @@ AccessorDescriptor* Map::FindAccessor(String* name) {
+ }
+
+
+-void JSObject::LocalLookup(String* name, LookupResult* result) {
++void JSObject::LocalLookup(String* name, LookupResult* result,
++ bool skip_fallback_interceptor) {
+ ASSERT(name->IsString());
+
+ Heap* heap = GetHeap();
+@@ -3174,22 +3176,30 @@ void JSObject::LocalLookup(String* name, LookupResult* result) {
+ }
+
+ // Check for lookup interceptor except when bootstrapping.
+- if (HasNamedInterceptor() && !heap->isolate()->bootstrapper()->IsActive()) {
++ bool wouldIntercept = HasNamedInterceptor() && !heap->isolate()->bootstrapper()->IsActive();
++ if (wouldIntercept && !map()->named_interceptor_is_fallback()) {
+ result->InterceptorResult(this);
+ return;
+ }
+
+ LocalLookupRealNamedProperty(name, result);
++
++ if (wouldIntercept && !skip_fallback_interceptor && !result->IsProperty() &&
++ map()->named_interceptor_is_fallback()) {
++ result->InterceptorResult(this);
++ return;
++ }
+ }
+
+
+-void JSObject::Lookup(String* name, LookupResult* result) {
++void JSObject::Lookup(String* name, LookupResult* result,
++ bool skip_fallback_interceptor) {
+ // Ecma-262 3rd 8.6.2.4
+ Heap* heap = GetHeap();
+ for (Object* current = this;
+ current != heap->null_value();
+ current = JSObject::cast(current)->GetPrototype()) {
+- JSObject::cast(current)->LocalLookup(name, result);
++ JSObject::cast(current)->LocalLookup(name, result, skip_fallback_interceptor);
+ if (result->IsProperty()) return;
+ }
+ result->NotFound();
+diff --git a/src/objects.h b/src/objects.h
+index 07e1089..a209cd0 100644
+--- a/src/objects.h
++++ b/src/objects.h
+@@ -1405,7 +1405,8 @@ class JSObject: public HeapObject {
+ MUST_USE_RESULT MaybeObject* SetProperty(String* key,
+ Object* value,
+ PropertyAttributes attributes,
+- StrictModeFlag strict_mode);
++ StrictModeFlag strict_mode,
++ bool skip_fallback_interceptor = false);
+ MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result,
+ String* key,
+ Object* value,
+@@ -1637,8 +1638,8 @@ class JSObject: public HeapObject {
+
+ // Lookup a property. If found, the result is valid and has
+ // detailed information.
+- void LocalLookup(String* name, LookupResult* result);
+- void Lookup(String* name, LookupResult* result);
++ void LocalLookup(String* name, LookupResult* result, bool skip_fallback_interceptor = false);
++ void Lookup(String* name, LookupResult* result, bool skip_fallback_interceptor = false);
+
+ // The following lookup functions skip interceptors.
+ void LocalLookupRealNamedProperty(String* name, LookupResult* result);
+@@ -3714,6 +3715,12 @@ class Map: public HeapObject {
+ inline void set_is_access_check_needed(bool access_check_needed);
+ inline bool is_access_check_needed();
+
++
++ // Whether the named interceptor is a fallback interceptor or not
++ inline void set_named_interceptor_is_fallback(bool value);
++ inline bool named_interceptor_is_fallback();
++
++
+ // [prototype]: implicit prototype object.
+ DECL_ACCESSORS(prototype, Object)
+
+@@ -3904,6 +3911,7 @@ class Map: public HeapObject {
+ static const int kHasExternalArrayElements = 6;
+
+ // Bit positions for bit field 3
++ static const int kNamedInterceptorIsFallback = 0;
+
+ // Layout of the default cache. It holds alternating name and code objects.
+ static const int kCodeCacheEntrySize = 2;
+@@ -6276,6 +6284,7 @@ class InterceptorInfo: public Struct {
+ DECL_ACCESSORS(deleter, Object)
+ DECL_ACCESSORS(enumerator, Object)
+ DECL_ACCESSORS(data, Object)
++ DECL_ACCESSORS(is_fallback, Smi)
+
+ static inline InterceptorInfo* cast(Object* obj);
+
+@@ -6295,7 +6304,8 @@ class InterceptorInfo: public Struct {
+ static const int kDeleterOffset = kQueryOffset + kPointerSize;
+ static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
+ static const int kDataOffset = kEnumeratorOffset + kPointerSize;
+- static const int kSize = kDataOffset + kPointerSize;
++ static const int kFallbackOffset = kDataOffset + kPointerSize;
++ static const int kSize = kFallbackOffset + kPointerSize;
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
+diff --git a/src/runtime.cc b/src/runtime.cc
+index 7335da8..660352c 100644
+--- a/src/runtime.cc
++++ b/src/runtime.cc
+@@ -1097,7 +1097,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
+ // Lookup the property in the global object, and don't set the
+ // value of the variable if the property is already there.
+ LookupResult lookup;
+- global->Lookup(*name, &lookup);
++ global->Lookup(*name, &lookup, true);
+ if (lookup.IsProperty()) {
+ // Determine if the property is local by comparing the holder
+ // against the global object. The information will be used to
+@@ -1152,7 +1152,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
+ }
+
+ LookupResult lookup;
+- global->LocalLookup(*name, &lookup);
++ global->LocalLookup(*name, &lookup, true);
+
+ PropertyAttributes attributes = is_const_property
+ ? static_cast<PropertyAttributes>(base | READ_ONLY)
+@@ -1196,7 +1196,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
+ name,
+ value,
+ attributes,
+- strict_mode));
++ strict_mode,
++ true));
+ }
+ }
+
+@@ -1343,7 +1344,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+ JSObject* real_holder = global;
+ LookupResult lookup;
+ while (true) {
+- real_holder->LocalLookup(*name, &lookup);
++ real_holder->LocalLookup(*name, &lookup, true);
+ if (lookup.IsProperty()) {
+ // Determine if this is a redeclaration of something read-only.
+ if (lookup.IsReadOnly()) {
+@@ -1400,7 +1401,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+
+ global = isolate->context()->global();
+ if (assign) {
+- return global->SetProperty(*name, args[2], attributes, strict_mode);
++ return global->SetProperty(*name, args[2], attributes, strict_mode, true);
+ }
+ return isolate->heap()->undefined_value();
+ }
+--
+1.7.2.3
+
diff --git a/src/v8/0004-Generalize-external-object-resources.patch b/src/v8/0004-Generalize-external-object-resources.patch
new file mode 100644
index 0000000000..3d5686fe27
--- /dev/null
+++ b/src/v8/0004-Generalize-external-object-resources.patch
@@ -0,0 +1,894 @@
+From 8f640251aeac30f08ddb7bc4c0fe6ba6ff7eabdd Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Mon, 23 May 2011 16:55:35 +1000
+Subject: [PATCH 4/8] Generalize external object resources
+
+V8 was already able to manage and finalize an external string
+resource. This change generalizes that mechanism to handle a
+single generic external resource - a v8::Object::ExternalResource
+derived instance - on normal JSObject's.
+
+This is useful for mapping C++ objects to JS objects where the
+C++ object's memory is effectively owned by the JS Object, and
+thus needs to destroyed when the JS Object is garbage collected.
+The V8 mailing list suggests using a weak persistent handle for
+this purpose, but that seems to incur a fairly massive performance
+penalty for short lived objects as weak persistent handle callbacks
+are not called until the object has been promoted into the old
+object space.
+---
+ include/v8.h | 25 ++++++
+ src/api.cc | 64 ++++++++++++++-
+ src/extensions/externalize-string-extension.cc | 4 +-
+ src/factory.cc | 11 +++
+ src/heap-inl.h | 101 +++++++++++++++---------
+ src/heap.cc | 68 ++++++++--------
+ src/heap.h | 42 +++++-----
+ src/liveobjectlist.cc | 4 +-
+ src/mark-compact.cc | 21 +++---
+ src/objects-inl.h | 41 +++++++++-
+ src/objects.h | 14 +++-
+ 11 files changed, 280 insertions(+), 115 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index 06085ec..9740251 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -1629,6 +1629,25 @@ class Object : public Value {
+ /** Sets a native pointer in an internal field. */
+ V8EXPORT void SetPointerInInternalField(int index, void* value);
+
++ class V8EXPORT ExternalResource { // NOLINT
++ public:
++ ExternalResource() {}
++ virtual ~ExternalResource() {}
++
++ protected:
++ virtual void Dispose() { delete this; }
++
++ private:
++ // Disallow copying and assigning.
++ ExternalResource(const ExternalResource&);
++ void operator=(const ExternalResource&);
++
++ friend class v8::internal::Heap;
++ };
++
++ V8EXPORT void SetExternalResource(ExternalResource *);
++ V8EXPORT ExternalResource *GetExternalResource();
++
+ // Testers for local properties.
+ V8EXPORT bool HasRealNamedProperty(Handle<String> key);
+ V8EXPORT bool HasRealIndexedProperty(uint32_t index);
+@@ -2330,6 +2349,12 @@ class V8EXPORT ObjectTemplate : public Template {
+ */
+ void SetInternalFieldCount(int value);
+
++ /**
++ * Sets whether the object can store an "external resource" object.
++ */
++ bool HasExternalResource();
++ void SetHasExternalResource(bool value);
++
+ private:
+ ObjectTemplate();
+ static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
+diff --git a/src/api.cc b/src/api.cc
+index c20b062..d81ece8 100644
+--- a/src/api.cc
++++ b/src/api.cc
+@@ -1294,6 +1294,34 @@ void ObjectTemplate::SetInternalFieldCount(int value) {
+ }
+
+
++bool ObjectTemplate::HasExternalResource()
++{
++ if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(),
++ "v8::ObjectTemplate::HasExternalResource()")) {
++ return 0;
++ }
++ return !Utils::OpenHandle(this)->has_external_resource()->IsUndefined();
++}
++
++
++void ObjectTemplate::SetHasExternalResource(bool value)
++{
++ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
++ if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetHasExternalResource()")) {
++ return;
++ }
++ ENTER_V8(isolate);
++ if (value) {
++ EnsureConstructor(this);
++ }
++ if (value) {
++ Utils::OpenHandle(this)->set_has_external_resource(i::Smi::FromInt(1));
++ } else {
++ Utils::OpenHandle(this)->set_has_external_resource(Utils::OpenHandle(this)->GetHeap()->undefined_value());
++ }
++}
++
++
+ // --- S c r i p t D a t a ---
+
+
+@@ -3648,6 +3676,34 @@ void v8::Object::SetPointerInInternalField(int index, void* value) {
+ }
+
+
++void v8::Object::SetExternalResource(v8::Object::ExternalResource *resource) {
++ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
++ ENTER_V8(isolate);
++ i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
++ if (CanBeEncodedAsSmi(resource)) {
++ obj->SetExternalResourceObject(EncodeAsSmi(resource));
++ } else {
++ obj->SetExternalResourceObject(*isolate->factory()->NewProxy(static_cast<i::Address>((void *)resource)));
++ }
++ if (!obj->IsSymbol()) {
++ isolate->heap()->external_resource_table()->AddObject(*obj);
++ }
++}
++
++
++v8::Object::ExternalResource *v8::Object::GetExternalResource() {
++ i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
++ i::Object* value = obj->GetExternalResourceObject();
++ if (value->IsSmi()) {
++ return reinterpret_cast<v8::Object::ExternalResource*>(i::Internals::GetExternalPointerFromSmi(value));
++ } else if (value->IsProxy()) {
++ return reinterpret_cast<v8::Object::ExternalResource*>(i::Proxy::cast(value)->proxy());
++ } else {
++ return NULL;
++ }
++}
++
++
+ // --- E n v i r o n m e n t ---
+
+
+@@ -4140,7 +4196,7 @@ Local<String> v8::String::NewExternal(
+ LOG_API(isolate, "String::NewExternal");
+ ENTER_V8(isolate);
+ i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
+- isolate->heap()->external_string_table()->AddString(*result);
++ isolate->heap()->external_resource_table()->AddString(*result);
+ return Utils::ToLocal(result);
+ }
+
+@@ -4158,7 +4214,7 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
+ }
+ bool result = obj->MakeExternal(resource);
+ if (result && !obj->IsSymbol()) {
+- isolate->heap()->external_string_table()->AddString(*obj);
++ isolate->heap()->external_resource_table()->AddString(*obj);
+ }
+ return result;
+ }
+@@ -4171,7 +4227,7 @@ Local<String> v8::String::NewExternal(
+ LOG_API(isolate, "String::NewExternal");
+ ENTER_V8(isolate);
+ i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource);
+- isolate->heap()->external_string_table()->AddString(*result);
++ isolate->heap()->external_resource_table()->AddString(*result);
+ return Utils::ToLocal(result);
+ }
+
+@@ -4190,7 +4246,7 @@ bool v8::String::MakeExternal(
+ }
+ bool result = obj->MakeExternal(resource);
+ if (result && !obj->IsSymbol()) {
+- isolate->heap()->external_string_table()->AddString(*obj);
++ isolate->heap()->external_resource_table()->AddString(*obj);
+ }
+ return result;
+ }
+diff --git a/src/extensions/externalize-string-extension.cc b/src/extensions/externalize-string-extension.cc
+index b3f83fe..8e50904 100644
+--- a/src/extensions/externalize-string-extension.cc
++++ b/src/extensions/externalize-string-extension.cc
+@@ -100,7 +100,7 @@ v8::Handle<v8::Value> ExternalizeStringExtension::Externalize(
+ data, string->length());
+ result = string->MakeExternal(resource);
+ if (result && !string->IsSymbol()) {
+- HEAP->external_string_table()->AddString(*string);
++ HEAP->external_resource_table()->AddString(*string);
+ }
+ if (!result) delete resource;
+ } else {
+@@ -110,7 +110,7 @@ v8::Handle<v8::Value> ExternalizeStringExtension::Externalize(
+ data, string->length());
+ result = string->MakeExternal(resource);
+ if (result && !string->IsSymbol()) {
+- HEAP->external_string_table()->AddString(*string);
++ HEAP->external_resource_table()->AddString(*string);
+ }
+ if (!result) delete resource;
+ }
+diff --git a/src/factory.cc b/src/factory.cc
+index dcdc645..d530a75 100644
+--- a/src/factory.cc
++++ b/src/factory.cc
+@@ -997,15 +997,21 @@ Handle<JSFunction> Factory::CreateApiFunction(
+ Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
+
+ int internal_field_count = 0;
++ bool has_external_resource = false;
++
+ if (!obj->instance_template()->IsUndefined()) {
+ Handle<ObjectTemplateInfo> instance_template =
+ Handle<ObjectTemplateInfo>(
+ ObjectTemplateInfo::cast(obj->instance_template()));
+ internal_field_count =
+ Smi::cast(instance_template->internal_field_count())->value();
++ has_external_resource =
++ !instance_template->has_external_resource()->IsUndefined();
+ }
+
+ int instance_size = kPointerSize * internal_field_count;
++ if (has_external_resource) instance_size += kPointerSize;
++
+ InstanceType type = INVALID_TYPE;
+ switch (instance_type) {
+ case JavaScriptObject:
+@@ -1040,6 +1046,11 @@ Handle<JSFunction> Factory::CreateApiFunction(
+
+ Handle<Map> map = Handle<Map>(result->initial_map());
+
++ // Mark as having external data object if needed
++ if (has_external_resource) {
++ map->set_has_external_resource(true);
++ }
++
+ // Mark as undetectable if needed.
+ if (obj->undetectable()) {
+ map->set_is_undetectable();
+diff --git a/src/heap-inl.h b/src/heap-inl.h
+index f4fce7b..58e7adf 100644
+--- a/src/heap-inl.h
++++ b/src/heap-inl.h
+@@ -205,21 +205,36 @@ MaybeObject* Heap::NumberFromUint32(uint32_t value) {
+ }
+
+
+-void Heap::FinalizeExternalString(String* string) {
+- ASSERT(string->IsExternalString());
+- v8::String::ExternalStringResourceBase** resource_addr =
+- reinterpret_cast<v8::String::ExternalStringResourceBase**>(
+- reinterpret_cast<byte*>(string) +
+- ExternalString::kResourceOffset -
+- kHeapObjectTag);
+-
+- // Dispose of the C++ object if it has not already been disposed.
+- if (*resource_addr != NULL) {
+- (*resource_addr)->Dispose();
+- }
++void Heap::FinalizeExternalString(HeapObject* string) {
++ ASSERT(string->IsExternalString() || string->map()->has_external_resource());
++
++ if (string->IsExternalString()) {
++ v8::String::ExternalStringResourceBase** resource_addr =
++ reinterpret_cast<v8::String::ExternalStringResourceBase**>(
++ reinterpret_cast<byte*>(string) +
++ ExternalString::kResourceOffset -
++ kHeapObjectTag);
++
++ // Dispose of the C++ object if it has not already been disposed.
++ if (*resource_addr != NULL) {
++ (*resource_addr)->Dispose();
++ }
+
+- // Clear the resource pointer in the string.
+- *resource_addr = NULL;
++ // Clear the resource pointer in the string.
++ *resource_addr = NULL;
++ } else {
++ JSObject *object = JSObject::cast(string);
++ Object *value = object->GetExternalResourceObject();
++ v8::Object::ExternalResource *resource = 0;
++ if (value->IsSmi()) {
++ resource = reinterpret_cast<v8::Object::ExternalResource*>(Internals::GetExternalPointerFromSmi(value));
++ } else if (value->IsProxy()) {
++ resource = reinterpret_cast<v8::Object::ExternalResource*>(Proxy::cast(value)->proxy());
++ }
++ if (resource) {
++ resource->Dispose();
++ }
++ }
+ }
+
+
+@@ -556,53 +571,63 @@ inline bool Heap::allow_allocation(bool new_state) {
+ #endif
+
+
+-void ExternalStringTable::AddString(String* string) {
+- ASSERT(string->IsExternalString());
++void ExternalResourceTable::AddString(String* string) {
++ ASSERT(string->IsExternalString() );
+ if (heap_->InNewSpace(string)) {
+- new_space_strings_.Add(string);
++ new_space_objects_.Add(string);
++ } else {
++ old_space_objects_.Add(string);
++ }
++}
++
++
++void ExternalResourceTable::AddObject(HeapObject* object) {
++ ASSERT(object->map()->has_external_resource());
++ if (heap_->InNewSpace(object)) {
++ new_space_objects_.Add(object);
+ } else {
+- old_space_strings_.Add(string);
++ old_space_objects_.Add(object);
+ }
+ }
+
+
+-void ExternalStringTable::Iterate(ObjectVisitor* v) {
+- if (!new_space_strings_.is_empty()) {
+- Object** start = &new_space_strings_[0];
+- v->VisitPointers(start, start + new_space_strings_.length());
++void ExternalResourceTable::Iterate(ObjectVisitor* v) {
++ if (!new_space_objects_.is_empty()) {
++ Object** start = &new_space_objects_[0];
++ v->VisitPointers(start, start + new_space_objects_.length());
+ }
+- if (!old_space_strings_.is_empty()) {
+- Object** start = &old_space_strings_[0];
+- v->VisitPointers(start, start + old_space_strings_.length());
++ if (!old_space_objects_.is_empty()) {
++ Object** start = &old_space_objects_[0];
++ v->VisitPointers(start, start + old_space_objects_.length());
+ }
+ }
+
+
+ // Verify() is inline to avoid ifdef-s around its calls in release
+ // mode.
+-void ExternalStringTable::Verify() {
++void ExternalResourceTable::Verify() {
+ #ifdef DEBUG
+- for (int i = 0; i < new_space_strings_.length(); ++i) {
+- ASSERT(heap_->InNewSpace(new_space_strings_[i]));
+- ASSERT(new_space_strings_[i] != HEAP->raw_unchecked_null_value());
++ for (int i = 0; i < new_space_objects_.length(); ++i) {
++ ASSERT(heap_->InNewSpace(new_space_objects_[i]));
++ ASSERT(new_space_objects_[i] != HEAP->raw_unchecked_null_value());
+ }
+- for (int i = 0; i < old_space_strings_.length(); ++i) {
+- ASSERT(!heap_->InNewSpace(old_space_strings_[i]));
+- ASSERT(old_space_strings_[i] != HEAP->raw_unchecked_null_value());
++ for (int i = 0; i < old_space_objects_.length(); ++i) {
++ ASSERT(!heap_->InNewSpace(old_space_objects_[i]));
++ ASSERT(old_space_objects_[i] != HEAP->raw_unchecked_null_value());
+ }
+ #endif
+ }
+
+
+-void ExternalStringTable::AddOldString(String* string) {
+- ASSERT(string->IsExternalString());
+- ASSERT(!heap_->InNewSpace(string));
+- old_space_strings_.Add(string);
++void ExternalResourceTable::AddOldObject(HeapObject* object) {
++ ASSERT(object->IsExternalString() || object->map()->has_external_resource());
++ ASSERT(!heap_->InNewSpace(object));
++ old_space_objects_.Add(object);
+ }
+
+
+-void ExternalStringTable::ShrinkNewStrings(int position) {
+- new_space_strings_.Rewind(position);
++void ExternalResourceTable::ShrinkNewObjects(int position) {
++ new_space_objects_.Rewind(position);
+ Verify();
+ }
+
+diff --git a/src/heap.cc b/src/heap.cc
+index 900f462..bf2940e 100644
+--- a/src/heap.cc
++++ b/src/heap.cc
+@@ -155,7 +155,7 @@ Heap::Heap()
+ memset(roots_, 0, sizeof(roots_[0]) * kRootListLength);
+ global_contexts_list_ = NULL;
+ mark_compact_collector_.heap_ = this;
+- external_string_table_.heap_ = this;
++ external_resource_table_.heap_ = this;
+ }
+
+
+@@ -1030,8 +1030,8 @@ void Heap::Scavenge() {
+
+ new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
+
+- UpdateNewSpaceReferencesInExternalStringTable(
+- &UpdateNewSpaceReferenceInExternalStringTableEntry);
++ UpdateNewSpaceReferencesInExternalResourceTable(
++ &UpdateNewSpaceReferenceInExternalResourceTableEntry);
+
+ LiveObjectList::UpdateReferencesForScavengeGC();
+ isolate()->runtime_profiler()->UpdateSamplesAfterScavenge();
+@@ -1053,38 +1053,38 @@ void Heap::Scavenge() {
+ }
+
+
+-String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap,
+- Object** p) {
++HeapObject* Heap::UpdateNewSpaceReferenceInExternalResourceTableEntry(Heap* heap,
++ Object** p) {
+ MapWord first_word = HeapObject::cast(*p)->map_word();
+
+ if (!first_word.IsForwardingAddress()) {
+ // Unreachable external string can be finalized.
+- heap->FinalizeExternalString(String::cast(*p));
++ heap->FinalizeExternalString(HeapObject::cast(*p));
+ return NULL;
+ }
+
+ // String is still reachable.
+- return String::cast(first_word.ToForwardingAddress());
++ return HeapObject::cast(first_word.ToForwardingAddress());
+ }
+
+
+-void Heap::UpdateNewSpaceReferencesInExternalStringTable(
+- ExternalStringTableUpdaterCallback updater_func) {
+- external_string_table_.Verify();
++void Heap::UpdateNewSpaceReferencesInExternalResourceTable(
++ ExternalResourceTableUpdaterCallback updater_func) {
++ external_resource_table_.Verify();
+
+- if (external_string_table_.new_space_strings_.is_empty()) return;
++ if (external_resource_table_.new_space_objects_.is_empty()) return;
+
+- Object** start = &external_string_table_.new_space_strings_[0];
+- Object** end = start + external_string_table_.new_space_strings_.length();
++ Object** start = &external_resource_table_.new_space_objects_[0];
++ Object** end = start + external_resource_table_.new_space_objects_.length();
+ Object** last = start;
+
+ for (Object** p = start; p < end; ++p) {
+ ASSERT(InFromSpace(*p));
+- String* target = updater_func(this, p);
++ HeapObject* target = updater_func(this, p);
+
+ if (target == NULL) continue;
+
+- ASSERT(target->IsExternalString());
++ ASSERT(target->IsExternalString() || target->map()->has_external_resource());
+
+ if (InNewSpace(target)) {
+ // String is still in new space. Update the table entry.
+@@ -1092,12 +1092,12 @@ void Heap::UpdateNewSpaceReferencesInExternalStringTable(
+ ++last;
+ } else {
+ // String got promoted. Move it to the old string list.
+- external_string_table_.AddOldString(target);
++ external_resource_table_.AddOldObject(target);
+ }
+ }
+
+ ASSERT(last <= end);
+- external_string_table_.ShrinkNewStrings(static_cast<int>(last - start));
++ external_resource_table_.ShrinkNewObjects(static_cast<int>(last - start));
+ }
+
+
+@@ -4468,7 +4468,7 @@ void Heap::IterateWeakRoots(ObjectVisitor* v, VisitMode mode) {
+ v->Synchronize("symbol_table");
+ if (mode != VISIT_ALL_IN_SCAVENGE) {
+ // Scavenge collections have special processing for this.
+- external_string_table_.Iterate(v);
++ external_resource_table_.Iterate(v);
+ }
+ v->Synchronize("external_string_table");
+ }
+@@ -4970,7 +4970,7 @@ void Heap::TearDown() {
+
+ isolate_->global_handles()->TearDown();
+
+- external_string_table_.TearDown();
++ external_resource_table_.TearDown();
+
+ new_space_.TearDown();
+
+@@ -5835,31 +5835,31 @@ void TranscendentalCache::Clear() {
+ }
+
+
+-void ExternalStringTable::CleanUp() {
++void ExternalResourceTable::CleanUp() {
+ int last = 0;
+- for (int i = 0; i < new_space_strings_.length(); ++i) {
+- if (new_space_strings_[i] == heap_->raw_unchecked_null_value()) continue;
+- if (heap_->InNewSpace(new_space_strings_[i])) {
+- new_space_strings_[last++] = new_space_strings_[i];
++ for (int i = 0; i < new_space_objects_.length(); ++i) {
++ if (new_space_objects_[i] == heap_->raw_unchecked_null_value()) continue;
++ if (heap_->InNewSpace(new_space_objects_[i])) {
++ new_space_objects_[last++] = new_space_objects_[i];
+ } else {
+- old_space_strings_.Add(new_space_strings_[i]);
++ old_space_objects_.Add(new_space_objects_[i]);
+ }
+ }
+- new_space_strings_.Rewind(last);
++ new_space_objects_.Rewind(last);
+ last = 0;
+- for (int i = 0; i < old_space_strings_.length(); ++i) {
+- if (old_space_strings_[i] == heap_->raw_unchecked_null_value()) continue;
+- ASSERT(!heap_->InNewSpace(old_space_strings_[i]));
+- old_space_strings_[last++] = old_space_strings_[i];
++ for (int i = 0; i < old_space_objects_.length(); ++i) {
++ if (old_space_objects_[i] == heap_->raw_unchecked_null_value()) continue;
++ ASSERT(!heap_->InNewSpace(old_space_objects_[i]));
++ old_space_objects_[last++] = old_space_objects_[i];
+ }
+- old_space_strings_.Rewind(last);
++ old_space_objects_.Rewind(last);
+ Verify();
+ }
+
+
+-void ExternalStringTable::TearDown() {
+- new_space_strings_.Free();
+- old_space_strings_.Free();
++void ExternalResourceTable::TearDown() {
++ new_space_objects_.Free();
++ old_space_objects_.Free();
+ }
+
+
+diff --git a/src/heap.h b/src/heap.h
+index ae4e9e7..8cbf378 100644
+--- a/src/heap.h
++++ b/src/heap.h
+@@ -237,8 +237,8 @@ class Isolate;
+ class WeakObjectRetainer;
+
+
+-typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap,
+- Object** pointer);
++typedef HeapObject* (*ExternalResourceTableUpdaterCallback)(Heap* heap,
++ Object** pointer);
+
+ typedef bool (*DirtyRegionCallback)(Heap* heap,
+ Address start,
+@@ -284,43 +284,45 @@ class PromotionQueue {
+ };
+
+
+-// External strings table is a place where all external strings are
+-// registered. We need to keep track of such strings to properly
+-// finalize them.
+-class ExternalStringTable {
++// External resource table is a place where all external strings and
++// objects with an external resource are registered. We need to keep
++// track of such strings to properly finalize them.
++class ExternalResourceTable {
+ public:
+ // Registers an external string.
+ inline void AddString(String* string);
++ // Registers an external object.
++ inline void AddObject(HeapObject* object);
+
+ inline void Iterate(ObjectVisitor* v);
+
+ // Restores internal invariant and gets rid of collected strings.
+- // Must be called after each Iterate() that modified the strings.
++ // Must be called after each Iterate() that modified the objects.
+ void CleanUp();
+
+ // Destroys all allocated memory.
+ void TearDown();
+
+ private:
+- ExternalStringTable() { }
++ ExternalResourceTable() { }
+
+ friend class Heap;
+
+ inline void Verify();
+
+- inline void AddOldString(String* string);
++ inline void AddOldObject(HeapObject* object);
+
+ // Notifies the table that only a prefix of the new list is valid.
+- inline void ShrinkNewStrings(int position);
++ inline void ShrinkNewObjects(int position);
+
+ // To speed up scavenge collections new space string are kept
+ // separate from old space strings.
+- List<Object*> new_space_strings_;
+- List<Object*> old_space_strings_;
++ List<Object*> new_space_objects_;
++ List<Object*> old_space_objects_;
+
+ Heap* heap_;
+
+- DISALLOW_COPY_AND_ASSIGN(ExternalStringTable);
++ DISALLOW_COPY_AND_ASSIGN(ExternalResourceTable);
+ };
+
+
+@@ -753,7 +755,7 @@ class Heap {
+
+ // Finalizes an external string by deleting the associated external
+ // data and clearing the resource pointer.
+- inline void FinalizeExternalString(String* string);
++ inline void FinalizeExternalString(HeapObject* string);
+
+ // Allocates an uninitialized object. The memory is non-executable if the
+ // hardware and OS allow.
+@@ -1191,8 +1193,8 @@ class Heap {
+ survived_since_last_expansion_ += survived;
+ }
+
+- void UpdateNewSpaceReferencesInExternalStringTable(
+- ExternalStringTableUpdaterCallback updater_func);
++ void UpdateNewSpaceReferencesInExternalResourceTable(
++ ExternalResourceTableUpdaterCallback updater_func);
+
+ void ProcessWeakReferences(WeakObjectRetainer* retainer);
+
+@@ -1228,8 +1230,8 @@ class Heap {
+ return &mark_compact_collector_;
+ }
+
+- ExternalStringTable* external_string_table() {
+- return &external_string_table_;
++ ExternalResourceTable* external_resource_table() {
++ return &external_resource_table_;
+ }
+
+ inline Isolate* isolate();
+@@ -1462,7 +1464,7 @@ class Heap {
+ // Performs a minor collection in new generation.
+ void Scavenge();
+
+- static String* UpdateNewSpaceReferenceInExternalStringTableEntry(
++ static HeapObject* UpdateNewSpaceReferenceInExternalResourceTableEntry(
+ Heap* heap,
+ Object** pointer);
+
+@@ -1593,7 +1595,7 @@ class Heap {
+ // configured through the API until it is setup.
+ bool configured_;
+
+- ExternalStringTable external_string_table_;
++ ExternalResourceTable external_resource_table_;
+
+ bool is_safe_to_read_maps_;
+
+diff --git a/src/liveobjectlist.cc b/src/liveobjectlist.cc
+index 5795a6b..8866e58 100644
+--- a/src/liveobjectlist.cc
++++ b/src/liveobjectlist.cc
+@@ -1989,7 +1989,7 @@ Object* LiveObjectList::PrintObj(int obj_id) {
+ ASSERT(resource->IsAscii());
+ Handle<String> dump_string =
+ Factory::NewExternalStringFromAscii(resource);
+- ExternalStringTable::AddString(*dump_string);
++ ExternalResourceTable::AddString(*dump_string);
+ return *dump_string;
+ } else {
+ delete resource;
+@@ -2193,7 +2193,7 @@ Object* LiveObjectList::GetPathPrivate(HeapObject* obj1, HeapObject* obj2) {
+ ASSERT(resource->IsAscii());
+ Handle<String> path_string =
+ Factory::NewExternalStringFromAscii(resource);
+- ExternalStringTable::AddString(*path_string);
++ ExternalResourceTable::AddString(*path_string);
+ return *path_string;
+ } else {
+ delete resource;
+diff --git a/src/mark-compact.cc b/src/mark-compact.cc
+index 68a5062..1b1e361 100644
+--- a/src/mark-compact.cc
++++ b/src/mark-compact.cc
+@@ -163,7 +163,7 @@ void MarkCompactCollector::Finish() {
+ // objects (empty string, illegal builtin).
+ heap()->isolate()->stub_cache()->Clear();
+
+- heap()->external_string_table_.CleanUp();
++ heap()->external_resource_table_.CleanUp();
+
+ // If we've just compacted old space there's no reason to check the
+ // fragmentation limit. Just return.
+@@ -1019,8 +1019,9 @@ class SymbolTableCleaner : public ObjectVisitor {
+
+ // Since no objects have yet been moved we can safely access the map of
+ // the object.
+- if ((*p)->IsExternalString()) {
+- heap_->FinalizeExternalString(String::cast(*p));
++ if ((*p)->IsExternalString() ||
++ (*p)->IsHeapObject() && HeapObject::cast(*p)->map()->has_external_resource()) {
++ heap_->FinalizeExternalString(HeapObject::cast(*p));
+ }
+ // Set the entry to null_value (as deleted).
+ *p = heap_->raw_unchecked_null_value();
+@@ -1433,8 +1434,8 @@ void MarkCompactCollector::MarkLiveObjects() {
+ SymbolTableCleaner v(heap());
+ symbol_table->IterateElements(&v);
+ symbol_table->ElementsRemoved(v.PointersRemoved());
+- heap()->external_string_table_.Iterate(&v);
+- heap()->external_string_table_.CleanUp();
++ heap()->external_resource_table_.Iterate(&v);
++ heap()->external_resource_table_.CleanUp();
+
+ // Process the weak references.
+ MarkCompactWeakObjectRetainer mark_compact_object_retainer;
+@@ -1948,11 +1949,11 @@ static void UpdatePointerToNewGen(HeapObject** p) {
+ }
+
+
+-static String* UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap,
+- Object** p) {
++static HeapObject* UpdateNewSpaceReferenceInExternalResourceTableEntry(Heap* heap,
++ Object** p) {
+ Address old_addr = HeapObject::cast(*p)->address();
+ Address new_addr = Memory::Address_at(old_addr);
+- return String::cast(HeapObject::FromAddress(new_addr));
++ return HeapObject::FromAddress(new_addr);
+ }
+
+
+@@ -2083,8 +2084,8 @@ static void SweepNewSpace(Heap* heap, NewSpace* space) {
+ updating_visitor.VisitPointer(heap->global_contexts_list_address());
+
+ // Update pointers from external string table.
+- heap->UpdateNewSpaceReferencesInExternalStringTable(
+- &UpdateNewSpaceReferenceInExternalStringTableEntry);
++ heap->UpdateNewSpaceReferencesInExternalResourceTable(
++ &UpdateNewSpaceReferenceInExternalResourceTableEntry);
+
+ // All pointers were updated. Update auxiliary allocation info.
+ heap->IncrementYoungSurvivorsCounter(survivors_size);
+diff --git a/src/objects-inl.h b/src/objects-inl.h
+index 6aaca2f..231b835 100644
+--- a/src/objects-inl.h
++++ b/src/objects-inl.h
+@@ -1392,13 +1392,13 @@ int JSObject::GetInternalFieldCount() {
+ // Make sure to adjust for the number of in-object properties. These
+ // properties do contribute to the size, but are not internal fields.
+ return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) -
+- map()->inobject_properties();
++ map()->inobject_properties() - map()->has_external_resource()?1:0;
+ }
+
+
+ int JSObject::GetInternalFieldOffset(int index) {
+ ASSERT(index < GetInternalFieldCount() && index >= 0);
+- return GetHeaderSize() + (kPointerSize * index);
++ return GetHeaderSize() + (kPointerSize * (index + map()->has_external_resource()?1:0));
+ }
+
+
+@@ -1407,7 +1407,7 @@ Object* JSObject::GetInternalField(int index) {
+ // Internal objects do follow immediately after the header, whereas in-object
+ // properties are at the end of the object. Therefore there is no need
+ // to adjust the index here.
+- return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index));
++ return READ_FIELD(this, GetHeaderSize() + (kPointerSize * (index + map()->has_external_resource()?1:0)));
+ }
+
+
+@@ -1416,12 +1416,29 @@ void JSObject::SetInternalField(int index, Object* value) {
+ // Internal objects do follow immediately after the header, whereas in-object
+ // properties are at the end of the object. Therefore there is no need
+ // to adjust the index here.
+- int offset = GetHeaderSize() + (kPointerSize * index);
++ int offset = GetHeaderSize() + (kPointerSize * (index + map()->has_external_resource()?1:0));
+ WRITE_FIELD(this, offset, value);
+ WRITE_BARRIER(this, offset);
+ }
+
+
++void JSObject::SetExternalResourceObject(Object *value) {
++ ASSERT(map()->has_external_resource());
++ int offset = GetHeaderSize();
++ WRITE_FIELD(this, offset, value);
++ WRITE_BARRIER(this, offset);
++}
++
++
++Object *JSObject::GetExternalResourceObject() {
++ if (map()->has_external_resource()) {
++ return READ_FIELD(this, GetHeaderSize());
++ } else {
++ return GetHeap()->undefined_value();
++ }
++}
++
++
+ // Access fast-case object properties at index. The use of these routines
+ // is needed to correctly distinguish between properties stored in-object and
+ // properties stored in the properties array.
+@@ -2521,6 +2538,20 @@ bool Map::is_shared() {
+ }
+
+
++void Map::set_has_external_resource(bool value) {
++ if (value) {
++ set_bit_field3(bit_field3() | (1 << kHasExternalResource));
++ } else {
++ set_bit_field3(bit_field3() & ~(1 << kHasExternalResource));
++ }
++}
++
++bool Map::has_external_resource()
++{
++ return ((1 << kHasExternalResource) & bit_field3()) != 0;
++}
++
++
+ void Map::set_named_interceptor_is_fallback(bool value)
+ {
+ if (value) {
+@@ -3017,6 +3048,8 @@ ACCESSORS(FunctionTemplateInfo, flag, Smi, kFlagOffset)
+ ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
+ ACCESSORS(ObjectTemplateInfo, internal_field_count, Object,
+ kInternalFieldCountOffset)
++ACCESSORS(ObjectTemplateInfo, has_external_resource, Object,
++ kHasExternalResourceOffset)
+
+ ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset)
+ ACCESSORS(SignatureInfo, args, Object, kArgsOffset)
+diff --git a/src/objects.h b/src/objects.h
+index a209cd0..1bdb5c7 100644
+--- a/src/objects.h
++++ b/src/objects.h
+@@ -1636,6 +1636,9 @@ class JSObject: public HeapObject {
+ inline Object* GetInternalField(int index);
+ inline void SetInternalField(int index, Object* value);
+
++ inline void SetExternalResourceObject(Object *);
++ inline Object *GetExternalResourceObject();
++
+ // Lookup a property. If found, the result is valid and has
+ // detailed information.
+ void LocalLookup(String* name, LookupResult* result, bool skip_fallback_interceptor = false);
+@@ -3715,6 +3718,12 @@ class Map: public HeapObject {
+ inline void set_is_access_check_needed(bool access_check_needed);
+ inline bool is_access_check_needed();
+
++
++ // Tells whether the instance has the space for an external resource
++ // object
++ inline void set_has_external_resource(bool value);
++ inline bool has_external_resource();
++
+
+ // Whether the named interceptor is a fallback interceptor or not
+ inline void set_named_interceptor_is_fallback(bool value);
+@@ -3912,6 +3921,7 @@ class Map: public HeapObject {
+
+ // Bit positions for bit field 3
+ static const int kNamedInterceptorIsFallback = 0;
++ static const int kHasExternalResource = 1;
+
+ // Layout of the default cache. It holds alternating name and code objects.
+ static const int kCodeCacheEntrySize = 2;
+@@ -6426,6 +6436,7 @@ class ObjectTemplateInfo: public TemplateInfo {
+ public:
+ DECL_ACCESSORS(constructor, Object)
+ DECL_ACCESSORS(internal_field_count, Object)
++ DECL_ACCESSORS(has_external_resource, Object)
+
+ static inline ObjectTemplateInfo* cast(Object* obj);
+
+@@ -6442,7 +6453,8 @@ class ObjectTemplateInfo: public TemplateInfo {
+ static const int kConstructorOffset = TemplateInfo::kHeaderSize;
+ static const int kInternalFieldCountOffset =
+ kConstructorOffset + kPointerSize;
+- static const int kSize = kInternalFieldCountOffset + kPointerSize;
++ static const int kHasExternalResourceOffset = kInternalFieldCountOffset + kPointerSize;
++ static const int kSize = kHasExternalResourceOffset + kPointerSize;
+ };
+
+
+--
+1.7.2.3
+
diff --git a/src/v8/0005-Introduce-a-QML-compilation-mode.patch b/src/v8/0005-Introduce-a-QML-compilation-mode.patch
new file mode 100644
index 0000000000..930e2b9453
--- /dev/null
+++ b/src/v8/0005-Introduce-a-QML-compilation-mode.patch
@@ -0,0 +1,1777 @@
+From de8b6a719219677dc8e34248de7836369bf1034d Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Mon, 23 May 2011 18:26:19 +1000
+Subject: [PATCH 5/8] Introduce a QML compilation mode
+
+In QML mode, there is a second global object - known as the QML
+global object. During property resolution, if a property is not
+present on the JS global object, it is resolve on the QML global
+object.
+
+This global object behavior is only enabled if a script is being
+compiled in QML mode. The object to use as the QML global object
+is passed as a parameter to the Script::Run() method. Any function
+closures etc. created during the run will retain a reference to this
+object, so different objects can be passed in different script
+runs.
+---
+ include/v8.h | 18 ++++++++--
+ src/api.cc | 52 ++++++++++++++++++++++++-----
+ src/arm/code-stubs-arm.cc | 4 ++
+ src/arm/full-codegen-arm.cc | 26 ++++++++------
+ src/arm/lithium-arm.cc | 2 +-
+ src/arm/lithium-arm.h | 6 +++-
+ src/arm/lithium-codegen-arm.cc | 7 ++--
+ src/arm/macro-assembler-arm.h | 5 +++
+ src/ast-inl.h | 5 +++
+ src/ast.h | 1 +
+ src/code-stubs.h | 2 +-
+ src/compiler.cc | 15 +++++++-
+ src/compiler.h | 22 ++++++++++--
+ src/contexts.cc | 23 +++++++++++++
+ src/contexts.h | 4 ++
+ src/execution.cc | 28 +++++++++++++--
+ src/execution.h | 6 +++
+ src/full-codegen.cc | 3 +-
+ src/full-codegen.h | 1 +
+ src/heap.cc | 2 +
+ src/hydrogen-instructions.h | 10 ++++-
+ src/hydrogen.cc | 2 +
+ src/ia32/code-stubs-ia32.cc | 7 ++++
+ src/ia32/full-codegen-ia32.cc | 26 ++++++++------
+ src/ia32/lithium-codegen-ia32.cc | 7 ++--
+ src/ia32/lithium-ia32.cc | 2 +-
+ src/ia32/lithium-ia32.h | 6 +++-
+ src/ia32/macro-assembler-ia32.h | 5 +++
+ src/objects-inl.h | 12 +++++++
+ src/objects.h | 5 +++
+ src/parser.cc | 27 +++++++++++++--
+ src/parser.h | 4 ++-
+ src/prettyprinter.cc | 3 ++
+ src/runtime.cc | 68 ++++++++++++++++++++++++-------------
+ src/runtime.h | 8 ++--
+ src/scopes.cc | 10 +++++
+ src/scopes.h | 7 ++++
+ src/variables.cc | 3 +-
+ src/variables.h | 5 +++
+ src/x64/code-stubs-x64.cc | 4 ++
+ src/x64/full-codegen-x64.cc | 26 ++++++++------
+ src/x64/lithium-codegen-x64.cc | 7 ++--
+ src/x64/lithium-x64.cc | 2 +-
+ src/x64/lithium-x64.h | 6 +++
+ src/x64/macro-assembler-x64.h | 5 +++
+ 45 files changed, 391 insertions(+), 108 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index 9740251..d04b73e 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -577,6 +577,10 @@ class ScriptOrigin {
+ */
+ class V8EXPORT Script {
+ public:
++ enum CompileFlags {
++ Default = 0x00,
++ QmlMode = 0x01
++ };
+
+ /**
+ * Compiles the specified script (context-independent).
+@@ -596,7 +600,8 @@ class V8EXPORT Script {
+ static Local<Script> New(Handle<String> source,
+ ScriptOrigin* origin = NULL,
+ ScriptData* pre_data = NULL,
+- Handle<String> script_data = Handle<String>());
++ Handle<String> script_data = Handle<String>(),
++ CompileFlags = Default);
+
+ /**
+ * Compiles the specified script using the specified file name
+@@ -609,7 +614,8 @@ class V8EXPORT Script {
+ * will use the currently entered context).
+ */
+ static Local<Script> New(Handle<String> source,
+- Handle<Value> file_name);
++ Handle<Value> file_name,
++ CompileFlags = Default);
+
+ /**
+ * Compiles the specified script (bound to current context).
+@@ -630,7 +636,8 @@ class V8EXPORT Script {
+ static Local<Script> Compile(Handle<String> source,
+ ScriptOrigin* origin = NULL,
+ ScriptData* pre_data = NULL,
+- Handle<String> script_data = Handle<String>());
++ Handle<String> script_data = Handle<String>(),
++ CompileFlags = Default);
+
+ /**
+ * Compiles the specified script using the specified file name
+@@ -647,7 +654,8 @@ class V8EXPORT Script {
+ */
+ static Local<Script> Compile(Handle<String> source,
+ Handle<Value> file_name,
+- Handle<String> script_data = Handle<String>());
++ Handle<String> script_data = Handle<String>(),
++ CompileFlags = Default);
+
+ /**
+ * Runs the script returning the resulting value. If the script is
+@@ -657,6 +665,7 @@ class V8EXPORT Script {
+ * compiled.
+ */
+ Local<Value> Run();
++ Local<Value> Run(Handle<Object> qml);
+
+ /**
+ * Returns the script id value.
+@@ -3325,6 +3334,7 @@ class V8EXPORT Context {
+ * JavaScript frames an empty handle is returned.
+ */
+ static Local<Context> GetCalling();
++ static Local<Object> GetCallingQmlGlobal();
+
+ /**
+ * Sets the security token for the context. To access an object in
+diff --git a/src/api.cc b/src/api.cc
+index d81ece8..0635f34 100644
+--- a/src/api.cc
++++ b/src/api.cc
+@@ -1372,7 +1372,8 @@ ScriptData* ScriptData::New(const char* data, int length) {
+ Local<Script> Script::New(v8::Handle<String> source,
+ v8::ScriptOrigin* origin,
+ v8::ScriptData* pre_data,
+- v8::Handle<String> script_data) {
++ v8::Handle<String> script_data,
++ v8::Script::CompileFlags compile_flags) {
+ i::Isolate* isolate = i::Isolate::Current();
+ ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>());
+ LOG_API(isolate, "Script::New");
+@@ -1409,7 +1410,8 @@ Local<Script> Script::New(v8::Handle<String> source,
+ NULL,
+ pre_data_impl,
+ Utils::OpenHandle(*script_data),
+- i::NOT_NATIVES_CODE);
++ i::NOT_NATIVES_CODE,
++ compile_flags);
+ has_pending_exception = result.is_null();
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>());
+ return Local<Script>(ToApi<Script>(result));
+@@ -1417,21 +1419,23 @@ Local<Script> Script::New(v8::Handle<String> source,
+
+
+ Local<Script> Script::New(v8::Handle<String> source,
+- v8::Handle<Value> file_name) {
++ v8::Handle<Value> file_name,
++ v8::Script::CompileFlags compile_flags) {
+ ScriptOrigin origin(file_name);
+- return New(source, &origin);
++ return New(source, &origin, 0, Handle<String>(), compile_flags);
+ }
+
+
+ Local<Script> Script::Compile(v8::Handle<String> source,
+ v8::ScriptOrigin* origin,
+ v8::ScriptData* pre_data,
+- v8::Handle<String> script_data) {
++ v8::Handle<String> script_data,
++ v8::Script::CompileFlags compile_flags) {
+ i::Isolate* isolate = i::Isolate::Current();
+ ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>());
+ LOG_API(isolate, "Script::Compile");
+ ENTER_V8(isolate);
+- Local<Script> generic = New(source, origin, pre_data, script_data);
++ Local<Script> generic = New(source, origin, pre_data, script_data, compile_flags);
+ if (generic.IsEmpty())
+ return generic;
+ i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
+@@ -1447,13 +1451,18 @@ Local<Script> Script::Compile(v8::Handle<String> source,
+
+ Local<Script> Script::Compile(v8::Handle<String> source,
+ v8::Handle<Value> file_name,
+- v8::Handle<String> script_data) {
++ v8::Handle<String> script_data,
++ v8::Script::CompileFlags compile_flags) {
+ ScriptOrigin origin(file_name);
+- return Compile(source, &origin, 0, script_data);
++ return Compile(source, &origin, 0, script_data, compile_flags);
+ }
+
+
+ Local<Value> Script::Run() {
++ return Run(Handle<Object>());
++}
++
++Local<Value> Script::Run(Handle<Object> qml) {
+ i::Isolate* isolate = i::Isolate::Current();
+ ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
+ LOG_API(isolate, "Script::Run");
+@@ -1472,10 +1481,11 @@ Local<Value> Script::Run() {
+ fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate);
+ }
+ EXCEPTION_PREAMBLE(isolate);
++ i::Handle<i::Object> qmlglobal = Utils::OpenHandle(*qml);
+ i::Handle<i::Object> receiver(
+ isolate->context()->global_proxy(), isolate);
+ i::Handle<i::Object> result =
+- i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
++ i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception, qmlglobal);
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
+ raw_result = *result;
+ }
+@@ -3939,6 +3949,30 @@ v8::Local<v8::Context> Context::GetCalling() {
+ }
+
+
++v8::Local<v8::Object> Context::GetCallingQmlGlobal() {
++ i::Isolate* isolate = i::Isolate::Current();
++ if (IsDeadCheck(isolate, "v8::Context::GetCallingQmlGlobal()")) {
++ return Local<Object>();
++ }
++
++ i::Context *context = isolate->context();
++ if (!context->qml_global()->IsUndefined()) {
++ i::Handle<i::Object> qmlglobal(context->qml_global());
++ return Utils::ToLocal(i::Handle<i::JSObject>::cast(qmlglobal));
++ }
++
++ i::JavaScriptFrameIterator it;
++ if (it.done()) return Local<Object>();
++ context = i::Context::cast(it.frame()->context());
++ if (!context->qml_global()->IsUndefined()) {
++ i::Handle<i::Object> qmlglobal(context->qml_global());
++ return Utils::ToLocal(i::Handle<i::JSObject>::cast(qmlglobal));
++ } else {
++ return Local<Object>();
++ }
++}
++
++
+ v8::Local<v8::Object> Context::Global() {
+ if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) {
+ return Local<v8::Object>();
+diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc
+index 8c147f9..a2626bf 100644
+--- a/src/arm/code-stubs-arm.cc
++++ b/src/arm/code-stubs-arm.cc
+@@ -166,6 +166,10 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
+ __ ldr(r1, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
+ __ str(r1, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_INDEX)));
+
++ // Copy the qml global object from the surrounding context.
++ __ ldr(r1, MemOperand(cp, Context::SlotOffset(Context::QML_GLOBAL_INDEX)));
++ __ str(r1, MemOperand(r0, Context::SlotOffset(Context::QML_GLOBAL_INDEX)));
++
+ // Initialize the rest of the slots to undefined.
+ __ LoadRoot(r1, Heap::kUndefinedValueRootIndex);
+ for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
+diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc
+index 871b453..a69f10d 100644
+--- a/src/arm/full-codegen-arm.cc
++++ b/src/arm/full-codegen-arm.cc
+@@ -154,12 +154,13 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
+
+ // Possibly allocate a local context.
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
+- if (heap_slots > 0) {
++ if (heap_slots > 0 ||
++ (scope()->is_qml_mode() && scope()->is_global_scope())) {
+ Comment cmnt(masm_, "[ Allocate local context");
+ // Argument to NewContext is the function, which is in r1.
+ __ push(r1);
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+- FastNewContextStub stub(heap_slots);
++ FastNewContextStub stub((heap_slots < 0)?0:heap_slots);
+ __ CallStub(&stub);
+ } else {
+ __ CallRuntime(Runtime::kNewContext, 1);
+@@ -1247,9 +1248,9 @@ void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions(
+ __ bind(&fast);
+ }
+
+- __ ldr(r0, GlobalObjectOperand());
++ __ ldr(r0, slot->var()->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ __ mov(r2, Operand(slot->var()->name()));
+- RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF)
++ RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF || slot->var()->is_qml_global())
+ ? RelocInfo::CODE_TARGET
+ : RelocInfo::CODE_TARGET_CONTEXT;
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
+@@ -1268,10 +1269,10 @@ void FullCodeGenerator::EmitVariableLoad(Variable* var) {
+ Comment cmnt(masm_, "Global variable");
+ // Use inline caching. Variable name is passed in r2 and the global
+ // object (receiver) in r0.
+- __ ldr(r0, GlobalObjectOperand());
++ __ ldr(r0, var->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ __ mov(r2, Operand(var->name()));
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
+- EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallIC(ic, var->is_qml_global()?RelocInfo::CODE_TARGET:RelocInfo::CODE_TARGET_CONTEXT);
+ context()->Plug(r0);
+
+ } else if (slot != NULL && slot->type() == Slot::LOOKUP) {
+@@ -1893,11 +1894,11 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var,
+ // assignment. Right-hand-side value is passed in r0, variable name in
+ // r2, and the global object in r1.
+ __ mov(r2, Operand(var->name()));
+- __ ldr(r1, GlobalObjectOperand());
++ __ ldr(r1, var->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ Handle<Code> ic = is_strict_mode()
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
+ : isolate()->builtins()->StoreIC_Initialize();
+- EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallIC(ic, var->is_qml_global()?RelocInfo::CODE_TARGET:RelocInfo::CODE_TARGET_CONTEXT);
+
+ } else if (op == Token::INIT_CONST) {
+ // Like var declarations, const declarations are hoisted to function
+@@ -2184,10 +2185,13 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(ResolveEvalFlag flag,
+ // Push the strict mode flag.
+ __ mov(r1, Operand(Smi::FromInt(strict_mode_flag())));
+ __ push(r1);
++ // Push the qml mode flag.
++ __ mov(r1, Operand(Smi::FromInt(is_qml_mode())));
++ __ push(r1);
+
+ __ CallRuntime(flag == SKIP_CONTEXT_LOOKUP
+ ? Runtime::kResolvePossiblyDirectEvalNoLookup
+- : Runtime::kResolvePossiblyDirectEval, 4);
++ : Runtime::kResolvePossiblyDirectEval, 5);
+ }
+
+
+@@ -2263,9 +2267,9 @@ void FullCodeGenerator::VisitCall(Call* expr) {
+ context()->DropAndPlug(1, r0);
+ } else if (var != NULL && !var->is_this() && var->is_global()) {
+ // Push global object as receiver for the call IC.
+- __ ldr(r0, GlobalObjectOperand());
++ __ ldr(r0, var->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ __ push(r0);
+- EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallWithIC(expr, var->name(), var->is_qml_global()?RelocInfo::CODE_TARGET:RelocInfo::CODE_TARGET_CONTEXT);
+ } else if (var != NULL && var->AsSlot() != NULL &&
+ var->AsSlot()->type() == Slot::LOOKUP) {
+ // Call to a lookup slot (dynamically introduced variable).
+diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc
+index 3f1d15b..8406a96 100644
+--- a/src/arm/lithium-arm.cc
++++ b/src/arm/lithium-arm.cc
+@@ -1195,7 +1195,7 @@ LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
+
+ LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
+ LOperand* context = UseRegisterAtStart(instr->value());
+- return DefineAsRegister(new LGlobalObject(context));
++ return DefineAsRegister(new LGlobalObject(context, instr->qml_global()));
+ }
+
+
+diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h
+index 6da7c86..10b901f 100644
+--- a/src/arm/lithium-arm.h
++++ b/src/arm/lithium-arm.h
+@@ -1378,13 +1378,17 @@ class LOuterContext: public LTemplateInstruction<1, 1, 0> {
+
+ class LGlobalObject: public LTemplateInstruction<1, 1, 0> {
+ public:
+- explicit LGlobalObject(LOperand* context) {
++ explicit LGlobalObject(LOperand* context, bool qml_global) {
+ inputs_[0] = context;
++ qml_global_ = qml_global;
+ }
+
+ DECLARE_CONCRETE_INSTRUCTION(GlobalObject, "global-object")
+
+ LOperand* context() { return InputAt(0); }
++ bool qml_global() { return qml_global_; }
++ private:
++ bool qml_global_;
+ };
+
+
+diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc
+index 4912449..db114ea 100644
+--- a/src/arm/lithium-codegen-arm.cc
++++ b/src/arm/lithium-codegen-arm.cc
+@@ -166,12 +166,13 @@ bool LCodeGen::GeneratePrologue() {
+
+ // Possibly allocate a local context.
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
+- if (heap_slots > 0) {
++ if (heap_slots > 0 ||
++ (scope()->is_qml_mode() && scope()->is_global_scope())) {
+ Comment(";;; Allocate local context");
+ // Argument to NewContext is the function, which is in r1.
+ __ push(r1);
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+- FastNewContextStub stub(heap_slots);
++ FastNewContextStub stub((heap_slots < 0)?0:heap_slots);
+ __ CallStub(&stub);
+ } else {
+ __ CallRuntime(Runtime::kNewContext, 1);
+@@ -2664,7 +2665,7 @@ void LCodeGen::DoOuterContext(LOuterContext* instr) {
+ void LCodeGen::DoGlobalObject(LGlobalObject* instr) {
+ Register context = ToRegister(instr->context());
+ Register result = ToRegister(instr->result());
+- __ ldr(result, ContextOperand(cp, Context::GLOBAL_INDEX));
++ __ ldr(result, ContextOperand(cp, instr->qml_global()?Context::QML_GLOBAL_INDEX:Context::GLOBAL_INDEX));
+ }
+
+
+diff --git a/src/arm/macro-assembler-arm.h b/src/arm/macro-assembler-arm.h
+index ab5efb0..d40cdbc 100644
+--- a/src/arm/macro-assembler-arm.h
++++ b/src/arm/macro-assembler-arm.h
+@@ -1056,6 +1056,11 @@ static inline MemOperand GlobalObjectOperand() {
+ }
+
+
++static inline MemOperand QmlGlobalObjectOperand() {
++ return ContextOperand(cp, Context::QML_GLOBAL_INDEX);
++}
++
++
+ #ifdef GENERATED_CODE_COVERAGE
+ #define CODE_COVERAGE_STRINGIFY(x) #x
+ #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
+diff --git a/src/ast-inl.h b/src/ast-inl.h
+index d80684a..adc5a1f 100644
+--- a/src/ast-inl.h
++++ b/src/ast-inl.h
+@@ -106,6 +106,11 @@ bool FunctionLiteral::strict_mode() const {
+ }
+
+
++bool FunctionLiteral::qml_mode() const {
++ return scope()->is_qml_mode();
++}
++
++
+ } } // namespace v8::internal
+
+ #endif // V8_AST_INL_H_
+diff --git a/src/ast.h b/src/ast.h
+index 65a25a9..f790dc0 100644
+--- a/src/ast.h
++++ b/src/ast.h
+@@ -1712,6 +1712,7 @@ class FunctionLiteral: public Expression {
+ int end_position() const { return end_position_; }
+ bool is_expression() const { return is_expression_; }
+ bool strict_mode() const;
++ bool qml_mode() const;
+
+ int materialized_literal_count() { return materialized_literal_count_; }
+ int expected_property_count() { return expected_property_count_; }
+diff --git a/src/code-stubs.h b/src/code-stubs.h
+index 56ef072..37e5383 100644
+--- a/src/code-stubs.h
++++ b/src/code-stubs.h
+@@ -303,7 +303,7 @@ class FastNewContextStub : public CodeStub {
+ static const int kMaximumSlots = 64;
+
+ explicit FastNewContextStub(int slots) : slots_(slots) {
+- ASSERT(slots_ > 0 && slots <= kMaximumSlots);
++ ASSERT(slots_ >= 0 && slots <= kMaximumSlots);
+ }
+
+ void Generate(MacroAssembler* masm);
+diff --git a/src/compiler.cc b/src/compiler.cc
+index 86d5de3..d2191b9 100755
+--- a/src/compiler.cc
++++ b/src/compiler.cc
+@@ -462,7 +462,8 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
+ v8::Extension* extension,
+ ScriptDataImpl* input_pre_data,
+ Handle<Object> script_data,
+- NativesFlag natives) {
++ NativesFlag natives,
++ v8::Script::CompileFlags compile_flags) {
+ Isolate* isolate = source->GetIsolate();
+ int source_length = source->length();
+ isolate->counters()->total_load_size()->Increment(source_length);
+@@ -523,6 +524,7 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
+ info.MarkAsGlobal();
+ info.SetExtension(extension);
+ info.SetPreParseData(pre_data);
++ if (compile_flags & v8::Script::QmlMode) info.MarkAsQmlMode();
+ if (natives == NATIVES_CODE) info.MarkAsAllowingNativesSyntax();
+ result = MakeFunctionInfo(&info);
+ if (extension == NULL && !result.is_null()) {
+@@ -543,7 +545,8 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
+ Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
+ Handle<Context> context,
+ bool is_global,
+- StrictModeFlag strict_mode) {
++ StrictModeFlag strict_mode,
++ bool qml_mode) {
+ Isolate* isolate = source->GetIsolate();
+ int source_length = source->length();
+ isolate->counters()->total_eval_size()->Increment(source_length);
+@@ -567,6 +570,7 @@ Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
+ CompilationInfo info(script);
+ info.MarkAsEval();
+ if (is_global) info.MarkAsGlobal();
++ if (qml_mode) info.MarkAsQmlMode();
+ if (strict_mode == kStrictMode) info.MarkAsStrictMode();
+ info.SetCallingContext(context);
+ result = MakeFunctionInfo(&info);
+@@ -610,6 +614,12 @@ bool Compiler::CompileLazy(CompilationInfo* info) {
+ info->MarkAsStrictMode();
+ }
+
++ // After parsing we know function's qml mode. Remember it.
++ if (info->function()->qml_mode()) {
++ shared->set_qml_mode(true);
++ info->MarkAsQmlMode();
++ }
++
+ // Compile the code.
+ if (!MakeCode(info)) {
+ if (!isolate->has_pending_exception()) {
+@@ -755,6 +765,7 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
+ *lit->this_property_assignments());
+ function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
+ function_info->set_strict_mode(lit->strict_mode());
++ function_info->set_qml_mode(lit->qml_mode());
+ }
+
+
+diff --git a/src/compiler.h b/src/compiler.h
+index e75e869..17cd369 100644
+--- a/src/compiler.h
++++ b/src/compiler.h
+@@ -54,6 +54,7 @@ class CompilationInfo BASE_EMBEDDED {
+ bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; }
+ bool is_strict_mode() const { return (flags_ & IsStrictMode::mask()) != 0; }
+ bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; }
++ bool is_qml_mode() const { return (flags_ & IsQmlMode::mask()) != 0; }
+ FunctionLiteral* function() const { return function_; }
+ Scope* scope() const { return scope_; }
+ Handle<Code> code() const { return code_; }
+@@ -83,6 +84,9 @@ class CompilationInfo BASE_EMBEDDED {
+ ASSERT(is_lazy());
+ flags_ |= IsInLoop::encode(true);
+ }
++ void MarkAsQmlMode() {
++ flags_ |= IsQmlMode::encode(true);
++ }
+ void MarkAsAllowingNativesSyntax() {
+ flags_ |= IsNativesSyntaxAllowed::encode(true);
+ }
+@@ -141,6 +145,7 @@ class CompilationInfo BASE_EMBEDDED {
+
+ // Determine whether or not we can adaptively optimize.
+ bool AllowOptimize() {
++ // XXX - fix qml mode optimizations
+ return V8::UseCrankshaft() && !closure_.is_null();
+ }
+
+@@ -163,8 +168,13 @@ class CompilationInfo BASE_EMBEDDED {
+
+ void Initialize(Mode mode) {
+ mode_ = V8::UseCrankshaft() ? mode : NONOPT;
+- if (!shared_info_.is_null() && shared_info_->strict_mode()) {
+- MarkAsStrictMode();
++ if (!shared_info_.is_null()) {
++ if (shared_info_->strict_mode()) {
++ MarkAsStrictMode();
++ }
++ if (shared_info_->qml_mode()) {
++ MarkAsQmlMode();
++ }
+ }
+ }
+
+@@ -187,6 +197,8 @@ class CompilationInfo BASE_EMBEDDED {
+ class IsStrictMode: public BitField<bool, 4, 1> {};
+ // Native syntax (%-stuff) allowed?
+ class IsNativesSyntaxAllowed: public BitField<bool, 5, 1> {};
++ // Qml mode
++ class IsQmlMode: public BitField<bool, 6, 1> {};
+
+ unsigned flags_;
+
+@@ -252,13 +264,15 @@ class Compiler : public AllStatic {
+ v8::Extension* extension,
+ ScriptDataImpl* pre_data,
+ Handle<Object> script_data,
+- NativesFlag is_natives_code);
++ NativesFlag is_natives_code,
++ v8::Script::CompileFlags compile_flags = v8::Script::Default);
+
+ // Compile a String source within a context for Eval.
+ static Handle<SharedFunctionInfo> CompileEval(Handle<String> source,
+ Handle<Context> context,
+ bool is_global,
+- StrictModeFlag strict_mode);
++ StrictModeFlag strict_mode,
++ bool qml_mode);
+
+ // Compile from function info (used for lazy compilation). Returns true on
+ // success and false if the compilation resulted in a stack overflow.
+diff --git a/src/contexts.cc b/src/contexts.cc
+index 520f3dd..da5cacb 100644
+--- a/src/contexts.cc
++++ b/src/contexts.cc
+@@ -89,6 +89,8 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
+ PrintF(")\n");
+ }
+
++ Handle<JSObject> qml_global;
++
+ do {
+ if (FLAG_trace_contexts) {
+ PrintF(" - looking in context %p", reinterpret_cast<void*>(*context));
+@@ -119,6 +121,10 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
+ }
+ }
+
++ if (qml_global.is_null() && !context->qml_global()->IsUndefined()) {
++ qml_global = Handle<JSObject>(context->qml_global(), isolate);
++ }
++
+ if (context->is_function_context()) {
+ // we have context-local slots
+
+@@ -198,6 +204,23 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
+ }
+ } while (follow_context_chain);
+
++ if (!qml_global.is_null()) {
++ if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0) {
++ *attributes = qml_global->GetLocalPropertyAttribute(*name);
++ } else {
++ *attributes = qml_global->GetPropertyAttribute(*name);
++ }
++
++ if (*attributes != ABSENT) {
++ // property found
++ if (FLAG_trace_contexts) {
++ PrintF("=> found property in qml global object %p\n",
++ reinterpret_cast<void*>(*qml_global));
++ }
++ return qml_global;
++ }
++ }
++
+ // slot not found
+ if (FLAG_trace_contexts) {
+ PrintF("=> no property/slot found\n");
+diff --git a/src/contexts.h b/src/contexts.h
+index e46619e..57d8e7b 100644
+--- a/src/contexts.h
++++ b/src/contexts.h
+@@ -182,6 +182,7 @@ class Context: public FixedArray {
+ FCONTEXT_INDEX,
+ PREVIOUS_INDEX,
+ EXTENSION_INDEX,
++ QML_GLOBAL_INDEX,
+ GLOBAL_INDEX,
+ MIN_CONTEXT_SLOTS,
+
+@@ -273,6 +274,9 @@ class Context: public FixedArray {
+ }
+ void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); }
+
++ JSObject *qml_global() { return reinterpret_cast<JSObject *>(get(QML_GLOBAL_INDEX)); }
++ void set_qml_global(JSObject *qml_global) { set(QML_GLOBAL_INDEX, qml_global); }
++
+ // Returns a JSGlobalProxy object or null.
+ JSObject* global_proxy();
+ void set_global_proxy(JSObject* global);
+diff --git a/src/execution.cc b/src/execution.cc
+index eb26438..1632076 100644
+--- a/src/execution.cc
++++ b/src/execution.cc
+@@ -70,7 +70,8 @@ static Handle<Object> Invoke(bool construct,
+ Handle<Object> receiver,
+ int argc,
+ Object*** args,
+- bool* has_pending_exception) {
++ bool* has_pending_exception,
++ Handle<Object> qml) {
+ Isolate* isolate = func->GetIsolate();
+
+ // Entering JavaScript.
+@@ -107,6 +108,12 @@ static Handle<Object> Invoke(bool construct,
+ // make the current one is indeed a global object.
+ ASSERT(func->context()->global()->IsGlobalObject());
+
++ Handle<JSObject> oldqml;
++ if (!qml.is_null()) {
++ oldqml = Handle<JSObject>(func->context()->qml_global());
++ func->context()->set_qml_global(JSObject::cast(*qml));
++ }
++
+ {
+ // Save and restore context around invocation and block the
+ // allocation of handles without explicit handle scopes.
+@@ -122,6 +129,9 @@ static Handle<Object> Invoke(bool construct,
+ receiver_pointer, argc, args);
+ }
+
++ if (!qml.is_null())
++ func->context()->set_qml_global(*oldqml);
++
+ #ifdef DEBUG
+ value->Verify();
+ #endif
+@@ -150,14 +160,24 @@ Handle<Object> Execution::Call(Handle<JSFunction> func,
+ int argc,
+ Object*** args,
+ bool* pending_exception) {
+- return Invoke(false, func, receiver, argc, args, pending_exception);
++ return Invoke(false, func, receiver, argc, args, pending_exception, Handle<Object>());
++}
++
++
++Handle<Object> Execution::Call(Handle<JSFunction> func,
++ Handle<Object> receiver,
++ int argc,
++ Object*** args,
++ bool* pending_exception,
++ Handle<Object> qml) {
++ return Invoke(false, func, receiver, argc, args, pending_exception, qml);
+ }
+
+
+ Handle<Object> Execution::New(Handle<JSFunction> func, int argc,
+ Object*** args, bool* pending_exception) {
+ return Invoke(true, func, Isolate::Current()->global(), argc, args,
+- pending_exception);
++ pending_exception, Handle<Object>());
+ }
+
+
+@@ -175,7 +195,7 @@ Handle<Object> Execution::TryCall(Handle<JSFunction> func,
+ catcher.SetCaptureMessage(false);
+
+ Handle<Object> result = Invoke(false, func, receiver, argc, args,
+- caught_exception);
++ caught_exception, Handle<Object>());
+
+ if (*caught_exception) {
+ ASSERT(catcher.HasCaught());
+diff --git a/src/execution.h b/src/execution.h
+index d4b80d2..a476eb4 100644
+--- a/src/execution.h
++++ b/src/execution.h
+@@ -56,6 +56,12 @@ class Execution : public AllStatic {
+ int argc,
+ Object*** args,
+ bool* pending_exception);
++ static Handle<Object> Call(Handle<JSFunction> func,
++ Handle<Object> receiver,
++ int argc,
++ Object*** args,
++ bool* pending_exception,
++ Handle<Object> qml);
+
+ // Construct object from function, the caller supplies an array of
+ // arguments. Arguments are Object* type. After function returns,
+diff --git a/src/full-codegen.cc b/src/full-codegen.cc
+index d6ba56e..2eaef0f 100644
+--- a/src/full-codegen.cc
++++ b/src/full-codegen.cc
+@@ -542,7 +542,7 @@ void FullCodeGenerator::VisitDeclarations(
+ // Do nothing in case of no declared global functions or variables.
+ if (globals > 0) {
+ Handle<FixedArray> array =
+- isolate()->factory()->NewFixedArray(2 * globals, TENURED);
++ isolate()->factory()->NewFixedArray(3 * globals, TENURED);
+ for (int j = 0, i = 0; i < length; i++) {
+ Declaration* decl = declarations->at(i);
+ Variable* var = decl->proxy()->var();
+@@ -567,6 +567,7 @@ void FullCodeGenerator::VisitDeclarations(
+ }
+ array->set(j++, *function);
+ }
++ array->set(j++, Smi::FromInt(var->is_qml_global()));
+ }
+ }
+ // Invoke the platform-dependent code generator to do the actual
+diff --git a/src/full-codegen.h b/src/full-codegen.h
+index d6ed1b9..e3241aa 100644
+--- a/src/full-codegen.h
++++ b/src/full-codegen.h
+@@ -505,6 +505,7 @@ class FullCodeGenerator: public AstVisitor {
+ StrictModeFlag strict_mode_flag() {
+ return is_strict_mode() ? kStrictMode : kNonStrictMode;
+ }
++ bool is_qml_mode() { return function()->qml_mode(); }
+ FunctionLiteral* function() { return info_->function(); }
+ Scope* scope() { return info_->scope(); }
+
+diff --git a/src/heap.cc b/src/heap.cc
+index bf2940e..da958c2 100644
+--- a/src/heap.cc
++++ b/src/heap.cc
+@@ -3795,6 +3795,7 @@ MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) {
+ context->set_previous(NULL);
+ context->set_extension(NULL);
+ context->set_global(function->context()->global());
++ context->set_qml_global(function->context()->qml_global());
+ ASSERT(!context->IsGlobalContext());
+ ASSERT(context->is_function_context());
+ ASSERT(result->IsContext());
+@@ -3817,6 +3818,7 @@ MaybeObject* Heap::AllocateWithContext(Context* previous,
+ context->set_previous(previous);
+ context->set_extension(extension);
+ context->set_global(previous->global());
++ context->set_qml_global(previous->qml_global());
+ ASSERT(!context->IsGlobalContext());
+ ASSERT(!context->is_function_context());
+ ASSERT(result->IsContext());
+diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
+index a623775..52455bc 100644
+--- a/src/hydrogen-instructions.h
++++ b/src/hydrogen-instructions.h
+@@ -1148,7 +1148,7 @@ class HOuterContext: public HUnaryOperation {
+
+ class HGlobalObject: public HUnaryOperation {
+ public:
+- explicit HGlobalObject(HValue* context) : HUnaryOperation(context) {
++ explicit HGlobalObject(HValue* context) : HUnaryOperation(context), qml_global_(false) {
+ set_representation(Representation::Tagged());
+ SetFlag(kUseGVN);
+ }
+@@ -1159,8 +1159,14 @@ class HGlobalObject: public HUnaryOperation {
+ return Representation::Tagged();
+ }
+
++ bool qml_global() { return qml_global_; }
++ void set_qml_global(bool v) { qml_global_ = v; }
++
+ protected:
+ virtual bool DataEquals(HValue* other) { return true; }
++
++ private:
++ bool qml_global_;
+ };
+
+
+@@ -1177,7 +1183,7 @@ class HGlobalReceiver: public HUnaryOperation {
+ virtual Representation RequiredInputRepresentation(int index) const {
+ return Representation::Tagged();
+ }
+-
++
+ protected:
+ virtual bool DataEquals(HValue* other) { return true; }
+ };
+diff --git a/src/hydrogen.cc b/src/hydrogen.cc
+index 73ea97d..d17e304 100644
+--- a/src/hydrogen.cc
++++ b/src/hydrogen.cc
+@@ -2918,6 +2918,7 @@ void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
+ HContext* context = new(zone()) HContext;
+ AddInstruction(context);
+ HGlobalObject* global_object = new(zone()) HGlobalObject(context);
++ if (variable->is_qml_global()) global_object->set_qml_global(true);
+ AddInstruction(global_object);
+ HLoadGlobalGeneric* instr =
+ new(zone()) HLoadGlobalGeneric(context,
+@@ -3307,6 +3308,7 @@ void HGraphBuilder::HandleGlobalVariableAssignment(Variable* var,
+ HContext* context = new(zone()) HContext;
+ AddInstruction(context);
+ HGlobalObject* global_object = new(zone()) HGlobalObject(context);
++ if (var->is_qml_global()) global_object->set_qml_global(true);
+ AddInstruction(global_object);
+ HStoreGlobalGeneric* instr =
+ new(zone()) HStoreGlobalGeneric(context,
+diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc
+index 5d32095..afa599e 100644
+--- a/src/ia32/code-stubs-ia32.cc
++++ b/src/ia32/code-stubs-ia32.cc
+@@ -147,6 +147,13 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
+ __ mov(ebx, Operand(ebx, Context::SlotOffset(Context::GLOBAL_INDEX)));
+ __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_INDEX)), ebx);
+
++ // Copy the qml global object from the surrounding context. We go through the
++ // context in the function (ecx) to match the allocation behavior we have
++ // in the runtime system (see Heap::AllocateFunctionContext).
++ __ mov(ebx, FieldOperand(ecx, JSFunction::kContextOffset));
++ __ mov(ebx, Operand(ebx, Context::SlotOffset(Context::QML_GLOBAL_INDEX)));
++ __ mov(Operand(eax, Context::SlotOffset(Context::QML_GLOBAL_INDEX)), ebx);
++
+ // Initialize the rest of the slots to undefined.
+ __ mov(ebx, factory->undefined_value());
+ for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
+diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
+index 5d153a8..0ddcde2 100644
+--- a/src/ia32/full-codegen-ia32.cc
++++ b/src/ia32/full-codegen-ia32.cc
+@@ -142,12 +142,13 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
+
+ // Possibly allocate a local context.
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
+- if (heap_slots > 0) {
++ if (heap_slots > 0 ||
++ (scope()->is_qml_mode() && scope()->is_global_scope())) {
+ Comment cmnt(masm_, "[ Allocate local context");
+ // Argument to NewContext is the function, which is still in edi.
+ __ push(edi);
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+- FastNewContextStub stub(heap_slots);
++ FastNewContextStub stub((heap_slots < 0)?0:heap_slots);
+ __ CallStub(&stub);
+ } else {
+ __ CallRuntime(Runtime::kNewContext, 1);
+@@ -1107,10 +1108,10 @@ void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions(
+
+ // All extension objects were empty and it is safe to use a global
+ // load IC call.
+- __ mov(eax, GlobalObjectOperand());
++ __ mov(eax, slot->var()->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ __ mov(ecx, slot->var()->name());
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
+- RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF)
++ RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF || slot->var()->is_qml_global())
+ ? RelocInfo::CODE_TARGET
+ : RelocInfo::CODE_TARGET_CONTEXT;
+ EmitCallIC(ic, mode);
+@@ -1214,10 +1215,10 @@ void FullCodeGenerator::EmitVariableLoad(Variable* var) {
+ Comment cmnt(masm_, "Global variable");
+ // Use inline caching. Variable name is passed in ecx and the global
+ // object on the stack.
+- __ mov(eax, GlobalObjectOperand());
++ __ mov(eax, var->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ __ mov(ecx, var->name());
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
+- EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallIC(ic, var->is_qml_global()?RelocInfo::CODE_TARGET:RelocInfo::CODE_TARGET_CONTEXT);
+ context()->Plug(eax);
+
+ } else if (slot != NULL && slot->type() == Slot::LOOKUP) {
+@@ -1837,11 +1838,11 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var,
+ // assignment. Right-hand-side value is passed in eax, variable name in
+ // ecx, and the global object on the stack.
+ __ mov(ecx, var->name());
+- __ mov(edx, GlobalObjectOperand());
++ __ mov(edx, var->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ Handle<Code> ic = is_strict_mode()
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
+ : isolate()->builtins()->StoreIC_Initialize();
+- EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallIC(ic, var->is_qml_global()?RelocInfo::CODE_TARGET:RelocInfo::CODE_TARGET_CONTEXT);
+
+ } else if (op == Token::INIT_CONST) {
+ // Like var declarations, const declarations are hoisted to function
+@@ -2113,9 +2114,12 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(ResolveEvalFlag flag,
+ // Push the strict mode flag.
+ __ push(Immediate(Smi::FromInt(strict_mode_flag())));
+
++ // Push the qml mode flag
++ __ push(Immediate(Smi::FromInt(is_qml_mode())));
++
+ __ CallRuntime(flag == SKIP_CONTEXT_LOOKUP
+ ? Runtime::kResolvePossiblyDirectEvalNoLookup
+- : Runtime::kResolvePossiblyDirectEval, 4);
++ : Runtime::kResolvePossiblyDirectEval, 5);
+ }
+
+
+@@ -2188,8 +2192,8 @@ void FullCodeGenerator::VisitCall(Call* expr) {
+ context()->DropAndPlug(1, eax);
+ } else if (var != NULL && !var->is_this() && var->is_global()) {
+ // Push global object as receiver for the call IC.
+- __ push(GlobalObjectOperand());
+- EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
++ __ push(var->is_qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
++ EmitCallWithIC(expr, var->name(), var->is_qml_global()?RelocInfo::CODE_TARGET:RelocInfo::CODE_TARGET_CONTEXT);
+ } else if (var != NULL && var->AsSlot() != NULL &&
+ var->AsSlot()->type() == Slot::LOOKUP) {
+ // Call to a lookup slot (dynamically introduced variable).
+diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc
+index 0f96f78..c1da075 100644
+--- a/src/ia32/lithium-codegen-ia32.cc
++++ b/src/ia32/lithium-codegen-ia32.cc
+@@ -159,12 +159,13 @@ bool LCodeGen::GeneratePrologue() {
+
+ // Possibly allocate a local context.
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
+- if (heap_slots > 0) {
++ if (heap_slots > 0 ||
++ (scope()->is_qml_mode() && scope()->is_global_scope())) {
+ Comment(";;; Allocate local context");
+ // Argument to NewContext is the function, which is still in edi.
+ __ push(edi);
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+- FastNewContextStub stub(heap_slots);
++ FastNewContextStub stub((heap_slots < 0)?0:heap_slots);
+ __ CallStub(&stub);
+ } else {
+ __ CallRuntime(Runtime::kNewContext, 1);
+@@ -2525,7 +2526,7 @@ void LCodeGen::DoOuterContext(LOuterContext* instr) {
+ void LCodeGen::DoGlobalObject(LGlobalObject* instr) {
+ Register context = ToRegister(instr->context());
+ Register result = ToRegister(instr->result());
+- __ mov(result, Operand(context, Context::SlotOffset(Context::GLOBAL_INDEX)));
++ __ mov(result, Operand(context, Context::SlotOffset(instr->qml_global()?Context::QML_GLOBAL_INDEX:Context::GLOBAL_INDEX)));
+ }
+
+
+diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc
+index 9ccd189..8e98b73 100644
+--- a/src/ia32/lithium-ia32.cc
++++ b/src/ia32/lithium-ia32.cc
+@@ -1205,7 +1205,7 @@ LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
+
+ LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
+ LOperand* context = UseRegisterAtStart(instr->value());
+- return DefineAsRegister(new LGlobalObject(context));
++ return DefineAsRegister(new LGlobalObject(context, instr->qml_global()));
+ }
+
+
+diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h
+index 9ace8f8..95ed001 100644
+--- a/src/ia32/lithium-ia32.h
++++ b/src/ia32/lithium-ia32.h
+@@ -1416,13 +1416,17 @@ class LOuterContext: public LTemplateInstruction<1, 1, 0> {
+
+ class LGlobalObject: public LTemplateInstruction<1, 1, 0> {
+ public:
+- explicit LGlobalObject(LOperand* context) {
++ explicit LGlobalObject(LOperand* context, bool qml_global) {
+ inputs_[0] = context;
++ qml_global_ = qml_global;
+ }
+
+ DECLARE_CONCRETE_INSTRUCTION(GlobalObject, "global-object")
+
+ LOperand* context() { return InputAt(0); }
++ bool qml_global() { return qml_global_; }
++ private:
++ bool qml_global_;
+ };
+
+
+diff --git a/src/ia32/macro-assembler-ia32.h b/src/ia32/macro-assembler-ia32.h
+index b986264..f8479ae 100644
+--- a/src/ia32/macro-assembler-ia32.h
++++ b/src/ia32/macro-assembler-ia32.h
+@@ -778,6 +778,11 @@ static inline Operand GlobalObjectOperand() {
+ }
+
+
++static inline Operand QmlGlobalObjectOperand() {
++ return ContextOperand(esi, Context::QML_GLOBAL_INDEX);
++}
++
++
+ // Generates an Operand for saving parameters after PrepareCallApiFunction.
+ Operand ApiParameterOperand(int index);
+
+diff --git a/src/objects-inl.h b/src/objects-inl.h
+index 231b835..1c7f83e 100644
+--- a/src/objects-inl.h
++++ b/src/objects-inl.h
+@@ -3242,6 +3242,18 @@ void SharedFunctionInfo::set_strict_mode(bool value) {
+ }
+
+
++bool SharedFunctionInfo::qml_mode() {
++ return BooleanBit::get(compiler_hints(), kQmlModeFunction);
++}
++
++
++void SharedFunctionInfo::set_qml_mode(bool value) {
++ set_compiler_hints(BooleanBit::set(compiler_hints(),
++ kQmlModeFunction,
++ value));
++}
++
++
+ ACCESSORS(CodeCache, default_cache, FixedArray, kDefaultCacheOffset)
+ ACCESSORS(CodeCache, normal_type_cache, Object, kNormalTypeCacheOffset)
+
+diff --git a/src/objects.h b/src/objects.h
+index 1bdb5c7..edbc47a 100644
+--- a/src/objects.h
++++ b/src/objects.h
+@@ -4331,6 +4331,10 @@ class SharedFunctionInfo: public HeapObject {
+ inline bool strict_mode();
+ inline void set_strict_mode(bool value);
+
++ // Indicates whether the function is a qml mode function
++ inline bool qml_mode();
++ inline void set_qml_mode(bool value);
++
+ // Indicates whether or not the code in the shared function support
+ // deoptimization.
+ inline bool has_deoptimization_support();
+@@ -4511,6 +4515,7 @@ class SharedFunctionInfo: public HeapObject {
+ static const int kCodeAgeMask = 0x7;
+ static const int kOptimizationDisabled = 6;
+ static const int kStrictModeFunction = 7;
++ static const int kQmlModeFunction = 8;
+
+ private:
+ #if V8_HOST_ARCH_32_BIT
+diff --git a/src/parser.cc b/src/parser.cc
+index a84ec6f..7f5c361 100644
+--- a/src/parser.cc
++++ b/src/parser.cc
+@@ -593,7 +593,8 @@ Parser::Parser(Handle<Script> script,
+
+ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
+ bool in_global_context,
+- StrictModeFlag strict_mode) {
++ StrictModeFlag strict_mode,
++ bool qml_mode) {
+ CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
+
+ HistogramTimerScope timer(isolate()->counters()->parse());
+@@ -609,11 +610,11 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
+ ExternalTwoByteStringUC16CharacterStream stream(
+ Handle<ExternalTwoByteString>::cast(source), 0, source->length());
+ scanner_.Initialize(&stream);
+- return DoParseProgram(source, in_global_context, strict_mode, &zone_scope);
++ return DoParseProgram(source, in_global_context, strict_mode, qml_mode, &zone_scope);
+ } else {
+ GenericStringUC16CharacterStream stream(source, 0, source->length());
+ scanner_.Initialize(&stream);
+- return DoParseProgram(source, in_global_context, strict_mode, &zone_scope);
++ return DoParseProgram(source, in_global_context, strict_mode, qml_mode, &zone_scope);
+ }
+ }
+
+@@ -621,6 +622,7 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
+ FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
+ bool in_global_context,
+ StrictModeFlag strict_mode,
++ bool qml_mode,
+ ZoneScope* zone_scope) {
+ ASSERT(target_stack_ == NULL);
+ if (pre_data_ != NULL) pre_data_->Initialize();
+@@ -641,6 +643,9 @@ FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
+ if (strict_mode == kStrictMode) {
+ top_scope_->EnableStrictMode();
+ }
++ if (qml_mode) {
++ scope->EnableQmlMode();
++ }
+ ZoneList<Statement*>* body = new ZoneList<Statement*>(16);
+ bool ok = true;
+ int beg_loc = scanner().location().beg_pos;
+@@ -729,6 +734,9 @@ FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
+ if (shared_info->strict_mode()) {
+ top_scope_->EnableStrictMode();
+ }
++ if (shared_info->qml_mode()) {
++ top_scope_->EnableQmlMode();
++ }
+
+ FunctionLiteralType type =
+ shared_info->is_expression() ? EXPRESSION : DECLARATION;
+@@ -1661,6 +1669,11 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
+ arguments->Add(value);
+ value = NULL; // zap the value to avoid the unnecessary assignment
+
++ int qml_mode = 0;
++ if (top_scope_->is_qml_mode() && !Isolate::Current()->global()->HasProperty(*name))
++ qml_mode = 1;
++ arguments->Add(NewNumberLiteral(qml_mode));
++
+ // Construct the call to Runtime_InitializeConstGlobal
+ // and add it to the initialization statement block.
+ // Note that the function does different things depending on
+@@ -1676,6 +1689,11 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
+ arguments->Add(NewNumberLiteral(
+ top_scope_->is_strict_mode() ? kStrictMode : kNonStrictMode));
+
++ int qml_mode = 0;
++ if (top_scope_->is_qml_mode() && !Isolate::Current()->global()->HasProperty(*name))
++ qml_mode = 1;
++ arguments->Add(NewNumberLiteral(qml_mode));
++
+ // Be careful not to assign a value to the global variable if
+ // we're in a with. The initialization value should not
+ // necessarily be stored in the global object in that case,
+@@ -5157,7 +5175,8 @@ bool ParserApi::Parse(CompilationInfo* info) {
+ Handle<String> source = Handle<String>(String::cast(script->source()));
+ result = parser.ParseProgram(source,
+ info->is_global(),
+- info->StrictMode());
++ info->StrictMode(),
++ info->is_qml_mode());
+ }
+ }
+
+diff --git a/src/parser.h b/src/parser.h
+index 64f1303..4d45e45 100644
+--- a/src/parser.h
++++ b/src/parser.h
+@@ -431,7 +431,8 @@ class Parser {
+ // Returns NULL if parsing failed.
+ FunctionLiteral* ParseProgram(Handle<String> source,
+ bool in_global_context,
+- StrictModeFlag strict_mode);
++ StrictModeFlag strict_mode,
++ bool qml_mode);
+
+ FunctionLiteral* ParseLazy(CompilationInfo* info);
+
+@@ -464,6 +465,7 @@ class Parser {
+ FunctionLiteral* DoParseProgram(Handle<String> source,
+ bool in_global_context,
+ StrictModeFlag strict_mode,
++ bool qml_mode,
+ ZoneScope* zone_scope);
+
+ // Report syntax error
+diff --git a/src/prettyprinter.cc b/src/prettyprinter.cc
+index c777ab4..1964e02 100644
+--- a/src/prettyprinter.cc
++++ b/src/prettyprinter.cc
+@@ -656,6 +656,9 @@ void AstPrinter::PrintLiteralWithModeIndented(const char* info,
+ EmbeddedVector<char, 256> buf;
+ int pos = OS::SNPrintF(buf, "%s (mode = %s", info,
+ Variable::Mode2String(var->mode()));
++ if (var->is_qml_global()) {
++ pos += OS::SNPrintF(buf + pos, ":QML");
++ }
+ OS::SNPrintF(buf + pos, ")");
+ PrintLiteralIndented(buf.start(), value, true);
+ }
+diff --git a/src/runtime.cc b/src/runtime.cc
+index 660352c..827d954 100644
+--- a/src/runtime.cc
++++ b/src/runtime.cc
+@@ -1065,8 +1065,6 @@ static Failure* ThrowRedeclarationError(Isolate* isolate,
+ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
+ ASSERT(args.length() == 4);
+ HandleScope scope(isolate);
+- Handle<GlobalObject> global = Handle<GlobalObject>(
+- isolate->context()->global());
+
+ Handle<Context> context = args.at<Context>(0);
+ CONVERT_ARG_CHECKED(FixedArray, pairs, 1);
+@@ -1075,6 +1073,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
+ static_cast<StrictModeFlag>(Smi::cast(args[3])->value());
+ ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode);
+
++ Handle<JSObject> js_global = Handle<JSObject>(isolate->context()->global());
++ Handle<JSObject> qml_global = Handle<JSObject>(isolate->context()->qml_global());
++
+ // Compute the property attributes. According to ECMA-262, section
+ // 13, page 71, the property must be read-only and
+ // non-deletable. However, neither SpiderMonkey nor KJS creates the
+@@ -1083,10 +1084,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) {
+
+ // Traverse the name/value pairs and set the properties.
+ int length = pairs->length();
+- for (int i = 0; i < length; i += 2) {
++ for (int i = 0; i < length; i += 3) {
+ HandleScope scope(isolate);
+ Handle<String> name(String::cast(pairs->get(i)));
+ Handle<Object> value(pairs->get(i + 1), isolate);
++ Handle<Smi> is_qml_global(Smi::cast(pairs->get(i + 2)));
++
++ Handle<JSObject> global = is_qml_global->value()?qml_global:js_global;
+
+ // We have to declare a global const property. To capture we only
+ // assign to it when evaluating the assignment for "const x =
+@@ -1316,20 +1320,25 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+ NoHandleAllocation nha;
+ // args[0] == name
+ // args[1] == strict_mode
+- // args[2] == value (optional)
++ // args[2] == qml_mode
++ // args[3] == value (optional)
+
+ // Determine if we need to assign to the variable if it already
+ // exists (based on the number of arguments).
+- RUNTIME_ASSERT(args.length() == 2 || args.length() == 3);
+- bool assign = args.length() == 3;
++ RUNTIME_ASSERT(args.length() == 3 || args.length() == 4);
++ bool assign = args.length() == 4;
+
+ CONVERT_ARG_CHECKED(String, name, 0);
+- GlobalObject* global = isolate->context()->global();
+ RUNTIME_ASSERT(args[1]->IsSmi());
+ StrictModeFlag strict_mode =
+ static_cast<StrictModeFlag>(Smi::cast(args[1])->value());
+ ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode);
+
++ RUNTIME_ASSERT(args[2]->IsSmi());
++ int qml_mode = Smi::cast(args[2])->value();
++
++ JSObject* global = qml_mode?isolate->context()->qml_global():isolate->context()->global();
++
+ // According to ECMA-262, section 12.2, page 62, the property must
+ // not be deletable.
+ PropertyAttributes attributes = DONT_DELETE;
+@@ -1350,7 +1359,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+ if (lookup.IsReadOnly()) {
+ // If we found readonly property on one of hidden prototypes,
+ // just shadow it.
+- if (real_holder != isolate->context()->global()) break;
++ if (real_holder != global) break;
+ return ThrowRedeclarationError(isolate, "const", name);
+ }
+
+@@ -1372,7 +1381,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+ // overwrite it with a variable declaration we must throw a
+ // re-declaration error. However if we found readonly property
+ // on one of hidden prototypes, just shadow it.
+- if (real_holder != isolate->context()->global()) break;
++ if (real_holder != global) break;
+ return ThrowRedeclarationError(isolate, "const", name);
+ }
+ }
+@@ -1384,7 +1393,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+ }
+
+ // Assign the value (or undefined) to the property.
+- Object* value = (assign) ? args[2] : isolate->heap()->undefined_value();
++ Object* value = (assign) ? args[3] : isolate->heap()->undefined_value();
+ return real_holder->SetProperty(
+ &lookup, *name, value, attributes, strict_mode);
+ }
+@@ -1399,9 +1408,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeVarGlobal) {
+ real_holder = JSObject::cast(proto);
+ }
+
+- global = isolate->context()->global();
++ global = qml_mode?isolate->context()->qml_global():isolate->context()->global();
+ if (assign) {
+- return global->SetProperty(*name, args[2], attributes, strict_mode, true);
++ return global->SetProperty(*name, args[3], attributes, strict_mode, true);
+ }
+ return isolate->heap()->undefined_value();
+ }
+@@ -1411,12 +1420,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) {
+ // All constants are declared with an initial value. The name
+ // of the constant is the first argument and the initial value
+ // is the second.
+- RUNTIME_ASSERT(args.length() == 2);
++ RUNTIME_ASSERT(args.length() == 3);
+ CONVERT_ARG_CHECKED(String, name, 0);
+ Handle<Object> value = args.at<Object>(1);
+
++ RUNTIME_ASSERT(args[2]->IsSmi());
++ int qml_mode = Smi::cast(args[2])->value();
++
+ // Get the current global object from top.
+- GlobalObject* global = isolate->context()->global();
++ JSObject* global = qml_mode?isolate->context()->qml_global():isolate->context()->global();
+
+ // According to ECMA-262, section 12.2, page 62, the property must
+ // not be deletable. Since it's a const, it must be READ_ONLY too.
+@@ -1456,7 +1468,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) {
+ // with setting the value because the property is either absent or
+ // read-only. We also have to do redo the lookup.
+ HandleScope handle_scope(isolate);
+- Handle<GlobalObject> global(isolate->context()->global());
++ Handle<JSObject> global(qml_mode?isolate->context()->qml_global():isolate->context()->global());
+
+ // BUG 1213575: Handle the case where we have to set a read-only
+ // property through an interceptor and only do it if it's
+@@ -8160,7 +8172,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) {
+ Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source,
+ context,
+ true,
+- kNonStrictMode);
++ kNonStrictMode,
++ false);
+ if (shared.is_null()) return Failure::Exception();
+ Handle<JSFunction> fun =
+ isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
+@@ -8173,14 +8186,16 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) {
+ static ObjectPair CompileGlobalEval(Isolate* isolate,
+ Handle<String> source,
+ Handle<Object> receiver,
+- StrictModeFlag strict_mode) {
++ StrictModeFlag strict_mode,
++ bool qml_mode) {
+ // Deal with a normal eval call with a string argument. Compile it
+ // and return the compiled function bound in the local context.
+ Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
+ source,
+ Handle<Context>(isolate->context()),
+ isolate->context()->IsGlobalContext(),
+- strict_mode);
++ strict_mode,
++ qml_mode);
+ if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
+ Handle<JSFunction> compiled =
+ isolate->factory()->NewFunctionFromSharedFunctionInfo(
+@@ -8190,7 +8205,7 @@ static ObjectPair CompileGlobalEval(Isolate* isolate,
+
+
+ RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) {
+- ASSERT(args.length() == 4);
++ ASSERT(args.length() == 5);
+
+ HandleScope scope(isolate);
+ Handle<Object> callee = args.at<Object>(0);
+@@ -8257,16 +8272,18 @@ RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) {
+ }
+
+ ASSERT(args[3]->IsSmi());
++ ASSERT(args[4]->IsSmi());
+ return CompileGlobalEval(isolate,
+ args.at<String>(1),
+ args.at<Object>(2),
+ static_cast<StrictModeFlag>(
+- Smi::cast(args[3])->value()));
++ Smi::cast(args[3])->value()),
++ Smi::cast(args[4])->value());
+ }
+
+
+ RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEvalNoLookup) {
+- ASSERT(args.length() == 4);
++ ASSERT(args.length() == 5);
+
+ HandleScope scope(isolate);
+ Handle<Object> callee = args.at<Object>(0);
+@@ -8280,11 +8297,13 @@ RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEvalNoLookup) {
+ }
+
+ ASSERT(args[3]->IsSmi());
++ ASSERT(args[4]->IsSmi());
+ return CompileGlobalEval(isolate,
+ args.at<String>(1),
+ args.at<Object>(2),
+ static_cast<StrictModeFlag>(
+- Smi::cast(args[3])->value()));
++ Smi::cast(args[3])->value()),
++ Smi::cast(args[4])->value());
+ }
+
+
+@@ -10633,7 +10652,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) {
+ Compiler::CompileEval(function_source,
+ context,
+ context->IsGlobalContext(),
+- kNonStrictMode);
++ kNonStrictMode,
++ false);
+ if (shared.is_null()) return Failure::Exception();
+ Handle<JSFunction> compiled_function =
+ isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context);
+@@ -10722,7 +10742,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluateGlobal) {
+ // Currently, the eval code will be executed in non-strict mode,
+ // even in the strict code context.
+ Handle<SharedFunctionInfo> shared =
+- Compiler::CompileEval(source, context, is_global, kNonStrictMode);
++ Compiler::CompileEval(source, context, is_global, kNonStrictMode, false);
+ if (shared.is_null()) return Failure::Exception();
+ Handle<JSFunction> compiled_function =
+ Handle<JSFunction>(
+diff --git a/src/runtime.h b/src/runtime.h
+index bf1ba68..5e97173 100644
+--- a/src/runtime.h
++++ b/src/runtime.h
+@@ -241,8 +241,8 @@ namespace internal {
+ \
+ /* Eval */ \
+ F(GlobalReceiver, 1, 1) \
+- F(ResolvePossiblyDirectEval, 4, 2) \
+- F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
++ F(ResolvePossiblyDirectEval, 5, 2) \
++ F(ResolvePossiblyDirectEvalNoLookup, 5, 2) \
+ \
+ F(SetProperty, -1 /* 4 or 5 */, 1) \
+ F(DefineOrRedefineDataProperty, 4, 1) \
+@@ -296,8 +296,8 @@ namespace internal {
+ /* Declarations and initialization */ \
+ F(DeclareGlobals, 4, 1) \
+ F(DeclareContextSlot, 4, 1) \
+- F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
+- F(InitializeConstGlobal, 2, 1) \
++ F(InitializeVarGlobal, -1 /* 3 or 4 */, 1) \
++ F(InitializeConstGlobal, 3, 1) \
+ F(InitializeConstContextSlot, 3, 1) \
+ F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
+ \
+diff --git a/src/scopes.cc b/src/scopes.cc
+index 8df93c5..734a217 100644
+--- a/src/scopes.cc
++++ b/src/scopes.cc
+@@ -198,6 +198,7 @@ void Scope::SetDefaults(Type type,
+ scope_calls_eval_ = false;
+ // Inherit the strict mode from the parent scope.
+ strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_;
++ qml_mode_ = (outer_scope != NULL) && outer_scope->qml_mode_;
+ outer_scope_calls_eval_ = false;
+ inner_scope_calls_eval_ = false;
+ outer_scope_is_eval_scope_ = false;
+@@ -796,6 +797,10 @@ void Scope::ResolveVariable(Scope* global_scope,
+ ASSERT(global_scope != NULL);
+ var = global_scope->DeclareGlobal(proxy->name());
+
++ if (qml_mode_ && !Isolate::Current()->global()->HasProperty(*(proxy->name()))) {
++ var->set_is_qml_global(true);
++ }
++
+ } else if (scope_inside_with_) {
+ // If we are inside a with statement we give up and look up
+ // the variable at runtime.
+@@ -816,6 +821,8 @@ void Scope::ResolveVariable(Scope* global_scope,
+ // variables.
+ if (context->GlobalIfNotShadowedByEval(proxy->name())) {
+ var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL);
++ if (qml_mode_ && !Isolate::Current()->global()->HasProperty(*(proxy->name())))
++ var->set_is_qml_global(true);
+
+ } else {
+ var = NonLocal(proxy->name(), Variable::DYNAMIC);
+@@ -827,6 +834,9 @@ void Scope::ResolveVariable(Scope* global_scope,
+ // variable is global unless it is shadowed by eval-introduced
+ // variables.
+ var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL);
++
++ if (qml_mode_ && !Isolate::Current()->global()->HasProperty(*(proxy->name())))
++ var->set_is_qml_global(true);
+ }
+ }
+ }
+diff --git a/src/scopes.h b/src/scopes.h
+index a0e56a4..6dd3f65 100644
+--- a/src/scopes.h
++++ b/src/scopes.h
+@@ -210,6 +210,11 @@ class Scope: public ZoneObject {
+ strict_mode_ = FLAG_strict_mode;
+ }
+
++ // Enable qml mode for this scope
++ void EnableQmlMode() {
++ qml_mode_ = true;
++ }
++
+ // ---------------------------------------------------------------------------
+ // Predicates.
+
+@@ -218,6 +223,7 @@ class Scope: public ZoneObject {
+ bool is_function_scope() const { return type_ == FUNCTION_SCOPE; }
+ bool is_global_scope() const { return type_ == GLOBAL_SCOPE; }
+ bool is_strict_mode() const { return strict_mode_; }
++ bool is_qml_mode() const { return qml_mode_; }
+
+ // Information about which scopes calls eval.
+ bool calls_eval() const { return scope_calls_eval_; }
+@@ -376,6 +382,7 @@ class Scope: public ZoneObject {
+ bool scope_contains_with_; // this scope contains a 'with' statement
+ bool scope_calls_eval_; // this scope contains an 'eval' call
+ bool strict_mode_; // this scope is a strict mode scope
++ bool qml_mode_; // this scope is a qml mode scope
+
+ // Computed via PropagateScopeInfo.
+ bool outer_scope_calls_eval_;
+diff --git a/src/variables.cc b/src/variables.cc
+index 0502722..190baf6 100644
+--- a/src/variables.cc
++++ b/src/variables.cc
+@@ -99,7 +99,8 @@ Variable::Variable(Scope* scope,
+ rewrite_(NULL),
+ is_valid_LHS_(is_valid_LHS),
+ is_accessed_from_inner_scope_(false),
+- is_used_(false) {
++ is_used_(false),
++ is_qml_global_(false) {
+ // names must be canonicalized for fast equality checks
+ ASSERT(name->IsSymbol());
+ }
+diff --git a/src/variables.h b/src/variables.h
+index b1ff0db..0b31d1a 100644
+--- a/src/variables.h
++++ b/src/variables.h
+@@ -141,6 +141,8 @@ class Variable: public ZoneObject {
+ Expression* rewrite() const { return rewrite_; }
+ void set_rewrite(Expression* expr) { rewrite_ = expr; }
+
++ bool is_qml_global() const { return is_qml_global_; }
++ void set_is_qml_global(bool is_qml_global) { is_qml_global_ = is_qml_global; }
+ private:
+ Scope* scope_;
+ Handle<String> name_;
+@@ -159,6 +161,9 @@ class Variable: public ZoneObject {
+ // Usage info.
+ bool is_accessed_from_inner_scope_; // set by variable resolver
+ bool is_used_;
++
++ // QML info
++ bool is_qml_global_;
+ };
+
+
+diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc
+index c365385..d923494 100644
+--- a/src/x64/code-stubs-x64.cc
++++ b/src/x64/code-stubs-x64.cc
+@@ -140,6 +140,10 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
+ __ movq(rbx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX)));
+ __ movq(Operand(rax, Context::SlotOffset(Context::GLOBAL_INDEX)), rbx);
+
++ // Copy the qml global object from the surrounding context.
++ __ movq(rbx, Operand(rsi, Context::SlotOffset(Context::QML_GLOBAL_INDEX)));
++ __ movq(Operand(rax, Context::SlotOffset(Context::QML_GLOBAL_INDEX)), rbx);
++
+ // Initialize the rest of the slots to undefined.
+ __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
+ for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
+diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
+index 97168cd..c45cdb6 100644
+--- a/src/x64/full-codegen-x64.cc
++++ b/src/x64/full-codegen-x64.cc
+@@ -141,12 +141,13 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
+
+ // Possibly allocate a local context.
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
+- if (heap_slots > 0) {
++ if (heap_slots > 0 ||
++ (scope()->is_qml_mode() && scope()->is_global_scope())) {
+ Comment cmnt(masm_, "[ Allocate local context");
+ // Argument to NewContext is the function, which is still in rdi.
+ __ push(rdi);
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+- FastNewContextStub stub(heap_slots);
++ FastNewContextStub stub((heap_slots < 0)?0:heap_slots);
+ __ CallStub(&stub);
+ } else {
+ __ CallRuntime(Runtime::kNewContext, 1);
+@@ -1119,10 +1120,10 @@ void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions(
+
+ // All extension objects were empty and it is safe to use a global
+ // load IC call.
+- __ movq(rax, GlobalObjectOperand());
++ __ movq(rax, slot->var()->is_qml_global() ? QmlGlobalObjectOperand() : GlobalObjectOperand());
+ __ Move(rcx, slot->var()->name());
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
+- RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF)
++ RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF || slot->var()->is_qml_global())
+ ? RelocInfo::CODE_TARGET
+ : RelocInfo::CODE_TARGET_CONTEXT;
+ EmitCallIC(ic, mode);
+@@ -1227,9 +1228,9 @@ void FullCodeGenerator::EmitVariableLoad(Variable* var) {
+ // Use inline caching. Variable name is passed in rcx and the global
+ // object on the stack.
+ __ Move(rcx, var->name());
+- __ movq(rax, GlobalObjectOperand());
++ __ movq(rax, var->is_qml_global() ? QmlGlobalObjectOperand() : GlobalObjectOperand());
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
+- EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallIC(ic, var->is_qml_global() ? RelocInfo::CODE_TARGET : RelocInfo::CODE_TARGET_CONTEXT);
+ context()->Plug(rax);
+
+ } else if (slot != NULL && slot->type() == Slot::LOOKUP) {
+@@ -1806,11 +1807,11 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var,
+ // assignment. Right-hand-side value is passed in rax, variable name in
+ // rcx, and the global object on the stack.
+ __ Move(rcx, var->name());
+- __ movq(rdx, GlobalObjectOperand());
++ __ movq(rdx, var->is_qml_global() ? QmlGlobalObjectOperand() : GlobalObjectOperand());
+ Handle<Code> ic = is_strict_mode()
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
+ : isolate()->builtins()->StoreIC_Initialize();
+- EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT);
++ EmitCallIC(ic, var->is_qml_global() ? RelocInfo::CODE_TARGET : RelocInfo::CODE_TARGET_CONTEXT);
+
+ } else if (op == Token::INIT_CONST) {
+ // Like var declarations, const declarations are hoisted to function
+@@ -2085,9 +2086,12 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(ResolveEvalFlag flag,
+ // Push the strict mode flag.
+ __ Push(Smi::FromInt(strict_mode_flag()));
+
++ // Push the qml mode flag
++ __ Push(Smi::FromInt(is_qml_mode()));
++
+ __ CallRuntime(flag == SKIP_CONTEXT_LOOKUP
+ ? Runtime::kResolvePossiblyDirectEvalNoLookup
+- : Runtime::kResolvePossiblyDirectEval, 4);
++ : Runtime::kResolvePossiblyDirectEval, 5);
+ }
+
+
+@@ -2160,8 +2164,8 @@ void FullCodeGenerator::VisitCall(Call* expr) {
+ } else if (var != NULL && !var->is_this() && var->is_global()) {
+ // Call to a global variable.
+ // Push global object as receiver for the call IC lookup.
+- __ push(GlobalObjectOperand());
+- EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
++ __ push(var->is_qml_global() ? QmlGlobalObjectOperand() : GlobalObjectOperand());
++ EmitCallWithIC(expr, var->name(), var->is_qml_global() ? RelocInfo::CODE_TARGET : RelocInfo::CODE_TARGET_CONTEXT);
+ } else if (var != NULL && var->AsSlot() != NULL &&
+ var->AsSlot()->type() == Slot::LOOKUP) {
+ // Call to a lookup slot (dynamically introduced variable).
+diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc
+index 202e7a2..45acbdf 100644
+--- a/src/x64/lithium-codegen-x64.cc
++++ b/src/x64/lithium-codegen-x64.cc
+@@ -174,12 +174,13 @@ bool LCodeGen::GeneratePrologue() {
+
+ // Possibly allocate a local context.
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
+- if (heap_slots > 0) {
++ if (heap_slots > 0 ||
++ (scope()->is_qml_mode() && scope()->is_global_scope())) {
+ Comment(";;; Allocate local context");
+ // Argument to NewContext is the function, which is still in rdi.
+ __ push(rdi);
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
+- FastNewContextStub stub(heap_slots);
++ FastNewContextStub stub((heap_slots < 0)?0:heap_slots);
+ __ CallStub(&stub);
+ } else {
+ __ CallRuntime(Runtime::kNewContext, 1);
+@@ -2540,7 +2541,7 @@ void LCodeGen::DoOuterContext(LOuterContext* instr) {
+
+ void LCodeGen::DoGlobalObject(LGlobalObject* instr) {
+ Register result = ToRegister(instr->result());
+- __ movq(result, GlobalObjectOperand());
++ __ movq(result, instr->qml_global()?QmlGlobalObjectOperand():GlobalObjectOperand());
+ }
+
+
+diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc
+index 07ca3a5..00feeac 100644
+--- a/src/x64/lithium-x64.cc
++++ b/src/x64/lithium-x64.cc
+@@ -1194,7 +1194,7 @@ LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) {
+
+
+ LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) {
+- return DefineAsRegister(new LGlobalObject);
++ return DefineAsRegister(new LGlobalObject(instr->qml_global()));
+ }
+
+
+diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h
+index 15bb894..16f754c 100644
+--- a/src/x64/lithium-x64.h
++++ b/src/x64/lithium-x64.h
+@@ -1365,7 +1365,13 @@ class LOuterContext: public LTemplateInstruction<1, 1, 0> {
+
+ class LGlobalObject: public LTemplateInstruction<1, 0, 0> {
+ public:
++ explicit LGlobalObject(bool qml_global) : qml_global_(qml_global) {}
++
+ DECLARE_CONCRETE_INSTRUCTION(GlobalObject, "global-object")
++
++ bool qml_global() { return qml_global_; }
++ private:
++ bool qml_global_;
+ };
+
+
+diff --git a/src/x64/macro-assembler-x64.h b/src/x64/macro-assembler-x64.h
+index 4c17720..aa284ed 100644
+--- a/src/x64/macro-assembler-x64.h
++++ b/src/x64/macro-assembler-x64.h
+@@ -1233,6 +1233,11 @@ static inline Operand GlobalObjectOperand() {
+ }
+
+
++static inline Operand QmlGlobalObjectOperand() {
++ return ContextOperand(rsi, Context::QML_GLOBAL_INDEX);
++}
++
++
+ // Provides access to exit frame stack space (not GCed).
+ static inline Operand StackSpaceOperand(int index) {
+ #ifdef _WIN64
+--
+1.7.2.3
+
diff --git a/src/v8/0006-Allow-access-to-the-calling-script-data.patch b/src/v8/0006-Allow-access-to-the-calling-script-data.patch
new file mode 100644
index 0000000000..214fe823c1
--- /dev/null
+++ b/src/v8/0006-Allow-access-to-the-calling-script-data.patch
@@ -0,0 +1,48 @@
+From 55ac15fff18ba2d0469c92c533e7ceb1c343fcd9 Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Wed, 25 May 2011 10:36:13 +1000
+Subject: [PATCH 6/8] Allow access to the calling script data
+
+---
+ include/v8.h | 1 +
+ src/api.cc | 12 ++++++++++++
+ 2 files changed, 13 insertions(+), 0 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index d04b73e..5f9e725 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -3335,6 +3335,7 @@ class V8EXPORT Context {
+ */
+ static Local<Context> GetCalling();
+ static Local<Object> GetCallingQmlGlobal();
++ static Local<Value> GetCallingScriptData();
+
+ /**
+ * Sets the security token for the context. To access an object in
+diff --git a/src/api.cc b/src/api.cc
+index 0635f34..ba487e8 100644
+--- a/src/api.cc
++++ b/src/api.cc
+@@ -3972,6 +3972,18 @@ v8::Local<v8::Object> Context::GetCallingQmlGlobal() {
+ }
+ }
+
++v8::Local<v8::Value> Context::GetCallingScriptData()
++{
++ i::Isolate* isolate = i::Isolate::Current();
++ if (IsDeadCheck(isolate, "v8::Context::GetCallingScriptData()")) {
++ return Local<Object>();
++ }
++
++ i::JavaScriptFrameIterator it;
++ if (it.done()) return Local<Object>();
++ i::Handle<i::Script> script(i::Script::cast(i::JSFunction::cast(it.frame()->function())->shared()->script()));
++ return Utils::ToLocal(i::Handle<i::Object>(script->data()));
++}
+
+ v8::Local<v8::Object> Context::Global() {
+ if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) {
+--
+1.7.2.3
+
diff --git a/src/v8/0007-Fix-warnings.patch b/src/v8/0007-Fix-warnings.patch
new file mode 100644
index 0000000000..1b7da91217
--- /dev/null
+++ b/src/v8/0007-Fix-warnings.patch
@@ -0,0 +1,46 @@
+From d37bb342f33c384e912ec7d86dfda8f384253ddd Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Fri, 27 May 2011 13:04:15 +1000
+Subject: [PATCH 7/8] Fix warnings
+
+---
+ include/v8.h | 16 ++++++++--------
+ 1 files changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index 5f9e725..255b90b 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -2414,7 +2414,7 @@ class V8EXPORT Extension { // NOLINT
+ const char** deps = 0);
+ virtual ~Extension() { }
+ virtual v8::Handle<v8::FunctionTemplate>
+- GetNativeFunction(v8::Handle<v8::String> name) {
++ GetNativeFunction(v8::Handle<v8::String>) {
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+@@ -3720,13 +3720,13 @@ class Internals {
+ return *reinterpret_cast<T*>(addr);
+ }
+
+- static inline bool CanCastToHeapObject(void* o) { return false; }
+- static inline bool CanCastToHeapObject(Context* o) { return true; }
+- static inline bool CanCastToHeapObject(String* o) { return true; }
+- static inline bool CanCastToHeapObject(Object* o) { return true; }
+- static inline bool CanCastToHeapObject(Message* o) { return true; }
+- static inline bool CanCastToHeapObject(StackTrace* o) { return true; }
+- static inline bool CanCastToHeapObject(StackFrame* o) { return true; }
++ static inline bool CanCastToHeapObject(void*) { return false; }
++ static inline bool CanCastToHeapObject(Context*) { return true; }
++ static inline bool CanCastToHeapObject(String*) { return true; }
++ static inline bool CanCastToHeapObject(Object*) { return true; }
++ static inline bool CanCastToHeapObject(Message*) { return true; }
++ static inline bool CanCastToHeapObject(StackTrace*) { return true; }
++ static inline bool CanCastToHeapObject(StackFrame*) { return true; }
+ };
+
+ } // namespace internal
+--
+1.7.2.3
+
diff --git a/src/v8/0008-Add-custom-object-compare-callback.patch b/src/v8/0008-Add-custom-object-compare-callback.patch
new file mode 100644
index 0000000000..ecc6eaa56d
--- /dev/null
+++ b/src/v8/0008-Add-custom-object-compare-callback.patch
@@ -0,0 +1,489 @@
+From eb2dadf516823ec342e6d75a3a78b2af7b1dea85 Mon Sep 17 00:00:00 2001
+From: Aaron Kennedy <aaron.kennedy@nokia.com>
+Date: Mon, 27 Jun 2011 14:57:28 +1000
+Subject: [PATCH 8/8] Add custom object compare callback
+
+A global custom object comparison callback can be set with:
+ V8::SetUserObjectComparisonCallbackFunction()
+When two JSObjects are compared (== or !=), if either one has
+the MarkAsUseUserObjectComparison() bit set, the custom comparison
+callback is invoked to do the actual comparison.
+
+This is useful when you have "value" objects that you want to
+compare as equal, even though they are actually different JS object
+instances.
+---
+ include/v8.h | 13 +++++++++++++
+ src/api.cc | 19 +++++++++++++++++++
+ src/arm/code-stubs-arm.cc | 42 ++++++++++++++++++++++++++++++++++++++++--
+ src/factory.cc | 8 ++++++++
+ src/ia32/code-stubs-ia32.cc | 40 ++++++++++++++++++++++++++++++++++++++++
+ src/isolate.h | 8 ++++++++
+ src/objects-inl.h | 15 +++++++++++++++
+ src/objects.h | 10 +++++++++-
+ src/runtime.cc | 23 +++++++++++++++++++++++
+ src/runtime.h | 1 +
+ src/top.cc | 5 +++++
+ src/x64/code-stubs-x64.cc | 37 +++++++++++++++++++++++++++++++++++++
+ 12 files changed, 218 insertions(+), 3 deletions(-)
+
+diff --git a/include/v8.h b/include/v8.h
+index 255b90b..52a5839 100644
+--- a/include/v8.h
++++ b/include/v8.h
+@@ -2364,6 +2364,12 @@ class V8EXPORT ObjectTemplate : public Template {
+ bool HasExternalResource();
+ void SetHasExternalResource(bool value);
+
++ /**
++ * Mark object instances of the template as using the user object
++ * comparison callback.
++ */
++ void MarkAsUseUserObjectComparison();
++
+ private:
+ ObjectTemplate();
+ static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
+@@ -2564,6 +2570,10 @@ typedef void (*FailedAccessCheckCallback)(Local<Object> target,
+ AccessType type,
+ Local<Value> data);
+
++// --- U s e r O b j e c t C o m p a r i s o n C a l l b a c k ---
++typedef bool (*UserObjectComparisonCallback)(Local<Object> lhs,
++ Local<Object> rhs);
++
+ // --- G a r b a g e C o l l e c t i o n C a l l b a c k s
+
+ /**
+@@ -2814,6 +2824,9 @@ class V8EXPORT V8 {
+ /** Callback function for reporting failed access checks.*/
+ static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
+
++ /** Callback for user object comparisons */
++ static void SetUserObjectComparisonCallbackFunction(UserObjectComparisonCallback);
++
+ /**
+ * Enables the host application to receive a notification before a
+ * garbage collection. Allocations are not allowed in the
+diff --git a/src/api.cc b/src/api.cc
+index ba487e8..930f338 100644
+--- a/src/api.cc
++++ b/src/api.cc
+@@ -1321,6 +1321,16 @@ void ObjectTemplate::SetHasExternalResource(bool value)
+ }
+ }
+
++void ObjectTemplate::MarkAsUseUserObjectComparison()
++{
++ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
++ if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUseUserObjectComparison()")) {
++ return;
++ }
++ ENTER_V8(isolate);
++ EnsureConstructor(this);
++ Utils::OpenHandle(this)->set_use_user_object_comparison(i::Smi::FromInt(1));
++}
+
+ // --- S c r i p t D a t a ---
+
+@@ -4628,6 +4638,15 @@ void V8::SetFailedAccessCheckCallbackFunction(
+ isolate->SetFailedAccessCheckCallback(callback);
+ }
+
++void V8::SetUserObjectComparisonCallbackFunction(
++ UserObjectComparisonCallback callback) {
++ i::Isolate* isolate = i::Isolate::Current();
++ if (IsDeadCheck(isolate, "v8::V8::SetUserObjectComparisonCallbackFunction()")) {
++ return;
++ }
++ isolate->SetUserObjectComparisonCallback(callback);
++}
++
+ void V8::AddObjectGroup(Persistent<Value>* objects,
+ size_t length,
+ RetainedObjectInfo* info) {
+diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc
+index a2626bf..749c9be 100644
+--- a/src/arm/code-stubs-arm.cc
++++ b/src/arm/code-stubs-arm.cc
+@@ -1563,6 +1563,36 @@ void CompareStub::Generate(MacroAssembler* masm) {
+ // NOTICE! This code is only reached after a smi-fast-case check, so
+ // it is certain that at least one operand isn't a smi.
+
++ {
++ Label not_user_equal, user_equal;
++ __ and_(r2, r1, Operand(r0));
++ __ tst(r2, Operand(kSmiTagMask));
++ __ b(eq, &not_user_equal);
++
++ __ CompareObjectType(r0, r2, r4, JS_OBJECT_TYPE);
++ __ b(ne, &not_user_equal);
++
++ __ CompareObjectType(r1, r3, r4, JS_OBJECT_TYPE);
++ __ b(ne, &not_user_equal);
++
++ __ ldrb(r2, FieldMemOperand(r2, Map::kBitField3Offset));
++ __ and_(r2, r2, Operand(1 << Map::kUseUserObjectComparison));
++ __ cmp(r2, Operand(1 << Map::kUseUserObjectComparison));
++ __ b(eq, &user_equal);
++
++ __ ldrb(r3, FieldMemOperand(r3, Map::kBitField3Offset));
++ __ and_(r3, r3, Operand(1 << Map::kUseUserObjectComparison));
++ __ cmp(r3, Operand(1 << Map::kUseUserObjectComparison));
++ __ b(ne, &not_user_equal);
++
++ __ bind(&user_equal);
++
++ __ Push(r0, r1);
++ __ TailCallRuntime(Runtime::kUserObjectEquals, 2, 1);
++
++ __ bind(&not_user_equal);
++ }
++
+ // Handle the case where the objects are identical. Either returns the answer
+ // or goes to slow. Only falls through if the objects were not identical.
+ EmitIdenticalObjectComparison(masm, &slow, cc_, never_nan_nan_);
+@@ -5802,10 +5832,18 @@ void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
+ __ tst(r2, Operand(kSmiTagMask));
+ __ b(eq, &miss);
+
+- __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE);
++ __ CompareObjectType(r0, r2, r3, JS_OBJECT_TYPE);
+ __ b(ne, &miss);
+- __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE);
++ __ ldrb(r2, FieldMemOperand(r2, Map::kBitField3Offset));
++ __ and_(r2, r2, Operand(1 << Map::kUseUserObjectComparison));
++ __ cmp(r2, Operand(1 << Map::kUseUserObjectComparison));
++ __ b(eq, &miss);
++ __ CompareObjectType(r1, r2, r3, JS_OBJECT_TYPE);
+ __ b(ne, &miss);
++ __ ldrb(r2, FieldMemOperand(r2, Map::kBitField3Offset));
++ __ and_(r2, r2, Operand(1 << Map::kUseUserObjectComparison));
++ __ cmp(r2, Operand(1 << Map::kUseUserObjectComparison));
++ __ b(eq, &miss);
+
+ ASSERT(GetCondition() == eq);
+ __ sub(r0, r0, Operand(r1));
+diff --git a/src/factory.cc b/src/factory.cc
+index d530a75..6f8c7de 100644
+--- a/src/factory.cc
++++ b/src/factory.cc
+@@ -998,6 +998,7 @@ Handle<JSFunction> Factory::CreateApiFunction(
+
+ int internal_field_count = 0;
+ bool has_external_resource = false;
++ bool use_user_object_comparison = false;
+
+ if (!obj->instance_template()->IsUndefined()) {
+ Handle<ObjectTemplateInfo> instance_template =
+@@ -1007,6 +1008,8 @@ Handle<JSFunction> Factory::CreateApiFunction(
+ Smi::cast(instance_template->internal_field_count())->value();
+ has_external_resource =
+ !instance_template->has_external_resource()->IsUndefined();
++ use_user_object_comparison =
++ !instance_template->use_user_object_comparison()->IsUndefined();
+ }
+
+ int instance_size = kPointerSize * internal_field_count;
+@@ -1051,6 +1054,11 @@ Handle<JSFunction> Factory::CreateApiFunction(
+ map->set_has_external_resource(true);
+ }
+
++ // Mark as using user object comparison if needed
++ if (use_user_object_comparison) {
++ map->set_use_user_object_comparison(true);
++ }
++
+ // Mark as undetectable if needed.
+ if (obj->undetectable()) {
+ map->set_is_undetectable();
+diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc
+index afa599e..0964ab9 100644
+--- a/src/ia32/code-stubs-ia32.cc
++++ b/src/ia32/code-stubs-ia32.cc
+@@ -3447,6 +3447,40 @@ void CompareStub::Generate(MacroAssembler* masm) {
+ __ Assert(not_zero, "Unexpected smi operands.");
+ }
+
++ {
++ NearLabel not_user_equal, user_equal;
++ __ test(eax, Immediate(kSmiTagMask));
++ __ j(zero, &not_user_equal);
++ __ test(edx, Immediate(kSmiTagMask));
++ __ j(zero, &not_user_equal);
++
++ __ CmpObjectType(eax, JS_OBJECT_TYPE, ebx);
++ __ j(not_equal, &not_user_equal);
++
++ __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx);
++ __ j(not_equal, &not_user_equal);
++
++ __ test_b(FieldOperand(ebx, Map::kBitField3Offset),
++ 1 << Map::kUseUserObjectComparison);
++ __ j(not_zero, &user_equal);
++ __ test_b(FieldOperand(ecx, Map::kBitField3Offset),
++ 1 << Map::kUseUserObjectComparison);
++ __ j(not_zero, &user_equal);
++
++ __ jmp(&not_user_equal);
++
++ __ bind(&user_equal);
++
++ __ pop(ebx); // Return address.
++ __ push(eax);
++ __ push(edx);
++ __ push(ebx);
++ __ TailCallRuntime(Runtime::kUserObjectEquals, 2, 1);
++
++ __ bind(&not_user_equal);
++ }
++
++
+ // NOTICE! This code is only reached after a smi-fast-case check, so
+ // it is certain that at least one operand isn't a smi.
+
+@@ -5592,8 +5626,14 @@ void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
+
+ __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx);
+ __ j(not_equal, &miss, not_taken);
++ __ test_b(FieldOperand(ecx, Map::kBitField3Offset),
++ 1 << Map::kUseUserObjectComparison);
++ __ j(not_zero, &miss);
+ __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx);
+ __ j(not_equal, &miss, not_taken);
++ __ test_b(FieldOperand(ecx, Map::kBitField3Offset),
++ 1 << Map::kUseUserObjectComparison);
++ __ j(not_zero, &miss);
+
+ ASSERT(GetCondition() == equal);
+ __ sub(eax, Operand(edx));
+diff --git a/src/isolate.h b/src/isolate.h
+index 35ffcb4..8130397 100644
+--- a/src/isolate.h
++++ b/src/isolate.h
+@@ -267,6 +267,9 @@ class ThreadLocalTop BASE_EMBEDDED {
+ // Call back function to report unsafe JS accesses.
+ v8::FailedAccessCheckCallback failed_access_check_callback_;
+
++ // Call back function for user object comparisons
++ v8::UserObjectComparisonCallback user_object_comparison_callback_;
++
+ private:
+ void InitializeInternal();
+
+@@ -699,6 +702,11 @@ class Isolate {
+ void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback);
+ void ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type);
+
++ void SetUserObjectComparisonCallback(v8::UserObjectComparisonCallback callback);
++ inline v8::UserObjectComparisonCallback UserObjectComparisonCallback() {
++ return thread_local_top()->user_object_comparison_callback_;
++ }
++
+ // Exception throwing support. The caller should use the result
+ // of Throw() as its return value.
+ Failure* Throw(Object* exception, MessageLocation* location = NULL);
+diff --git a/src/objects-inl.h b/src/objects-inl.h
+index 1c7f83e..1765441 100644
+--- a/src/objects-inl.h
++++ b/src/objects-inl.h
+@@ -2552,6 +2552,19 @@ bool Map::has_external_resource()
+ }
+
+
++void Map::set_use_user_object_comparison(bool value) {
++ if (value) {
++ set_bit_field3(bit_field3() | (1 << kUseUserObjectComparison));
++ } else {
++ set_bit_field3(bit_field3() & ~(1 << kUseUserObjectComparison));
++ }
++}
++
++bool Map::use_user_object_comparison() {
++ return ((1 << kUseUserObjectComparison) & bit_field3()) != 0;
++}
++
++
+ void Map::set_named_interceptor_is_fallback(bool value)
+ {
+ if (value) {
+@@ -3050,6 +3063,8 @@ ACCESSORS(ObjectTemplateInfo, internal_field_count, Object,
+ kInternalFieldCountOffset)
+ ACCESSORS(ObjectTemplateInfo, has_external_resource, Object,
+ kHasExternalResourceOffset)
++ACCESSORS(ObjectTemplateInfo, use_user_object_comparison, Object,
++ kUseUserObjectComparisonOffset)
+
+ ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset)
+ ACCESSORS(SignatureInfo, args, Object, kArgsOffset)
+diff --git a/src/objects.h b/src/objects.h
+index edbc47a..e75e9f1 100644
+--- a/src/objects.h
++++ b/src/objects.h
+@@ -3724,6 +3724,11 @@ class Map: public HeapObject {
+ inline void set_has_external_resource(bool value);
+ inline bool has_external_resource();
+
++
++ // Tells whether the user object comparison callback should be used for
++ // comparisons involving this object
++ inline void set_use_user_object_comparison(bool value);
++ inline bool use_user_object_comparison();
+
+ // Whether the named interceptor is a fallback interceptor or not
+ inline void set_named_interceptor_is_fallback(bool value);
+@@ -3922,6 +3927,7 @@ class Map: public HeapObject {
+ // Bit positions for bit field 3
+ static const int kNamedInterceptorIsFallback = 0;
+ static const int kHasExternalResource = 1;
++ static const int kUseUserObjectComparison = 2;
+
+ // Layout of the default cache. It holds alternating name and code objects.
+ static const int kCodeCacheEntrySize = 2;
+@@ -6442,6 +6448,7 @@ class ObjectTemplateInfo: public TemplateInfo {
+ DECL_ACCESSORS(constructor, Object)
+ DECL_ACCESSORS(internal_field_count, Object)
+ DECL_ACCESSORS(has_external_resource, Object)
++ DECL_ACCESSORS(use_user_object_comparison, Object)
+
+ static inline ObjectTemplateInfo* cast(Object* obj);
+
+@@ -6459,7 +6466,8 @@ class ObjectTemplateInfo: public TemplateInfo {
+ static const int kInternalFieldCountOffset =
+ kConstructorOffset + kPointerSize;
+ static const int kHasExternalResourceOffset = kInternalFieldCountOffset + kPointerSize;
+- static const int kSize = kHasExternalResourceOffset + kPointerSize;
++ static const int kUseUserObjectComparisonOffset = kHasExternalResourceOffset + kPointerSize;
++ static const int kSize = kUseUserObjectComparisonOffset + kPointerSize;
+ };
+
+
+diff --git a/src/runtime.cc b/src/runtime.cc
+index 827d954..d552ddb 100644
+--- a/src/runtime.cc
++++ b/src/runtime.cc
+@@ -6279,6 +6279,29 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringEquals) {
+ }
+
+
++RUNTIME_FUNCTION(MaybeObject*, Runtime_UserObjectEquals) {
++ NoHandleAllocation ha;
++ ASSERT(args.length() == 2);
++
++ CONVERT_CHECKED(JSObject, lhs, args[1]);
++ CONVERT_CHECKED(JSObject, rhs, args[0]);
++
++ bool result;
++
++ v8::UserObjectComparisonCallback callback = isolate->UserObjectComparisonCallback();
++ if (callback) {
++ HandleScope scope(isolate);
++ Handle<JSObject> lhs_handle(lhs);
++ Handle<JSObject> rhs_handle(rhs);
++ result = callback(v8::Utils::ToLocal(lhs_handle), v8::Utils::ToLocal(rhs_handle));
++ } else {
++ result = (lhs == rhs);
++ }
++
++ return Smi::FromInt(result?0:1);
++}
++
++
+ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberCompare) {
+ NoHandleAllocation ha;
+ ASSERT(args.length() == 3);
+diff --git a/src/runtime.h b/src/runtime.h
+index 5e97173..0d754f9 100644
+--- a/src/runtime.h
++++ b/src/runtime.h
+@@ -146,6 +146,7 @@ namespace internal {
+ /* Comparisons */ \
+ F(NumberEquals, 2, 1) \
+ F(StringEquals, 2, 1) \
++ F(UserObjectEquals, 2, 1) \
+ \
+ F(NumberCompare, 3, 1) \
+ F(SmiLexicographicCompare, 2, 1) \
+diff --git a/src/top.cc b/src/top.cc
+index e078ee9..c345383 100644
+--- a/src/top.cc
++++ b/src/top.cc
+@@ -68,6 +68,7 @@ void ThreadLocalTop::InitializeInternal() {
+ thread_id_ = ThreadId::Invalid();
+ external_caught_exception_ = false;
+ failed_access_check_callback_ = NULL;
++ user_object_comparison_callback_ = NULL;
+ save_context_ = NULL;
+ catcher_ = NULL;
+ }
+@@ -387,6 +388,10 @@ void Isolate::SetFailedAccessCheckCallback(
+ thread_local_top()->failed_access_check_callback_ = callback;
+ }
+
++void Isolate::SetUserObjectComparisonCallback(
++ v8::UserObjectComparisonCallback callback) {
++ thread_local_top()->user_object_comparison_callback_ = callback;
++}
+
+ void Isolate::ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type) {
+ if (!thread_local_top()->failed_access_check_callback_) return;
+diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc
+index d923494..10b9b56 100644
+--- a/src/x64/code-stubs-x64.cc
++++ b/src/x64/code-stubs-x64.cc
+@@ -2443,6 +2443,37 @@ void CompareStub::Generate(MacroAssembler* masm) {
+ __ bind(&ok);
+ }
+
++ {
++ NearLabel not_user_equal, user_equal;
++ __ JumpIfSmi(rax, &not_user_equal);
++ __ JumpIfSmi(rdx, &not_user_equal);
++
++ __ CmpObjectType(rax, JS_OBJECT_TYPE, rbx);
++ __ j(not_equal, &not_user_equal);
++
++ __ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx);
++ __ j(not_equal, &not_user_equal);
++
++ __ testb(FieldOperand(rbx, Map::kBitField3Offset),
++ Immediate(1 << Map::kUseUserObjectComparison));
++ __ j(not_zero, &user_equal);
++ __ testb(FieldOperand(rcx, Map::kBitField3Offset),
++ Immediate(1 << Map::kUseUserObjectComparison));
++ __ j(not_zero, &user_equal);
++
++ __ jmp(&not_user_equal);
++
++ __ bind(&user_equal);
++
++ __ pop(rbx); // Return address.
++ __ push(rax);
++ __ push(rdx);
++ __ push(rbx);
++ __ TailCallRuntime(Runtime::kUserObjectEquals, 2, 1);
++
++ __ bind(&not_user_equal);
++ }
++
+ // The compare stub returns a positive, negative, or zero 64-bit integer
+ // value in rax, corresponding to result of comparing the two inputs.
+ // NOTICE! This code is only reached after a smi-fast-case check, so
+@@ -4471,8 +4502,14 @@ void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
+
+ __ CmpObjectType(rax, JS_OBJECT_TYPE, rcx);
+ __ j(not_equal, &miss, not_taken);
++ __ testb(FieldOperand(rcx, Map::kBitField3Offset),
++ Immediate(1 << Map::kUseUserObjectComparison));
++ __ j(not_zero, &miss);
+ __ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx);
+ __ j(not_equal, &miss, not_taken);
++ __ testb(FieldOperand(rcx, Map::kBitField3Offset),
++ Immediate(1 << Map::kUseUserObjectComparison));
++ __ j(not_zero, &miss);
+
+ ASSERT(GetCondition() == equal);
+ __ subq(rax, rdx);
+--
+1.7.2.3
+
diff --git a/src/v8/README b/src/v8/README
new file mode 100644
index 0000000000..2dc39705aa
--- /dev/null
+++ b/src/v8/README
@@ -0,0 +1 @@
+These patches apply cleanly against v8 at 2eaa4b29586fdbd5d41f7b7d9e72ecca6d53dbd2
diff --git a/src/v8/v8.pro b/src/v8/v8.pro
new file mode 100644
index 0000000000..c3d2e634c1
--- /dev/null
+++ b/src/v8/v8.pro
@@ -0,0 +1,263 @@
+TEMPLATE = lib
+CONFIG += staticlib
+
+CONFIG += building-libs
+
+QT =
+
+win32|mac:!macx-xcode:CONFIG += debug_and_release
+macx:CONFIG(debug, debug|release) {
+ TARGET = v8_debug
+}
+
+equals(QT_ARCH, "x64")|contains(CONFIG, x86_64):CONFIG += arch_x86_64
+else:equals(QT_ARCH, "i386"):CONFIG += arch_i386
+else:equals(QT_ARCH, "arm"):CONFIG += arch_arm
+
+include($$PWD/v8base.pri)
+
+V8_GENERATED_SOURCES_DIR = generated
+
+# 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
+}
+
+INCLUDEPATH += \
+ $$V8DIR/src
+
+# $$V8DIR/include
+
+V8SOURCES = \
+ $$V8DIR/src/accessors.cc \
+ $$V8DIR/src/allocation.cc \
+ $$V8DIR/src/api.cc \
+ $$V8DIR/src/assembler.cc \
+ $$V8DIR/src/ast.cc \
+ $$V8DIR/src/atomicops_internals_x86_gcc.cc \
+ $$V8DIR/src/bignum.cc \
+ $$V8DIR/src/bignum-dtoa.cc \
+ $$V8DIR/src/bootstrapper.cc \
+ $$V8DIR/src/builtins.cc \
+ $$V8DIR/src/cached-powers.cc \
+ $$V8DIR/src/checks.cc \
+ $$V8DIR/src/circular-queue.cc \
+ $$V8DIR/src/code-stubs.cc \
+ $$V8DIR/src/codegen.cc \
+ $$V8DIR/src/compilation-cache.cc \
+ $$V8DIR/src/compiler.cc \
+ $$V8DIR/src/contexts.cc \
+ $$V8DIR/src/conversions.cc \
+ $$V8DIR/src/counters.cc \
+ $$V8DIR/src/cpu-profiler.cc \
+ $$V8DIR/src/data-flow.cc \
+ $$V8DIR/src/dateparser.cc \
+ $$V8DIR/src/debug-agent.cc \
+ $$V8DIR/src/debug.cc \
+ $$V8DIR/src/deoptimizer.cc \
+ $$V8DIR/src/disassembler.cc \
+ $$V8DIR/src/diy-fp.cc \
+ $$V8DIR/src/dtoa.cc \
+ $$V8DIR/src/execution.cc \
+ $$V8DIR/src/factory.cc \
+ $$V8DIR/src/flags.cc \
+ $$V8DIR/src/frame-element.cc \
+ $$V8DIR/src/frames.cc \
+ $$V8DIR/src/full-codegen.cc \
+ $$V8DIR/src/func-name-inferrer.cc \
+ $$V8DIR/src/gdb-jit.cc \
+ $$V8DIR/src/global-handles.cc \
+ $$V8DIR/src/fast-dtoa.cc \
+ $$V8DIR/src/fixed-dtoa.cc \
+ $$V8DIR/src/handles.cc \
+ $$V8DIR/src/hashmap.cc \
+ $$V8DIR/src/heap-profiler.cc \
+ $$V8DIR/src/heap.cc \
+ $$V8DIR/src/hydrogen.cc \
+ $$V8DIR/src/hydrogen-instructions.cc \
+ $$V8DIR/src/ic.cc \
+ $$V8DIR/src/inspector.cc \
+ $$V8DIR/src/interpreter-irregexp.cc \
+ $$V8DIR/src/isolate.cc \
+ $$V8DIR/src/jsregexp.cc \
+ $$V8DIR/src/lithium-allocator.cc \
+ $$V8DIR/src/lithium.cc \
+ $$V8DIR/src/liveedit.cc \
+ $$V8DIR/src/liveobjectlist.cc \
+ $$V8DIR/src/log-utils.cc \
+ $$V8DIR/src/log.cc \
+ $$V8DIR/src/mark-compact.cc \
+ $$V8DIR/src/messages.cc \
+ $$V8DIR/src/objects.cc \
+ $$V8DIR/src/objects-printer.cc \
+ $$V8DIR/src/objects-visiting.cc \
+ $$V8DIR/src/parser.cc \
+ $$V8DIR/src/preparser.cc \
+ $$V8DIR/src/preparse-data.cc \
+ $$V8DIR/src/profile-generator.cc \
+ $$V8DIR/src/property.cc \
+ $$V8DIR/src/regexp-macro-assembler-irregexp.cc \
+ $$V8DIR/src/regexp-macro-assembler.cc \
+ $$V8DIR/src/regexp-stack.cc \
+ $$V8DIR/src/rewriter.cc \
+ $$V8DIR/src/runtime.cc \
+ $$V8DIR/src/runtime-profiler.cc \
+ $$V8DIR/src/safepoint-table.cc \
+ $$V8DIR/src/scanner-base.cc \
+ $$V8DIR/src/scanner.cc \
+ $$V8DIR/src/scopeinfo.cc \
+ $$V8DIR/src/scopes.cc \
+ $$V8DIR/src/serialize.cc \
+ $$V8DIR/src/snapshot-common.cc \
+ $$V8DIR/src/spaces.cc \
+ $$V8DIR/src/string-search.cc \
+ $$V8DIR/src/string-stream.cc \
+ $$V8DIR/src/strtod.cc \
+ $$V8DIR/src/stub-cache.cc \
+ $$V8DIR/src/token.cc \
+ $$V8DIR/src/top.cc \
+ $$V8DIR/src/type-info.cc \
+ $$V8DIR/src/unicode.cc \
+ $$V8DIR/src/utils.cc \
+ $$V8DIR/src/v8-counters.cc \
+ $$V8DIR/src/v8.cc \
+ $$V8DIR/src/v8threads.cc \
+ $$V8DIR/src/variables.cc \
+ $$V8DIR/src/version.cc \
+ $$V8DIR/src/zone.cc \
+ $$V8DIR/src/extensions/gc-extension.cc \
+ $$V8DIR/src/extensions/externalize-string-extension.cc
+
+V8SOURCES += \
+ $$V8DIR/src/snapshot-empty.cc \
+
+arch_arm {
+DEFINES += V8_TARGET_ARCH_ARM
+V8SOURCES += \
+ $$V8DIR/src/arm/builtins-arm.cc \
+ $$V8DIR/src/arm/code-stubs-arm.cc \
+ $$V8DIR/src/arm/codegen-arm.cc \
+ $$V8DIR/src/arm/constants-arm.cc \
+ $$V8DIR/src/arm/cpu-arm.cc \
+ $$V8DIR/src/arm/debug-arm.cc \
+ $$V8DIR/src/arm/deoptimizer-arm.cc \
+ $$V8DIR/src/arm/disasm-arm.cc \
+ $$V8DIR/src/arm/frames-arm.cc \
+ $$V8DIR/src/arm/full-codegen-arm.cc \
+ $$V8DIR/src/arm/ic-arm.cc \
+ $$V8DIR/src/arm/lithium-arm.cc \
+ $$V8DIR/src/arm/lithium-codegen-arm.cc \
+ $$V8DIR/src/arm/lithium-gap-resolver-arm.cc \
+ $$V8DIR/src/arm/macro-assembler-arm.cc \
+ $$V8DIR/src/arm/regexp-macro-assembler-arm.cc \
+ $$V8DIR/src/arm/stub-cache-arm.cc \
+ $$V8DIR/src/arm/assembler-arm.cc
+}
+
+arch_i386 {
+DEFINES += V8_TARGET_ARCH_IA32
+V8SOURCES += \
+ $$V8DIR/src/ia32/assembler-ia32.cc \
+ $$V8DIR/src/ia32/builtins-ia32.cc \
+ $$V8DIR/src/ia32/code-stubs-ia32.cc \
+ $$V8DIR/src/ia32/codegen-ia32.cc \
+ $$V8DIR/src/ia32/cpu-ia32.cc \
+ $$V8DIR/src/ia32/debug-ia32.cc \
+ $$V8DIR/src/ia32/deoptimizer-ia32.cc \
+ $$V8DIR/src/ia32/disasm-ia32.cc \
+ $$V8DIR/src/ia32/frames-ia32.cc \
+ $$V8DIR/src/ia32/full-codegen-ia32.cc \
+ $$V8DIR/src/ia32/ic-ia32.cc \
+ $$V8DIR/src/ia32/lithium-codegen-ia32.cc \
+ $$V8DIR/src/ia32/lithium-gap-resolver-ia32.cc \
+ $$V8DIR/src/ia32/lithium-ia32.cc \
+ $$V8DIR/src/ia32/macro-assembler-ia32.cc \
+ $$V8DIR/src/ia32/regexp-macro-assembler-ia32.cc \
+ $$V8DIR/src/ia32/stub-cache-ia32.cc
+}
+
+# FIXME Should we use QT_CONFIG instead? What about 32 bit Macs?
+arch_x86_64 {
+DEFINES += V8_TARGET_ARCH_X64
+V8SOURCES += \
+ $$V8DIR/src/x64/assembler-x64.cc \
+ $$V8DIR/src/x64/builtins-x64.cc \
+ $$V8DIR/src/x64/code-stubs-x64.cc \
+ $$V8DIR/src/x64/codegen-x64.cc \
+ $$V8DIR/src/x64/cpu-x64.cc \
+ $$V8DIR/src/x64/debug-x64.cc \
+ $$V8DIR/src/x64/deoptimizer-x64.cc \
+ $$V8DIR/src/x64/disasm-x64.cc \
+ $$V8DIR/src/x64/frames-x64.cc \
+ $$V8DIR/src/x64/full-codegen-x64.cc \
+ $$V8DIR/src/x64/ic-x64.cc \
+ $$V8DIR/src/x64/lithium-codegen-x64.cc \
+ $$V8DIR/src/x64/lithium-gap-resolver-x64.cc \
+ $$V8DIR/src/x64/lithium-x64.cc \
+ $$V8DIR/src/x64/macro-assembler-x64.cc \
+ $$V8DIR/src/x64/regexp-macro-assembler-x64.cc \
+ $$V8DIR/src/x64/stub-cache-x64.cc
+}
+
+unix:!symbian:!macx {
+V8SOURCES += \
+ $$V8DIR/src/platform-linux.cc \
+ $$V8DIR/src/platform-posix.cc
+}
+
+#os:macos
+macx {
+V8SOURCES += \
+ $$V8DIR/src/platform-macos.cc \
+ $$V8DIR/src/platform-posix.cc
+}
+
+win32 {
+V8SOURCES += \
+ $$V8DIR/src/platform-win32.cc
+}
+
+#mode:debug
+CONFIG(debug) {
+ V8SOURCES += \
+ $$V8DIR/src/objects-debug.cc \
+ $$V8DIR/src/prettyprinter.cc \
+ $$V8DIR/src/regexp-macro-assembler-tracer.cc
+}
+
+V8_LIBRARY_FILES = \
+ $$V8DIR/src/runtime.js \
+ $$V8DIR/src/v8natives.js \
+ $$V8DIR/src/array.js \
+ $$V8DIR/src/string.js \
+ $$V8DIR/src/uri.js \
+ $$V8DIR/src/math.js \
+ $$V8DIR/src/messages.js \
+ $$V8DIR/src/apinatives.js \
+ $$V8DIR/src/date.js \
+ $$V8DIR/src/regexp.js \
+ $$V8DIR/src/json.js \
+ $$V8DIR/src/liveedit-debugger.js \
+ $$V8DIR/src/mirror-debugger.js \
+ $$V8DIR/src/debug-debugger.js
+
+SOURCES += $$V8SOURCES
+
+v8_js2c.commands = python $$V8DIR/tools/js2c.py $$V8_GENERATED_SOURCES_DIR/libraries.cpp $$V8_GENERATED_SOURCES_DIR/libraries-empty.cpp CORE
+v8_js2c.commands += $$V8DIR/src/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 $$V8DIR/src/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
+QMAKE_EXTRA_COMPILERS += v8_js2c
diff --git a/src/v8/v8base.pri b/src/v8/v8base.pri
new file mode 100644
index 0000000000..f57663ed3e
--- /dev/null
+++ b/src/v8/v8base.pri
@@ -0,0 +1,18 @@
+V8DIR = $$(V8DIR)
+isEmpty(V8DIR) {
+ V8DIR = $$PWD/../3rdparty/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
+ # FIXME how to find 4.5 series?
+ 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/src/v8/wrapcc.pl b/src/v8/wrapcc.pl
new file mode 100755
index 0000000000..463ab059ba
--- /dev/null
+++ b/src/v8/wrapcc.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+#############################################################################
+##
+## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+## All rights reserved.
+## Contact: Nokia Corporation (qt-info@nokia.com)
+##
+## This file is part of the translations module of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:LGPL$
+## No Commercial Usage
+## This file contains pre-release code and may not be distributed.
+## You may use this file in accordance with the terms and conditions
+## contained in the Technology Preview License Agreement accompanying
+## this package.
+##
+## GNU Lesser General Public License Usage
+## Alternatively, 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.
+##
+## If you have questions regarding the use of this file, please contact
+## Nokia at qt-info@nokia.com.
+##
+##
+##
+##
+##
+##
+##
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+scalar(@ARGV) == 2 or die "Usage: $0 INFILE OUTFILE";
+my $inFile = $ARGV[0];
+my $outFile = $ARGV[1];
+open FILE, ">", $outFile or die "Error: could not open $outFile for writing";
+print FILE "#include \"$inFile\"\n";
+close FILE;
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 9ef9ce8a16..d72f745d25 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -1,103 +1,118 @@
TEMPLATE = subdirs
+
+METATYPETESTS += \
+ qdeclarativemetatype \
+ qmetaobjectbuilder
+
+PUBLICTESTS += \
+ examples \
+ geometry \
+ nodes \
+ parserstress \
+ qdeclarativecomponent \
+ qdeclarativecontext \
+ qdeclarativeengine \
+ qdeclarativeerror \
+ qdeclarativefolderlistmodel \
+ qdeclarativeinfo \
+ qdeclarativelayoutitem \
+ qdeclarativelistreference \
+ qdeclarativemoduleplugin \
+ qdeclarativeparticles \
+ qdeclarativepixmapcache \
+ qdeclarativeqt \
+ qdeclarativeview \
+ qdeclarativeviewer \
+ qdeclarativexmlhttprequest \
+ moduleqt47
+
+PRIVATETESTS += \
+ qdeclarativeanchors \
+ qdeclarativeanimatedimage \
+ qdeclarativeanimations \
+ qdeclarativeapplication \
+ qdeclarativebehaviors \
+ qdeclarativebinding \
+ qdeclarativeborderimage \
+ qdeclarativeconnection \
+ qdeclarativedebug \
+ qdeclarativedebugclient \
+ qdeclarativedebughelper \
+ qdeclarativedebugservice \
+ qdeclarativeecmascript \
+ qdeclarativeflickable \
+ qdeclarativeflipable \
+ qdeclarativefocusscope \
+ qdeclarativefontloader \
+ qdeclarativegridview \
+ qdeclarativeimage \
+ qdeclarativeimageprovider \
+ qdeclarativeinstruction \
+ qdeclarativeitem \
+ qdeclarativelanguage \
+ qdeclarativelistmodel \
+ qdeclarativelistview \
+ qdeclarativeloader \
+ qdeclarativemousearea \
+ qdeclarativepathview \
+ qdeclarativepincharea \
+ qdeclarativepositioners \
+ qdeclarativeproperty \
+ qdeclarativepropertymap \
+ qdeclarativerepeater \
+ # qdeclarativescriptdebugging \
+ qdeclarativesmoothedanimation \
+ qdeclarativespringanimation \
+ qdeclarativestyledtext \
+ qdeclarativesqldatabase \
+ qdeclarativestates \
+ qdeclarativesystempalette \
+ qdeclarativetext \
+ qdeclarativetextedit \
+ qdeclarativetextinput \
+ qdeclarativetimer \
+ qdeclarativevaluetypes \
+ qdeclarativevisualdatamodel \
+ qdeclarativeworkerscript \
+ qdeclarativexmllistmodel \
+ qpacketprotocol \
+ qdeclarativev4 \
+ v8
+
+SGTESTS = \
+ qsganimatedimage \
+ qsgborderimage \
+ qsgcanvas \
+ qsgflickable \
+ qsgflipable \
+ qsgfocusscope \
+ qsggridview \
+ qsgimage \
+ qsgitem \
+ qsglistview \
+ qsgloader \
+ qsgmousearea \
+ qsgpathview \
+ qsgpincharea \
+ qsgpositioners \
+ qsgrepeater \
+ qsgtext \
+ qsgtextedit \
+ qsgtextinput \
+ qsgvisualdatamodel \
+
+
+SUBDIRS += $$PUBLICTESTS
+
!symbian: {
-SUBDIRS += \
- qdeclarativemetatype \
- qmetaobjectbuilder
+ SUBDIRS += $$METATYPETESTS
}
-SUBDIRS += \
- examples \
- parserstress \
- qdeclarativecomponent \
- qdeclarativecontext \
- qdeclarativeengine \
- qdeclarativeerror \
- qdeclarativefolderlistmodel \
- qdeclarativeinfo \
- qdeclarativelayoutitem \
- qdeclarativelistreference \
- qdeclarativemoduleplugin \
- qdeclarativeparticles \
- qdeclarativepixmapcache \
- qdeclarativeqt \
- qdeclarativeview \
- qdeclarativeviewer \
- qdeclarativexmlhttprequest \
- moduleqt47
-
contains(QT_CONFIG, private_tests) {
- SUBDIRS += \
- qdeclarativeanchors \
- qdeclarativeanimatedimage \
- qdeclarativeanimations \
- qdeclarativeapplication \
- qdeclarativebehaviors \
- qdeclarativebinding \
- qdeclarativeborderimage \
- qdeclarativechangeset \
- qdeclarativeconnection \
- qdeclarativedebug \
- qdeclarativedebugclient \
- qdeclarativedebugservice \
- qdeclarativeecmascript \
- qdeclarativeflickable \
- qdeclarativeflipable \
- qdeclarativefocusscope \
- qdeclarativefontloader \
- qdeclarativegridview \
- qdeclarativeimage \
- qdeclarativeimageprovider \
- qdeclarativeinstruction \
- qdeclarativeitem \
- qdeclarativelanguage \
- qdeclarativelistmodel \
- qdeclarativelistview \
- qdeclarativeloader \
- qdeclarativemousearea \
- qdeclarativepathview \
- qdeclarativepincharea \
- qdeclarativepositioners \
- qdeclarativeproperty \
- qdeclarativepropertymap \
- qdeclarativerepeater \
- qdeclarativesmoothedanimation \
- qdeclarativespringanimation \
- qdeclarativestyledtext \
- qdeclarativesqldatabase \
- qdeclarativestates \
- qdeclarativesystempalette \
- qdeclarativetext \
- qdeclarativetextedit \
- qdeclarativetextinput \
- qdeclarativetimer \
- qdeclarativevaluetypes \
- qdeclarativevisualdatamodel \
- qdeclarativeworkerscript \
- qdeclarativexmllistmodel \
- qpacketprotocol \
- qdeclarativev4 \
- qsganimatedimage \
- qsgborderimage \
- qsgcanvas \
- qsgflickable \
- qsgflipable \
- qsgfocusscope \
- qsggridview \
- qsgimage \
- qsgitem \
- qsglistview \
- qsgloader \
- qsgmousearea \
- qsgpathview \
- qsgpincharea \
- qsgpositioners \
- qsgrepeater \
- qsgtext \
- qsgtextedit \
- qsgtextinput \
- qsgvisualdatamodel
-
+ SUBDIRS += $$PRIVATETESTS
+ SUBDIRS += $$SGTESTS
}
# Tests which should run in Pulse
PULSE_TESTS = $$SUBDIRS
+
diff --git a/tests/auto/declarative/node/nodes.pro b/tests/auto/declarative/nodes/nodes.pro
index 19d3b09a43..19d3b09a43 100644
--- a/tests/auto/declarative/node/nodes.pro
+++ b/tests/auto/declarative/nodes/nodes.pro
diff --git a/tests/auto/declarative/node/tst_nodestest.cpp b/tests/auto/declarative/nodes/tst_nodestest.cpp
index 6b1fa85a4a..1d825fbd34 100644
--- a/tests/auto/declarative/node/tst_nodestest.cpp
+++ b/tests/auto/declarative/nodes/tst_nodestest.cpp
@@ -220,6 +220,8 @@ void NodesTest::simulatedEffect_data()
void NodesTest::simulatedEffect()
{
+ QSKIP("QTBUG-20029", SkipAll);
+
QFETCH(bool, connected);
QSGRootNode root;
diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp
index 97cd0c9ea5..fdb8ff7dc2 100644
--- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp
+++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp
@@ -342,7 +342,7 @@ void tst_qdeclarativecontext::setContextProperty()
QDeclarativeContext ctxt(engine.rootContext());
ctxt.setContextProperty("ctxtProp", QVariant());
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1: TypeError: Result of expression 'ctxtProp' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1: TypeError: Cannot read property 'a' of undefined");
QObject *obj = component.create(&ctxt);
QVariant v = obj->property("obj");
diff --git a/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp b/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp
index 5fecd29c51..f67d5c5a89 100644
--- a/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp
+++ b/tests/auto/declarative/qdeclarativedebughelper/tst_qdeclarativedebughelper.cpp
@@ -52,7 +52,6 @@
class tst_qdeclarativedebughelper : public QObject {
Q_OBJECT
private slots:
- void getScriptEngine();
void setAnimationSlowDownFactor();
void enableDebugging();
};
@@ -71,15 +70,6 @@ public:
}
};
-void tst_qdeclarativedebughelper::getScriptEngine()
-{
- QDeclarativeEngine engine;
-
- QScriptEngine *scriptEngine = QDeclarativeDebugHelper::getScriptEngine(&engine);
- QVERIFY(scriptEngine);
- QCOMPARE(scriptEngine, QDeclarativeEnginePrivate::getScriptEngine(&engine));
-}
-
void tst_qdeclarativedebughelper::setAnimationSlowDownFactor()
{
TestAnimation animation;
@@ -87,7 +77,7 @@ void tst_qdeclarativedebughelper::setAnimationSlowDownFactor()
// first check whether setup works
QCOMPARE(animation.updateCalled, 0);
animation.start();
- QTest::qWait(animation.totalDuration() + 50);
+ QTest::qWait(animation.totalDuration() + 150);
#ifdef Q_OS_WIN
if (animation.state() != QAbstractAnimation::Stopped)
QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort);
@@ -99,14 +89,14 @@ void tst_qdeclarativedebughelper::setAnimationSlowDownFactor()
animation.updateCalled = 0;
QDeclarativeDebugHelper::setAnimationSlowDownFactor(0.0);
animation.start();
- QTest::qWait(animation.totalDuration() + 50);
+ QTest::qWait(animation.totalDuration() + 150);
QVERIFY(animation.updateCalled <= 1); // updateCurrentTime seems to be called at least once
// now run them again
animation.updateCalled = 0;
QDeclarativeDebugHelper::setAnimationSlowDownFactor(2.0);
animation.start();
- QTest::qWait(animation.totalDuration() + 50);
+ QTest::qWait(animation.totalDuration() + 150);
QVERIFY(animation.updateCalled > 1);
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml
index a778dcc8b6..0455271dac 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml
@@ -6,17 +6,24 @@ QtObject {
property int a
property variant b
+ property bool test1: false;
+ property bool test2: false;
+
Component.onCompleted: {
try {
root.a = undefined;
} catch(e) {
- console.log (e.fileName + ":" + e.lineNumber + ":" + e);
+ if (e.message == "Cannot assign [undefined] to int" &&
+ e.stack.indexOf("propertyAssignmentErrors.qml:14") != -1)
+ root.test1 = true;
}
try {
root.a = "Hello";
} catch(e) {
- console.log (e.fileName + ":" + e.lineNumber + ":" + e);
+ if (e.message == "Cannot assign QString to int" &&
+ e.stack.indexOf("propertyAssignmentErrors.qml:22") != -1)
+ root.test2 = true;
}
}
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml
index b7bb366698..7fcf2bebd7 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml
@@ -4,5 +4,5 @@ import "qtbug_11600.js" as Test
QtObject {
id: goo
- property bool test: undefined == goo.Test.foo
+ property bool test: undefined == goo.Test
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml
index b1342fea90..9b07080054 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml
@@ -11,6 +11,7 @@ QtObject {
id: root
property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider }
property variant scarceResourceCopy;
+ property string srp_name: a.toString();
function retrieveScarceResource() {
root.scarceResourceCopy = scarceResourceProvider.scarceResource(); // common syntax error, should throw exception
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 3c4c336822..6f8764055a 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -49,7 +49,6 @@
#include <QtCore/qdir.h>
#include <QtCore/qnumeric.h>
#include <private/qdeclarativeengine_p.h>
-#include <private/qdeclarativeglobalscriptclass_p.h>
#include <private/qscriptdeclarativeclass_p.h>
#include "testtypes.h"
#include "testhttpserver.h"
@@ -180,7 +179,6 @@ private slots:
void aliasBindingsAssignCorrectly();
void aliasBindingsOverrideTarget();
void aliasWritesOverrideBindings();
- void pushCleanContext();
void realToInt();
void include();
@@ -1213,7 +1211,11 @@ void tst_qdeclarativeecmascript::functionErrors()
url = componentTwo.url().toString();
object = componentTwo.create();
QVERIFY(object != 0);
- warning = url + QLatin1String(":16: TypeError: Result of expression 'scarceResourceProvider.scarceResource' [[object Object]] is not a function.");
+
+ QString srpname = object->property("srp_name").toString();
+
+ warning = url + QLatin1String(":17: TypeError: Property 'scarceResource' of object ") + srpname +
+ QLatin1String(" is not a function");
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); // we expect a meaningful warning to be printed.
QMetaObject::invokeMethod(object, "retrieveScarceResource");
delete object;
@@ -1228,15 +1230,12 @@ void tst_qdeclarativeecmascript::propertyAssignmentErrors()
QString url = component.url().toString();
- QString warning1 = url + ":11:Error: Cannot assign [undefined] to int";
- QString warning2 = url + ":17:Error: Cannot assign QString to int";
-
- QTest::ignoreMessage(QtDebugMsg, warning1.toLatin1().constData());
- QTest::ignoreMessage(QtDebugMsg, warning2.toLatin1().constData());
-
QObject *object = component.create();
QVERIFY(object != 0);
+ QCOMPARE(object->property("test1").toBool(), true);
+ QCOMPARE(object->property("test2").toBool(), true);
+
delete object;
}
@@ -1291,7 +1290,7 @@ void tst_qdeclarativeecmascript::exceptionClearsOnReeval()
QDeclarativeComponent component(&engine, TEST_FILE("exceptionClearsOnReeval.qml"));
QString url = component.url().toString();
- QString warning = url + ":4: TypeError: Result of expression 'objectProperty' [null] is not an object.";
+ QString warning = url + ":4: TypeError: Cannot read property 'objectProperty' of null";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
@@ -1504,56 +1503,119 @@ void tst_qdeclarativeecmascript::regExpBug()
delete object;
}
+static inline bool evaluate_error(QV8Engine *engine, v8::Handle<v8::Object> o, const char *source)
+{
+ QString functionSource = QLatin1String("(function(object) { return ") +
+ QLatin1String(source) + QLatin1String(" })");
+ v8::TryCatch tc;
+ v8::Local<v8::Script> program = v8::Script::Compile(engine->toString(functionSource));
+ if (tc.HasCaught())
+ return false;
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run());
+ if (function.IsEmpty())
+ return false;
+ v8::Handle<v8::Value> args[] = { o };
+ function->Call(engine->global(), 1, args);
+ return tc.HasCaught();
+}
+
+static inline bool evaluate_value(QV8Engine *engine, v8::Handle<v8::Object> o,
+ const char *source, v8::Handle<v8::Value> result)
+{
+ QString functionSource = QLatin1String("(function(object) { return ") +
+ QLatin1String(source) + QLatin1String(" })");
+ v8::TryCatch tc;
+ v8::Local<v8::Script> program = v8::Script::Compile(engine->toString(functionSource));
+ if (tc.HasCaught())
+ return false;
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run());
+ if (function.IsEmpty())
+ return false;
+ v8::Handle<v8::Value> args[] = { o };
+
+ v8::Handle<v8::Value> value = function->Call(engine->global(), 1, args);
+
+ if (tc.HasCaught())
+ return false;
+
+ return value->StrictEquals(result);
+}
+
+static inline v8::Handle<v8::Value> evaluate(QV8Engine *engine, v8::Handle<v8::Object> o,
+ const char *source)
+{
+ QString functionSource = QLatin1String("(function(object) { return ") +
+ QLatin1String(source) + QLatin1String(" })");
+ v8::TryCatch tc;
+ v8::Local<v8::Script> program = v8::Script::Compile(engine->toString(functionSource));
+ if (tc.HasCaught())
+ return v8::Handle<v8::Value>();
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run());
+ if (function.IsEmpty())
+ return v8::Handle<v8::Value>();
+ v8::Handle<v8::Value> args[] = { o };
+
+ v8::Handle<v8::Value> value = function->Call(engine->global(), 1, args);
+
+ if (tc.HasCaught())
+ return v8::Handle<v8::Value>();
+ return value;
+}
+
+#define EVALUATE_ERROR(source) evaluate_error(engine, object, source)
+#define EVALUATE_VALUE(source, result) evaluate_value(engine, object, source, result)
+#define EVALUATE(source) evaluate(engine, object, source)
+
void tst_qdeclarativeecmascript::callQtInvokables()
{
MyInvokableObject o;
QDeclarativeEngine qmlengine;
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine);
- QScriptEngine *engine = &ep->scriptEngine;
+
+ QV8Engine *engine = &ep->v8engine;
- QStringList names; QList<QScriptValue> values;
- names << QLatin1String("object"); values << ep->objectClass->newQObject(&o);
- names << QLatin1String("undefined"); values << engine->undefinedValue();
+ v8::HandleScope handle_scope;
+ v8::Context::Scope scope(engine->context());
- ep->globalClass->explicitSetProperty(names, values);
+ v8::Local<v8::Object> object = engine->newQObject(&o)->ToObject();
// Non-existent methods
o.reset();
- QCOMPARE(engine->evaluate("object.method_nonexistent()").isError(), true);
+ QVERIFY(EVALUATE_ERROR("object.method_nonexistent()"));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), -1);
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QCOMPARE(engine->evaluate("object.method_nonexistent(10, 11)").isError(), true);
+ QVERIFY(EVALUATE_ERROR("object.method_nonexistent(10, 11)"));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), -1);
QCOMPARE(o.actuals().count(), 0);
// Insufficient arguments
o.reset();
- QCOMPARE(engine->evaluate("object.method_int()").isError(), true);
+ QVERIFY(EVALUATE_ERROR("object.method_int()"));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), -1);
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QCOMPARE(engine->evaluate("object.method_intint(10)").isError(), true);
+ QVERIFY(EVALUATE_ERROR("object.method_intint(10)"));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), -1);
QCOMPARE(o.actuals().count(), 0);
// Excessive arguments
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(10, 11)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(10, 11)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(10));
o.reset();
- QCOMPARE(engine->evaluate("object.method_intint(10, 11, 12)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_intint(10, 11, 12)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 9);
QCOMPARE(o.actuals().count(), 2);
@@ -1562,27 +1624,28 @@ void tst_qdeclarativeecmascript::callQtInvokables()
// Test return types
o.reset();
- QCOMPARE(engine->evaluate("object.method_NoArgs()").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_NoArgs()", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 0);
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QVERIFY(engine->evaluate("object.method_NoArgs_int()").strictlyEquals(QScriptValue(engine, 6)));
+ QVERIFY(EVALUATE_VALUE("object.method_NoArgs_int()", v8::Integer::New(6)));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 1);
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QVERIFY(engine->evaluate("object.method_NoArgs_real()").strictlyEquals(QScriptValue(engine, 19.75)));
+ QVERIFY(EVALUATE_VALUE("object.method_NoArgs_real()", v8::Number::New(19.75)));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 2);
QCOMPARE(o.actuals().count(), 0);
o.reset();
{
- QScriptValue ret = engine->evaluate("object.method_NoArgs_QPointF()");
- QCOMPARE(ret.toVariant(), QVariant(QPointF(123, 4.5)));
+ v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QPointF()");
+ QVERIFY(!ret.IsEmpty());
+ QCOMPARE(engine->toVariant(ret, -1), QVariant(QPointF(123, 4.5)));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 3);
QCOMPARE(o.actuals().count(), 0);
@@ -1590,81 +1653,83 @@ void tst_qdeclarativeecmascript::callQtInvokables()
o.reset();
{
- QScriptValue ret = engine->evaluate("object.method_NoArgs_QObject()");
- QVERIFY(ret.isQObject());
- QCOMPARE(ret.toQObject(), (QObject *)&o);
+ v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QObject()");
+ QCOMPARE(engine->toQObject(ret), (QObject *)&o);
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 4);
QCOMPARE(o.actuals().count(), 0);
}
o.reset();
- QCOMPARE(engine->evaluate("object.method_NoArgs_unknown()").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_NoArgs_unknown()", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 5);
QCOMPARE(o.actuals().count(), 0);
+ // XXX enable once qml/qtscript integration is implemented
+#if 0
o.reset();
{
- QScriptValue ret = engine->evaluate("object.method_NoArgs_QScriptValue()");
- QVERIFY(ret.isString());
- QCOMPARE(ret.toString(), QString("Hello world"));
+ v8::Handle<v8::Value> ret = EVALUATE("object.method_NoArgs_QScriptValue()");
+ QVERIFY(ret->IsString());
+ QCOMPARE(engine->toString(ret), QString("Hello world"));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 6);
QCOMPARE(o.actuals().count(), 0);
}
+#endif
o.reset();
- QVERIFY(engine->evaluate("object.method_NoArgs_QVariant()").strictlyEquals(QScriptValue(engine, "QML rocks")));
+ QVERIFY(EVALUATE_VALUE("object.method_NoArgs_QVariant()", engine->toString("QML rocks")));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 7);
QCOMPARE(o.actuals().count(), 0);
// Test arg types
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(94)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(94)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(94));
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(\"94\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(\"94\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(94));
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(\"not a number\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(\"not a number\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_int(object)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_int(object)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 8);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_intint(122, 9)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_intint(122, 9)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 9);
QCOMPARE(o.actuals().count(), 2);
@@ -1672,56 +1737,56 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(1), QVariant(9));
o.reset();
- QCOMPARE(engine->evaluate("object.method_real(94.3)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_real(94.3)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 10);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(94.3));
o.reset();
- QCOMPARE(engine->evaluate("object.method_real(\"94.3\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_real(\"94.3\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 10);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(94.3));
o.reset();
- QCOMPARE(engine->evaluate("object.method_real(\"not a number\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_real(\"not a number\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 10);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qIsNaN(o.actuals().at(0).toDouble()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_real(null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_real(null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 10);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_real(undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_real(undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 10);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qIsNaN(o.actuals().at(0).toDouble()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_real(object)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_real(object)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 10);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qIsNaN(o.actuals().at(0).toDouble()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QString(\"Hello world\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QString(\"Hello world\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 11);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant("Hello world"));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QString(19)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QString(19)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 11);
QCOMPARE(o.actuals().count(), 1);
@@ -1730,7 +1795,7 @@ void tst_qdeclarativeecmascript::callQtInvokables()
o.reset();
{
QString expected = "MyInvokableObject(0x" + QString::number((quintptr)&o, 16) + ")";
- QCOMPARE(engine->evaluate("object.method_QString(object)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QString(object)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 11);
QCOMPARE(o.actuals().count(), 1);
@@ -1738,126 +1803,128 @@ void tst_qdeclarativeecmascript::callQtInvokables()
}
o.reset();
- QCOMPARE(engine->evaluate("object.method_QString(null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QString(null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 11);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QString()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QString(undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QString(undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 11);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QString()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QPointF(0)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QPointF(0)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 12);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QPointF()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QPointF(null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QPointF(null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 12);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QPointF()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QPointF(undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QPointF(undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 12);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QPointF()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QPointF(object)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QPointF(object)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 12);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QPointF()));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QPointF(object.method_get_QPointF())").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPointF())", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 12);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QPointF(99.3, -10.2)));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QPointF(object.method_get_QPoint())").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPoint())", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 12);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QPointF(9, 12)));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QObject(0)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QObject(0)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 13);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QObject(\"Hello world\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QObject(\"Hello world\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 13);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QObject(null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QObject(null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 13);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QObject(undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QObject(undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 13);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QObject(object)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QObject(object)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 13);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)&o));
+ // XXX enable once qml/qtscript integration is implemented
+#if 0
o.reset();
- QCOMPARE(engine->evaluate("object.method_QScriptValue(null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 14);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isNull());
o.reset();
- QCOMPARE(engine->evaluate("object.method_QScriptValue(undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 14);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isUndefined());
o.reset();
- QCOMPARE(engine->evaluate("object.method_QScriptValue(19)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(19)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 14);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).strictlyEquals(QScriptValue(engine, 19)));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QScriptValue([19, 20])").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QScriptValue([19, 20])", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 14);
QCOMPARE(o.actuals().count(), 1);
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isArray());
o.reset();
- QCOMPARE(engine->evaluate("object.method_intQScriptValue(4, null)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(4, null)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 15);
QCOMPARE(o.actuals().count(), 2);
@@ -1865,7 +1932,7 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isNull());
o.reset();
- QCOMPARE(engine->evaluate("object.method_intQScriptValue(8, undefined)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(8, undefined)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 15);
QCOMPARE(o.actuals().count(), 2);
@@ -1873,7 +1940,7 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isUndefined());
o.reset();
- QCOMPARE(engine->evaluate("object.method_intQScriptValue(3, 19)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(3, 19)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 15);
QCOMPARE(o.actuals().count(), 2);
@@ -1881,28 +1948,29 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).strictlyEquals(QScriptValue(engine, 19)));
o.reset();
- QCOMPARE(engine->evaluate("object.method_intQScriptValue(44, [19, 20])").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(44, [19, 20])", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 15);
QCOMPARE(o.actuals().count(), 2);
QCOMPARE(o.actuals().at(0), QVariant(44));
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isArray());
+#endif
o.reset();
- QCOMPARE(engine->evaluate("object.method_overload()").isError(), true);
+ QVERIFY(EVALUATE_ERROR("object.method_overload()"));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), -1);
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QCOMPARE(engine->evaluate("object.method_overload(10)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_overload(10)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 16);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(10));
o.reset();
- QCOMPARE(engine->evaluate("object.method_overload(10, 11)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_overload(10, 11)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 17);
QCOMPARE(o.actuals().count(), 2);
@@ -1910,21 +1978,21 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(1), QVariant(11));
o.reset();
- QCOMPARE(engine->evaluate("object.method_overload(\"Hello\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_overload(\"Hello\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 18);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(QString("Hello")));
o.reset();
- QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_with_enum(9)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 19);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(9));
o.reset();
- QVERIFY(engine->evaluate("object.method_default(10)").strictlyEquals(QScriptValue(19)));
+ QVERIFY(EVALUATE_VALUE("object.method_default(10)", v8::Integer::New(19)));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 20);
QCOMPARE(o.actuals().count(), 2);
@@ -1932,7 +2000,7 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(1), QVariant(19));
o.reset();
- QVERIFY(engine->evaluate("object.method_default(10, 13)").strictlyEquals(QScriptValue(13)));
+ QVERIFY(EVALUATE_VALUE("object.method_default(10, 13)", v8::Integer::New(13)));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 20);
QCOMPARE(o.actuals().count(), 2);
@@ -1940,14 +2008,14 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(1), QVariant(13));
o.reset();
- QCOMPARE(engine->evaluate("object.method_inherited(9)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_inherited(9)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), -3);
QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(9));
o.reset();
- QCOMPARE(engine->evaluate("object.method_QVariant(9)").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QVariant(9)", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 21);
QCOMPARE(o.actuals().count(), 2);
@@ -1955,7 +2023,7 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(1), QVariant());
o.reset();
- QCOMPARE(engine->evaluate("object.method_QVariant(\"Hello\", \"World\")").isUndefined(), true);
+ QVERIFY(EVALUATE_VALUE("object.method_QVariant(\"Hello\", \"World\")", v8::Undefined()));
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 21);
QCOMPARE(o.actuals().count(), 2);
@@ -2250,7 +2318,8 @@ void tst_qdeclarativeecmascript::ownership()
QVERIFY(own.object != 0);
QObject *object = component.create(context);
- QDeclarativeEnginePrivate::getScriptEngine(&engine)->collectGarbage();
+
+ engine.collectGarbage();
QCoreApplication::processEvents(QEventLoop::DeferredDeletion);
@@ -2267,7 +2336,8 @@ void tst_qdeclarativeecmascript::ownership()
QVERIFY(own.object != 0);
QObject *object = component.create(context);
- QDeclarativeEnginePrivate::getScriptEngine(&engine)->collectGarbage();
+
+ engine.collectGarbage();
QCoreApplication::processEvents(QEventLoop::DeferredDeletion);
@@ -2351,6 +2421,7 @@ void tst_qdeclarativeecmascript::ownershipCustomReturnValue()
delete object;
}
+ engine.collectGarbage();
QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion);
QVERIFY(source.value == 0);
@@ -2514,6 +2585,8 @@ void tst_qdeclarativeecmascript::signalWithUnknownTypes()
void tst_qdeclarativeecmascript::moduleApi()
{
+ QSKIP("Module API not supported with V8", SkipAll);
+
QDeclarativeComponent component(&engine, TEST_FILE("moduleApi.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
@@ -2582,7 +2655,7 @@ void tst_qdeclarativeecmascript::importScripts()
// then, ensure that unintended behaviour does not work.
QDeclarativeComponent failOneComponent(&engine, TEST_FILE("jsimportfail/failOne.qml"));
- QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Result of expression 'TestScriptImport.ImportOneJs' [undefined] is not an object.");
+ QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Cannot call method 'greetingString' of undefined");
QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
object = failOneComponent.create();
QVERIFY(object != 0);
@@ -2596,7 +2669,7 @@ void tst_qdeclarativeecmascript::importScripts()
QVERIFY(object->property("importScriptFunctionValue").toString().isEmpty());
delete object;
QDeclarativeComponent failThreeComponent(&engine, TEST_FILE("jsimportfail/failThree.qml"));
- expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Result of expression 'testQtObject.TestModuleImport.JsQtTest' [undefined] is not an object.");
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Cannot read property 'JsQtTest' of undefined");
QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
object = failThreeComponent.create();
QVERIFY(object != 0);
@@ -2652,7 +2725,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(object != 0);
QVERIFY(object->property("scarceResourceCopy").isValid());
QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(!eo->scarceResourceIsDetached()); // there are two copies of it in existence: the property of object, and the property of eo.
delete object;
@@ -2662,7 +2735,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(object != 0);
QVERIFY(object->property("scarceResourceCopy").isValid());
QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(!eo->scarceResourceIsDetached()); // there are two copies of it in existence: the property of object, and the property of eo.
delete object;
@@ -2671,7 +2744,7 @@ void tst_qdeclarativeecmascript::scarceResources()
object = componentThree.create();
QVERIFY(object != 0);
QVERIFY(!(object->property("scarceResourceCopy").isValid())); // was manually released prior to being returned.
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should have explicitly been released during the evaluation of the binding.
delete object;
@@ -2683,7 +2756,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(object != 0);
QVERIFY(object->property("scarceResourceTest").isValid());
QCOMPARE(object->property("scarceResourceTest").toInt(), 100);
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // the resource should have been released after the binding was evaluated.
delete object;
@@ -2693,7 +2766,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(object != 0);
QVERIFY(object->property("scarceResourceTest").isValid());
QCOMPARE(object->property("scarceResourceTest").toInt(), 100);
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(!eo->scarceResourceIsDetached()); // this won't be detached since we explicitly preserved it.
delete object;
@@ -2703,7 +2776,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(object != 0);
QVERIFY(object->property("scarceResourceTest").isValid());
QCOMPARE(object->property("scarceResourceTest").toInt(), 100);
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // all resources were released manually or automatically released.
delete object;
@@ -2712,14 +2785,14 @@ void tst_qdeclarativeecmascript::scarceResources()
QDeclarativeComponent componentSeven(&engine, TEST_FILE("scarceresources/scarceResourceCopyImportNoBinding.qml"));
object = componentSeven.create();
QVERIFY(object != 0); // the import should have caused the addition of a resource to the ScarceResources list
- QVERIFY(ep->scarceResources == 0); // but they should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // but they should have been released by this point.
delete object;
QDeclarativeComponent componentEight(&engine, TEST_FILE("scarceresources/scarceResourceCopyImportFail.qml"));
object = componentEight.create();
QVERIFY(object != 0);
QVERIFY(!object->property("scarceResourceCopy").isValid()); // wasn't preserved, so shouldn't be valid.
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
delete object;
QDeclarativeComponent componentNine(&engine, TEST_FILE("scarceresources/scarceResourceCopyImport.qml"));
@@ -2730,7 +2803,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(object->property("scarceResourceAssignedCopyOne").isValid()); // assigned before destroy(), so should be valid.
QCOMPARE(object->property("scarceResourceAssignedCopyOne").value<QPixmap>(), origPixmap);
QVERIFY(!object->property("scarceResourceAssignedCopyTwo").isValid()); // assigned after destroy(), so should be invalid.
- QVERIFY(ep->scarceResources == 0); // this will still be zero, because "preserve()" REMOVES it from this list.
+ QVERIFY(ep->scarceResources.isEmpty()); // this will still be zero, because "preserve()" REMOVES it from this list.
delete object;
// test that scarce resources are handled properly in signal invocation
@@ -2753,7 +2826,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QCOMPARE(srsc->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(!(eo->scarceResourceIsDetached())); // should be another copy of the resource now.
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
delete object;
// test that scarce resources are handled properly from js functions in qml files
@@ -2772,7 +2845,7 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(!object->property("scarceResourceCopy").isValid()); // just released, so should not be valid
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
delete object;
// test that if an exception occurs while invoking js function from cpp, that the resources are released.
@@ -2782,13 +2855,14 @@ void tst_qdeclarativeecmascript::scarceResources()
QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
- QString expectedWarning = QLatin1String("file://") + TEST_FILE("scarceresources/scarceResourceFunctionFail.qml").toLocalFile() + QLatin1String(":16: TypeError: Result of expression 'scarceResourceProvider.scarceResource' [[object Object]] is not a function.");
- QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData()); // we expect a meaningful warning to be printed.
+ QString srp_name = object->property("srp_name").toString();
+ QString expectedWarning = componentTwelve.url().toString() + QLatin1String(":17: TypeError: Property 'scarceResource' of object ") + srp_name + QLatin1String(" is not a function");
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning)); // we expect a meaningful warning to be printed.
QMetaObject::invokeMethod(object, "retrieveScarceResource");
QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred.
eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
- QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ QVERIFY(ep->scarceResources.isEmpty()); // should have been released by this point.
delete object;
}
@@ -3074,11 +3148,11 @@ void tst_qdeclarativeecmascript::functionAssignmentfromJS_invalid()
QVERIFY(!o->property("a").isValid());
QString url = component.url().toString();
- QString warning = url + ":63: Unable to assign QString to int";
+ QString warning = url + ":67: Unable to assign QString to int";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
o->setProperty("assignWrongType", true);
- warning = url + ":70: Unable to assign QString to int";
+ warning = url + ":71: Unable to assign QString to int";
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
o->setProperty("assignWrongTypeToValueType", true);
@@ -3494,44 +3568,6 @@ void tst_qdeclarativeecmascript::revision()
}
}
-// Test for QScriptDeclarativeClass::pushCleanContext()
-void tst_qdeclarativeecmascript::pushCleanContext()
-{
- QScriptEngine engine;
- engine.globalObject().setProperty("a", 6);
- QCOMPARE(engine.evaluate("a").toInt32(), 6);
-
- // First confirm pushContext() behaves as we expect
- QScriptValue object = engine.newObject();
- object.setProperty("a", 15);
- QScriptContext *context1 = engine.pushContext();
- context1->pushScope(object);
- QCOMPARE(engine.evaluate("a").toInt32(), 15);
-
- QScriptContext *context2 = engine.pushContext();
- Q_UNUSED(context2);
- QCOMPARE(engine.evaluate("a").toInt32(), 15);
- QScriptValue func1 = engine.evaluate("(function() { return a; })");
-
- // Now check that pushCleanContext() works
- QScriptDeclarativeClass::pushCleanContext(&engine);
- QCOMPARE(engine.evaluate("a").toInt32(), 6);
- QScriptValue func2 = engine.evaluate("(function() { return a; })");
-
- engine.popContext();
- QCOMPARE(engine.evaluate("a").toInt32(), 15);
-
- engine.popContext();
- QCOMPARE(engine.evaluate("a").toInt32(), 15);
-
- engine.popContext();
- QCOMPARE(engine.evaluate("a").toInt32(), 6);
-
- // Check that function objects created in these contexts work
- QCOMPARE(func1.call().toInt32(), 15);
- QCOMPARE(func2.call().toInt32(), 6);
-}
-
void tst_qdeclarativeecmascript::realToInt()
{
QDeclarativeComponent component(&engine, TEST_FILE("realToInt.qml"));
diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
index 1aa9a5d5b1..e6e87d1bbd 100644
--- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
+++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
@@ -332,7 +332,7 @@ void tst_qdeclarativeinstruction::dump()
i.storeScriptString.propertyIndex = 24;
i.storeScriptString.value = 3;
i.storeScriptString.scope = 1;
- i.storeScriptString.bindingId = 3;
+ i.storeScriptString.bindingId = 4;
data->addInstruction(i);
}
@@ -366,7 +366,7 @@ void tst_qdeclarativeinstruction::dump()
{
QDeclarativeInstruction i;
- i.setType(QDeclarativeInstruction::StoreCompiledBinding);
+ i.setType(QDeclarativeInstruction::StoreV4Binding);
i.assignBinding.property = 27;
i.assignBinding.value = 2;
i.assignBinding.context = 4;
@@ -536,7 +536,7 @@ void tst_qdeclarativeinstruction::dump()
<< "25\t\tSTORE_VARIANT_OBJECT\t22"
<< "26\t\tSTORE_INTERFACE\t\t23"
<< "27\t\tSTORE_SIGNAL\t\t2\t3\t\t\"console.log(1921)\""
- << "28\t\tSTORE_SCRIPT_STRING\t24\t3\t1\t3"
+ << "28\t\tSTORE_SCRIPT_STRING\t24\t3\t1\t4"
<< "29\t\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\""
<< "30\t\tASSIGN_CUSTOMTYPE\t25\t6\t9"
<< "31\t\tSTORE_BINDING\t26\t3\t2"
diff --git a/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml
index bb20ecc8f6..48fb38da2b 100644
--- a/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml
+++ b/tests/auto/declarative/qdeclarativeitem/data/mapCoordinates.qml
@@ -33,11 +33,11 @@ Item {
function checkMapAToInvalid(x, y) {
var pos = itemA.mapToItem(1122, x, y)
- return pos.x == undefined && pos.y == undefined
+ return pos == undefined;
}
function checkMapAFromInvalid(x, y) {
var pos = itemA.mapFromItem(1122, x, y)
- return pos.x == undefined && pos.y == undefined
+ return pos == undefined;
}
}
diff --git a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml
index bfd547ed32..a1a599c9a5 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/data/model.qml
+++ b/tests/auto/declarative/qdeclarativelistmodel/data/model.qml
@@ -19,4 +19,8 @@ Item {
item.done = true
}
}
+
+ function runEval(js) {
+ eval(js);
+ }
}
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index d923a7a7cb..07a6d82752 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -69,7 +69,6 @@ public:
private:
int roleFromName(const QDeclarativeListModel *model, const QString &roleName);
- QScriptValue nestedListValue(QScriptEngine *eng) const;
QDeclarativeItem *createWorkerTest(QDeclarativeEngine *eng, QDeclarativeComponent *component, QDeclarativeListModel *model);
void waitForWorker(QDeclarativeItem *item);
@@ -108,6 +107,7 @@ private slots:
void property_changes_worker_data();
void clear();
};
+
int tst_qdeclarativelistmodel::roleFromName(const QDeclarativeListModel *model, const QString &roleName)
{
QList<int> roles = model->roles();
@@ -118,16 +118,6 @@ int tst_qdeclarativelistmodel::roleFromName(const QDeclarativeListModel *model,
return -1;
}
-QScriptValue tst_qdeclarativelistmodel::nestedListValue(QScriptEngine *eng) const
-{
- QScriptValue list = eng->newArray();
- list.setProperty(0, eng->newObject());
- list.setProperty(1, eng->newObject());
- QScriptValue sv = eng->newObject();
- sv.setProperty("foo", list);
- return sv;
-}
-
QDeclarativeItem *tst_qdeclarativelistmodel::createWorkerTest(QDeclarativeEngine *eng, QDeclarativeComponent *component, QDeclarativeListModel *model)
{
QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component->create());
@@ -152,19 +142,74 @@ void tst_qdeclarativelistmodel::waitForWorker(QDeclarativeItem *item)
QVERIFY(timer.isActive());
}
+void tst_qdeclarativelistmodel::static_types_data()
+{
+ QTest::addColumn<QString>("qml");
+ QTest::addColumn<QVariant>("value");
+
+ QTest::newRow("string")
+ << "ListElement { foo: \"bar\" }"
+ << QVariant(QString("bar"));
+
+ QTest::newRow("real")
+ << "ListElement { foo: 10.5 }"
+ << QVariant(10.5);
+
+ QTest::newRow("real0")
+ << "ListElement { foo: 0 }"
+ << QVariant(double(0));
+
+ QTest::newRow("bool")
+ << "ListElement { foo: false }"
+ << QVariant(false);
+
+ QTest::newRow("bool")
+ << "ListElement { foo: true }"
+ << QVariant(true);
+
+ QTest::newRow("enum")
+ << "ListElement { foo: Text.AlignHCenter }"
+ << QVariant(double(QDeclarativeText::AlignHCenter));
+}
+
+void tst_qdeclarativelistmodel::static_types()
+{
+ QFETCH(QString, qml);
+ QFETCH(QVariant, value);
+
+ qml = "import QtQuick 1.0\nItem { property variant test: model.get(0).foo; ListModel { id: model; " + qml + " } }";
+
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
+ component.setData(qml.toUtf8(),
+ QUrl::fromLocalFile(QString("dummy.qml")));
+
+ QVERIFY(!component.isError());
+
+ QObject *obj = component.create();
+ QVERIFY(obj != 0);
+
+ QVariant actual = obj->property("test");
+
+ QCOMPARE(actual, value);
+ QCOMPARE(actual.toString(), value.toString());
+
+ delete obj;
+}
+
void tst_qdeclarativelistmodel::static_i18n()
{
QString expect = QString::fromUtf8("na\303\257ve");
- QString componentStr = "import QtQuick 1.0\nListModel { ListElement { prop1: \""+expect+"\"; prop2: QT_TR_NOOP(\""+expect+"\") } }";
+ QString componentStr = "import QtQuick 1.0\nItem { property string prop1: model.get(0).prop1; property string prop2: model.get(0).prop2; ListModel { id: model; ListElement { prop1: \""+expect+"\"; prop2: QT_TR_NOOP(\""+expect+"\") } } }";
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine);
component.setData(componentStr.toUtf8(), QUrl::fromLocalFile(""));
- QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create());
+ QObject *obj = component.create();
QVERIFY(obj != 0);
- QString prop1 = obj->get(0).property(QLatin1String("prop1")).toString();
+ QString prop1 = obj->property("prop1").toString();
QCOMPARE(prop1,expect);
- QString prop2 = obj->get(0).property(QLatin1String("prop2")).toString();
+ QString prop2 = obj->property("prop2").toString();
QCOMPARE(prop2,expect); // (no, not translated, QT_TR_NOOP is a no-op)
delete obj;
}
@@ -180,25 +225,29 @@ void tst_qdeclarativelistmodel::static_nestedElements()
QString componentStr =
"import QtQuick 1.0\n"
- "ListModel {\n"
- " ListElement {\n"
- " attributes: [\n";
+ "Item {\n"
+ " property variant count: model.get(0).attributes.count\n"
+ " ListModel {\n"
+ " id: model\n"
+ " ListElement {\n"
+ " attributes: [\n";
componentStr += elementsStr.toUtf8().constData();
componentStr +=
- " ]\n"
- " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
"}";
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine);
component.setData(componentStr.toUtf8(), QUrl::fromLocalFile(""));
- QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create());
+ QObject *obj = component.create();
QVERIFY(obj != 0);
- QScriptValue prop = obj->get(0).property(QLatin1String("attributes")).property(QLatin1String("count"));
- QVERIFY(prop.isNumber());
- QCOMPARE(prop.toInt32(), qint32(elementCount));
+ QVariant count = obj->property("count");
+ QCOMPARE(count.type(), QVariant::Int);
+ QCOMPARE(count.toInt(), elementCount);
delete obj;
}
@@ -384,8 +433,6 @@ void tst_qdeclarativelistmodel::dynamic_worker()
qApp->processEvents();
}
-
-
void tst_qdeclarativelistmodel::dynamic_worker_sync_data()
{
dynamic_data();
@@ -438,6 +485,17 @@ void tst_qdeclarativelistmodel::dynamic_worker_sync()
qApp->processEvents();
}
+#define RUNEVAL(object, string) \
+ QVERIFY(QMetaObject::invokeMethod(object, "runEval", Q_ARG(QVariant, QString(string))));
+
+inline QVariant runexpr(QDeclarativeEngine *engine, const QString &str)
+{
+ QDeclarativeExpression expr(engine->rootContext(), 0, str);
+ return expr.evaluate();
+}
+
+#define RUNEXPR(string) runexpr(&engine, QString(string))
+
void tst_qdeclarativelistmodel::convertNestedToFlat_fail()
{
// If a model has nested data, it cannot be used at all from a worker script
@@ -450,11 +508,9 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_fail()
QDeclarativeItem *item = createWorkerTest(&eng, &component, &model);
QVERIFY(item != 0);
- QScriptEngine s_eng;
- QScriptValue plainData = s_eng.newObject();
- plainData.setProperty("foo", QScriptValue(123));
- model.append(plainData);
- model.append(nestedListValue(&s_eng));
+ RUNEVAL(item, "model.append({foo: 123})");
+ RUNEVAL(item, "model.append({foo: [{}, {}]})");
+
QCOMPARE(model.count(), 2);
QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML ListModel: List contains list-type data and cannot be used from a worker script");
@@ -482,6 +538,7 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_fail_data()
}
void tst_qdeclarativelistmodel::convertNestedToFlat_ok()
+
{
// If a model only has plain data, it can be modified from a worker script. However,
// once the model is used from a worker script, it no longer accepts nested data
@@ -494,10 +551,8 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_ok()
QDeclarativeItem *item = createWorkerTest(&eng, &component, &model);
QVERIFY(item != 0);
- QScriptEngine s_eng;
- QScriptValue plainData = s_eng.newObject();
- plainData.setProperty("foo", QScriptValue(123));
- model.append(plainData);
+ RUNEVAL(item, "model.append({foo: 123})");
+
QCOMPARE(model.count(), 1);
QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", Q_ARG(QVariant, script)));
@@ -505,20 +560,21 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_ok()
// can still add plain data
int count = model.count();
- model.append(plainData);
+
+ RUNEVAL(item, "model.append({foo: 123})");
+
QCOMPARE(model.count(), count+1);
- QScriptValue nested = nestedListValue(&s_eng);
const char *warning = "<Unknown File>: QML ListModel: Cannot add list-type data when modifying or after modification from a worker script";
QTest::ignoreMessage(QtWarningMsg, warning);
- model.append(nested);
+ RUNEVAL(item, "model.append({foo: [{}, {}]})");
QTest::ignoreMessage(QtWarningMsg, warning);
- model.insert(0, nested);
+ RUNEVAL(item, "model.insert(0, {foo: [{}, {}]})");
QTest::ignoreMessage(QtWarningMsg, warning);
- model.set(0, nested);
+ RUNEVAL(item, "model.set(0, {foo: [{}, {}]})");
QCOMPARE(model.count(), count+1);
@@ -531,67 +587,6 @@ void tst_qdeclarativelistmodel::convertNestedToFlat_ok_data()
convertNestedToFlat_fail_data();
}
-void tst_qdeclarativelistmodel::static_types_data()
-{
- QTest::addColumn<QString>("qml");
- QTest::addColumn<QVariant>("value");
-
- QTest::newRow("string")
- << "ListElement { foo: \"bar\" }"
- << QVariant(QString("bar"));
-
- QTest::newRow("real")
- << "ListElement { foo: 10.5 }"
- << QVariant(10.5);
-
- QTest::newRow("real0")
- << "ListElement { foo: 0 }"
- << QVariant(double(0));
-
- QTest::newRow("bool")
- << "ListElement { foo: false }"
- << QVariant(false);
-
- QTest::newRow("bool")
- << "ListElement { foo: true }"
- << QVariant(true);
-
- QTest::newRow("enum")
- << "ListElement { foo: Text.AlignHCenter }"
- << QVariant(double(QDeclarativeText::AlignHCenter));
-}
-
-void tst_qdeclarativelistmodel::static_types()
-{
- QFETCH(QString, qml);
- QFETCH(QVariant, value);
-
- qml = "import QtQuick 1.0\nListModel { " + qml + " }";
-
- QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine);
- component.setData(qml.toUtf8(),
- QUrl::fromLocalFile(QString("dummy.qml")));
-
- if (value.toString().startsWith("QTBUG-"))
- QEXPECT_FAIL("",value.toString().toLatin1(),Abort);
-
- QVERIFY(!component.isError());
-
- QDeclarativeListModel *obj = qobject_cast<QDeclarativeListModel*>(component.create());
- QVERIFY(obj != 0);
-
- QScriptValue actual = obj->get(0).property(QLatin1String("foo"));
-
- QCOMPARE(actual.isString(), value.type() == QVariant::String);
- QCOMPARE(actual.isBoolean(), value.type() == QVariant::Bool);
- QCOMPARE(actual.isNumber(), value.type() == QVariant::Double);
-
- QCOMPARE(actual.toString(), value.toString());
-
- delete obj;
-}
-
void tst_qdeclarativelistmodel::enumerate()
{
QDeclarativeEngine eng;
@@ -608,7 +603,6 @@ void tst_qdeclarativelistmodel::enumerate()
delete item;
}
-
void tst_qdeclarativelistmodel::error_data()
{
QTest::addColumn<QString>("qml");
@@ -701,21 +695,16 @@ void tst_qdeclarativelistmodel::set()
QDeclarativeEngine engine;
QDeclarativeListModel model;
QDeclarativeEngine::setContextForObject(&model,engine.rootContext());
- engine.rootContext()->setContextObject(&model);
- QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&engine);
+ engine.rootContext()->setContextProperty("model", &model);
- QScriptValue sv = seng->newObject();
- sv.setProperty("test", QScriptValue(false));
- model.append(sv);
+ RUNEXPR("model.append({test:false})");
+ RUNEXPR("model.set(0, {test:true})");
- sv.setProperty("test", QScriptValue(true));
- model.set(0, sv);
- QCOMPARE(model.get(0).property("test").toBool(), true); // triggers creation of model cache
+ QCOMPARE(RUNEXPR("model.get(0).test").toBool(), true); // triggers creation of model cache
QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(true));
- sv.setProperty("test", QScriptValue(false));
- model.set(0, sv);
- QCOMPARE(model.get(0).property("test").toBool(), false); // tests model cache is updated
+ RUNEXPR("model.set(0, {test:false})");
+ QCOMPARE(RUNEXPR("model.get(0).test").toBool(), false); // tests model cache is updated
QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(false));
}
@@ -729,8 +718,8 @@ void tst_qdeclarativelistmodel::get()
QFETCH(QString, roleName);
QFETCH(QVariant, roleValue);
- QDeclarativeEngine eng;
- QDeclarativeComponent component(&eng);
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
component.setData(
"import QtQuick 1.0\n"
"ListModel { \n"
@@ -743,7 +732,7 @@ void tst_qdeclarativelistmodel::get()
QVERIFY(role >= 0);
QSignalSpy spy(model, SIGNAL(itemsChanged(int, int, QList<int>)));
- QDeclarativeExpression expr(eng.rootContext(), model, expression);
+ QDeclarativeExpression expr(engine.rootContext(), model, expression);
expr.evaluate();
QVERIFY(!expr.hasError());
@@ -792,17 +781,12 @@ void tst_qdeclarativelistmodel::get_worker()
QDeclarativeComponent component(&eng, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
QDeclarativeItem *item = createWorkerTest(&eng, &component, &model);
QVERIFY(item != 0);
- QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&eng);
// Add some values like get() test
- QScriptValue sv = seng->newObject();
- sv.setProperty(QLatin1String("roleA"), seng->newVariant(QVariant::fromValue(100)));
- model.append(sv);
- sv = seng->newObject();
- sv.setProperty(QLatin1String("roleA"), seng->newVariant(QVariant::fromValue(200)));
- sv.setProperty(QLatin1String("roleB"), seng->newVariant(QVariant::fromValue(400)));
- model.append(sv);
- model.append(sv);
+ RUNEVAL(item, "model.append({roleA: 100})");
+ RUNEVAL(item, "model.append({roleA: 200, roleB: 400})");
+ RUNEVAL(item, "model.append({roleA: 200, roleB: 400})");
+
int role = roleFromName(&model, roleName);
QVERIFY(role >= 0);
@@ -1055,7 +1039,6 @@ void tst_qdeclarativelistmodel::property_changes_data()
<< "b" << 0 << true << "get(0).b.count == 0";
}
-
void tst_qdeclarativelistmodel::property_changes_worker()
{
// nested models are not supported when WorkerScript is involved
@@ -1108,33 +1091,26 @@ void tst_qdeclarativelistmodel::clear()
QDeclarativeEngine engine;
QDeclarativeListModel model;
QDeclarativeEngine::setContextForObject(&model, engine.rootContext());
- engine.rootContext()->setContextObject(&model);
-
- QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&engine);
- QScriptValue sv = seng->newObject();
- QVariant result;
+ engine.rootContext()->setContextProperty("model", &model);
model.clear();
QCOMPARE(model.count(), 0);
- sv.setProperty("propertyA", "value a");
- sv.setProperty("propertyB", "value b");
- model.append(sv);
+ RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\"})");
QCOMPARE(model.count(), 1);
model.clear();
QCOMPARE(model.count(), 0);
- model.append(sv);
- model.append(sv);
+ RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\"})");
+ RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\"})");
QCOMPARE(model.count(), 2);
model.clear();
QCOMPARE(model.count(), 0);
// clearing does not remove the roles
- sv.setProperty("propertyC", "value c");
- model.append(sv);
+ RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\", propertyC: \"value c\"})");
QList<int> roles = model.roles();
model.clear();
QCOMPARE(model.count(), 0);
diff --git a/tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml b/tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml
new file mode 100644
index 0000000000..06203285a9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/dateTimeConversion.qml
@@ -0,0 +1,14 @@
+import QtQuick 1.0
+
+QtObject {
+ // months are 0-based - so January = 0, December = 11.
+ property variant qtime: new Date(0,0,0,14,15,38,200) // yyyy/MM/dd 14:15:38.200
+ property variant qdate: new Date(2008,11,24) // 2008/12/24 hh:mm:ss.zzz
+ property variant qdatetime: new Date(2008,11,24,14,15,38,200) // 2008/12/24 14:15:38.200
+
+ property variant qdatetime2: new Date(2852,11,31,23,59,59,500) // 2852/12/31 23:59:59.500
+ property variant qdatetime3: new Date(1970,0,1,0,0,0,0) // 1970/01/01 00:00:00.000
+ property variant qdatetime4: new Date(1586,1,2) // 1586/02/02 hh:mm:ss.zzz
+ property variant qdatetime5: new Date(955,0,1,0,0,0,0) // 955/01/01 00:00:00.000
+ property variant qdatetime6: new Date(113,1,24,14,15,38,200) // 113/02/24 14:15:38.200
+}
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index 960616294f..948307d955 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -82,8 +82,11 @@ private slots:
void createComponent_pragmaLibrary();
void createQmlObject();
void consoleLog();
+ void dateTimeConversion();
void dateTimeFormatting();
void dateTimeFormatting_data();
+ void dateTimeFormattingVariants();
+ void dateTimeFormattingVariants_data();
void isQtObject();
void btoa();
void atob();
@@ -412,11 +415,11 @@ void tst_qdeclarativeqt::createQmlObject()
QDeclarativeComponent component(&engine, TEST_FILE("createQmlObject.qml"));
QString warning1 = component.url().toString() + ":7: Error: Qt.createQmlObject(): Invalid arguments";
- QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject() failed to create object: \n " + TEST_FILE("inline").toString() + ":2:10: Blah is not a type";
- QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject() failed to create object: \n " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name";
+ QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject(): failed to create object: \n " + TEST_FILE("inline").toString() + ":2:10: Blah is not a type";
+ QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name";
QString warning4 = component.url().toString()+ ":9: Error: Qt.createQmlObject(): Missing parent object";
QString warning5 = component.url().toString()+ ":8: Error: Qt.createQmlObject(): Invalid arguments";
- QString warning6 = "RunTimeError: Qt.createQmlObject() failed to create object: \n " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method";
+ QString warning6 = "RunTimeError: Qt.createQmlObject(): failed to create object: \n " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -448,6 +451,31 @@ void tst_qdeclarativeqt::consoleLog()
delete object;
}
+void tst_qdeclarativeqt::dateTimeConversion()
+{
+ QDate date(2008,12,24);
+ QTime time(14,15,38,200);
+ QDateTime dateTime(date, time);
+ QDateTime dateTime2(QDate(2852,12,31), QTime(23,59,59,500));
+ QDateTime dateTime3(QDate(1970,1,1), QTime(0,0,0,0));
+ QDateTime dateTime4(QDate(1586,2,2), QTime(0,0,0,0));
+ QDateTime dateTime5(QDate(955,1,1), QTime(0,0,0,0));
+ QDateTime dateTime6(QDate(113,2,24), QTime(14,15,38,200));
+
+ QDeclarativeEngine eng;
+ QDeclarativeComponent component(&eng, TEST_FILE("dateTimeConversion.qml"));
+ QObject *obj = component.create();
+
+ QCOMPARE(obj->property("qdate").toDate(), date);
+ QCOMPARE(obj->property("qtime").toTime(), time);
+ QCOMPARE(obj->property("qdatetime").toDateTime(), dateTime);
+ QCOMPARE(obj->property("qdatetime2").toDateTime(), dateTime2);
+ QCOMPARE(obj->property("qdatetime3").toDateTime(), dateTime3);
+ QCOMPARE(obj->property("qdatetime4").toDateTime(), dateTime4);
+ QCOMPARE(obj->property("qdatetime5").toDateTime(), dateTime5);
+ QCOMPARE(obj->property("qdatetime6").toDateTime(), dateTime6);
+}
+
void tst_qdeclarativeqt::dateTimeFormatting()
{
QFETCH(QString, method);
@@ -482,14 +510,13 @@ void tst_qdeclarativeqt::dateTimeFormatting()
QVERIFY(object != 0);
QVERIFY(inputProperties.count() > 0);
-
QVariant result;
foreach(const QString &prop, inputProperties) {
QVERIFY(QMetaObject::invokeMethod(object, method.toUtf8().constData(),
Q_RETURN_ARG(QVariant, result),
Q_ARG(QVariant, prop)));
-
QStringList output = result.toStringList();
+ QCOMPARE(output.size(), expectedResults.size());
for (int i=0; i<output.count(); i++)
QCOMPARE(output[i], expectedResults[i]);
}
@@ -530,6 +557,86 @@ void tst_qdeclarativeqt::dateTimeFormatting_data()
<< dateTime.toString("M/d/yy H:m:s a"));
}
+void tst_qdeclarativeqt::dateTimeFormattingVariants()
+{
+ QFETCH(QString, method);
+ QFETCH(QVariant, variant);
+ QFETCH(QStringList, expectedResults);
+
+ QDeclarativeEngine eng;
+ eng.rootContext()->setContextProperty("qvariant", variant);
+ QDeclarativeComponent component(&eng, TEST_FILE("formatting.qml"));
+
+ QStringList warnings;
+ warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format"
+ << component.url().toString() + ":36: Error: Qt.formatDate(): Invalid arguments"
+ << component.url().toString() + ":40: Error: Qt.formatTime(): Invalid time format"
+ << component.url().toString() + ":39: Error: Qt.formatTime(): Invalid arguments"
+ << component.url().toString() + ":43: Error: Qt.formatDateTime(): Invalid datetime format"
+ << component.url().toString() + ":42: Error: Qt.formatDateTime(): Invalid arguments";
+
+ foreach (const QString &warning, warnings)
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+
+ QObject *object = component.create();
+ QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString()));
+ QVERIFY(object != 0);
+
+ QVariant result;
+ QVERIFY(QMetaObject::invokeMethod(object, method.toUtf8().constData(),
+ Q_RETURN_ARG(QVariant, result),
+ Q_ARG(QVariant, QString(QLatin1String("qvariant")))));
+ QStringList output = result.toStringList();
+ QCOMPARE(output, expectedResults);
+
+ delete object;
+}
+
+void tst_qdeclarativeqt::dateTimeFormattingVariants_data()
+{
+ QTest::addColumn<QString>("method");
+ QTest::addColumn<QVariant>("variant");
+ QTest::addColumn<QStringList>("expectedResults");
+
+ QDateTime temporary;
+
+ QTime time(11, 16, 39, 755);
+ temporary = QDateTime(QDate(1970,1,1), time);
+ QTest::newRow("formatDate, qtime") << "formatDate" << QVariant::fromValue(time) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
+ QTest::newRow("formatDateTime, qtime") << "formatDateTime" << QVariant::fromValue(time) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
+ QTest::newRow("formatTime, qtime") << "formatTime" << QVariant::fromValue(time) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
+
+ QDate date(2011,5,31);
+ temporary = QDateTime(date);
+ QTest::newRow("formatDate, qdate") << "formatDate" << QVariant::fromValue(date) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
+ QTest::newRow("formatDateTime, qdate") << "formatDateTime" << QVariant::fromValue(date) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
+ QTest::newRow("formatTime, qdate") << "formatTime" << QVariant::fromValue(date) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
+
+ QDateTime dateTime(date, time);
+ temporary = dateTime;
+ QTest::newRow("formatDate, qdatetime") << "formatDate" << QVariant::fromValue(dateTime) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
+ QTest::newRow("formatDateTime, qdatetime") << "formatDateTime" << QVariant::fromValue(dateTime) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
+ QTest::newRow("formatTime, qdatetime") << "formatTime" << QVariant::fromValue(dateTime) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
+
+ QString string(QLatin1String("2011/05/31 11:16:39.755"));
+ temporary = QDateTime::fromString(string, "yyyy/MM/dd HH:mm:ss.zzz");
+ QTest::newRow("formatDate, qstring") << "formatDate" << QVariant::fromValue(string) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
+ QTest::newRow("formatDateTime, qstring") << "formatDateTime" << QVariant::fromValue(string) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
+ QTest::newRow("formatTime, qstring") << "formatTime" << QVariant::fromValue(string) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
+
+ QColor color(Qt::red);
+ temporary = QVariant::fromValue(color).toDateTime();
+ QTest::newRow("formatDate, qcolor") << "formatDate" << QVariant::fromValue(color) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
+ QTest::newRow("formatDateTime, qcolor") << "formatDateTime" << QVariant::fromValue(color) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
+ QTest::newRow("formatTime, qcolor") << "formatTime" << QVariant::fromValue(color) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
+
+ int integer(4);
+ temporary = QVariant::fromValue(integer).toDateTime();
+ QTest::newRow("formatDate, int") << "formatDate" << QVariant::fromValue(integer) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
+ QTest::newRow("formatDateTime, int") << "formatDateTime" << QVariant::fromValue(integer) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
+ QTest::newRow("formatTime, int") << "formatTime" << QVariant::fromValue(integer) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
+}
+
void tst_qdeclarativeqt::isQtObject()
{
QDeclarativeComponent component(&engine, TEST_FILE("isQtObject.qml"));
diff --git a/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp b/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp
index 37755a9929..94b1cd630a 100644
--- a/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp
+++ b/tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp
@@ -230,7 +230,8 @@ void tst_qdeclarativesqldatabase::testQml_cleanopen()
// making it more like the tests are running in new processes.
testQml();
- QDeclarativeEnginePrivate::getScriptEngine(engine)->collectGarbage(); // close databases
+ engine->collectGarbage();
+
foreach (QString dbname, QSqlDatabase::connectionNames()) {
QSqlDatabase::removeDatabase(dbname);
}
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
index 39c3a9419c..ee787e2923 100644
--- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
@@ -451,9 +451,9 @@ void tst_qdeclarativevisualdatamodel::modelProperties()
QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData");
QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData");
QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData");
- QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
- QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
- QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Cannot read property 'display' of undefined");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Cannot read property 'display' of undefined");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Cannot read property 'display' of undefined");
view.setSource(source);
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js
new file mode 100644
index 0000000000..5c4c5ec906
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.js
@@ -0,0 +1,6 @@
+WorkerScript.onMessage = function() {
+}
+for (var ii = 0; ii < 100; ++ii) {
+ var a = "HELLO WORLD";
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml
new file mode 100644
index 0000000000..d05918a074
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeworkerscript/data/stressDispose.qml
@@ -0,0 +1,13 @@
+import QtQuick 1.0
+
+Item {
+ WorkerScript {
+ id: worker
+ source: "stressDispose.js"
+ }
+
+ Component.onCompleted: {
+ worker.sendMessage(10);
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
index 66090ce7ff..2c85040f5f 100644
--- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
+++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp
@@ -53,8 +53,6 @@
#include <private/qdeclarativeengine_p.h>
#include "../../../shared/util.h"
-Q_DECLARE_METATYPE(QScriptValue)
-
#ifdef Q_OS_SYMBIAN
// In Symbian OS test data is located in applications private dir
#define SRCDIR "."
@@ -82,6 +80,7 @@ private slots:
void script_included();
void scriptError_onLoad();
void scriptError_onCall();
+ void stressDispose();
private:
void waitForEchoMessage(QDeclarativeWorkerScript *worker) {
@@ -191,13 +190,12 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject()
// QVariant roundtrip, since the properties will be stored in a QVariantMap.
QString jsObject = "{'haste': 1125, 'name': 'zyz', 'spell power': 3101}";
- QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(worker));
- QScriptValue sv = engine->newObject();
- sv.setProperty("haste", 1125);
- sv.setProperty("name", "zyz");
- sv.setProperty("spell power", 3101);
+ QVariantMap map;
+ map.insert("haste", 1125);
+ map.insert("name", "zyz");
+ map.insert("spell power", 3101);
- QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(sv))));
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, qVariantFromValue(map))));
waitForEchoMessage(worker);
QVariant result = qVariantFromValue(false);
@@ -261,7 +259,7 @@ void tst_QDeclarativeWorkerScript::scriptError_onLoad()
QVERIFY(worker != 0);
QTRY_COMPARE(qdeclarativeworkerscript_lastWarning,
- TEST_FILE("data/script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Parse error"));
+ TEST_FILE("data/script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Unexpected identifier"));
qInstallMsgHandler(previousMsgHandler);
qApp->processEvents();
@@ -286,6 +284,18 @@ void tst_QDeclarativeWorkerScript::scriptError_onCall()
delete worker;
}
+// Rapidly create and destroy worker scripts to test resources are being disposed
+// in the correct isolate
+void tst_QDeclarativeWorkerScript::stressDispose()
+{
+ for (int ii = 0; ii < 100; ++ii) {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, SRCDIR "/data/stressDispose.qml");
+ QObject *o = component.create();
+ QVERIFY(o);
+ delete o;
+ }
+}
QTEST_MAIN(tst_QDeclarativeWorkerScript)
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml
index 68f22f5f33..312292deaf 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/invalidMethodUsage.qml
@@ -1,7 +1,6 @@
import QtQuick 1.0
QtObject {
- property bool onreadystatechange: false
property bool readyState: false
property bool status: false
property bool statusText: false
@@ -19,17 +18,6 @@ QtObject {
var o = 10;
try {
- XMLHttpRequest.prototype.onreadystatechange
- } catch (e) {
- if (!(e instanceof ReferenceError))
- return;
-
- if (e.message != "Not an XMLHttpRequest object")
- return;
-
- onreadystatechange = true;
- }
- try {
XMLHttpRequest.prototype.readyState
} catch (e) {
if (!(e instanceof ReferenceError))
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
index aad68c5926..d2b7d5b50e 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
@@ -977,7 +977,6 @@ void tst_qdeclarativexmlhttprequest::invalidMethodUsage()
QObject *object = component.create();
QVERIFY(object != 0);
- QCOMPARE(object->property("onreadystatechange").toBool(), true);
QCOMPARE(object->property("readyState").toBool(), true);
QCOMPARE(object->property("status").toBool(), true);
QCOMPARE(object->property("statusText").toBool(), true);
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml b/tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml
new file mode 100644
index 0000000000..4e03503f90
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/get.qml
@@ -0,0 +1,61 @@
+import QtQuick 1.0
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "name/string()" }
+ XmlRole { name: "type"; query: "type/string()" }
+ XmlRole { name: "age"; query: "age/number()" }
+ XmlRole { name: "size"; query: "size/string()" }
+
+ id: root
+
+ property bool preTest: false
+ property bool postTest: false
+
+ function runPreTest() {
+ if (root.get(0) != undefined)
+ return;
+
+ preTest = true;
+ }
+
+ function runPostTest() {
+ if (root.get(-1) != undefined)
+ return;
+
+ var row = root.get(0);
+ if (row.name != "Polly" ||
+ row.type != "Parrot" ||
+ row.age != 12 ||
+ row.size != "Small")
+ return;
+
+ row = root.get(1);
+ if (row.name != "Penny" ||
+ row.type != "Turtle" ||
+ row.age != 4 ||
+ row.size != "Small")
+ return;
+
+ row = root.get(7);
+ if (row.name != "Rover" ||
+ row.type != "Dog" ||
+ row.age != 0 ||
+ row.size != "Large")
+ return;
+
+ row = root.get(8);
+ if (row.name != "Tiny" ||
+ row.type != "Elephant" ||
+ row.age != 15 ||
+ row.size != "Large")
+ return;
+
+ if (root.get(9) != undefined)
+ return;
+
+ postTest = true;
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index 7df2dc340d..37bafebdc4 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -520,40 +520,17 @@ void tst_qdeclarativexmllistmodel::data()
void tst_qdeclarativexmllistmodel::get()
{
- QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/get.qml"));
QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
QVERIFY(model != 0);
- QVERIFY(model->get(0).isUndefined());
+
+ QVERIFY(QMetaObject::invokeMethod(model, "runPreTest"));
+ QCOMPARE(model->property("preTest").toBool(), true);
QTRY_COMPARE(model->count(), 9);
- QVERIFY(model->get(-1).isUndefined());
-
- QScriptValue sv = model->get(0);
- QCOMPARE(sv.property("name").toString(), QLatin1String("Polly"));
- QCOMPARE(sv.property("type").toString(), QLatin1String("Parrot"));
- QCOMPARE(sv.property("age").toNumber(), qsreal(12));
- QCOMPARE(sv.property("size").toString(), QLatin1String("Small"));
-
- sv = model->get(1);
- QCOMPARE(sv.property("name").toString(), QLatin1String("Penny"));
- QCOMPARE(sv.property("type").toString(), QLatin1String("Turtle"));
- QCOMPARE(sv.property("age").toNumber(), qsreal(4));
- QCOMPARE(sv.property("size").toString(), QLatin1String("Small"));
-
- sv = model->get(7);
- QCOMPARE(sv.property("name").toString(), QLatin1String("Rover"));
- QCOMPARE(sv.property("type").toString(), QLatin1String("Dog"));
- QCOMPARE(sv.property("age").toNumber(), qsreal(0));
- QCOMPARE(sv.property("size").toString(), QLatin1String("Large"));
-
- sv = model->get(8);
- QCOMPARE(sv.property("name").toString(), QLatin1String("Tiny"));
- QCOMPARE(sv.property("type").toString(), QLatin1String("Elephant"));
- QCOMPARE(sv.property("age").toNumber(), qsreal(15));
- QCOMPARE(sv.property("size").toString(), QLatin1String("Large"));
-
- sv = model->get(9);
- QVERIFY(sv.isUndefined());
+
+ QVERIFY(QMetaObject::invokeMethod(model, "runPostTest"));
+ QCOMPARE(model->property("postTest").toBool(), true);
delete model;
}
diff --git a/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp b/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp
index 14c0ab2724..5b53a0f1b4 100644
--- a/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp
+++ b/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp
@@ -466,9 +466,9 @@ void tst_qsgvisualdatamodel::modelProperties()
QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData");
QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData");
QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData");
- QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
- QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
- QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined");
view.setSource(source);
diff --git a/tests/auto/declarative/v8/Makefile.nonqt b/tests/auto/declarative/v8/Makefile.nonqt
new file mode 100644
index 0000000000..20be72ea9b
--- /dev/null
+++ b/tests/auto/declarative/v8/Makefile.nonqt
@@ -0,0 +1,11 @@
+release-m32:
+ g++ -o v8test_release_m32 -m32 -O2 v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8
+
+debug-m32:
+ g++ -o v8test_debug_m32 -m32 -g v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8_g
+
+release:
+ g++ -o v8test_release -O2 v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8
+
+debug:
+ g++ -o v8test_debug -g v8main.cpp v8test.cpp -L../../../../src/3rdparty/v8/ -lv8_g
diff --git a/tests/auto/declarative/v8/README.txt b/tests/auto/declarative/v8/README.txt
new file mode 100644
index 0000000000..a5df6201be
--- /dev/null
+++ b/tests/auto/declarative/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/src/declarative/qml/qdeclarativelistscriptclass_p.h b/tests/auto/declarative/v8/tst_v8.cpp
index e6ea02e8eb..32d100e968 100644
--- a/src/declarative/qml/qdeclarativelistscriptclass_p.h
+++ b/tests/auto/declarative/v8/tst_v8.cpp
@@ -4,7 +4,7 @@
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
+** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
@@ -38,50 +38,42 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <qtest.h>
+#include "v8test.h"
-#ifndef QDECLARATIVELISTSCRIPTCLASS_P_H
-#define QDECLARATIVELISTSCRIPTCLASS_P_H
+using namespace v8;
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qscriptdeclarativeclass_p.h>
-#include "qdeclarativelist.h"
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeEngine;
-class QDeclarativeListScriptClass : public QScriptDeclarativeClass
+class tst_v8 : public QObject
{
+ Q_OBJECT
public:
- QDeclarativeListScriptClass(QDeclarativeEngine *);
- ~QDeclarativeListScriptClass();
+ tst_v8() {}
- QScriptValue newList(QObject *, int, int);
- QScriptValue newList(const QDeclarativeListProperty<QObject> &, int);
+private slots:
+ void initTestCase() {}
+ void cleanupTestCase() {}
-protected:
- virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
- QScriptClass::QueryFlags flags);
- virtual Value property(Object *, const Identifier &);
- virtual QVariant toVariant(Object *, bool *ok);
+ void eval();
+ void userobjectcompare();
+};
-private:
- PersistentIdentifier m_lengthId;
- QDeclarativeEngine *engine;
+void tst_v8::eval()
+{
+ QVERIFY(v8test_eval());
+}
- quint32 lastIndex;
-};
+void tst_v8::userobjectcompare()
+{
+ QVERIFY(v8test_userobjectcompare());
+}
-QT_END_NAMESPACE
+int main(int argc, char *argv[])
+{
+ V8::SetFlagsFromCommandLine(&argc, argv, true);
-#endif // QDECLARATIVELISTSCRIPTCLASS_P_H
+ QCoreApplication app(argc, argv);
+ tst_v8 tc;
+ return QTest::qExec(&tc, argc, argv);
+}
+#include "tst_v8.moc"
diff --git a/tests/auto/declarative/v8/v8.pro b/tests/auto/declarative/v8/v8.pro
new file mode 100644
index 0000000000..1030d174b6
--- /dev/null
+++ b/tests/auto/declarative/v8/v8.pro
@@ -0,0 +1,15 @@
+load(qttest_p4)
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_v8.cpp v8test.cpp
+HEADERS += v8test.h
+
+CONFIG += parallel_test
+
+LIBS += -L../../../../src/v8/
+macx:CONFIG(debug, debug|release) {
+ LIBS += -lv8_debug
+} else {
+ LIBS += -lv8
+}
+
diff --git a/tests/auto/declarative/v8/v8main.cpp b/tests/auto/declarative/v8/v8main.cpp
new file mode 100644
index 0000000000..5930f53f90
--- /dev/null
+++ b/tests/auto/declarative/v8/v8main.cpp
@@ -0,0 +1,17 @@
+#include "v8test.h"
+#include <stdio.h>
+
+#define RUN_TEST(testname) { \
+ if (!v8test_ ## testname()) \
+ printf ("Test %s FAILED\n", # testname); \
+}
+
+int main(int argc, char *argv[])
+{
+ v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+
+ RUN_TEST(eval);
+ RUN_TEST(userobjectcompare);
+
+ return -1;
+}
diff --git a/tests/auto/declarative/v8/v8test.cpp b/tests/auto/declarative/v8/v8test.cpp
new file mode 100644
index 0000000000..27d39c5970
--- /dev/null
+++ b/tests/auto/declarative/v8/v8test.cpp
@@ -0,0 +1,254 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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; \
+ } \
+}
+
+
+bool v8test_eval()
+{
+ BEGINTEST();
+
+ HandleScope handle_scope;
+ Persistent<Context> context = Context::New();
+ Context::Scope context_scope(context);
+
+ Local<Object> qmlglobal = Object::New();
+ qmlglobal->Set(String::New("a"), Integer::New(1922));
+
+ Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL,
+ Handle<String>(), Script::QmlMode);
+
+ TryCatch tc;
+ Local<Value> result = script->Run(qmlglobal);
+
+ VERIFY(!tc.HasCaught());
+ VERIFY(result->Int32Value() == 1922);
+
+cleanup:
+ context.Dispose();
+
+ ENDTEST();
+}
+
+static int userObjectComparisonCalled = 0;
+static bool userObjectComparisonReturn = false;
+static Local<Object> expectedLhs;
+static Local<Object> expectedRhs;
+static bool expectedObjectsCompared = false;
+
+#define SET_EXPECTED(lhs, rhs) { \
+ expectedObjectsCompared = false; \
+ expectedLhs = lhs; \
+ expectedRhs = rhs; \
+}
+
+static bool UserObjectComparison(Local<Object> lhs, Local<Object> rhs)
+{
+ userObjectComparisonCalled++;
+
+ expectedObjectsCompared = (lhs == expectedLhs && rhs == expectedRhs);
+
+ return userObjectComparisonReturn;
+}
+
+inline bool runscript(const char *source) {
+ Local<Script> script = Script::Compile(String::New(source));
+ Local<Value> result = script->Run();
+ return result->BooleanValue();
+}
+
+bool v8test_userobjectcompare()
+{
+ BEGINTEST();
+
+ HandleScope handle_scope;
+ Persistent<Context> context = Context::New();
+ Context::Scope context_scope(context);
+
+ V8::SetUserObjectComparisonCallbackFunction(UserObjectComparison);
+
+ Local<ObjectTemplate> ot = ObjectTemplate::New();
+ ot->MarkAsUseUserObjectComparison();
+
+ Local<Object> uoc1 = ot->NewInstance();
+ Local<Object> uoc2 = ot->NewInstance();
+ context->Global()->Set(String::New("uoc1a"), uoc1);
+ context->Global()->Set(String::New("uoc1b"), uoc1);
+ context->Global()->Set(String::New("uoc2"), uoc2);
+ Local<Object> obj1 = Object::New();
+ context->Global()->Set(String::New("obj1a"), obj1);
+ context->Global()->Set(String::New("obj1b"), obj1);
+ context->Global()->Set(String::New("obj2"), Object::New());
+ Local<String> string1 = String::New("Hello World");
+ context->Global()->Set(String::New("string1a"), string1);
+ context->Global()->Set(String::New("string1b"), string1);
+ context->Global()->Set(String::New("string2"), v8::String::New("Goodbye World"));
+
+ // XXX Opportunity for optimization - don't invoke user callback if objects are
+ // equal.
+#if 0
+ userObjectComparisonCalled = 0; userObjectComparisonReturn = false;
+ VERIFY(true == runscript("uoc1a == uoc1b"));
+ VERIFY(userObjectComparisonCalled == 0);
+#endif
+
+ // Comparing two uoc objects invokes uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ VERIFY(false == runscript("uoc1a == uoc2"));
+ VERIFY(userObjectComparisonCalled == 1);
+
+ VERIFY(false == runscript("uoc2 == uoc1a"));
+ VERIFY(userObjectComparisonCalled == 2);
+ userObjectComparisonReturn = true;
+ VERIFY(true == runscript("uoc1a == uoc2"));
+ VERIFY(userObjectComparisonCalled == 3);
+ VERIFY(true == runscript("uoc2 == uoc1a"));
+ VERIFY(userObjectComparisonCalled == 4);
+
+ // != on two uoc object invokes uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ VERIFY(true == runscript("uoc1a != uoc2"));
+ VERIFY(userObjectComparisonCalled == 1);
+ VERIFY(true == runscript("uoc2 != uoc1a"));
+ VERIFY(userObjectComparisonCalled == 2);
+ userObjectComparisonReturn = true;
+ VERIFY(false == runscript("uoc1a != uoc2"));
+ VERIFY(userObjectComparisonCalled == 3);
+ VERIFY(false == runscript("uoc2 != uoc1a"));
+ VERIFY(userObjectComparisonCalled == 4);
+
+ // Comparison against a non-object doesn't invoke uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ VERIFY(false == runscript("uoc1a == string1a"));
+ VERIFY(userObjectComparisonCalled == 0);
+ VERIFY(false == runscript("string1a == uoc1a"));
+ VERIFY(userObjectComparisonCalled == 0);
+ VERIFY(false == runscript("2 == uoc1a"));
+ VERIFY(userObjectComparisonCalled == 0);
+ VERIFY(true == runscript("uoc1a != string1a"));
+ VERIFY(userObjectComparisonCalled == 0);
+ VERIFY(true == runscript("string1a != uoc1a"));
+ VERIFY(userObjectComparisonCalled == 0);
+ VERIFY(true == runscript("2 != uoc1a"));
+ VERIFY(userObjectComparisonCalled == 0);
+
+ // Comparison against a non-uoc-object still invokes uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ VERIFY(false == runscript("uoc1a == obj1a"));
+ VERIFY(userObjectComparisonCalled == 1);
+ VERIFY(false == runscript("obj1a == uoc1a"));
+ VERIFY(userObjectComparisonCalled == 2);
+ userObjectComparisonReturn = true;
+ VERIFY(true == runscript("uoc1a == obj1a"));
+ VERIFY(userObjectComparisonCalled == 3);
+ VERIFY(true == runscript("obj1a == uoc1a"));
+ VERIFY(userObjectComparisonCalled == 4);
+
+ // != comparison against a non-uoc-object still invokes uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ VERIFY(true == runscript("uoc1a != obj1a"));
+ VERIFY(userObjectComparisonCalled == 1);
+ VERIFY(true == runscript("obj1a != uoc1a"));
+ VERIFY(userObjectComparisonCalled == 2);
+ userObjectComparisonReturn = true;
+ VERIFY(false == runscript("uoc1a != obj1a"));
+ VERIFY(userObjectComparisonCalled == 3);
+ VERIFY(false == runscript("obj1a != uoc1a"));
+ VERIFY(userObjectComparisonCalled == 4);
+
+ // Comparing two non-uoc objects does not invoke uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ VERIFY(true == runscript("obj1a == obj1a"));
+ VERIFY(true == runscript("obj1a == obj1b"));
+ VERIFY(false == runscript("obj1a == obj2"));
+ VERIFY(false == runscript("obj1a == string1a"));
+ VERIFY(true == runscript("string1a == string1a"));
+ VERIFY(true == runscript("string1a == string1b"));
+ VERIFY(false == runscript("string1a == string2"));
+ VERIFY(userObjectComparisonCalled == 0);
+
+ // Correct lhs and rhs passed to uoc
+ userObjectComparisonCalled = 0;
+ userObjectComparisonReturn = false;
+ SET_EXPECTED(uoc1, uoc2);
+ VERIFY(false == runscript("uoc1a == uoc2"));
+ VERIFY(true == expectedObjectsCompared);
+ SET_EXPECTED(uoc2, uoc1);
+ VERIFY(false == runscript("uoc2 == uoc1a"));
+ VERIFY(true == expectedObjectsCompared);
+ SET_EXPECTED(uoc1, uoc2);
+ VERIFY(true == runscript("uoc1a != uoc2"));
+ VERIFY(true == expectedObjectsCompared);
+ SET_EXPECTED(uoc2, uoc1);
+ VERIFY(true == runscript("uoc2 != uoc1a"));
+ VERIFY(true == expectedObjectsCompared);
+ SET_EXPECTED(uoc1, obj1);
+ VERIFY(false == runscript("uoc1a == obj1a"));
+ VERIFY(true == expectedObjectsCompared);
+ SET_EXPECTED(obj1, uoc1);
+ VERIFY(false == runscript("obj1a == uoc1a"));
+ VERIFY(true == expectedObjectsCompared);
+
+cleanup:
+ V8::SetUserObjectComparisonCallbackFunction(0);
+ context.Dispose();
+
+ ENDTEST();
+}
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/tests/auto/declarative/v8/v8test.h
index 9aee1d7e3a..31acefc8b3 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
+++ b/tests/auto/declarative/v8/v8test.h
@@ -4,7 +4,7 @@
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
+** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
@@ -39,48 +39,13 @@
**
****************************************************************************/
-#ifndef QDECLARATIVEGLOBALSCRIPTCLASS_P_H
-#define QDECLARATIVEGLOBALSCRIPTCLASS_P_H
+#ifndef V8TEST_H
+#define V8TEST_H
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
+#include "../../../../src/3rdparty/v8/include/v8.h"
-#include <QtScript/qscriptclass.h>
-#include <QtCore/qset.h>
+bool v8test_eval();
+bool v8test_userobjectcompare();
-QT_BEGIN_NAMESPACE
+#endif // V8TEST_H
-class Q_AUTOTEST_EXPORT QDeclarativeGlobalScriptClass : public QScriptClass
-{
-public:
- QDeclarativeGlobalScriptClass(QScriptEngine *);
-
- virtual QueryFlags queryProperty(const QScriptValue &object,
- const QScriptString &name,
- QueryFlags flags, uint *id);
-
- virtual void setProperty(QScriptValue &object, const QScriptString &name,
- uint id, const QScriptValue &value);
-
- void explicitSetProperty(const QStringList &, const QList<QScriptValue> &);
-
- const QScriptValue &staticGlobalObject() const { return m_staticGlobalObject; }
-
- const QSet<QString> &illegalNames() const { return m_illegalNames; }
-
-private:
- QSet<QString> m_illegalNames;
- QScriptValue m_staticGlobalObject;
-};
-
-QT_END_NAMESPACE
-
-#endif // QDECLARATIVEGLOBALSCRIPTCLASS_P_H