Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: test/cctest/test-global-object.cc

Issue 12040039: Always fail when trying to store to an undeclared global variable, even if it was found. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-global-object.cc
diff --git a/test/mjsunit/regress/regress-2499.js b/test/cctest/test-global-object.cc
similarity index 65%
copy from test/mjsunit/regress/regress-2499.js
copy to test/cctest/test-global-object.cc
index 52aad874db6fcdc89f5ee1ae4db45304e64b0e77..049b53d117b61f7b918fca9e6e368aca6520ebb7 100644
--- a/test/mjsunit/regress/regress-2499.js
+++ b/test/cctest/test-global-object.cc
@@ -25,16 +25,29 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --allow-natives-syntax
+#include "v8.h"
-function foo(word, nBits) {
- return (word[1] >>> nBits) | (word[0] << (32 - nBits));
-}
+#include "cctest.h"
-word = [0x1001, 0];
+using namespace v8;
-var expected = foo(word, 1);
-foo(word, 1);
-%OptimizeFunctionOnNextCall(foo);
-var optimized = foo(word, 1);
-assertEquals(expected, optimized)
+// This test fails if properties on the prototype of the global object appear
+// as declared globals.
+TEST(StrictUndeclaredGlobalVariable) {
+ HandleScope scope;
+ v8::Local<v8::String> var_name = v8_str("x");
+ v8::Local<v8::String> result_name = v8_str("z");
+ LocalContext context;
+ v8::Local<v8::Script> script =
+ v8_compile("\"use strict\";"
+ "var z;"
+ "try { x = 42; z = 10; } catch (e) { z = 20; };");
Jakob Kummerow 2013/01/23 15:51:25 Would be nice to assert that we're getting the rig
Toon Verwaest 2013/01/23 16:03:53 Done.
+ v8::Handle<v8::Object> proto = v8::Object::New();
+ v8::Handle<v8::Object> global =
+ context->Global()->GetPrototype().As<v8::Object>();
+ proto->Set(var_name, v8_num(100));
+ global->SetPrototype(proto);
+ script->Run();
+ v8::Local<v8::Value> result = context->Global()->Get(result_name);
+ CHECK_EQ(20, result->Int32Value());
+}
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698