OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
(...skipping 15986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15997 templ->NewInstance(env.local()).ToLocalChecked(); | 15997 templ->NewInstance(env.local()).ToLocalChecked(); |
15998 { | 15998 { |
15999 v8::TryCatch try_catch(isolate); | 15999 v8::TryCatch try_catch(isolate); |
16000 CHECK(access_checked->DefineOwnProperty(env.local(), v8_str("foo"), | 16000 CHECK(access_checked->DefineOwnProperty(env.local(), v8_str("foo"), |
16001 v8::Integer::New(isolate, 42)) | 16001 v8::Integer::New(isolate, 42)) |
16002 .IsNothing()); | 16002 .IsNothing()); |
16003 CHECK(try_catch.HasCaught()); | 16003 CHECK(try_catch.HasCaught()); |
16004 } | 16004 } |
16005 } | 16005 } |
16006 | 16006 |
| 16007 TEST(DefineProperty) { |
| 16008 LocalContext env; |
| 16009 v8::Isolate* isolate = env->GetIsolate(); |
| 16010 v8::HandleScope handle_scope(isolate); |
| 16011 |
| 16012 v8::Local<v8::Name> p; |
| 16013 |
| 16014 CompileRun( |
| 16015 "var a = {};" |
| 16016 "var b = [];" |
| 16017 "Object.defineProperty(a, 'v1', {value: 23});" |
| 16018 "Object.defineProperty(a, 'v2', {value: 23, configurable: true});"); |
| 16019 |
| 16020 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast( |
| 16021 env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked()); |
| 16022 v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast( |
| 16023 env->Global()->Get(env.local(), v8_str("b")).ToLocalChecked()); |
| 16024 |
| 16025 v8::PropertyDescriptor desc(v8_num(42)); |
| 16026 { |
| 16027 // Use a data descriptor. |
| 16028 |
| 16029 // Cannot change a non-configurable property. |
| 16030 p = v8_str("v1"); |
| 16031 v8::TryCatch try_catch(isolate); |
| 16032 CHECK(!obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16033 CHECK(!try_catch.HasCaught()); |
| 16034 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16035 CHECK(val->IsNumber()); |
| 16036 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); |
| 16037 |
| 16038 // Change a configurable property. |
| 16039 p = v8_str("v2"); |
| 16040 obj->DefineProperty(env.local(), p, desc).FromJust(); |
| 16041 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16042 CHECK(!try_catch.HasCaught()); |
| 16043 val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16044 CHECK(val->IsNumber()); |
| 16045 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16046 |
| 16047 // Check that missing writable has default value false. |
| 16048 p = v8_str("v12"); |
| 16049 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16050 CHECK(!try_catch.HasCaught()); |
| 16051 val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16052 CHECK(val->IsNumber()); |
| 16053 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16054 v8::PropertyDescriptor desc2(v8_num(43)); |
| 16055 CHECK(!obj->DefineProperty(env.local(), p, desc2).FromJust()); |
| 16056 val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16057 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16058 CHECK(!try_catch.HasCaught()); |
| 16059 } |
| 16060 |
| 16061 { |
| 16062 // Set a regular property. |
| 16063 p = v8_str("v3"); |
| 16064 v8::TryCatch try_catch(isolate); |
| 16065 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16066 CHECK(!try_catch.HasCaught()); |
| 16067 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16068 CHECK(val->IsNumber()); |
| 16069 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16070 } |
| 16071 |
| 16072 { |
| 16073 // Set an indexed property. |
| 16074 v8::TryCatch try_catch(isolate); |
| 16075 CHECK(obj->DefineProperty(env.local(), v8_str("1"), desc).FromJust()); |
| 16076 CHECK(!try_catch.HasCaught()); |
| 16077 v8::Local<v8::Value> val = obj->Get(env.local(), 1).ToLocalChecked(); |
| 16078 CHECK(val->IsNumber()); |
| 16079 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16080 } |
| 16081 |
| 16082 { |
| 16083 // No special case when changing array length. |
| 16084 v8::TryCatch try_catch(isolate); |
| 16085 // Use a writable descriptor, otherwise the next test, that changes |
| 16086 // the array length will fail. |
| 16087 v8::PropertyDescriptor desc(v8_num(42), true); |
| 16088 CHECK(arr->DefineProperty(env.local(), v8_str("length"), desc).FromJust()); |
| 16089 CHECK(!try_catch.HasCaught()); |
| 16090 } |
| 16091 |
| 16092 { |
| 16093 // Special cases for arrays: index exceeds the array's length. |
| 16094 v8::TryCatch try_catch(isolate); |
| 16095 CHECK(arr->DefineProperty(env.local(), v8_str("100"), desc).FromJust()); |
| 16096 CHECK(!try_catch.HasCaught()); |
| 16097 CHECK_EQ(101U, arr->Length()); |
| 16098 v8::Local<v8::Value> val = arr->Get(env.local(), 100).ToLocalChecked(); |
| 16099 CHECK(val->IsNumber()); |
| 16100 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16101 |
| 16102 // Set an existing entry. |
| 16103 CHECK(arr->DefineProperty(env.local(), v8_str("0"), desc).FromJust()); |
| 16104 CHECK(!try_catch.HasCaught()); |
| 16105 val = arr->Get(env.local(), 0).ToLocalChecked(); |
| 16106 CHECK(val->IsNumber()); |
| 16107 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16108 } |
| 16109 |
| 16110 { |
| 16111 // Use a generic descriptor. |
| 16112 v8::PropertyDescriptor desc_generic; |
| 16113 |
| 16114 p = v8_str("v4"); |
| 16115 v8::TryCatch try_catch(isolate); |
| 16116 CHECK(obj->DefineProperty(env.local(), p, desc_generic).FromJust()); |
| 16117 CHECK(!try_catch.HasCaught()); |
| 16118 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16119 CHECK(val->IsUndefined()); |
| 16120 |
| 16121 obj->Set(env.local(), p, v8_num(1)).FromJust(); |
| 16122 CHECK(!try_catch.HasCaught()); |
| 16123 |
| 16124 val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16125 CHECK(val->IsUndefined()); |
| 16126 CHECK(!try_catch.HasCaught()); |
| 16127 } |
| 16128 |
| 16129 { |
| 16130 // Use a data descriptor with undefined value. |
| 16131 v8::PropertyDescriptor desc_empty(v8::Undefined(isolate)); |
| 16132 |
| 16133 v8::TryCatch try_catch(isolate); |
| 16134 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); |
| 16135 CHECK(!try_catch.HasCaught()); |
| 16136 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16137 CHECK(val->IsUndefined()); |
| 16138 CHECK(!try_catch.HasCaught()); |
| 16139 } |
| 16140 |
| 16141 { |
| 16142 // Use a descriptor with attribute == v8::ReadOnly. |
| 16143 v8::PropertyDescriptor desc_read_only(v8_num(42), false); |
| 16144 desc_read_only.set_enumerable(true); |
| 16145 desc_read_only.set_configurable(true); |
| 16146 |
| 16147 p = v8_str("v5"); |
| 16148 v8::TryCatch try_catch(isolate); |
| 16149 CHECK(obj->DefineProperty(env.local(), p, desc_read_only).FromJust()); |
| 16150 CHECK(!try_catch.HasCaught()); |
| 16151 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16152 CHECK(val->IsNumber()); |
| 16153 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16154 CHECK_EQ(v8::ReadOnly, |
| 16155 obj->GetPropertyAttributes(env.local(), p).FromJust()); |
| 16156 CHECK(!try_catch.HasCaught()); |
| 16157 } |
| 16158 |
| 16159 { |
| 16160 // Use an accessor descriptor with empty handles. |
| 16161 v8::PropertyDescriptor desc_empty(v8::Undefined(isolate), |
| 16162 v8::Undefined(isolate)); |
| 16163 |
| 16164 p = v8_str("v6"); |
| 16165 v8::TryCatch try_catch(isolate); |
| 16166 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); |
| 16167 CHECK(!try_catch.HasCaught()); |
| 16168 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16169 CHECK(val->IsUndefined()); |
| 16170 CHECK(!try_catch.HasCaught()); |
| 16171 } |
| 16172 |
| 16173 { |
| 16174 // Use an accessor descriptor. |
| 16175 CompileRun( |
| 16176 "var set = function(x) {this.val = 2*x;};" |
| 16177 "var get = function() {return this.val || 0;};"); |
| 16178 |
| 16179 v8::Local<v8::Function> get = v8::Local<v8::Function>::Cast( |
| 16180 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); |
| 16181 v8::Local<v8::Function> set = v8::Local<v8::Function>::Cast( |
| 16182 env->Global()->Get(env.local(), v8_str("set")).ToLocalChecked()); |
| 16183 v8::PropertyDescriptor desc(get, set); |
| 16184 |
| 16185 p = v8_str("v7"); |
| 16186 v8::TryCatch try_catch(isolate); |
| 16187 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16188 CHECK(!try_catch.HasCaught()); |
| 16189 |
| 16190 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16191 CHECK(val->IsNumber()); |
| 16192 CHECK_EQ(0.0, val->NumberValue(env.local()).FromJust()); |
| 16193 CHECK(!try_catch.HasCaught()); |
| 16194 |
| 16195 obj->Set(env.local(), p, v8_num(7)).FromJust(); |
| 16196 CHECK(!try_catch.HasCaught()); |
| 16197 |
| 16198 val = obj->Get(env.local(), p).ToLocalChecked(); |
| 16199 CHECK(val->IsNumber()); |
| 16200 CHECK_EQ(14.0, val->NumberValue(env.local()).FromJust()); |
| 16201 CHECK(!try_catch.HasCaught()); |
| 16202 } |
| 16203 |
| 16204 { |
| 16205 // Redefine an existing property. |
| 16206 |
| 16207 // desc = {value: 42, enumerable: true} |
| 16208 v8::PropertyDescriptor desc(v8_num(42)); |
| 16209 desc.set_enumerable(true); |
| 16210 |
| 16211 p = v8_str("v8"); |
| 16212 v8::TryCatch try_catch(isolate); |
| 16213 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16214 CHECK(!try_catch.HasCaught()); |
| 16215 |
| 16216 // desc = {enumerable: true} |
| 16217 v8::PropertyDescriptor desc_true((v8::Local<v8::Value>())); |
| 16218 desc_true.set_enumerable(true); |
| 16219 |
| 16220 // Successful redefinition because all present attributes have the same |
| 16221 // value as the current descriptor. |
| 16222 CHECK(obj->DefineProperty(env.local(), p, desc_true).FromJust()); |
| 16223 CHECK(!try_catch.HasCaught()); |
| 16224 |
| 16225 // desc = {} |
| 16226 v8::PropertyDescriptor desc_empty; |
| 16227 // Successful redefinition because no attributes are overwritten in the |
| 16228 // current descriptor. |
| 16229 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); |
| 16230 CHECK(!try_catch.HasCaught()); |
| 16231 |
| 16232 // desc = {enumerable: false} |
| 16233 v8::PropertyDescriptor desc_false((v8::Local<v8::Value>())); |
| 16234 desc_false.set_enumerable(false); |
| 16235 // Not successful because we cannot define a different value for enumerable. |
| 16236 CHECK(!obj->DefineProperty(env.local(), p, desc_false).FromJust()); |
| 16237 CHECK(!try_catch.HasCaught()); |
| 16238 } |
| 16239 |
| 16240 { |
| 16241 // Redefine a property that has a getter. |
| 16242 CompileRun("var get = function() {};"); |
| 16243 v8::Local<v8::Function> get = v8::Local<v8::Function>::Cast( |
| 16244 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); |
| 16245 |
| 16246 // desc = {get: function() {}} |
| 16247 v8::PropertyDescriptor desc(get, v8::Local<v8::Function>()); |
| 16248 v8::TryCatch try_catch(isolate); |
| 16249 |
| 16250 p = v8_str("v9"); |
| 16251 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16252 CHECK(!try_catch.HasCaught()); |
| 16253 |
| 16254 // desc_empty = {} |
| 16255 // Successful because we are not redefining the current getter. |
| 16256 v8::PropertyDescriptor desc_empty; |
| 16257 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); |
| 16258 CHECK(!try_catch.HasCaught()); |
| 16259 |
| 16260 // desc = {get: function() {}} |
| 16261 // Successful because we redefine the getter with its current value. |
| 16262 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); |
| 16263 CHECK(!try_catch.HasCaught()); |
| 16264 |
| 16265 // desc = {get: undefined} |
| 16266 v8::PropertyDescriptor desc_undefined(v8::Undefined(isolate), |
| 16267 v8::Local<v8::Function>()); |
| 16268 // Not successful because we cannot redefine with the current value of get |
| 16269 // with undefined. |
| 16270 CHECK(!obj->DefineProperty(env.local(), p, desc_undefined).FromJust()); |
| 16271 CHECK(!try_catch.HasCaught()); |
| 16272 } |
| 16273 |
| 16274 CompileRun("Object.freeze(a);"); |
| 16275 { |
| 16276 // We cannot change non-extensible objects. |
| 16277 v8::TryCatch try_catch(isolate); |
| 16278 CHECK(!obj->DefineProperty(env.local(), v8_str("v10"), desc).FromJust()); |
| 16279 CHECK(!try_catch.HasCaught()); |
| 16280 } |
| 16281 |
| 16282 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
| 16283 templ->SetAccessCheckCallback(AccessAlwaysBlocked); |
| 16284 v8::Local<v8::Object> access_checked = |
| 16285 templ->NewInstance(env.local()).ToLocalChecked(); |
| 16286 { |
| 16287 v8::TryCatch try_catch(isolate); |
| 16288 CHECK(access_checked->DefineProperty(env.local(), v8_str("v11"), desc) |
| 16289 .IsNothing()); |
| 16290 CHECK(try_catch.HasCaught()); |
| 16291 } |
| 16292 } |
16007 | 16293 |
16008 THREADED_TEST(GetCurrentContextWhenNotInContext) { | 16294 THREADED_TEST(GetCurrentContextWhenNotInContext) { |
16009 i::Isolate* isolate = CcTest::i_isolate(); | 16295 i::Isolate* isolate = CcTest::i_isolate(); |
16010 CHECK(isolate != NULL); | 16296 CHECK(isolate != NULL); |
16011 CHECK(isolate->context() == NULL); | 16297 CHECK(isolate->context() == NULL); |
16012 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 16298 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
16013 v8::HandleScope scope(v8_isolate); | 16299 v8::HandleScope scope(v8_isolate); |
16014 // The following should not crash, but return an empty handle. | 16300 // The following should not crash, but return an empty handle. |
16015 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); | 16301 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); |
16016 CHECK(current.IsEmpty()); | 16302 CHECK(current.IsEmpty()); |
(...skipping 7315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23332 "V8.Test", 0, 10000, v8::internal::HistogramTimer::MILLISECOND, 50, | 23618 "V8.Test", 0, 10000, v8::internal::HistogramTimer::MILLISECOND, 50, |
23333 reinterpret_cast<v8::internal::Isolate*>(isolate)); | 23619 reinterpret_cast<v8::internal::Isolate*>(isolate)); |
23334 histogramTimer.Start(); | 23620 histogramTimer.Start(); |
23335 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 23621 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
23336 CHECK_EQ(0, last_event_status); | 23622 CHECK_EQ(0, last_event_status); |
23337 histogramTimer.Stop(); | 23623 histogramTimer.Stop(); |
23338 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 23624 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
23339 CHECK_EQ(1, last_event_status); | 23625 CHECK_EQ(1, last_event_status); |
23340 } | 23626 } |
23341 | 23627 |
| 23628 TEST(PropertyDescriptor) { |
| 23629 LocalContext context; |
| 23630 v8::Isolate* isolate = context->GetIsolate(); |
| 23631 v8::HandleScope scope(isolate); |
| 23632 |
| 23633 { // empty descriptor |
| 23634 v8::PropertyDescriptor desc; |
| 23635 CHECK(!desc.has_value()); |
| 23636 CHECK(!desc.has_set()); |
| 23637 CHECK(!desc.has_get()); |
| 23638 CHECK(!desc.has_enumerable()); |
| 23639 CHECK(!desc.has_configurable()); |
| 23640 CHECK(!desc.has_writable()); |
| 23641 } |
| 23642 { |
| 23643 // data descriptor |
| 23644 v8::PropertyDescriptor desc(v8_num(42)); |
| 23645 desc.set_enumerable(false); |
| 23646 CHECK(desc.value() == v8_num(42)); |
| 23647 CHECK(desc.has_value()); |
| 23648 CHECK(!desc.has_set()); |
| 23649 CHECK(!desc.has_get()); |
| 23650 CHECK(desc.has_enumerable()); |
| 23651 CHECK(!desc.enumerable()); |
| 23652 CHECK(!desc.has_configurable()); |
| 23653 CHECK(!desc.has_writable()); |
| 23654 } |
| 23655 { |
| 23656 // data descriptor |
| 23657 v8::PropertyDescriptor desc(v8_num(42)); |
| 23658 desc.set_configurable(true); |
| 23659 CHECK(desc.value() == v8_num(42)); |
| 23660 CHECK(desc.has_value()); |
| 23661 CHECK(!desc.has_set()); |
| 23662 CHECK(!desc.has_get()); |
| 23663 CHECK(desc.has_configurable()); |
| 23664 CHECK(desc.configurable()); |
| 23665 CHECK(!desc.has_enumerable()); |
| 23666 CHECK(!desc.has_writable()); |
| 23667 } |
| 23668 { |
| 23669 // data descriptor |
| 23670 v8::PropertyDescriptor desc(v8_num(42)); |
| 23671 desc.set_configurable(false); |
| 23672 CHECK(desc.value() == v8_num(42)); |
| 23673 CHECK(desc.has_value()); |
| 23674 CHECK(!desc.has_set()); |
| 23675 CHECK(!desc.has_get()); |
| 23676 CHECK(desc.has_configurable()); |
| 23677 CHECK(!desc.configurable()); |
| 23678 CHECK(!desc.has_enumerable()); |
| 23679 CHECK(!desc.has_writable()); |
| 23680 } |
| 23681 { |
| 23682 // data descriptor |
| 23683 v8::PropertyDescriptor desc(v8_num(42), false); |
| 23684 CHECK(desc.value() == v8_num(42)); |
| 23685 CHECK(desc.has_value()); |
| 23686 CHECK(!desc.has_set()); |
| 23687 CHECK(!desc.has_get()); |
| 23688 CHECK(!desc.has_enumerable()); |
| 23689 CHECK(!desc.has_configurable()); |
| 23690 CHECK(desc.has_writable()); |
| 23691 CHECK(!desc.writable()); |
| 23692 } |
| 23693 { |
| 23694 // data descriptor |
| 23695 v8::PropertyDescriptor desc(v8::Local<v8::Value>(), true); |
| 23696 CHECK(!desc.has_value()); |
| 23697 CHECK(!desc.has_set()); |
| 23698 CHECK(!desc.has_get()); |
| 23699 CHECK(!desc.has_enumerable()); |
| 23700 CHECK(!desc.has_configurable()); |
| 23701 CHECK(desc.has_writable()); |
| 23702 CHECK(desc.writable()); |
| 23703 } |
| 23704 { |
| 23705 // accessor descriptor |
| 23706 CompileRun("var set = function() {return 43;};"); |
| 23707 |
| 23708 v8::Local<v8::Function> set = |
| 23709 v8::Local<v8::Function>::Cast(context->Global() |
| 23710 ->Get(context.local(), v8_str("set")) |
| 23711 .ToLocalChecked()); |
| 23712 v8::PropertyDescriptor desc(v8::Undefined(isolate), set); |
| 23713 desc.set_configurable(false); |
| 23714 CHECK(!desc.has_value()); |
| 23715 CHECK(desc.has_get()); |
| 23716 CHECK(desc.get() == v8::Undefined(isolate)); |
| 23717 CHECK(desc.has_set()); |
| 23718 CHECK(desc.set() == set); |
| 23719 CHECK(!desc.has_enumerable()); |
| 23720 CHECK(desc.has_configurable()); |
| 23721 CHECK(!desc.configurable()); |
| 23722 CHECK(!desc.has_writable()); |
| 23723 } |
| 23724 { |
| 23725 // accessor descriptor with Proxy |
| 23726 CompileRun( |
| 23727 "var set = new Proxy(function() {}, {});" |
| 23728 "var get = undefined;"); |
| 23729 |
| 23730 v8::Local<v8::Value> get = |
| 23731 v8::Local<v8::Value>::Cast(context->Global() |
| 23732 ->Get(context.local(), v8_str("get")) |
| 23733 .ToLocalChecked()); |
| 23734 v8::Local<v8::Function> set = |
| 23735 v8::Local<v8::Function>::Cast(context->Global() |
| 23736 ->Get(context.local(), v8_str("set")) |
| 23737 .ToLocalChecked()); |
| 23738 v8::PropertyDescriptor desc(get, set); |
| 23739 desc.set_configurable(false); |
| 23740 CHECK(!desc.has_value()); |
| 23741 CHECK(desc.get() == v8::Undefined(isolate)); |
| 23742 CHECK(desc.has_get()); |
| 23743 CHECK(desc.set() == set); |
| 23744 CHECK(desc.has_set()); |
| 23745 CHECK(!desc.has_enumerable()); |
| 23746 CHECK(desc.has_configurable()); |
| 23747 CHECK(!desc.configurable()); |
| 23748 CHECK(!desc.has_writable()); |
| 23749 } |
| 23750 { |
| 23751 // accessor descriptor with empty function handle |
| 23752 v8::Local<v8::Function> get = v8::Local<v8::Function>(); |
| 23753 v8::PropertyDescriptor desc(get, get); |
| 23754 CHECK(!desc.has_value()); |
| 23755 CHECK(!desc.has_get()); |
| 23756 CHECK(!desc.has_set()); |
| 23757 CHECK(!desc.has_enumerable()); |
| 23758 CHECK(!desc.has_configurable()); |
| 23759 CHECK(!desc.has_writable()); |
| 23760 } |
| 23761 } |
23342 | 23762 |
23343 TEST(Promises) { | 23763 TEST(Promises) { |
23344 LocalContext context; | 23764 LocalContext context; |
23345 v8::Isolate* isolate = context->GetIsolate(); | 23765 v8::Isolate* isolate = context->GetIsolate(); |
23346 v8::HandleScope scope(isolate); | 23766 v8::HandleScope scope(isolate); |
23347 | 23767 |
23348 // Creation. | 23768 // Creation. |
23349 Local<v8::Promise::Resolver> pr = | 23769 Local<v8::Promise::Resolver> pr = |
23350 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); | 23770 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
23351 Local<v8::Promise::Resolver> rr = | 23771 Local<v8::Promise::Resolver> rr = |
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25524 | 25944 |
25525 // Put the function into context1 and call it. Since the access check | 25945 // Put the function into context1 and call it. Since the access check |
25526 // callback always returns true, the call succeeds even though the tokens | 25946 // callback always returns true, the call succeeds even though the tokens |
25527 // are different. | 25947 // are different. |
25528 context1->Enter(); | 25948 context1->Enter(); |
25529 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); | 25949 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); |
25530 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); | 25950 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); |
25531 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); | 25951 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); |
25532 context1->Exit(); | 25952 context1->Exit(); |
25533 } | 25953 } |
OLD | NEW |