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

Side by Side Diff: test/cctest/test-api-interceptors.cc

Issue 2807333003: [api] Add DefineProperty() method that skips interceptors.
Patch Set: Extend DefineProperty API Created 3 years, 7 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
« test/cctest/test-api.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "test/cctest/test-api.h" 7 #include "test/cctest/test-api.h"
8 8
9 #include "include/v8-util.h" 9 #include "include/v8-util.h"
10 #include "src/api.h" 10 #include "src/api.h"
(...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 "Object.freeze(obj.x); " 1809 "Object.freeze(obj.x); "
1810 "Object.isFrozen(obj.x);"; 1810 "Object.isFrozen(obj.x);";
1811 1811
1812 CHECK(v8_compile(code) 1812 CHECK(v8_compile(code)
1813 ->Run(env.local()) 1813 ->Run(env.local())
1814 .ToLocalChecked() 1814 .ToLocalChecked()
1815 ->BooleanValue(env.local()) 1815 ->BooleanValue(env.local())
1816 .FromJust()); 1816 .FromJust());
1817 } 1817 }
1818 1818
1819 // Check that the descriptor callback is not triggered for DefineProperty
Franzi 2017/05/10 09:17:52 Is this description correct? I thought we're skip
1820 // when bypass_interceptor = true
1821 THREADED_TEST(DefinerCallbackWithoutDescriptorInterceptor) {
1822 v8::Isolate* isolate = CcTest::isolate();
1823 v8::HandleScope scope(isolate);
1824 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
1825
1826 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
1827 nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr,
1828 NotInterceptingPropertyDefineCallback));
Franzi 2017/05/10 09:17:52 This tests seems to make more sense if you set an
1829
1830 LocalContext context;
1831 v8::Local<v8::Name> p;
1832
1833 v8::Local<v8::Object> obj =
1834 templ->NewInstance(context.local()).ToLocalChecked();
1835
1836 descriptor_was_called = 0;
1837
1838 // bypass_interceptor = false (default) triggers the descriptor callback
1839 // Use a generic descriptor.
1840 v8::PropertyDescriptor desc_generic;
1841
1842 p = v8_str("v1");
1843
1844 CHECK(obj->DefineProperty(context.local(), p, desc_generic).FromJust());
1845 CHECK_EQ(1, descriptor_was_called);
1846
1847 descriptor_was_called = 0;
1848
1849 // bypass_interceptor = true does not trigger the descriptor callback
1850 p = v8_str("v2");
Franzi 2017/05/10 09:17:52 Why are you using a different p here?
1851
1852 CHECK(obj->DefineProperty(context.local(), p, desc_generic, true).FromJust());
1853 CHECK_EQ(0, descriptor_was_called);
1854 }
1855
1819 // Check that the descriptor passed to the callback is enumerable. 1856 // Check that the descriptor passed to the callback is enumerable.
1820 namespace { 1857 namespace {
1821 void CheckEnumerablePropertyDefineCallback( 1858 void CheckEnumerablePropertyDefineCallback(
1822 Local<Name> name, const v8::PropertyDescriptor& desc, 1859 Local<Name> name, const v8::PropertyDescriptor& desc,
1823 const v8::PropertyCallbackInfo<v8::Value>& info) { 1860 const v8::PropertyCallbackInfo<v8::Value>& info) {
1824 CHECK(desc.has_value()); 1861 CHECK(desc.has_value());
1825 CHECK_EQ(42, desc.value() 1862 CHECK_EQ(42, desc.value()
1826 ->Int32Value(info.GetIsolate()->GetCurrentContext()) 1863 ->Int32Value(info.GetIsolate()->GetCurrentContext())
1827 .FromJust()); 1864 .FromJust());
1828 CHECK(desc.has_enumerable()); 1865 CHECK(desc.has_enumerable());
(...skipping 3185 matching lines...) Expand 10 before | Expand all | Expand 10 after
5014 ->Set(env.local(), v8_str("Fun"), 5051 ->Set(env.local(), v8_str("Fun"),
5015 fun_templ->GetFunction(env.local()).ToLocalChecked()) 5052 fun_templ->GetFunction(env.local()).ToLocalChecked())
5016 .FromJust()); 5053 .FromJust());
5017 5054
5018 CompileRun( 5055 CompileRun(
5019 "var f = new Fun();" 5056 "var f = new Fun();"
5020 "Number.prototype.__proto__ = f;" 5057 "Number.prototype.__proto__ = f;"
5021 "var a = 42;" 5058 "var a = 42;"
5022 "for (var i = 0; i<3; i++) { a.foo; }"); 5059 "for (var i = 0; i<3; i++) { a.foo; }");
5023 } 5060 }
OLDNEW
« test/cctest/test-api.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698