LCOV - app.info - js/src/jsapi-tests/testLookup.cpp

LCOV - code coverage report
| Current view: | directory - js/src/jsapi-tests - testLookup.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 41 | 36 | 87.8 %
| Date: | 2012-04-07 | Functions: | 14 | 11 | 78.6 %

           1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
           2                 :  * vim: set ts=8 sw=4 et tw=99:
           3                 :  */
           4                 :
           5                 : #include "tests.h"
           6                 : #include "jsfun.h"  // for js::IsInternalFunctionObject
           7                 :
           8                 : #include "jsobjinlines.h"
           9                 :
          10               4 : BEGIN_TEST(testLookup_bug522590)
          11                 : {
          12                 :     // Define a function that makes method-bearing objects.
          13               2 :     jsvalRoot x(cx);
          14               1 :     EXEC("function mkobj() { return {f: function () {return 2;}} }");
          15                 :
          16                 :     // Calling mkobj() multiple times must create multiple functions in ES5.
          17               1 :     EVAL("mkobj().f !== mkobj().f", x.addr());
          18               1 :     CHECK_SAME(x, JSVAL_TRUE);
          19                 :
          20                 :     // Now make x.f a method.
          21               1 :     EVAL("mkobj()", x.addr());
          22               1 :     JSObject *xobj = JSVAL_TO_OBJECT(x);
          23                 :
          24                 :     // This lookup must not return an internal function object.
          25               2 :     jsvalRoot r(cx);
          26               1 :     CHECK(JS_LookupProperty(cx, xobj, "f", r.addr()));
          27               1 :     CHECK(JSVAL_IS_OBJECT(r));
          28               1 :     JSObject *funobj = JSVAL_TO_OBJECT(r);
          29               1 :     CHECK(funobj->isFunction());
          30               1 :     CHECK(!js::IsInternalFunctionObject(funobj));
          31                 :
          32               1 :     return true;
          33                 : }
          34               1 : END_TEST(testLookup_bug522590)
          35                 :
          36                 : JSBool
          37               3 : document_resolve(JSContext *cx, JSObject *obj, jsid id, unsigned flags, JSObject **objp)
          38                 : {
          39                 :     // If id is "all", and we're not detecting, resolve document.all=true.
          40               6 :     jsvalRoot v(cx);
          41               3 :     if (!JS_IdToValue(cx, id, v.addr()))
          42               0 :         return false;
          43               3 :     if (JSVAL_IS_STRING(v.value())) {
          44               3 :         JSString *str = JSVAL_TO_STRING(v.value());
          45               3 :         JSFlatString *flatStr = JS_FlattenString(cx, str);
          46               3 :         if (!flatStr)
          47               0 :             return false;
          48               3 :         if (JS_FlatStringEqualsAscii(flatStr, "all") && !(flags & JSRESOLVE_DETECTING)) {
          49               0 :             JSBool ok = JS_DefinePropertyById(cx, obj, id, JSVAL_TRUE, NULL, NULL, 0);
          50               0 :             *objp = ok ? obj : NULL;
          51               0 :             return ok;
          52                 :         }
          53                 :     }
          54               3 :     *objp = NULL;
          55               3 :     return true;
          56                 : }
          57                 :
          58                 : static JSClass document_class = {
          59                 :     "document", JSCLASS_NEW_RESOLVE,
          60                 :     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
          61                 :     JS_EnumerateStub, (JSResolveOp) document_resolve, JS_ConvertStub
          62                 : };
          63                 :
          64               4 : BEGIN_TEST(testLookup_bug570195)
          65                 : {
          66               1 :     JSObject *obj = JS_NewObject(cx, &document_class, NULL, NULL);
          67               1 :     CHECK(obj);
          68               1 :     CHECK(JS_DefineProperty(cx, global, "document", OBJECT_TO_JSVAL(obj), NULL, NULL, 0));
          69               2 :     jsvalRoot v(cx);
          70               1 :     EVAL("document.all ? true : false", v.addr());
          71               1 :     CHECK_SAME(v.value(), JSVAL_FALSE);
          72               1 :     EVAL("document.hasOwnProperty('all')", v.addr());
          73               1 :     CHECK_SAME(v.value(), JSVAL_FALSE);
          74               1 :     return true;
          75                 : }
          76               3 : END_TEST(testLookup_bug570195)

Generated by: LCOV version 1.7