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

Side by Side Diff: test/cctest/test-unscopables-hidden-prototype.cc

Issue 384963002: ES6 Unscopables (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdlib.h>
6
7 #include "src/v8.h"
8 #include "test/cctest/cctest.h"
9
10 namespace {
11
12
13 static void Cleanup() {
14 CompileRun(
15 "delete object.x;"
16 "delete hidden_prototype.x;"
17 "delete object[Symbol.unscopables];"
18 "delete hidden_prototype[Symbol.unscopables];");
19 }
20
21
22 TEST(Unscopables) {
23 i::FLAG_harmony_unscopables = true;
24
25 LocalContext context;
26 v8::Isolate* isolate = context->GetIsolate();
27 v8::HandleScope handle_scope(isolate);
28
29 v8::Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
30 v8::Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
31 t0->SetHiddenPrototype(true);
32 t1->Inherit(t0);
33
34 v8::Local<v8::Object> object = t1->GetFunction()->NewInstance();
35 v8::Local<v8::Object> hidden_prototype =
36 v8::Local<v8::Object>::Cast(object->GetPrototype());
37
38 context->Global()->Set(v8_str("object"), object);
39 context->Global()->Set(v8_str("hidden_prototype"), hidden_prototype);
40
41 CHECK_EQ(1, CompileRun(
42 "var result;"
43 "var x = 0;"
44 "object.x = 1;"
45 "with (object) {"
46 " result = x;"
47 "}"
48 "result")->Int32Value());
49
50 Cleanup();
51 CHECK_EQ(2, CompileRun(
52 "var result;"
53 "var x = 0;"
54 "hidden_prototype.x = 2;"
55 "with (object) {"
56 " result = x;"
57 "}"
58 "result")->Int32Value());
59
60 Cleanup();
61 CHECK_EQ(0, CompileRun(
62 "var result;"
63 "var x = 0;"
64 "object.x = 3;"
65 "object[Symbol.unscopables] = {x: true};"
66 "with (object) {"
67 " result = x;"
68 "}"
69 "result")->Int32Value());
70
71 Cleanup();
72 CHECK_EQ(0, CompileRun(
73 "var result;"
74 "var x = 0;"
75 "hidden_prototype.x = 4;"
76 "hidden_prototype[Symbol.unscopables] = {x: true};"
77 "with (object) {"
78 " result = x;"
79 "}"
80 "result")->Int32Value());
81
82 Cleanup();
83 CHECK_EQ(5, CompileRun(
84 "var result;"
85 "var x = 0;"
86 "object.x = 5;"
87 "hidden_prototype[Symbol.unscopables] = {x: true};"
88 "with (object) {"
89 " result = x;"
90 "}"
91 "result")->Int32Value());
92
93 Cleanup();
94 CHECK_EQ(6, CompileRun(
95 "var result;"
96 "var x = 0;"
97 "hidden_prototype.x = 6;"
98 "object[Symbol.unscopables] = {x: true};"
99 "with (object) {"
100 " result = x;"
101 "}"
102 "result")->Int32Value());
103 }
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698