Bug 775317. Add a test for the JSOPTION_VAROBJFIX behavior of JS_EvaluateScript. r=jorendorff
☠☠ backed out by ad5866c81a03 ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 21 Jul 2012 22:37:43 -0400
changeset 105529 f142f32a98a3849089b235818a1ed359d633084c
parent 105528 ef14686c31d02a1f6ffc456d5599eb7b0dc5a7d5
child 105530 ad5866c81a03d90889d2369ad83884e20c0be8c7
push idunknown
push userunknown
push dateunknown
reviewersjorendorff
bugs775317
milestone17.0a1
Bug 775317. Add a test for the JSOPTION_VAROBJFIX behavior of JS_EvaluateScript. r=jorendorff
js/src/jsapi-tests/Makefile.in
js/src/jsapi-tests/testJSEvaluateScript.cpp
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -59,16 +59,17 @@ CPPSRCS = \
   testStringBuffer.cpp \
   testTrap.cpp \
   testTypedArrays.cpp \
   testUTF8.cpp \
   testValueABI.cpp \
   testVersion.cpp \
   testXDR.cpp \
   testProfileStrings.cpp \
+  testJSEvaluateScript.cpp \
   $(NULL)
 
 CSRCS = \
   valueABI.c
 
 # Disabled: an entirely unrelated test seems to cause this to fail.  Moreover,
 # given the test's dependence on interactions between the compiler, the GC, and
 # conservative stack scanning, the fix isn't obvious: more investigation
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/testJSEvaluateScript.cpp
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sw=4 et tw=99:
+ */
+
+#include "tests.h"
+
+BEGIN_TEST(testJSEvaluateScript)
+{
+    jsvalRoot proto(cx);
+    JSObject *obj = JS_NewObject(cx, NULL, NULL, global);
+    CHECK(obj);
+
+    uint32_t options = JS_GetOptions(cx);
+    CHECK(options & JSOPTION_VAROBJFIX);
+
+    static const char src[] = "var x = 5;";
+
+    JS::Value retval;
+    CHECK(JS_EvaluateScript(cx, obj, src, sizeof(src) - 1, __FILE__, __LINE__,
+                            &retval));
+
+    JSBool hasProp = JS_TRUE;
+    CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
+    CHECK(!hasProp);
+
+    hasProp = JS_FALSE;
+    CHECK(JS_HasProperty(cx, global, "x", &hasProp));
+    CHECK(hasProp);
+
+    // Now do the same thing, but without JSOPTION_VAROBJFIX
+    JS_SetOptions(cx, options & ~JSOPTION_VAROBJFIX);
+
+    static const char src2[] = "var y = 5;";
+
+    CHECK(JS_EvaluateScript(cx, obj, src2, sizeof(src2) - 1, __FILE__, __LINE__,
+                            &retval));
+
+    hasProp = JS_FALSE;
+    CHECK(JS_AlreadyHasOwnProperty(cx, obj, "y", &hasProp));
+    CHECK(hasProp);
+
+    hasProp = JS_TRUE;
+    CHECK(JS_AlreadyHasOwnProperty(cx, global, "y", &hasProp));
+    CHECK(!hasProp);
+
+    return true;
+}
+END_TEST(testJSEvaluateScript)
+
+