diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testSetPropertyIgnoringNamedGetter.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testSetPropertyIgnoringNamedGetter.cpp')
-rw-r--r-- | js/src/jsapi-tests/testSetPropertyIgnoringNamedGetter.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testSetPropertyIgnoringNamedGetter.cpp b/js/src/jsapi-tests/testSetPropertyIgnoringNamedGetter.cpp new file mode 100644 index 000000000..3150986dd --- /dev/null +++ b/js/src/jsapi-tests/testSetPropertyIgnoringNamedGetter.cpp @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + */ + +#include "jsfriendapi.h" + +#include "js/Proxy.h" + +#include "jsapi-tests/tests.h" + +using namespace js; +using namespace JS; + +class CustomProxyHandler : public Wrapper +{ + public: + CustomProxyHandler() : Wrapper(0) {} + + bool getPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id, + MutableHandle<PropertyDescriptor> desc) const override + { + return impl(cx, proxy, id, desc, false); + } + + bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id, + MutableHandle<PropertyDescriptor> desc) const override + { + return impl(cx, proxy, id, desc, true); + } + + bool set(JSContext* cx, HandleObject proxy, HandleId id, HandleValue v, HandleValue receiver, + ObjectOpResult& result) const override + { + Rooted<PropertyDescriptor> desc(cx); + if (!Wrapper::getPropertyDescriptor(cx, proxy, id, &desc)) + return false; + return SetPropertyIgnoringNamedGetter(cx, proxy, id, v, receiver, desc, result); + } + + private: + bool impl(JSContext* cx, HandleObject proxy, HandleId id, + MutableHandle<PropertyDescriptor> desc, bool ownOnly) const + { + if (JSID_IS_STRING(id)) { + bool match; + if (!JS_StringEqualsAscii(cx, JSID_TO_STRING(id), "phantom", &match)) + return false; + if (match) { + desc.object().set(proxy); + desc.attributesRef() = JSPROP_ENUMERATE; + desc.value().setInt32(42); + return true; + } + } + + if (ownOnly) + return Wrapper::getOwnPropertyDescriptor(cx, proxy, id, desc); + return Wrapper::getPropertyDescriptor(cx, proxy, id, desc); + } + +}; + +const CustomProxyHandler customProxyHandler; + + +BEGIN_TEST(testSetPropertyIgnoringNamedGetter_direct) +{ + RootedValue protov(cx); + EVAL("Object.prototype", &protov); + + RootedValue targetv(cx); + EVAL("({})", &targetv); + + RootedObject proxyObj(cx, NewProxyObject(cx, &customProxyHandler, targetv, + &protov.toObject(), ProxyOptions())); + CHECK(proxyObj); + + CHECK(JS_DefineProperty(cx, global, "target", targetv, 0)); + CHECK(JS_DefineProperty(cx, global, "proxy", proxyObj, 0)); + + RootedValue v(cx); + EVAL("Object.getOwnPropertyDescriptor(proxy, 'phantom').value", &v); + CHECK_SAME(v, Int32Value(42)); + + EXEC("proxy.phantom = 123"); + EVAL("Object.getOwnPropertyDescriptor(proxy, 'phantom').value", &v); + CHECK_SAME(v, Int32Value(42)); + EVAL("target.phantom", &v); + CHECK_SAME(v, Int32Value(123)); + + return true; +} +END_TEST(testSetPropertyIgnoringNamedGetter_direct) |