1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testJSEvaluateScript.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + */ 1.7 + 1.8 +#include "jsapi-tests/tests.h" 1.9 + 1.10 +BEGIN_TEST(testJSEvaluateScript) 1.11 +{ 1.12 + JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), global)); 1.13 + CHECK(obj); 1.14 + 1.15 + CHECK(JS::ContextOptionsRef(cx).varObjFix()); 1.16 + 1.17 + static const char src[] = "var x = 5;"; 1.18 + 1.19 + JS::RootedValue retval(cx); 1.20 + CHECK(JS_EvaluateScript(cx, obj, src, sizeof(src) - 1, __FILE__, __LINE__, &retval)); 1.21 + 1.22 + bool hasProp = true; 1.23 + CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp)); 1.24 + CHECK(!hasProp); 1.25 + 1.26 + hasProp = false; 1.27 + CHECK(JS_HasProperty(cx, global, "x", &hasProp)); 1.28 + CHECK(hasProp); 1.29 + 1.30 + // Now do the same thing, but without JSOPTION_VAROBJFIX 1.31 + JS::ContextOptionsRef(cx).setVarObjFix(false); 1.32 + 1.33 + static const char src2[] = "var y = 5;"; 1.34 + 1.35 + CHECK(JS_EvaluateScript(cx, obj, src2, sizeof(src2) - 1, __FILE__, __LINE__, &retval)); 1.36 + 1.37 + hasProp = false; 1.38 + CHECK(JS_AlreadyHasOwnProperty(cx, obj, "y", &hasProp)); 1.39 + CHECK(hasProp); 1.40 + 1.41 + hasProp = true; 1.42 + CHECK(JS_AlreadyHasOwnProperty(cx, global, "y", &hasProp)); 1.43 + CHECK(!hasProp); 1.44 + 1.45 + return true; 1.46 +} 1.47 +END_TEST(testJSEvaluateScript) 1.48 + 1.49 +