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

Side by Side Diff: test/cctest/test-global-object.cc

Issue 1449393002: Remove deprecated functions the smaller half of the remaing tests (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « test/cctest/test-global-handles.cc ('k') | test/cctest/test-javascript-arm64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // TODO(jochen): Remove this after the setting is turned on globally.
29 #define V8_IMMINENT_DEPRECATION_WARNINGS
30
28 #include "src/api.h" 31 #include "src/api.h"
29 #include "src/v8.h" 32 #include "src/v8.h"
30 #include "test/cctest/cctest.h" 33 #include "test/cctest/cctest.h"
31 34
32 using ::v8::Array; 35 using ::v8::Array;
33 using ::v8::Context; 36 using ::v8::Context;
34 using ::v8::Local; 37 using ::v8::Local;
35 using ::v8::Value; 38 using ::v8::Value;
36 39
37 // This test fails if properties on the prototype of the global object appear 40 // This test fails if properties on the prototype of the global object appear
38 // as declared globals. 41 // as declared globals.
39 TEST(StrictUndeclaredGlobalVariable) { 42 TEST(StrictUndeclaredGlobalVariable) {
40 v8::HandleScope scope(CcTest::isolate()); 43 v8::HandleScope scope(CcTest::isolate());
41 v8::Local<v8::String> var_name = v8_str("x"); 44 v8::Local<v8::String> var_name = v8_str("x");
42 LocalContext context; 45 LocalContext context;
43 v8::TryCatch try_catch(CcTest::isolate()); 46 v8::TryCatch try_catch(CcTest::isolate());
44 v8::Local<v8::Script> script = v8_compile("\"use strict\"; x = 42;"); 47 v8::Local<v8::Script> script = v8_compile("\"use strict\"; x = 42;");
45 v8::Handle<v8::Object> proto = v8::Object::New(CcTest::isolate()); 48 v8::Local<v8::Object> proto = v8::Object::New(CcTest::isolate());
46 v8::Handle<v8::Object> global = 49 v8::Local<v8::Object> global =
47 context->Global()->GetPrototype().As<v8::Object>(); 50 context->Global()->GetPrototype().As<v8::Object>();
48 proto->Set(var_name, v8_num(100)); 51 proto->Set(context.local(), var_name, v8_num(100)).FromJust();
49 global->SetPrototype(proto); 52 global->SetPrototype(context.local(), proto).FromJust();
50 script->Run(); 53 CHECK(script->Run(context.local()).IsEmpty());
51 CHECK(try_catch.HasCaught()); 54 CHECK(try_catch.HasCaught());
52 v8::String::Utf8Value exception(try_catch.Exception()); 55 v8::String::Utf8Value exception(try_catch.Exception());
53 CHECK_EQ(0, strcmp("ReferenceError: x is not defined", *exception)); 56 CHECK_EQ(0, strcmp("ReferenceError: x is not defined", *exception));
54 } 57 }
55 58
56 59
57 TEST(KeysGlobalObject_Regress2764) { 60 TEST(KeysGlobalObject_Regress2764) {
58 LocalContext env1; 61 LocalContext env1;
59 v8::HandleScope scope(env1->GetIsolate()); 62 v8::HandleScope scope(env1->GetIsolate());
60 63
61 // Create second environment. 64 // Create second environment.
62 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 65 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
63 66
64 Local<Value> token = v8_str("foo"); 67 Local<Value> token = v8_str("foo");
65 68
66 // Set same security token for env1 and env2. 69 // Set same security token for env1 and env2.
67 env1->SetSecurityToken(token); 70 env1->SetSecurityToken(token);
68 env2->SetSecurityToken(token); 71 env2->SetSecurityToken(token);
69 72
70 // Create a reference to env2 global from env1 global. 73 // Create a reference to env2 global from env1 global.
71 env1->Global()->Set(v8_str("global2"), env2->Global()); 74 env1->Global()
75 ->Set(env1.local(), v8_str("global2"), env2->Global())
76 .FromJust();
72 // Set some global variables in global2 77 // Set some global variables in global2
73 env2->Global()->Set(v8_str("a"), v8_str("a")); 78 env2->Global()->Set(env2, v8_str("a"), v8_str("a")).FromJust();
74 env2->Global()->Set(v8_str("42"), v8_str("42")); 79 env2->Global()->Set(env2, v8_str("42"), v8_str("42")).FromJust();
75 80
76 // List all entries from global2. 81 // List all entries from global2.
77 Local<Array> result; 82 Local<Array> result;
78 result = Local<Array>::Cast(CompileRun("Object.keys(global2)")); 83 result = Local<Array>::Cast(CompileRun("Object.keys(global2)"));
79 CHECK_EQ(2u, result->Length()); 84 CHECK_EQ(2u, result->Length());
80 CHECK(v8_str("42")->Equals(result->Get(0))); 85 CHECK(
81 CHECK(v8_str("a")->Equals(result->Get(1))); 86 v8_str("42")
87 ->Equals(env1.local(), result->Get(env1.local(), 0).ToLocalChecked())
88 .FromJust());
89 CHECK(
90 v8_str("a")
91 ->Equals(env1.local(), result->Get(env1.local(), 1).ToLocalChecked())
92 .FromJust());
82 93
83 result = 94 result =
84 Local<Array>::Cast(CompileRun("Object.getOwnPropertyNames(global2)")); 95 Local<Array>::Cast(CompileRun("Object.getOwnPropertyNames(global2)"));
85 CHECK_LT(2u, result->Length()); 96 CHECK_LT(2u, result->Length());
86 // Check that all elements are in the property names 97 // Check that all elements are in the property names
87 ExpectTrue("-1 < Object.getOwnPropertyNames(global2).indexOf('42')"); 98 ExpectTrue("-1 < Object.getOwnPropertyNames(global2).indexOf('42')");
88 ExpectTrue("-1 < Object.getOwnPropertyNames(global2).indexOf('a')"); 99 ExpectTrue("-1 < Object.getOwnPropertyNames(global2).indexOf('a')");
89 100
90 // Hold on to global from env2 and detach global from env2. 101 // Hold on to global from env2 and detach global from env2.
91 env2->DetachGlobal(); 102 env2->DetachGlobal();
92 103
93 // List again all entries from the detached global2. 104 // List again all entries from the detached global2.
94 result = Local<Array>::Cast(CompileRun("Object.keys(global2)")); 105 result = Local<Array>::Cast(CompileRun("Object.keys(global2)"));
95 CHECK_EQ(0u, result->Length()); 106 CHECK_EQ(0u, result->Length());
96 result = 107 result =
97 Local<Array>::Cast(CompileRun("Object.getOwnPropertyNames(global2)")); 108 Local<Array>::Cast(CompileRun("Object.getOwnPropertyNames(global2)"));
98 CHECK_EQ(0u, result->Length()); 109 CHECK_EQ(0u, result->Length());
99 } 110 }
OLDNEW
« no previous file with comments | « test/cctest/test-global-handles.cc ('k') | test/cctest/test-javascript-arm64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698