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

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

Issue 2807333003: [api] Add DefineProperty() method that skips interceptors.
Patch Set: Previous commit with rebasing 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
« include/v8.h ('K') | « src/objects.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 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 ->BooleanValue(env.local()) 1566 ->BooleanValue(env.local())
1567 .FromJust()); 1567 .FromJust());
1568 CHECK(v8_compile("delete obj.myProperty") 1568 CHECK(v8_compile("delete obj.myProperty")
1569 ->Run(env.local()) 1569 ->Run(env.local())
1570 .ToLocalChecked() 1570 .ToLocalChecked()
1571 ->BooleanValue(env.local()) 1571 ->BooleanValue(env.local())
1572 .FromJust()); 1572 .FromJust());
1573 } 1573 }
1574 1574
1575 namespace { 1575 namespace {
1576 int definer_was_called;
1577
1576 void NotInterceptingPropertyDefineCallback( 1578 void NotInterceptingPropertyDefineCallback(
1577 Local<Name> name, const v8::PropertyDescriptor& desc, 1579 Local<Name> name, const v8::PropertyDescriptor& desc,
1578 const v8::PropertyCallbackInfo<v8::Value>& info) { 1580 const v8::PropertyCallbackInfo<v8::Value>& info) {
1581 definer_was_called++;
1579 // Do not intercept by not calling info.GetReturnValue().Set(). 1582 // Do not intercept by not calling info.GetReturnValue().Set().
1580 } 1583 }
1581 1584
1582 void InterceptingPropertyDefineCallback( 1585 void InterceptingPropertyDefineCallback(
1583 Local<Name> name, const v8::PropertyDescriptor& desc, 1586 Local<Name> name, const v8::PropertyDescriptor& desc,
1584 const v8::PropertyCallbackInfo<v8::Value>& info) { 1587 const v8::PropertyCallbackInfo<v8::Value>& info) {
1585 // Intercept the callback by setting a non-empty handle 1588 // Intercept the callback by setting a non-empty handle
1589 definer_was_called++;
1586 info.GetReturnValue().Set(name); 1590 info.GetReturnValue().Set(name);
1587 } 1591 }
1588 1592
1589 void CheckDescriptorInDefineCallback( 1593 void CheckDescriptorInDefineCallback(
1590 Local<Name> name, const v8::PropertyDescriptor& desc, 1594 Local<Name> name, const v8::PropertyDescriptor& desc,
1591 const v8::PropertyCallbackInfo<v8::Value>& info) { 1595 const v8::PropertyCallbackInfo<v8::Value>& info) {
1592 CHECK(!desc.has_writable()); 1596 CHECK(!desc.has_writable());
1593 CHECK(!desc.has_value()); 1597 CHECK(!desc.has_value());
1594 CHECK(!desc.has_enumerable()); 1598 CHECK(!desc.has_enumerable());
1595 CHECK(desc.has_configurable()); 1599 CHECK(desc.has_configurable());
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 "Object.freeze(obj.x); " 1813 "Object.freeze(obj.x); "
1810 "Object.isFrozen(obj.x);"; 1814 "Object.isFrozen(obj.x);";
1811 1815
1812 CHECK(v8_compile(code) 1816 CHECK(v8_compile(code)
1813 ->Run(env.local()) 1817 ->Run(env.local())
1814 .ToLocalChecked() 1818 .ToLocalChecked()
1815 ->BooleanValue(env.local()) 1819 ->BooleanValue(env.local())
1816 .FromJust()); 1820 .FromJust());
1817 } 1821 }
1818 1822
1823 // Check that the define interceptor is not triggered for DefineProperty
1824 // with the SKIP_INTERCEPTORS flag.
1825 THREADED_TEST(DefinePropertyWithoutInterceptors) {
1826 v8::Isolate* isolate = CcTest::isolate();
1827 v8::HandleScope scope(isolate);
1828 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
1829
1830 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
1831 nullptr, nullptr, nullptr, nullptr, nullptr,
1832 InterceptingPropertyDefineCallback));
1833
1834 LocalContext context;
1835 v8::Local<v8::Name> p;
1836
1837 v8::Local<v8::Object> obj =
1838 templ->NewInstance(context.local()).ToLocalChecked();
1839
1840 definer_was_called = 0;
1841
1842 // Use a generic descriptor.
1843 v8::PropertyDescriptor desc_generic;
1844
1845 p = v8_str("foo");
1846
1847 // DONT_SKIP_INTERCEPTORS (default) triggers the interceptors when setting
1848 // own property of an object.
1849 CHECK(obj->DefineProperty(context.local(), p, desc_generic).FromJust());
1850 CHECK_EQ(1, definer_was_called);
1851
1852 definer_was_called = 0;
1853
1854 // SKIP_INTERCEPTORS does not trigger the interceptors.
1855 CHECK(obj->DefineProperty(context.local(), p, desc_generic,
1856 v8::SKIP_INTERCEPTORS)
1857 .FromJust());
1858 CHECK_EQ(0, definer_was_called);
1859 }
1860
1819 // Check that the descriptor passed to the callback is enumerable. 1861 // Check that the descriptor passed to the callback is enumerable.
1820 namespace { 1862 namespace {
1821 void CheckEnumerablePropertyDefineCallback( 1863 void CheckEnumerablePropertyDefineCallback(
1822 Local<Name> name, const v8::PropertyDescriptor& desc, 1864 Local<Name> name, const v8::PropertyDescriptor& desc,
1823 const v8::PropertyCallbackInfo<v8::Value>& info) { 1865 const v8::PropertyCallbackInfo<v8::Value>& info) {
1824 CHECK(desc.has_value()); 1866 CHECK(desc.has_value());
1825 CHECK_EQ(42, desc.value() 1867 CHECK_EQ(42, desc.value()
1826 ->Int32Value(info.GetIsolate()->GetCurrentContext()) 1868 ->Int32Value(info.GetIsolate()->GetCurrentContext())
1827 .FromJust()); 1869 .FromJust());
1828 CHECK(desc.has_enumerable()); 1870 CHECK(desc.has_enumerable());
(...skipping 3185 matching lines...) Expand 10 before | Expand all | Expand 10 after
5014 ->Set(env.local(), v8_str("Fun"), 5056 ->Set(env.local(), v8_str("Fun"),
5015 fun_templ->GetFunction(env.local()).ToLocalChecked()) 5057 fun_templ->GetFunction(env.local()).ToLocalChecked())
5016 .FromJust()); 5058 .FromJust());
5017 5059
5018 CompileRun( 5060 CompileRun(
5019 "var f = new Fun();" 5061 "var f = new Fun();"
5020 "Number.prototype.__proto__ = f;" 5062 "Number.prototype.__proto__ = f;"
5021 "var a = 42;" 5063 "var a = 42;"
5022 "for (var i = 0; i<3; i++) { a.foo; }"); 5064 "for (var i = 0; i<3; i++) { a.foo; }");
5023 } 5065 }
OLDNEW
« include/v8.h ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698