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

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

Issue 1378323003: [runtime-object]: part fix element key list on global object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixing nits Created 5 years, 2 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 | « src/runtime/runtime-object.cc ('k') | test/mjsunit/global-properties.js » ('j') | 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/cctest/test-global-object.cc b/test/cctest/test-global-object.cc
index 9cc755e4e1dd2b06f23d02a4709bf2f9c65408c3..c696086061b8d2331db733922cc90d67a5852202 100644
--- a/test/cctest/test-global-object.cc
+++ b/test/cctest/test-global-object.cc
@@ -25,10 +25,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include "src/api.h"
#include "src/v8.h"
-
#include "test/cctest/cctest.h"
+using ::v8::Array;
+using ::v8::Context;
+using ::v8::Local;
+using ::v8::Value;
+
// This test fails if properties on the prototype of the global object appear
// as declared globals.
TEST(StrictUndeclaredGlobalVariable) {
@@ -47,3 +52,48 @@ TEST(StrictUndeclaredGlobalVariable) {
v8::String::Utf8Value exception(try_catch.Exception());
CHECK_EQ(0, strcmp("ReferenceError: x is not defined", *exception));
}
+
+
+TEST(KeysGlobalObject_Regress2764) {
+ LocalContext env1;
+ v8::HandleScope scope(env1->GetIsolate());
+
+ // Create second environment.
+ v8::Handle<Context> env2 = Context::New(env1->GetIsolate());
+
+ Local<Value> token = v8_str("foo");
+
+ // Set same security token for env1 and env2.
+ env1->SetSecurityToken(token);
+ env2->SetSecurityToken(token);
+
+ // Create a reference to env2 global from env1 global.
+ env1->Global()->Set(v8_str("global2"), env2->Global());
+ // Set some global variables in global2
+ env2->Global()->Set(v8_str("a"), v8_str("a"));
+ env2->Global()->Set(v8_str("42"), v8_str("42"));
+
+ // List all entries from global2.
+ Local<Array> result;
+ result = Local<Array>::Cast(CompileRun("Object.keys(global2)"));
+ CHECK_EQ(2u, result->Length());
+ CHECK(v8_str("42")->Equals(result->Get(0)));
+ CHECK(v8_str("a")->Equals(result->Get(1)));
+
+ result =
+ Local<Array>::Cast(CompileRun("Object.getOwnPropertyNames(global2)"));
+ CHECK_LT(2u, result->Length());
+ // Check that all elements are in the property names
+ ExpectTrue("-1 < Object.getOwnPropertyNames(global2).indexOf('42')");
+ ExpectTrue("-1 < Object.getOwnPropertyNames(global2).indexOf('a')");
+
+ // Hold on to global from env2 and detach global from env2.
+ env2->DetachGlobal();
+
+ // List again all entries from the detached global2.
+ result = Local<Array>::Cast(CompileRun("Object.keys(global2)"));
+ CHECK_EQ(0u, result->Length());
+ result =
+ Local<Array>::Cast(CompileRun("Object.getOwnPropertyNames(global2)"));
+ CHECK_EQ(0u, result->Length());
+}
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/global-properties.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698