1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "js/PropertyAndElement.h" // JS_DefineProperty, JS_DefinePropertyById, JS_GetProperty
9 #include "jsapi-tests/tests.h"
10 #include "vm/JSFunction.h" // for js::IsInternalFunctionObject
12 #include "vm/JSObject-inl.h"
14 BEGIN_TEST(testLookup_bug522590
) {
15 // Define a function that makes method-bearing objects.
16 JS::RootedValue
x(cx
);
17 EXEC("function mkobj() { return {f: function () {return 2;}} }");
19 // Calling mkobj() multiple times must create multiple functions in ES5.
20 EVAL("mkobj().f !== mkobj().f", &x
);
23 // Now make x.f a method.
25 JS::RootedObject
xobj(cx
, x
.toObjectOrNull());
27 // This lookup must not return an internal function object.
28 JS::RootedValue
r(cx
);
29 CHECK(JS_GetProperty(cx
, xobj
, "f", &r
));
31 JSObject
* funobj
= &r
.toObject();
32 CHECK(funobj
->is
<JSFunction
>());
33 CHECK(!js::IsInternalFunctionObject(*funobj
));
37 END_TEST(testLookup_bug522590
)
39 static const JSClass DocumentAllClass
= {"DocumentAll",
40 JSCLASS_EMULATES_UNDEFINED
};
42 bool document_resolve(JSContext
* cx
, JS::HandleObject obj
, JS::HandleId id
,
44 // If id is "all", resolve document.all=true.
45 JS::RootedValue
v(cx
);
46 if (!JS_IdToValue(cx
, id
, &v
)) {
51 JSString
* str
= v
.toString();
52 JSLinearString
* linearStr
= JS_EnsureLinearString(cx
, str
);
56 if (JS_LinearStringEqualsLiteral(linearStr
, "all")) {
57 JS::Rooted
<JSObject
*> docAll(cx
, JS_NewObject(cx
, &DocumentAllClass
));
62 JS::Rooted
<JS::Value
> allValue(cx
, JS::ObjectValue(*docAll
));
63 if (!JS_DefinePropertyById(cx
, obj
, id
, allValue
, JSPROP_RESOLVING
)) {
76 static const JSClassOps document_classOps
= {
77 nullptr, // addProperty
78 nullptr, // delProperty
80 nullptr, // newEnumerate
81 document_resolve
, // resolve
82 nullptr, // mayResolve
89 static const JSClass document_class
= {"document", 0, &document_classOps
};
91 BEGIN_TEST(testLookup_bug570195
) {
92 JS::RootedObject
obj(cx
, JS_NewObject(cx
, &document_class
));
94 CHECK(JS_DefineProperty(cx
, global
, "document", obj
, 0));
95 JS::RootedValue
v(cx
);
96 EVAL("document.all ? true : false", &v
);
98 EVAL("document.hasOwnProperty('all')", &v
);
102 END_TEST(testLookup_bug570195
)