Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
r12374 committed - Test case for conflicting global declarations across multiple scripts....
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
codesite-nore...@google.com  
View profile   Translate to Translated (View Original)
 More options Aug 23 2012, 12:38 pm
From: codesite-nore...@google.com
Date: Thu, 23 Aug 2012 16:38:26 +0000
Local: Thurs, Aug 23 2012 12:38 pm
Subject: [v8] r12374 committed - Test case for conflicting global declarations across multiple scripts....
Revision: 12374
Author:   rossb...@chromium.org
Date:     Thu Aug 23 09:38:15 2012
Log:      Test case for conflicting global declarations across multiple  
scripts.

R=u...@chromium.org
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10872037
http://code.google.com/p/v8/source/detail?r=12374

Modified:
  /branches/bleeding_edge/test/cctest/test-decls.cc

=======================================
--- /branches/bleeding_edge/test/cctest/test-decls.cc   Thu Jun 21 04:31:30  
2012
+++ /branches/bleeding_edge/test/cctest/test-decls.cc   Thu Aug 23 09:38:15  
2012
@@ -37,7 +37,8 @@

  enum Expectations {
    EXPECT_RESULT,
-  EXPECT_EXCEPTION
+  EXPECT_EXCEPTION,
+  EXPECT_ERROR
  };

@@ -95,7 +96,6 @@
   private:
    bool is_initialized_;
    Persistent<Context> context_;
-  Local<String> property_;

    int get_count_;
    int set_count_;
@@ -139,7 +139,13 @@
    HandleScope scope;
    TryCatch catcher;
    catcher.SetVerbose(true);
-  Local<Value> result = Script::Compile(String::New(source))->Run();
+  Local<Script> script = Script::Compile(String::New(source));
+  if (expectations == EXPECT_ERROR) {
+    CHECK(script.IsEmpty());
+    return;
+  }
+  CHECK(!script.IsEmpty());
+  Local<Value> result = script->Run();
    CHECK_EQ(get, get_count());
    CHECK_EQ(set, set_count());
    CHECK_EQ(query, query_count());
@@ -681,3 +687,214 @@
                    EXPECT_RESULT, Number::New(0));
    }
  }
+
+
+
+class SimpleContext {
+ public:
+  SimpleContext() {
+    context_ = Context::New(0);
+    context_->Enter();
+  }
+
+  virtual ~SimpleContext() {
+    context_->Exit();
+    context_.Dispose();
+  }
+
+  void Check(const char* source,
+             Expectations expectations,
+             v8::Handle<Value> value = Local<Value>()) {
+    HandleScope scope;
+    TryCatch catcher;
+    catcher.SetVerbose(true);
+    Local<Script> script = Script::Compile(String::New(source));
+    if (expectations == EXPECT_ERROR) {
+      CHECK(script.IsEmpty());
+      return;
+    }
+    CHECK(!script.IsEmpty());
+    Local<Value> result = script->Run();
+    if (expectations == EXPECT_RESULT) {
+      CHECK(!catcher.HasCaught());
+      if (!value.IsEmpty()) {
+        CHECK_EQ(value, result);
+      }
+    } else {
+      CHECK(expectations == EXPECT_EXCEPTION);
+      CHECK(catcher.HasCaught());
+      if (!value.IsEmpty()) {
+        CHECK_EQ(value, catcher.Exception());
+      }
+    }
+  }
+
+ private:
+  Persistent<Context> context_;
+};
+
+
+TEST(MultiScriptConflicts) {
+  HandleScope scope;
+
+  { SimpleContext context;
+    context.Check("var x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("var x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+    context.Check("const x = 3; x",
+                  EXPECT_RESULT, Number::New(3));
+    context.Check("const x = 4; x",
+                  EXPECT_RESULT, Number::New(4));
+    context.Check("x = 5; x",
+                  EXPECT_RESULT, Number::New(5));
+    context.Check("var x = 6; x",
+                  EXPECT_RESULT, Number::New(6));
+    context.Check("this.x",
+                  EXPECT_RESULT, Number::New(6));
+    context.Check("function x() { return 7 }; x()",
+                  EXPECT_RESULT, Number::New(7));
+  }
+
+  { SimpleContext context;
+    context.Check("const x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("var x = 2; x",  // assignment ignored
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("const x = 3; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("x = 4; x",  // assignment ignored
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("var x = 5; x",  // assignment ignored
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("this.x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("function x() { return 7 }; x",
+                  EXPECT_EXCEPTION);
+  }
+
+  i::FLAG_use_strict = true;
+  i::FLAG_harmony_scoping = true;
+
+  { SimpleContext context;
+    context.Check("var x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("this.x",
+                  EXPECT_RESULT, Number::New(1));
+  }
+
+  { SimpleContext context;
+    context.Check("let x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+    context.Check("x",
+                  EXPECT_RESULT, Number::New(2));
+    context.Check("this.x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("const x = 3; x",
+                  EXPECT_RESULT, Number::New(3));
+    context.Check("x",
+                  EXPECT_RESULT, Number::New(3));
+    context.Check("this.x",
+                  EXPECT_RESULT, Number::New(3));
+  }
+
+  { SimpleContext context;
+    context.Check("function x() { return 4 }; x()",
+                  EXPECT_RESULT, Number::New(4));
+    context.Check("x()",
+                  EXPECT_RESULT, Number::New(4));
+    context.Check("this.x()",
+                  EXPECT_RESULT, Number::New(4));
+  }
+
+  // TODO(rossberg): All of the below should actually be errors in Harmony.
+
+  { SimpleContext context;
+    context.Check("var x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("let x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("var x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("const x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("function x() { return 1 }; x()",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("let x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("function x() { return 1 }; x()",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("const x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("let x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("var x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("let x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("let x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("let x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("const x = 2; x",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("let x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("function x() { return 2 }; x()",
+                  EXPECT_RESULT, Number::New(2));
+  }
+
+  { SimpleContext context;
+    context.Check("const x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("var x = 2; x",
+                  EXPECT_RESULT, Number::New(1));
+  }
+
+  { SimpleContext context;
+    context.Check("const x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("let x = 2; x",
+                  EXPECT_EXCEPTION);
+  }
+
+  { SimpleContext context;
+    context.Check("const x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("const x = 2; x",
+                  EXPECT_RESULT, Number::New(1));
+  }
+
+  { SimpleContext context;
+    context.Check("const x = 1; x",
+                  EXPECT_RESULT, Number::New(1));
+    context.Check("function x() { return 2 }; x()",
+                  EXPECT_EXCEPTION);
+  }
+}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »