Ticket #2241: FixSpidermonkeyWrappers_v1.1.diff​

File FixSpidermonkeyWrappers_v1.1.diff​, 3.8 KB (added by Yves, 10 years ago)

This version adds an error at compile-time to inform about the need to patch Spidermonkey

Line 
1Index: source/scriptinterface/ScriptExtraHeaders.h
2===================================================================
3--- source/scriptinterface/ScriptExtraHeaders.h (Revision 14215)
4+++ source/scriptinterface/ScriptExtraHeaders.h (Arbeitskopie)
5@@ -62,4 +62,14 @@
6 # endif
7 #endif
8
9+/*
10+ * The official version of the SpiderMonkey 1.8.5 library has a bug when cloning objects with wrappers.
11+ * https://bugzilla.mozilla.org/show_bug.cgi?id=667388
12+ *
13+ * 0 A.D. will not work properly if this bug is not fixed in your version of the SpiderMonkey library!
14+ * Check this link for background information and information about how to solve the problem.
15+ * http://trac.wildfiregames.com/ticket/2241
16+ */
17+cassert(FIX_FOR_CLONING_WRAPPERS_APPLIED);
18+
19 #endif // INCLUDED_SCRIPTEXTRAHEADERS
20Index: libraries/source/spidermonkey/build.sh
21===================================================================
22--- libraries/source/spidermonkey/build.sh (Revision 14215)
23+++ libraries/source/spidermonkey/build.sh (Arbeitskopie)
24@@ -50,6 +50,7 @@
25 # Apply patches
26 patch -p0 < openbsd-spidermonkey-650742.diff
27 patch -p0 < openbsd-spidermonkey-634609.diff
28+patch -p0 < wrapper-patch.diff
29
30 cd js-1.8.5/js/src
31
32Index: libraries/source/spidermonkey/wrapper-patch.diff
33===================================================================
34--- libraries/source/spidermonkey/wrapper-patch.diff (Revision 0)
35+++ libraries/source/spidermonkey/wrapper-patch.diff (Arbeitskopie)
36@@ -0,0 +1,67 @@
37+--- js-1.8.5/js/src/jsversion.h 2013-11-17 12:08:26.068159175 +0100
38++++ js-1.8.5/js/src/jsversion.h 2013-11-21 19:09:57.536779617 +0100
39+@@ -219,3 +219,12 @@
40+ * support likely to be made opt-in at some future time.
41+ */
42+ #define OLD_GETTER_SETTER_METHODS 1
43++
44++/*
45++ * The official version of the SpiderMonkey 1.8.5 library has a bug when cloning objects with wrappers.
46++ * https://bugzilla.mozilla.org/show_bug.cgi?id=667388
47++ * Users of the library can check for FIX_FOR_CLONING_WRAPPERS_APPLIED to inform package maintainers
48++ * and people who compile from source that this fix is required for the software to work properly
49++ * (with static_assert or something similar).
50++ */
51++#define FIX_FOR_CLONING_WRAPPERS_APPLIED 1
52+--- js-1.8.5/js/src/jsclone.cpp
53++++ js-1.8.5/js/src/jsclone.cpp
54+@@ -40,6 +40,7 @@
55+ #include "jsdate.h"
56+ #include "jsregexp.h"
57+ #include "jstypedarray.h"
58++#include "jswrapper.h"
59+
60+ #include "jsregexpinlines.h"
61+
62+@@ -503,6 +504,8 @@
63+ bool
64+ JSStructuredCloneWriter::startWrite(const js::Value &v)
65+ {
66++ assertSameCompartment(context(), v);
67++
68+ if (v.isString()) {
69+ return writeString(SCTAG_STRING, v.toString());
70+ } else if (v.isNumber()) {
71+@@ -515,6 +518,19 @@
72+ return out.writePair(SCTAG_UNDEFINED, 0);
73+ } else if (v.isObject()) {
74+ JSObject *obj = &v.toObject();
75++
76++ // The object might be a security wrapper. See if we can clone what's
77++ // behind it. If we can, unwrap the object.
78++ obj = JS_UnwrapObject(context(), obj);
79++ if (!obj)
80++ return false;
81++
82++ // If we unwrapped above, we'll need to enter the underlying compartment.
83++ // Let the AutoEnterCompartment do the right thing for us.
84++ JSAutoEnterCompartment ac;
85++ if (!ac.enter(context(), obj))
86++ return false;
87++
88+ if (obj->isRegExp()) {
89+ RegExp *re = RegExp::extractFrom(obj);
90+ return out.writePair(SCTAG_REGEXP_OBJECT, re->getFlags()) &&
91+@@ -554,6 +570,12 @@
92+
93+ while (!counts.empty()) {
94+ JSObject *obj = &objs.back().toObject();
95++
96++ // The objects in |obj| can live in other compartments.
97++ JSAutoEnterCompartment ac;
98++ if (!ac.enter(context(), obj))
99++ return false;
100++
101+ if (counts.back()) {
102+ counts.back()--;
103+ jsid id = ids.back();