Chromium Code Reviews| 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 const v8::PropertyDescriptor desc(v8_num(42), true, false, false); | |
| 16026 { | |
| 16027 // Use a data descriptor. | |
| 16028 | |
| 16029 // Can't 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 configurable property | |
| 16039 p = v8_str("v2"); | |
| 16040 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); | |
| 16041 CHECK(!try_catch.HasCaught()); | |
| 16042 val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16043 CHECK(val->IsNumber()); | |
| 16044 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 16045 } | |
| 16046 | |
| 16047 { | |
| 16048 // Set a regular property. | |
| 16049 p = v8_str("v3"); | |
| 16050 v8::TryCatch try_catch(isolate); | |
| 16051 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); | |
| 16052 CHECK(!try_catch.HasCaught()); | |
| 16053 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16054 CHECK(val->IsNumber()); | |
| 16055 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 16056 } | |
| 16057 | |
| 16058 { | |
| 16059 // Set an indexed property. | |
| 16060 v8::TryCatch try_catch(isolate); | |
| 16061 CHECK(obj->DefineProperty(env.local(), v8_str("1"), desc).FromJust()); | |
| 16062 CHECK(!try_catch.HasCaught()); | |
| 16063 v8::Local<v8::Value> val = obj->Get(env.local(), 1).ToLocalChecked(); | |
| 16064 CHECK(val->IsNumber()); | |
| 16065 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 16066 } | |
| 16067 | |
| 16068 { | |
| 16069 // No special case when changing array length. | |
| 16070 v8::TryCatch try_catch(isolate); | |
| 16071 CHECK(arr->DefineProperty(env.local(), v8_str("length"), desc).FromJust()); | |
| 16072 CHECK(!try_catch.HasCaught()); | |
| 16073 } | |
| 16074 | |
| 16075 { | |
| 16076 // Special cases for arrays: index exceeds the array's length. | |
| 16077 v8::TryCatch try_catch(isolate); | |
| 16078 CHECK(arr->DefineProperty(env.local(), v8_str("100"), desc).FromJust()); | |
| 16079 CHECK(!try_catch.HasCaught()); | |
| 16080 CHECK_EQ(101U, arr->Length()); | |
| 16081 v8::Local<v8::Value> val = arr->Get(env.local(), 100).ToLocalChecked(); | |
| 16082 CHECK(val->IsNumber()); | |
| 16083 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 16084 | |
| 16085 // Set an existing entry. | |
| 16086 CHECK(arr->DefineProperty(env.local(), v8_str("0"), desc).FromJust()); | |
| 16087 CHECK(!try_catch.HasCaught()); | |
| 16088 val = arr->Get(env.local(), 0).ToLocalChecked(); | |
| 16089 CHECK(val->IsNumber()); | |
| 16090 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 16091 } | |
| 16092 | |
| 16093 { | |
| 16094 // Use a generic descriptor. | |
| 16095 const v8::PropertyDescriptor desc_generic; | |
| 16096 | |
| 16097 p = v8_str("v4"); | |
| 16098 v8::TryCatch try_catch(isolate); | |
| 16099 CHECK(obj->DefineProperty(env.local(), p, desc_generic).FromJust()); | |
| 16100 CHECK(!try_catch.HasCaught()); | |
| 16101 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16102 CHECK(val->IsUndefined()); | |
| 16103 | |
| 16104 obj->Set(env.local(), p, v8_num(1)).FromJust(); | |
| 16105 CHECK(!try_catch.HasCaught()); | |
| 16106 | |
| 16107 val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16108 CHECK(val->IsUndefined()); | |
| 16109 CHECK(!try_catch.HasCaught()); | |
| 16110 } | |
| 16111 | |
| 16112 { | |
| 16113 // Use a data descriptor with empty handle should return Nothing. | |
| 16114 const v8::PropertyDescriptor desc_empty(v8::Local<v8::Value>(), true, false, | |
| 16115 false); | |
| 16116 | |
| 16117 v8::TryCatch try_catch(isolate); | |
| 16118 CHECK(obj->DefineProperty(env.local(), p, desc_empty).IsNothing()); | |
| 16119 CHECK(!try_catch.HasCaught()); | |
| 16120 } | |
| 16121 | |
| 16122 { | |
| 16123 // Use a data descriptor with undefined value. | |
| 16124 const v8::PropertyDescriptor desc_empty(v8::Undefined(isolate), true, false, | |
| 16125 false); | |
| 16126 | |
| 16127 v8::TryCatch try_catch(isolate); | |
| 16128 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); | |
| 16129 CHECK(!try_catch.HasCaught()); | |
| 16130 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16131 CHECK(val->IsUndefined()); | |
| 16132 CHECK(!try_catch.HasCaught()); | |
| 16133 } | |
| 16134 | |
| 16135 { | |
| 16136 // Use a descriptor with attribute == v8::ReadOnly. | |
| 16137 v8::PropertyDescriptor desc_read_only(v8_num(42), true, false, true); | |
| 16138 desc_read_only.set_enumerable(true); | |
| 16139 desc_read_only.set_configurable(true); | |
| 16140 | |
| 16141 p = v8_str("v5"); | |
| 16142 v8::TryCatch try_catch(isolate); | |
| 16143 CHECK(obj->DefineProperty(env.local(), p, desc_read_only).FromJust()); | |
| 16144 CHECK(!try_catch.HasCaught()); | |
| 16145 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16146 CHECK(val->IsNumber()); | |
| 16147 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 16148 CHECK_EQ(v8::ReadOnly, | |
| 16149 obj->GetPropertyAttributes(env.local(), p).FromJust()); | |
| 16150 CHECK(!try_catch.HasCaught()); | |
| 16151 } | |
| 16152 | |
| 16153 { | |
| 16154 // Use an accessor descriptor with empty handles. | |
| 16155 const v8::PropertyDescriptor desc_empty(v8::Local<v8::Function>(), true, | |
| 16156 v8::Local<v8::Function>(), true); | |
| 16157 | |
| 16158 p = v8_str("v6"); | |
| 16159 v8::TryCatch try_catch(isolate); | |
| 16160 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); | |
| 16161 CHECK(!try_catch.HasCaught()); | |
| 16162 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16163 CHECK(val->IsUndefined()); | |
| 16164 CHECK(!try_catch.HasCaught()); | |
| 16165 } | |
| 16166 | |
| 16167 { | |
| 16168 // Use an accessor descriptor. | |
| 16169 CompileRun( | |
| 16170 "var set = function(x) {this.val = 2*x;};" | |
| 16171 "var get = function() {return this.val || 0;};"); | |
| 16172 | |
| 16173 v8::Local<v8::Function> get = v8::Local<v8::Function>::Cast( | |
| 16174 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); | |
| 16175 v8::Local<v8::Function> set = v8::Local<v8::Function>::Cast( | |
| 16176 env->Global()->Get(env.local(), v8_str("set")).ToLocalChecked()); | |
| 16177 const v8::PropertyDescriptor desc(get, true, set, true); | |
| 16178 | |
| 16179 p = v8_str("v7"); | |
| 16180 v8::TryCatch try_catch(isolate); | |
| 16181 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); | |
| 16182 CHECK(!try_catch.HasCaught()); | |
| 16183 | |
| 16184 v8::Local<v8::Value> val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16185 CHECK(val->IsNumber()); | |
| 16186 CHECK_EQ(0.0, val->NumberValue(env.local()).FromJust()); | |
| 16187 CHECK(!try_catch.HasCaught()); | |
| 16188 | |
| 16189 obj->Set(env.local(), p, v8_num(7)).FromJust(); | |
| 16190 CHECK(!try_catch.HasCaught()); | |
| 16191 | |
| 16192 val = obj->Get(env.local(), p).ToLocalChecked(); | |
| 16193 CHECK(val->IsNumber()); | |
| 16194 CHECK_EQ(14.0, val->NumberValue(env.local()).FromJust()); | |
| 16195 CHECK(!try_catch.HasCaught()); | |
| 16196 } | |
| 16197 | |
| 16198 { | |
| 16199 // Re-define a property | |
| 16200 // desc = {value: 42, enumerable: true} | |
| 16201 v8::PropertyDescriptor desc(v8_num(42), true, false, false); | |
| 16202 desc.set_enumerable(true); | |
| 16203 | |
| 16204 p = v8_str("v8"); | |
| 16205 v8::TryCatch try_catch(isolate); | |
| 16206 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); | |
| 16207 CHECK(!try_catch.HasCaught()); | |
| 16208 | |
| 16209 // desc = {enumerable: true} | |
| 16210 // successful because has_enumerable with same value as existing descriptor | |
| 16211 v8::PropertyDescriptor desc_true(v8::Local<v8::Value>(), false, false, | |
| 16212 false); | |
| 16213 desc_true.set_enumerable(true); | |
| 16214 CHECK(obj->DefineProperty(env.local(), p, desc_true).FromJust()); | |
| 16215 CHECK(!try_catch.HasCaught()); | |
| 16216 | |
| 16217 // desc = {} | |
| 16218 // successful because !has_enumerable | |
| 16219 const v8::PropertyDescriptor desc_empty; | |
| 16220 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); | |
| 16221 CHECK(!try_catch.HasCaught()); | |
| 16222 | |
| 16223 // desc = {enumerable: false} | |
| 16224 v8::PropertyDescriptor desc_false(v8::Local<v8::Value>(), false, false, | |
| 16225 false); | |
| 16226 desc_false.set_enumerable(false); | |
| 16227 // not successful, because we cannot overwrite enumerable | |
| 16228 CHECK(!obj->DefineProperty(env.local(), p, desc_false).FromJust()); | |
| 16229 CHECK(!try_catch.HasCaught()); | |
| 16230 } | |
| 16231 | |
| 16232 { | |
| 16233 // Re-define a property that has a getter | |
| 16234 CompileRun("var get = function() {};"); | |
| 16235 v8::Local<v8::Function> get = v8::Local<v8::Function>::Cast( | |
| 16236 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); | |
| 16237 | |
| 16238 // desc = {get: function() {}} | |
| 16239 const v8::PropertyDescriptor desc(get, true, v8::Local<v8::Function>(), | |
| 16240 false); | |
| 16241 v8::TryCatch try_catch(isolate); | |
| 16242 | |
| 16243 p = v8_str("v9"); | |
| 16244 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); | |
| 16245 CHECK(!try_catch.HasCaught()); | |
| 16246 | |
| 16247 // desc = {} | |
| 16248 // successful because get not redefined | |
| 16249 const v8::PropertyDescriptor desc_empty; | |
| 16250 CHECK(obj->DefineProperty(env.local(), p, desc_empty).FromJust()); | |
| 16251 CHECK(!try_catch.HasCaught()); | |
| 16252 | |
| 16253 // desc = {get: function() {}} | |
| 16254 // successful because re-define with same value | |
|
Jakob Kummerow
2016/08/26 13:28:30
nit: here and other comments: capitalization, gram
| |
| 16255 CHECK(obj->DefineProperty(env.local(), p, desc).FromJust()); | |
| 16256 CHECK(!try_catch.HasCaught()); | |
| 16257 | |
| 16258 // desc = {get: undefined} | |
| 16259 const v8::PropertyDescriptor desc_undefined( | |
| 16260 v8::Local<v8::Function>(), true, v8::Local<v8::Function>(), false); | |
| 16261 // not successful, because we cannot overwrite with undefined | |
| 16262 CHECK(!obj->DefineProperty(env.local(), p, desc_undefined).FromJust()); | |
| 16263 CHECK(!try_catch.HasCaught()); | |
| 16264 } | |
| 16265 | |
| 16266 CompileRun("Object.freeze(a);"); | |
| 16267 { | |
| 16268 // Can't change non-extensible objects. | |
| 16269 v8::TryCatch try_catch(isolate); | |
| 16270 CHECK(!obj->DefineProperty(env.local(), v8_str("v10"), desc).FromJust()); | |
| 16271 CHECK(!try_catch.HasCaught()); | |
| 16272 } | |
| 16273 | |
| 16274 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | |
| 16275 templ->SetAccessCheckCallback(AccessAlwaysBlocked); | |
| 16276 v8::Local<v8::Object> access_checked = | |
| 16277 templ->NewInstance(env.local()).ToLocalChecked(); | |
| 16278 { | |
| 16279 v8::TryCatch try_catch(isolate); | |
| 16280 CHECK(access_checked->DefineProperty(env.local(), v8_str("v11"), desc) | |
| 16281 .IsNothing()); | |
| 16282 CHECK(try_catch.HasCaught()); | |
| 16283 } | |
| 16284 } | |
| 16007 | 16285 |
| 16008 THREADED_TEST(GetCurrentContextWhenNotInContext) { | 16286 THREADED_TEST(GetCurrentContextWhenNotInContext) { |
| 16009 i::Isolate* isolate = CcTest::i_isolate(); | 16287 i::Isolate* isolate = CcTest::i_isolate(); |
| 16010 CHECK(isolate != NULL); | 16288 CHECK(isolate != NULL); |
| 16011 CHECK(isolate->context() == NULL); | 16289 CHECK(isolate->context() == NULL); |
| 16012 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 16290 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 16013 v8::HandleScope scope(v8_isolate); | 16291 v8::HandleScope scope(v8_isolate); |
| 16014 // The following should not crash, but return an empty handle. | 16292 // The following should not crash, but return an empty handle. |
| 16015 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); | 16293 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); |
| 16016 CHECK(current.IsEmpty()); | 16294 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, | 23610 "V8.Test", 0, 10000, v8::internal::HistogramTimer::MILLISECOND, 50, |
| 23333 reinterpret_cast<v8::internal::Isolate*>(isolate)); | 23611 reinterpret_cast<v8::internal::Isolate*>(isolate)); |
| 23334 histogramTimer.Start(); | 23612 histogramTimer.Start(); |
| 23335 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 23613 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
| 23336 CHECK_EQ(0, last_event_status); | 23614 CHECK_EQ(0, last_event_status); |
| 23337 histogramTimer.Stop(); | 23615 histogramTimer.Stop(); |
| 23338 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 23616 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
| 23339 CHECK_EQ(1, last_event_status); | 23617 CHECK_EQ(1, last_event_status); |
| 23340 } | 23618 } |
| 23341 | 23619 |
| 23620 TEST(PropertyDescriptor) { | |
| 23621 LocalContext context; | |
| 23622 v8::Isolate* isolate = context->GetIsolate(); | |
| 23623 v8::HandleScope scope(isolate); | |
| 23624 | |
| 23625 { // empty descriptor | |
| 23626 v8::PropertyDescriptor desc; | |
| 23627 CHECK(!desc.has_value()); | |
| 23628 CHECK(desc.value() == v8::Local<v8::Value>()); | |
| 23629 CHECK(!desc.has_set()); | |
| 23630 CHECK(!desc.has_get()); | |
| 23631 CHECK(!desc.enumerable()); | |
|
Jakob Kummerow
2016/08/26 13:28:30
This seems rather pointless. Given that !desc.has_
| |
| 23632 CHECK(!desc.has_enumerable()); | |
| 23633 CHECK(!desc.configurable()); | |
| 23634 CHECK(!desc.has_configurable()); | |
| 23635 CHECK(!desc.writable()); | |
| 23636 CHECK(!desc.has_writable()); | |
| 23637 } | |
| 23638 | |
| 23639 { // data descriptor | |
| 23640 v8::PropertyDescriptor desc(v8_num(42), true, false, false); | |
| 23641 CHECK(desc.value() == v8_num(42)); | |
| 23642 CHECK(desc.has_value()); | |
| 23643 CHECK(!desc.has_set()); | |
| 23644 CHECK(!desc.has_get()); | |
| 23645 CHECK(!desc.enumerable()); | |
| 23646 CHECK(!desc.has_enumerable()); | |
| 23647 CHECK(!desc.configurable()); | |
| 23648 CHECK(!desc.has_configurable()); | |
| 23649 CHECK(!desc.writable()); | |
| 23650 CHECK(!desc.has_writable()); | |
| 23651 } | |
| 23652 { | |
| 23653 // data descriptor | |
| 23654 v8::PropertyDescriptor desc(v8_num(42), false, false, false); | |
| 23655 desc.set_enumerable(true); | |
| 23656 CHECK(desc.value() == v8_num(42)); | |
| 23657 CHECK(!desc.has_value()); | |
| 23658 CHECK(!desc.has_set()); | |
| 23659 CHECK(!desc.has_get()); | |
| 23660 CHECK(desc.enumerable()); | |
| 23661 CHECK(desc.has_enumerable()); | |
| 23662 CHECK(!desc.configurable()); | |
| 23663 CHECK(!desc.has_configurable()); | |
| 23664 CHECK(!desc.writable()); | |
| 23665 CHECK(!desc.has_writable()); | |
| 23666 } | |
| 23667 { | |
| 23668 // data descriptor | |
| 23669 v8::PropertyDescriptor desc(v8_num(42), false, false, false); | |
| 23670 desc.set_enumerable(false); | |
| 23671 CHECK(desc.value() == v8_num(42)); | |
| 23672 CHECK(!desc.has_value()); | |
| 23673 CHECK(!desc.has_set()); | |
| 23674 CHECK(!desc.has_get()); | |
| 23675 CHECK(!desc.enumerable()); | |
| 23676 CHECK(desc.has_enumerable()); | |
| 23677 CHECK(!desc.configurable()); | |
| 23678 CHECK(!desc.has_configurable()); | |
| 23679 CHECK(!desc.writable()); | |
| 23680 CHECK(!desc.has_writable()); | |
| 23681 } | |
| 23682 { | |
| 23683 // data descriptor | |
| 23684 v8::PropertyDescriptor desc(v8_num(42), false, false, false); | |
| 23685 desc.set_configurable(true); | |
| 23686 CHECK(desc.value() == v8_num(42)); | |
| 23687 CHECK(!desc.has_value()); | |
| 23688 CHECK(!desc.has_set()); | |
| 23689 CHECK(!desc.has_get()); | |
| 23690 CHECK(!desc.enumerable()); | |
| 23691 CHECK(!desc.has_enumerable()); | |
| 23692 CHECK(desc.configurable()); | |
| 23693 CHECK(desc.has_configurable()); | |
| 23694 CHECK(!desc.writable()); | |
| 23695 CHECK(!desc.has_writable()); | |
| 23696 } | |
| 23697 { | |
| 23698 // data descriptor | |
| 23699 v8::PropertyDescriptor desc(v8_num(42), false, false, false); | |
| 23700 desc.set_configurable(false); | |
| 23701 CHECK(desc.value() == v8_num(42)); | |
| 23702 CHECK(!desc.has_value()); | |
| 23703 CHECK(!desc.has_set()); | |
| 23704 CHECK(!desc.has_get()); | |
| 23705 CHECK(!desc.enumerable()); | |
| 23706 CHECK(!desc.has_enumerable()); | |
| 23707 CHECK(!desc.configurable()); | |
| 23708 CHECK(desc.has_configurable()); | |
| 23709 CHECK(!desc.writable()); | |
| 23710 CHECK(!desc.has_writable()); | |
| 23711 } | |
| 23712 { | |
| 23713 // data descriptor | |
| 23714 v8::PropertyDescriptor desc(v8_num(42), false, true, false); | |
| 23715 CHECK(desc.value() == v8_num(42)); | |
| 23716 CHECK(!desc.has_value()); | |
| 23717 CHECK(!desc.has_set()); | |
| 23718 CHECK(!desc.has_get()); | |
| 23719 CHECK(!desc.enumerable()); | |
| 23720 CHECK(!desc.has_enumerable()); | |
| 23721 CHECK(!desc.configurable()); | |
| 23722 CHECK(!desc.has_configurable()); | |
| 23723 CHECK(desc.writable()); | |
| 23724 CHECK(!desc.has_writable()); | |
| 23725 } | |
| 23726 { | |
| 23727 // data descriptor | |
| 23728 v8::PropertyDescriptor desc(v8_num(42), false, false, true); | |
| 23729 CHECK(desc.value() == v8_num(42)); | |
| 23730 CHECK(!desc.has_value()); | |
| 23731 CHECK(!desc.has_set()); | |
| 23732 CHECK(!desc.has_get()); | |
| 23733 CHECK(!desc.enumerable()); | |
| 23734 CHECK(!desc.has_enumerable()); | |
| 23735 CHECK(!desc.configurable()); | |
| 23736 CHECK(!desc.has_configurable()); | |
| 23737 CHECK(!desc.writable()); | |
| 23738 CHECK(desc.has_writable()); | |
| 23739 } | |
| 23740 { | |
| 23741 // data descriptor | |
| 23742 v8::PropertyDescriptor desc(v8::Local<v8::Value>(), false, false, true); | |
| 23743 CHECK(desc.value() == v8::Local<v8::Value>()); | |
| 23744 CHECK(!desc.has_value()); | |
| 23745 CHECK(!desc.has_set()); | |
| 23746 CHECK(!desc.has_get()); | |
| 23747 CHECK(!desc.has_enumerable()); | |
| 23748 CHECK(!desc.has_configurable()); | |
| 23749 CHECK(!desc.writable()); | |
| 23750 CHECK(desc.has_writable()); | |
| 23751 } | |
| 23752 { | |
| 23753 // accessor descriptor | |
| 23754 CompileRun( | |
| 23755 "var set = function() {return 43;};" | |
| 23756 "var get = function() {return 42;};"); | |
| 23757 | |
| 23758 v8::Local<v8::Function> get = | |
| 23759 v8::Local<v8::Function>::Cast(context->Global() | |
| 23760 ->Get(context.local(), v8_str("get")) | |
| 23761 .ToLocalChecked()); | |
| 23762 v8::Local<v8::Function> set = | |
| 23763 v8::Local<v8::Function>::Cast(context->Global() | |
| 23764 ->Get(context.local(), v8_str("set")) | |
| 23765 .ToLocalChecked()); | |
| 23766 v8::PropertyDescriptor desc(get, false, set, true); | |
| 23767 desc.set_configurable(false); | |
| 23768 CHECK(!desc.has_value()); | |
| 23769 CHECK(desc.get() == get); | |
| 23770 CHECK(!desc.has_get()); | |
| 23771 CHECK(desc.set() == set); | |
| 23772 CHECK(desc.has_set()); | |
| 23773 CHECK(!desc.enumerable()); | |
| 23774 CHECK(!desc.has_enumerable()); | |
| 23775 CHECK(!desc.configurable()); | |
| 23776 CHECK(desc.has_configurable()); | |
| 23777 CHECK(!desc.writable()); | |
| 23778 CHECK(!desc.has_writable()); | |
| 23779 } | |
| 23780 { | |
| 23781 // accessor descriptor with Proxy | |
| 23782 CompileRun( | |
| 23783 "var set = new Proxy(function() {}, {});" | |
| 23784 "var get = function() {return 42;};"); | |
| 23785 | |
| 23786 v8::Local<v8::Function> get = | |
| 23787 v8::Local<v8::Function>::Cast(context->Global() | |
| 23788 ->Get(context.local(), v8_str("get")) | |
| 23789 .ToLocalChecked()); | |
| 23790 v8::Local<v8::Function> set = | |
| 23791 v8::Local<v8::Function>::Cast(context->Global() | |
| 23792 ->Get(context.local(), v8_str("set")) | |
| 23793 .ToLocalChecked()); | |
| 23794 v8::PropertyDescriptor desc(get, false, set, true); | |
| 23795 desc.set_configurable(false); | |
| 23796 CHECK(!desc.has_value()); | |
| 23797 CHECK(desc.get() == get); | |
| 23798 CHECK(!desc.has_get()); | |
| 23799 CHECK(desc.set() == set); | |
| 23800 CHECK(desc.has_set()); | |
| 23801 CHECK(!desc.enumerable()); | |
| 23802 CHECK(!desc.has_enumerable()); | |
| 23803 CHECK(!desc.configurable()); | |
| 23804 CHECK(desc.has_configurable()); | |
| 23805 CHECK(!desc.writable()); | |
| 23806 CHECK(!desc.has_writable()); | |
| 23807 } | |
| 23808 { | |
| 23809 // accessor descriptor with empty function handle | |
| 23810 v8::Local<v8::Function> get = v8::Local<v8::Function>(); | |
| 23811 v8::PropertyDescriptor desc(get, false, v8::Local<v8::Function>(), false); | |
| 23812 CHECK(!desc.has_value()); | |
| 23813 CHECK(desc.get() == get); | |
| 23814 CHECK(!desc.has_get()); | |
| 23815 CHECK(desc.set() == v8::Local<v8::Function>()); | |
| 23816 CHECK(!desc.has_set()); | |
| 23817 CHECK(!desc.enumerable()); | |
| 23818 CHECK(!desc.has_enumerable()); | |
| 23819 CHECK(!desc.configurable()); | |
| 23820 CHECK(!desc.has_configurable()); | |
| 23821 CHECK(!desc.writable()); | |
| 23822 CHECK(!desc.has_writable()); | |
| 23823 } | |
| 23824 } | |
| 23342 | 23825 |
| 23343 TEST(Promises) { | 23826 TEST(Promises) { |
| 23344 LocalContext context; | 23827 LocalContext context; |
| 23345 v8::Isolate* isolate = context->GetIsolate(); | 23828 v8::Isolate* isolate = context->GetIsolate(); |
| 23346 v8::HandleScope scope(isolate); | 23829 v8::HandleScope scope(isolate); |
| 23347 | 23830 |
| 23348 // Creation. | 23831 // Creation. |
| 23349 Local<v8::Promise::Resolver> pr = | 23832 Local<v8::Promise::Resolver> pr = |
| 23350 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); | 23833 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
| 23351 Local<v8::Promise::Resolver> rr = | 23834 Local<v8::Promise::Resolver> rr = |
| (...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 25524 | 26007 |
| 25525 // Put the function into context1 and call it. Since the access check | 26008 // Put the function into context1 and call it. Since the access check |
| 25526 // callback always returns true, the call succeeds even though the tokens | 26009 // callback always returns true, the call succeeds even though the tokens |
| 25527 // are different. | 26010 // are different. |
| 25528 context1->Enter(); | 26011 context1->Enter(); |
| 25529 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); | 26012 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); |
| 25530 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); | 26013 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); |
| 25531 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); | 26014 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); |
| 25532 context1->Exit(); | 26015 context1->Exit(); |
| 25533 } | 26016 } |
| OLD | NEW |