Chromium Code Reviews| 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..8a78af41fd2c49bf875f1f95dfec2255a6b6463a 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,51 @@ 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')"); |
| + // ExpectTrue("global2.hasOwnProperty('42')"); |
|
Toon Verwaest
2015/10/05 11:14:32
Leftover tests?
|
| + // ExpectTrue("global2.hasOwnProperty('a')"); |
| + |
| + // Hold on to global from env2 and detach global from env2. |
| + // Local<v8::Object> global2 = env2->Global(); |
| + 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()); |
| +} |