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 CompileRun( |
| 16013 "var a = {};" |
| 16014 "var b = [];" |
| 16015 "Object.defineProperty(a, 'foo', {value: 23});" |
| 16016 "Object.defineProperty(a, 'bar', {value: 23, configurable: true});"); |
| 16017 |
| 16018 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast( |
| 16019 env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked()); |
| 16020 v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast( |
| 16021 env->Global()->Get(env.local(), v8_str("b")).ToLocalChecked()); |
| 16022 |
| 16023 const v8::PropertyDescriptor desc = v8::PropertyDescriptor(v8_num(42), true); |
| 16024 { |
| 16025 // Use a data descriptor. |
| 16026 |
| 16027 // Can't change a non-configurable property. |
| 16028 v8::TryCatch try_catch(isolate); |
| 16029 CHECK(!obj->DefineProperty(env.local(), v8_str("foo"), &desc).FromJust()); |
| 16030 CHECK(!try_catch.HasCaught()); |
| 16031 v8::Local<v8::Value> val = |
| 16032 obj->Get(env.local(), v8_str("foo")).ToLocalChecked(); |
| 16033 CHECK(val->IsNumber()); |
| 16034 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); |
| 16035 |
| 16036 // Change configurable property |
| 16037 CHECK(obj->DefineProperty(env.local(), v8_str("bar"), &desc).FromJust()); |
| 16038 CHECK(!try_catch.HasCaught()); |
| 16039 val = obj->Get(env.local(), v8_str("bar")).ToLocalChecked(); |
| 16040 CHECK(val->IsNumber()); |
| 16041 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16042 } |
| 16043 |
| 16044 { |
| 16045 // Set a regular property. |
| 16046 v8::TryCatch try_catch(isolate); |
| 16047 CHECK(obj->DefineProperty(env.local(), v8_str("blub"), &desc).FromJust()); |
| 16048 CHECK(!try_catch.HasCaught()); |
| 16049 v8::Local<v8::Value> val = |
| 16050 obj->Get(env.local(), v8_str("blub")).ToLocalChecked(); |
| 16051 CHECK(val->IsNumber()); |
| 16052 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16053 } |
| 16054 |
| 16055 { |
| 16056 // Set an indexed property. |
| 16057 v8::TryCatch try_catch(isolate); |
| 16058 CHECK(obj->DefineProperty(env.local(), v8_str("1"), &desc).FromJust()); |
| 16059 CHECK(!try_catch.HasCaught()); |
| 16060 v8::Local<v8::Value> val = obj->Get(env.local(), 1).ToLocalChecked(); |
| 16061 CHECK(val->IsNumber()); |
| 16062 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16063 } |
| 16064 |
| 16065 { |
| 16066 // No special case when changing array length. |
| 16067 v8::TryCatch try_catch(isolate); |
| 16068 CHECK(arr->DefineProperty(env.local(), v8_str("length"), &desc).FromJust()); |
| 16069 CHECK(!try_catch.HasCaught()); |
| 16070 } |
| 16071 |
| 16072 { |
| 16073 // Special cases for arrays: index exceeds the array's length. |
| 16074 v8::TryCatch try_catch(isolate); |
| 16075 CHECK(arr->DefineProperty(env.local(), v8_str("100"), &desc).FromJust()); |
| 16076 CHECK(!try_catch.HasCaught()); |
| 16077 CHECK_EQ(101U, arr->Length()); |
| 16078 v8::Local<v8::Value> val = arr->Get(env.local(), 100).ToLocalChecked(); |
| 16079 CHECK(val->IsNumber()); |
| 16080 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16081 |
| 16082 // Set an existing entry. |
| 16083 CHECK(arr->DefineProperty(env.local(), v8_str("0"), &desc).FromJust()); |
| 16084 CHECK(!try_catch.HasCaught()); |
| 16085 val = arr->Get(env.local(), 0).ToLocalChecked(); |
| 16086 CHECK(val->IsNumber()); |
| 16087 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16088 } |
| 16089 |
| 16090 { |
| 16091 // Use a generic descriptor. |
| 16092 const v8::PropertyDescriptor desc = v8::PropertyDescriptor(); |
| 16093 |
| 16094 v8::TryCatch try_catch(isolate); |
| 16095 CHECK( |
| 16096 obj->DefineProperty(env.local(), v8_str("generic"), &desc).FromJust()); |
| 16097 CHECK(!try_catch.HasCaught()); |
| 16098 v8::Local<v8::Value> val = |
| 16099 obj->Get(env.local(), v8_str("generic")).ToLocalChecked(); |
| 16100 CHECK(val->IsUndefined()); |
| 16101 |
| 16102 obj->Set(env.local(), v8_str("generic"), v8_num(1)).FromJust(); |
| 16103 CHECK(!try_catch.HasCaught()); |
| 16104 |
| 16105 val = obj->Get(env.local(), v8_str("generic")).ToLocalChecked(); |
| 16106 CHECK(val->IsUndefined()); |
| 16107 CHECK(!try_catch.HasCaught()); |
| 16108 } |
| 16109 |
| 16110 { |
| 16111 // Use a data descriptor with empty handle. |
| 16112 const v8::PropertyDescriptor desc = |
| 16113 v8::PropertyDescriptor(v8::Local<v8::Value>(), true); |
| 16114 |
| 16115 v8::TryCatch try_catch(isolate); |
| 16116 CHECK( |
| 16117 obj->DefineProperty(env.local(), v8_str("generic"), &desc).FromJust()); |
| 16118 CHECK(!try_catch.HasCaught()); |
| 16119 v8::Local<v8::Value> val = |
| 16120 obj->Get(env.local(), v8_str("generic")).ToLocalChecked(); |
| 16121 CHECK(val->IsUndefined()); |
| 16122 CHECK(!try_catch.HasCaught()); |
| 16123 } |
| 16124 |
| 16125 { |
| 16126 // Use a descriptor with attribute == v8::ReadOnly. |
| 16127 const v8::PropertyDescriptor desc = v8::PropertyDescriptor( |
| 16128 v8_num(42), true, true, true, true, true, false, true); |
| 16129 |
| 16130 v8::TryCatch try_catch(isolate); |
| 16131 CHECK(obj->DefineProperty(env.local(), v8_str("lala"), &desc).FromJust()); |
| 16132 CHECK(!try_catch.HasCaught()); |
| 16133 v8::Local<v8::Value> val = |
| 16134 obj->Get(env.local(), v8_str("lala")).ToLocalChecked(); |
| 16135 CHECK(val->IsNumber()); |
| 16136 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); |
| 16137 CHECK_EQ( |
| 16138 v8::ReadOnly, |
| 16139 obj->GetPropertyAttributes(env.local(), v8_str("lala")).FromJust()); |
| 16140 CHECK(!try_catch.HasCaught()); |
| 16141 } |
| 16142 |
| 16143 { |
| 16144 // Use an accessor descriptor with empty handles. |
| 16145 const v8::PropertyDescriptor desc = v8::PropertyDescriptor( |
| 16146 v8::Local<v8::Function>(), true, v8::Local<v8::Function>(), true); |
| 16147 |
| 16148 v8::TryCatch try_catch(isolate); |
| 16149 CHECK(obj->DefineProperty(env.local(), v8_str("undef_accessor"), &desc) |
| 16150 .FromJust()); |
| 16151 CHECK(!try_catch.HasCaught()); |
| 16152 v8::Local<v8::Value> val = |
| 16153 obj->Get(env.local(), v8_str("undef_accessor")).ToLocalChecked(); |
| 16154 CHECK(val->IsUndefined()); |
| 16155 CHECK(!try_catch.HasCaught()); |
| 16156 } |
| 16157 |
| 16158 { |
| 16159 // Use an accessor descriptor. |
| 16160 CompileRun( |
| 16161 "var set = function(x) {this.val = 2*x;};" |
| 16162 "var get = function() {return this.val || 0;};"); |
| 16163 |
| 16164 v8::Local<v8::Function> get = v8::Local<v8::Function>::Cast( |
| 16165 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); |
| 16166 v8::Local<v8::Function> set = v8::Local<v8::Function>::Cast( |
| 16167 env->Global()->Get(env.local(), v8_str("set")).ToLocalChecked()); |
| 16168 const v8::PropertyDescriptor desc = |
| 16169 v8::PropertyDescriptor(get, true, set, true); |
| 16170 |
| 16171 v8::TryCatch try_catch(isolate); |
| 16172 CHECK(obj->DefineProperty(env.local(), v8_str("twice"), &desc).FromJust()); |
| 16173 CHECK(!try_catch.HasCaught()); |
| 16174 |
| 16175 v8::Local<v8::Value> val = |
| 16176 obj->Get(env.local(), v8_str("twice")).ToLocalChecked(); |
| 16177 CHECK(val->IsNumber()); |
| 16178 CHECK_EQ(0.0, val->NumberValue(env.local()).FromJust()); |
| 16179 CHECK(!try_catch.HasCaught()); |
| 16180 |
| 16181 obj->Set(env.local(), v8_str("twice"), v8_num(7)).FromJust(); |
| 16182 CHECK(!try_catch.HasCaught()); |
| 16183 |
| 16184 val = obj->Get(env.local(), v8_str("twice")).ToLocalChecked(); |
| 16185 CHECK(val->IsNumber()); |
| 16186 CHECK_EQ(14.0, val->NumberValue(env.local()).FromJust()); |
| 16187 CHECK(!try_catch.HasCaught()); |
| 16188 } |
| 16189 |
| 16190 { |
| 16191 // Re-define a property |
| 16192 // desc = {value: 42, enumerable: true} |
| 16193 const v8::PropertyDescriptor desc = |
| 16194 v8::PropertyDescriptor(v8_num(42), false, true, true); |
| 16195 v8::TryCatch try_catch(isolate); |
| 16196 CHECK( |
| 16197 obj->DefineProperty(env.local(), v8_str("has_enum"), &desc).FromJust()); |
| 16198 CHECK(!try_catch.HasCaught()); |
| 16199 |
| 16200 // desc = {enumerable: true} |
| 16201 // successful because has_enumerable with same value as existing descriptor |
| 16202 const v8::PropertyDescriptor desc_true = |
| 16203 v8::PropertyDescriptor(v8::Local<v8::Value>(), false, true, true); |
| 16204 CHECK(obj->DefineProperty(env.local(), v8_str("has_enum"), &desc_true) |
| 16205 .FromJust()); |
| 16206 CHECK(!try_catch.HasCaught()); |
| 16207 |
| 16208 // desc = {} |
| 16209 // successful because !has_enumerable |
| 16210 const v8::PropertyDescriptor desc_empty = v8::PropertyDescriptor(); |
| 16211 CHECK(obj->DefineProperty(env.local(), v8_str("has_enum"), &desc_empty) |
| 16212 .FromJust()); |
| 16213 CHECK(!try_catch.HasCaught()); |
| 16214 |
| 16215 // desc = {enumerable: false} |
| 16216 const v8::PropertyDescriptor desc_false = |
| 16217 v8::PropertyDescriptor(v8::Local<v8::Value>(), false, false, true); |
| 16218 // not be successful, because we cannot overwrite enumerable |
| 16219 CHECK(!obj->DefineProperty(env.local(), v8_str("has_enum"), &desc_false) |
| 16220 .FromJust()); |
| 16221 CHECK(!try_catch.HasCaught()); |
| 16222 } |
| 16223 |
| 16224 CompileRun("Object.freeze(a);"); |
| 16225 { |
| 16226 // Can't change non-extensible objects. |
| 16227 v8::TryCatch try_catch(isolate); |
| 16228 CHECK(!obj->DefineProperty(env.local(), v8_str("baz"), &desc).FromJust()); |
| 16229 CHECK(!try_catch.HasCaught()); |
| 16230 } |
| 16231 |
| 16232 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
| 16233 templ->SetAccessCheckCallback(AccessAlwaysBlocked); |
| 16234 v8::Local<v8::Object> access_checked = |
| 16235 templ->NewInstance(env.local()).ToLocalChecked(); |
| 16236 { |
| 16237 v8::TryCatch try_catch(isolate); |
| 16238 CHECK(access_checked->DefineProperty(env.local(), v8_str("foo"), &desc) |
| 16239 .IsNothing()); |
| 16240 CHECK(try_catch.HasCaught()); |
| 16241 } |
| 16242 } |
16007 | 16243 |
16008 THREADED_TEST(GetCurrentContextWhenNotInContext) { | 16244 THREADED_TEST(GetCurrentContextWhenNotInContext) { |
16009 i::Isolate* isolate = CcTest::i_isolate(); | 16245 i::Isolate* isolate = CcTest::i_isolate(); |
16010 CHECK(isolate != NULL); | 16246 CHECK(isolate != NULL); |
16011 CHECK(isolate->context() == NULL); | 16247 CHECK(isolate->context() == NULL); |
16012 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 16248 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
16013 v8::HandleScope scope(v8_isolate); | 16249 v8::HandleScope scope(v8_isolate); |
16014 // The following should not crash, but return an empty handle. | 16250 // The following should not crash, but return an empty handle. |
16015 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); | 16251 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext(); |
16016 CHECK(current.IsEmpty()); | 16252 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, | 23568 "V8.Test", 0, 10000, v8::internal::HistogramTimer::MILLISECOND, 50, |
23333 reinterpret_cast<v8::internal::Isolate*>(isolate)); | 23569 reinterpret_cast<v8::internal::Isolate*>(isolate)); |
23334 histogramTimer.Start(); | 23570 histogramTimer.Start(); |
23335 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 23571 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
23336 CHECK_EQ(0, last_event_status); | 23572 CHECK_EQ(0, last_event_status); |
23337 histogramTimer.Stop(); | 23573 histogramTimer.Stop(); |
23338 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 23574 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
23339 CHECK_EQ(1, last_event_status); | 23575 CHECK_EQ(1, last_event_status); |
23340 } | 23576 } |
23341 | 23577 |
| 23578 TEST(PropertyDescriptor) { |
| 23579 LocalContext context; |
| 23580 v8::Isolate* isolate = context->GetIsolate(); |
| 23581 v8::HandleScope scope(isolate); |
| 23582 |
| 23583 // empty descriptor |
| 23584 v8::PropertyDescriptor desc; |
| 23585 CHECK(!desc.has_value()); |
| 23586 CHECK(desc.value() == v8::Local<v8::Value>()); |
| 23587 CHECK(!desc.has_set()); |
| 23588 CHECK(!desc.has_get()); |
| 23589 CHECK(!desc.enumerable()); |
| 23590 CHECK(!desc.has_enumerable()); |
| 23591 CHECK(!desc.configurable()); |
| 23592 CHECK(!desc.has_configurable()); |
| 23593 CHECK(!desc.writable()); |
| 23594 CHECK(!desc.has_writable()); |
| 23595 |
| 23596 // data descriptor |
| 23597 desc = v8::PropertyDescriptor(v8_num(42), true); |
| 23598 CHECK(desc.value() == v8_num(42)); |
| 23599 CHECK(desc.has_value()); |
| 23600 CHECK(!desc.has_set()); |
| 23601 CHECK(!desc.has_get()); |
| 23602 CHECK(!desc.enumerable()); |
| 23603 CHECK(!desc.has_enumerable()); |
| 23604 CHECK(!desc.configurable()); |
| 23605 CHECK(!desc.has_configurable()); |
| 23606 CHECK(!desc.writable()); |
| 23607 CHECK(!desc.has_writable()); |
| 23608 |
| 23609 // data descriptor |
| 23610 desc = v8::PropertyDescriptor(v8_num(42), false, true); |
| 23611 CHECK(desc.value() == v8_num(42)); |
| 23612 CHECK(!desc.has_value()); |
| 23613 CHECK(!desc.has_set()); |
| 23614 CHECK(!desc.has_get()); |
| 23615 CHECK(desc.enumerable()); |
| 23616 CHECK(!desc.has_enumerable()); |
| 23617 CHECK(!desc.configurable()); |
| 23618 CHECK(!desc.has_configurable()); |
| 23619 CHECK(!desc.writable()); |
| 23620 CHECK(!desc.has_writable()); |
| 23621 |
| 23622 // data descriptor |
| 23623 desc = v8::PropertyDescriptor(v8_num(42), false, false, true); |
| 23624 CHECK(desc.value() == v8_num(42)); |
| 23625 CHECK(!desc.has_value()); |
| 23626 CHECK(!desc.has_set()); |
| 23627 CHECK(!desc.has_get()); |
| 23628 CHECK(!desc.enumerable()); |
| 23629 CHECK(desc.has_enumerable()); |
| 23630 CHECK(!desc.configurable()); |
| 23631 CHECK(!desc.has_configurable()); |
| 23632 CHECK(!desc.writable()); |
| 23633 CHECK(!desc.has_writable()); |
| 23634 |
| 23635 // data descriptor |
| 23636 desc = v8::PropertyDescriptor(v8_num(42), false, false, false, true); |
| 23637 CHECK(desc.value() == v8_num(42)); |
| 23638 CHECK(!desc.has_value()); |
| 23639 CHECK(!desc.has_set()); |
| 23640 CHECK(!desc.has_get()); |
| 23641 CHECK(!desc.enumerable()); |
| 23642 CHECK(!desc.has_enumerable()); |
| 23643 CHECK(desc.configurable()); |
| 23644 CHECK(!desc.has_configurable()); |
| 23645 CHECK(!desc.writable()); |
| 23646 CHECK(!desc.has_writable()); |
| 23647 |
| 23648 // data descriptor |
| 23649 desc = v8::PropertyDescriptor(v8_num(42), false, false, false, false, true); |
| 23650 CHECK(desc.value() == v8_num(42)); |
| 23651 CHECK(!desc.has_value()); |
| 23652 CHECK(!desc.has_set()); |
| 23653 CHECK(!desc.has_get()); |
| 23654 CHECK(!desc.enumerable()); |
| 23655 CHECK(!desc.has_enumerable()); |
| 23656 CHECK(!desc.configurable()); |
| 23657 CHECK(desc.has_configurable()); |
| 23658 CHECK(!desc.writable()); |
| 23659 CHECK(!desc.has_writable()); |
| 23660 |
| 23661 // data descriptor |
| 23662 desc = v8::PropertyDescriptor(v8_num(42), false, false, false, false, false, |
| 23663 true); |
| 23664 CHECK(desc.value() == v8_num(42)); |
| 23665 CHECK(!desc.has_value()); |
| 23666 CHECK(!desc.has_set()); |
| 23667 CHECK(!desc.has_get()); |
| 23668 CHECK(!desc.enumerable()); |
| 23669 CHECK(!desc.has_enumerable()); |
| 23670 CHECK(!desc.configurable()); |
| 23671 CHECK(!desc.has_configurable()); |
| 23672 CHECK(desc.writable()); |
| 23673 CHECK(!desc.has_writable()); |
| 23674 |
| 23675 // data descriptor |
| 23676 desc = v8::PropertyDescriptor(v8_num(42), false, false, false, false, false, |
| 23677 false, true); |
| 23678 CHECK(desc.value() == v8_num(42)); |
| 23679 CHECK(!desc.has_value()); |
| 23680 CHECK(!desc.has_set()); |
| 23681 CHECK(!desc.has_get()); |
| 23682 CHECK(!desc.enumerable()); |
| 23683 CHECK(!desc.has_enumerable()); |
| 23684 CHECK(!desc.configurable()); |
| 23685 CHECK(!desc.has_configurable()); |
| 23686 CHECK(!desc.writable()); |
| 23687 CHECK(desc.has_writable()); |
| 23688 |
| 23689 // data descriptor |
| 23690 desc = v8::PropertyDescriptor(v8::Local<v8::Value>(), false, false, false, |
| 23691 false, false, false, true); |
| 23692 CHECK(!desc.has_value()); |
| 23693 CHECK(!desc.has_set()); |
| 23694 CHECK(!desc.has_get()); |
| 23695 CHECK(!desc.has_enumerable()); |
| 23696 CHECK(!desc.has_configurable()); |
| 23697 CHECK(desc.has_writable()); |
| 23698 CHECK(!desc.writable()); |
| 23699 |
| 23700 // accessor descriptor |
| 23701 LocalContext env; |
| 23702 |
| 23703 CompileRun( |
| 23704 "var set = function() {return 43;};" |
| 23705 "var get = function() {return 42;};"); |
| 23706 |
| 23707 v8::Local<v8::Function> get = v8::Local<v8::Function>::Cast( |
| 23708 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); |
| 23709 v8::Local<v8::Function> set = v8::Local<v8::Function>::Cast( |
| 23710 env->Global()->Get(env.local(), v8_str("set")).ToLocalChecked()); |
| 23711 desc = |
| 23712 v8::PropertyDescriptor(get, false, set, true, false, false, false, true); |
| 23713 CHECK(!desc.has_value()); |
| 23714 CHECK(desc.get() == get); |
| 23715 CHECK(!desc.has_get()); |
| 23716 CHECK(desc.set() == set); |
| 23717 CHECK(desc.has_set()); |
| 23718 CHECK(!desc.enumerable()); |
| 23719 CHECK(!desc.has_enumerable()); |
| 23720 CHECK(!desc.configurable()); |
| 23721 CHECK(desc.has_configurable()); |
| 23722 CHECK(!desc.writable()); |
| 23723 CHECK(!desc.has_writable()); |
| 23724 |
| 23725 // accessor descriptor with Proxy |
| 23726 CompileRun( |
| 23727 "var set = new Proxy(function() {}, {});" |
| 23728 "var get = function() {return 42;};"); |
| 23729 |
| 23730 get = v8::Local<v8::Function>::Cast( |
| 23731 env->Global()->Get(env.local(), v8_str("get")).ToLocalChecked()); |
| 23732 set = v8::Local<v8::Function>::Cast( |
| 23733 env->Global()->Get(env.local(), v8_str("set")).ToLocalChecked()); |
| 23734 desc = |
| 23735 v8::PropertyDescriptor(get, false, set, true, false, false, false, true); |
| 23736 CHECK(!desc.has_value()); |
| 23737 CHECK(desc.get() == get); |
| 23738 CHECK(!desc.has_get()); |
| 23739 CHECK(desc.set() == set); |
| 23740 CHECK(desc.has_set()); |
| 23741 CHECK(!desc.enumerable()); |
| 23742 CHECK(!desc.has_enumerable()); |
| 23743 CHECK(!desc.configurable()); |
| 23744 CHECK(desc.has_configurable()); |
| 23745 CHECK(!desc.writable()); |
| 23746 CHECK(!desc.has_writable()); |
| 23747 |
| 23748 // accessor descriptor with empty function handle |
| 23749 get = v8::Local<v8::Function>(); |
| 23750 desc = v8::PropertyDescriptor(get, false); |
| 23751 CHECK(!desc.has_value()); |
| 23752 CHECK(desc.get() == get); |
| 23753 CHECK(!desc.has_get()); |
| 23754 CHECK(desc.set() == v8::Local<v8::Function>()); |
| 23755 CHECK(!desc.has_set()); |
| 23756 CHECK(!desc.enumerable()); |
| 23757 CHECK(!desc.has_enumerable()); |
| 23758 CHECK(!desc.configurable()); |
| 23759 CHECK(!desc.has_configurable()); |
| 23760 CHECK(!desc.writable()); |
| 23761 CHECK(!desc.has_writable()); |
| 23762 } |
23342 | 23763 |
23343 TEST(Promises) { | 23764 TEST(Promises) { |
23344 LocalContext context; | 23765 LocalContext context; |
23345 v8::Isolate* isolate = context->GetIsolate(); | 23766 v8::Isolate* isolate = context->GetIsolate(); |
23346 v8::HandleScope scope(isolate); | 23767 v8::HandleScope scope(isolate); |
23347 | 23768 |
23348 // Creation. | 23769 // Creation. |
23349 Local<v8::Promise::Resolver> pr = | 23770 Local<v8::Promise::Resolver> pr = |
23350 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); | 23771 v8::Promise::Resolver::New(context.local()).ToLocalChecked(); |
23351 Local<v8::Promise::Resolver> rr = | 23772 Local<v8::Promise::Resolver> rr = |
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25524 | 25945 |
25525 // Put the function into context1 and call it. Since the access check | 25946 // Put the function into context1 and call it. Since the access check |
25526 // callback always returns true, the call succeeds even though the tokens | 25947 // callback always returns true, the call succeeds even though the tokens |
25527 // are different. | 25948 // are different. |
25528 context1->Enter(); | 25949 context1->Enter(); |
25529 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); | 25950 context1->Global()->Set(context1, v8_str("fun"), fun).FromJust(); |
25530 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); | 25951 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); |
25531 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); | 25952 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); |
25532 context1->Exit(); | 25953 context1->Exit(); |
25533 } | 25954 } |
OLD | NEW |