michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsfun.h" // for js::IsInternalFunctionObject michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: #include "jsobjinlines.h" michael@0: michael@0: BEGIN_TEST(testLookup_bug522590) michael@0: { michael@0: // Define a function that makes method-bearing objects. michael@0: JS::RootedValue x(cx); michael@0: EXEC("function mkobj() { return {f: function () {return 2;}} }"); michael@0: michael@0: // Calling mkobj() multiple times must create multiple functions in ES5. michael@0: EVAL("mkobj().f !== mkobj().f", &x); michael@0: CHECK_SAME(x, JSVAL_TRUE); michael@0: michael@0: // Now make x.f a method. michael@0: EVAL("mkobj()", &x); michael@0: JS::RootedObject xobj(cx, JSVAL_TO_OBJECT(x)); michael@0: michael@0: // This lookup must not return an internal function object. michael@0: JS::RootedValue r(cx); michael@0: CHECK(JS_LookupProperty(cx, xobj, "f", &r)); michael@0: CHECK(r.isObject()); michael@0: JSObject *funobj = &r.toObject(); michael@0: CHECK(funobj->is()); michael@0: CHECK(!js::IsInternalFunctionObject(funobj)); michael@0: michael@0: return true; michael@0: } michael@0: END_TEST(testLookup_bug522590) michael@0: michael@0: static const JSClass DocumentAllClass = { michael@0: "DocumentAll", michael@0: JSCLASS_EMULATES_UNDEFINED, michael@0: JS_PropertyStub, michael@0: JS_DeletePropertyStub, michael@0: JS_PropertyStub, michael@0: JS_StrictPropertyStub, michael@0: JS_EnumerateStub, michael@0: JS_ResolveStub, michael@0: JS_ConvertStub michael@0: }; michael@0: michael@0: bool michael@0: document_resolve(JSContext *cx, JS::HandleObject obj, JS::HandleId id, michael@0: JS::MutableHandleObject objp) michael@0: { michael@0: // If id is "all", resolve document.all=true. michael@0: JS::RootedValue v(cx); michael@0: if (!JS_IdToValue(cx, id, &v)) michael@0: return false; michael@0: if (JSVAL_IS_STRING(v)) { michael@0: JSString *str = JSVAL_TO_STRING(v); michael@0: JSFlatString *flatStr = JS_FlattenString(cx, str); michael@0: if (!flatStr) michael@0: return false; michael@0: if (JS_FlatStringEqualsAscii(flatStr, "all")) { michael@0: JS::Rooted docAll(cx, michael@0: JS_NewObject(cx, &DocumentAllClass, JS::NullPtr(), JS::NullPtr())); michael@0: if (!docAll) michael@0: return false; michael@0: JS::Rooted allValue(cx, ObjectValue(*docAll)); michael@0: bool ok = JS_DefinePropertyById(cx, obj, id, allValue, nullptr, nullptr, 0); michael@0: objp.set(ok ? obj.get() : nullptr); michael@0: return ok; michael@0: } michael@0: } michael@0: objp.set(nullptr); michael@0: return true; michael@0: } michael@0: michael@0: static const JSClass document_class = { michael@0: "document", JSCLASS_NEW_RESOLVE, michael@0: JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, michael@0: JS_EnumerateStub, (JSResolveOp) document_resolve, JS_ConvertStub michael@0: }; michael@0: michael@0: BEGIN_TEST(testLookup_bug570195) michael@0: { michael@0: JS::RootedObject obj(cx, JS_NewObject(cx, &document_class, JS::NullPtr(), JS::NullPtr())); michael@0: CHECK(obj); michael@0: CHECK(JS_DefineProperty(cx, global, "document", obj, 0)); michael@0: JS::RootedValue v(cx); michael@0: EVAL("document.all ? true : false", &v); michael@0: CHECK_SAME(v, JSVAL_FALSE); michael@0: EVAL("document.hasOwnProperty('all')", &v); michael@0: CHECK_SAME(v, JSVAL_TRUE); michael@0: return true; michael@0: } michael@0: END_TEST(testLookup_bug570195)