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/testForwardSetProperty.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/testForwardSetProperty.cpp')
-rw-r--r-- | js/src/jsapi-tests/testForwardSetProperty.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testForwardSetProperty.cpp b/js/src/jsapi-tests/testForwardSetProperty.cpp new file mode 100644 index 000000000..eea07c279 --- /dev/null +++ b/js/src/jsapi-tests/testForwardSetProperty.cpp @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "jsapi-tests/tests.h" + +using namespace JS; + +BEGIN_TEST(testForwardSetProperty) +{ + RootedValue v1(cx); + EVAL("var foundValue; \n" + "var obj1 = { set prop(val) { foundValue = this; } }; \n" + "obj1;", + &v1); + + RootedValue v2(cx); + EVAL("var obj2 = Object.create(obj1); \n" + "obj2;", + &v2); + + RootedValue v3(cx); + EVAL("var obj3 = {}; \n" + "obj3;", + &v3); + + RootedObject obj1(cx, &v1.toObject()); + RootedObject obj2(cx, &v2.toObject()); + RootedObject obj3(cx, &v3.toObject()); + + RootedValue setval(cx, Int32Value(42)); + + RootedValue propkey(cx); + EVAL("'prop';", &propkey); + + RootedId prop(cx); + CHECK(JS_ValueToId(cx, propkey, &prop)); + + EXEC("function assertEq(a, b, msg) \n" + "{ \n" + " if (!Object.is(a, b)) \n" + " throw new Error('Assertion failure: ' + msg); \n" + "}"); + + // Non-strict setter + + JS::ObjectOpResult result; + CHECK(JS_ForwardSetPropertyTo(cx, obj2, prop, setval, v3, result)); + CHECK(result); + + EXEC("assertEq(foundValue, obj3, 'wrong receiver passed to setter');"); + + CHECK(JS_ForwardSetPropertyTo(cx, obj2, prop, setval, setval, result)); + CHECK(result); + + EXEC("assertEq(typeof foundValue === 'object', true, \n" + " 'passing 42 as receiver to non-strict setter ' + \n" + " 'must box');"); + + EXEC("assertEq(foundValue instanceof Number, true, \n" + " 'passing 42 as receiver to non-strict setter ' + \n" + " 'must box to a Number');"); + + EXEC("assertEq(foundValue.valueOf(), 42, \n" + " 'passing 42 as receiver to non-strict setter ' + \n" + " 'must box to new Number(42)');"); + + // Strict setter + + RootedValue v4(cx); + EVAL("({ set prop(val) { 'use strict'; foundValue = this; } })", &v4); + RootedObject obj4(cx, &v4.toObject()); + + CHECK(JS_ForwardSetPropertyTo(cx, obj4, prop, setval, v3, result)); + CHECK(result); + + EXEC("assertEq(foundValue, obj3, 'wrong receiver passed to strict setter');"); + + CHECK(JS_ForwardSetPropertyTo(cx, obj4, prop, setval, setval, result)); + CHECK(result); + + EXEC("assertEq(foundValue, 42, \n" + " '42 passed as receiver to strict setter was mangled');"); + + return true; +} +END_TEST(testForwardSetProperty) |