Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(mythria): Remove this after this flag is turned on globally | |
| 6 #define V8_IMMINENT_DEPRECATION_WARNINGS | |
| 7 | |
| 5 #include <stdlib.h> | 8 #include <stdlib.h> |
| 6 | 9 |
| 7 #include "src/v8.h" | 10 #include "src/v8.h" |
| 8 #include "test/cctest/cctest.h" | 11 #include "test/cctest/cctest.h" |
| 9 | 12 |
| 10 namespace { | 13 namespace { |
| 11 | 14 |
| 12 | 15 |
| 13 static void Cleanup() { | 16 static void Cleanup() { |
| 14 CompileRun( | 17 CompileRun( |
| 15 "delete object.x;" | 18 "delete object.x;" |
| 16 "delete hidden_prototype.x;" | 19 "delete hidden_prototype.x;" |
| 17 "delete object[Symbol.unscopables];" | 20 "delete object[Symbol.unscopables];" |
| 18 "delete hidden_prototype[Symbol.unscopables];"); | 21 "delete hidden_prototype[Symbol.unscopables];"); |
| 19 } | 22 } |
| 20 | 23 |
| 21 | 24 |
| 22 TEST(Unscopables) { | 25 TEST(Unscopables) { |
| 23 LocalContext context; | 26 LocalContext context; |
| 24 v8::Isolate* isolate = context->GetIsolate(); | 27 v8::Isolate* isolate = context->GetIsolate(); |
| 25 v8::HandleScope handle_scope(isolate); | 28 v8::HandleScope handle_scope(isolate); |
| 29 v8::Local<v8::Context> curr_context = isolate->GetCurrentContext(); | |
|
rmcilroy
2015/09/10 09:30:16
nit - please don't abbreviate - current_context.
mythria_google
2015/09/10 10:07:29
Done.
| |
| 26 | 30 |
| 27 v8::Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); | 31 v8::Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); |
| 28 v8::Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 32 v8::Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
| 29 | 33 |
| 30 t1->SetHiddenPrototype(true); | 34 t1->SetHiddenPrototype(true); |
| 31 | 35 |
| 32 v8::Local<v8::Object> object = t0->GetFunction()->NewInstance(); | 36 v8::Local<v8::Object> object = t0->GetFunction(curr_context) |
| 33 v8::Local<v8::Object> hidden_prototype = t1->GetFunction()->NewInstance(); | 37 .ToLocalChecked() |
| 38 ->NewInstance(curr_context) | |
| 39 .ToLocalChecked(); | |
| 40 v8::Local<v8::Object> hidden_prototype = t1->GetFunction(curr_context) | |
| 41 .ToLocalChecked() | |
| 42 ->NewInstance(curr_context) | |
| 43 .ToLocalChecked(); | |
| 34 | 44 |
| 35 object->SetPrototype(hidden_prototype); | 45 object->SetPrototype(curr_context, hidden_prototype).FromMaybe(false); |
|
rmcilroy
2015/09/10 09:30:16
Could you add a CHECK() around this to check the v
jochen (gone - plz use gerrit)
2015/09/10 09:33:24
Just use .FromJust() that checks internally.
mythria_google
2015/09/10 10:07:29
Done.
mythria_google
2015/09/10 10:07:29
Done.
| |
| 36 | 46 |
| 37 context->Global()->Set(v8_str("object"), object); | 47 context->Global() |
| 38 context->Global()->Set(v8_str("hidden_prototype"), hidden_prototype); | 48 ->Set(curr_context, v8_str("object"), object) |
| 49 .FromMaybe(false); | |
| 50 context->Global() | |
| 51 ->Set(curr_context, v8_str("hidden_prototype"), hidden_prototype) | |
| 52 .FromMaybe(false); | |
| 39 | 53 |
| 40 CHECK_EQ(1, CompileRun( | 54 CHECK_EQ(1, CompileRun("var result;" |
| 41 "var result;" | 55 "var x = 0;" |
| 42 "var x = 0;" | 56 "object.x = 1;" |
| 43 "object.x = 1;" | 57 "with (object) {" |
| 44 "with (object) {" | 58 " result = x;" |
| 45 " result = x;" | 59 "}" |
| 46 "}" | 60 "result") |
| 47 "result")->Int32Value()); | 61 ->Int32Value(curr_context) |
| 62 .FromMaybe(-1)); | |
|
rmcilroy
2015/09/10 09:30:16
nit - could .FromMaybe(-1) be on the same line as
jochen (gone - plz use gerrit)
2015/09/10 09:33:24
same here... FromJust()
mythria_google
2015/09/10 10:07:30
This is git cl format. I can move FromMaybe to the
mythria_google
2015/09/10 10:07:30
Done.
rmcilroy
2015/09/10 10:41:05
If this is what git cl format wants then I'm fine
| |
| 48 | 63 |
| 49 Cleanup(); | 64 Cleanup(); |
| 50 CHECK_EQ(2, CompileRun( | 65 CHECK_EQ(2, CompileRun("var result;" |
| 51 "var result;" | 66 "var x = 0;" |
| 52 "var x = 0;" | 67 "hidden_prototype.x = 2;" |
| 53 "hidden_prototype.x = 2;" | 68 "with (object) {" |
| 54 "with (object) {" | 69 " result = x;" |
| 55 " result = x;" | 70 "}" |
| 56 "}" | 71 "result") |
| 57 "result")->Int32Value()); | 72 ->Int32Value(curr_context) |
| 73 .FromMaybe(-1)); | |
| 58 | 74 |
| 59 Cleanup(); | 75 Cleanup(); |
| 60 CHECK_EQ(0, CompileRun( | 76 CHECK_EQ(0, CompileRun("var result;" |
| 61 "var result;" | 77 "var x = 0;" |
| 62 "var x = 0;" | 78 "object.x = 3;" |
| 63 "object.x = 3;" | 79 "object[Symbol.unscopables] = {x: true};" |
| 64 "object[Symbol.unscopables] = {x: true};" | 80 "with (object) {" |
| 65 "with (object) {" | 81 " result = x;" |
| 66 " result = x;" | 82 "}" |
| 67 "}" | 83 "result") |
| 68 "result")->Int32Value()); | 84 ->Int32Value(curr_context) |
| 85 .FromMaybe(-1)); | |
| 69 | 86 |
| 70 Cleanup(); | 87 Cleanup(); |
| 71 CHECK_EQ(0, CompileRun( | 88 CHECK_EQ(0, CompileRun("var result;" |
| 72 "var result;" | 89 "var x = 0;" |
| 73 "var x = 0;" | 90 "hidden_prototype.x = 4;" |
| 74 "hidden_prototype.x = 4;" | 91 "hidden_prototype[Symbol.unscopables] = {x: true};" |
| 75 "hidden_prototype[Symbol.unscopables] = {x: true};" | 92 "with (object) {" |
| 76 "with (object) {" | 93 " result = x;" |
| 77 " result = x;" | 94 "}" |
| 78 "}" | 95 "result") |
| 79 "result")->Int32Value()); | 96 ->Int32Value(curr_context) |
| 97 .FromMaybe(-1)); | |
| 80 | 98 |
| 81 Cleanup(); | 99 Cleanup(); |
| 82 CHECK_EQ(0, CompileRun( | 100 CHECK_EQ(0, CompileRun("var result;" |
| 83 "var result;" | 101 "var x = 0;" |
| 84 "var x = 0;" | 102 "object.x = 5;" |
| 85 "object.x = 5;" | 103 "hidden_prototype[Symbol.unscopables] = {x: true};" |
| 86 "hidden_prototype[Symbol.unscopables] = {x: true};" | 104 "with (object) {" |
| 87 "with (object) {" | 105 " result = x;" |
| 88 " result = x;" | 106 "}" |
| 89 "}" | 107 "result;") |
| 90 "result;")->Int32Value()); | 108 ->Int32Value(curr_context) |
| 109 .FromMaybe(-1)); | |
| 91 | 110 |
| 92 Cleanup(); | 111 Cleanup(); |
| 93 CHECK_EQ(0, CompileRun( | 112 CHECK_EQ(0, CompileRun("var result;" |
| 94 "var result;" | 113 "var x = 0;" |
| 95 "var x = 0;" | 114 "hidden_prototype.x = 6;" |
| 96 "hidden_prototype.x = 6;" | 115 "object[Symbol.unscopables] = {x: true};" |
| 97 "object[Symbol.unscopables] = {x: true};" | 116 "with (object) {" |
| 98 "with (object) {" | 117 " result = x;" |
| 99 " result = x;" | 118 "}" |
| 100 "}" | 119 "result") |
| 101 "result")->Int32Value()); | 120 ->Int32Value(curr_context) |
| 121 .FromMaybe(-1)); | |
| 102 } | 122 } |
| 103 } | 123 } |
| OLD | NEW |