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

LCOV - code coverage report
| Current view: | directory - js/src/jsapi-tests - testSetProperty.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 21 | 21 | 100.0 %
| 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                 :
           7                 : static JSBool
           8               1 : nativeGet(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
           9                 : {
          10               1 :     *vp = INT_TO_JSVAL(17);
          11               1 :     return JS_TRUE;
          12                 : }
          13                 :
          14               4 : BEGIN_TEST(testSetProperty_NativeGetterStubSetter)
          15                 : {
          16               2 :     jsvalRoot vobj(cx);
          17               1 :     JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
          18               1 :     CHECK(obj);
          19               1 :     vobj = OBJECT_TO_JSVAL(obj);
          20                 :
          21               1 :     CHECK(JS_DefineProperty(cx, global, "globalProp", vobj,
          22                 :                             JS_PropertyStub, JS_StrictPropertyStub,
          23                 :                             JSPROP_ENUMERATE));
          24                 :
          25               1 :     CHECK(JS_DefineProperty(cx, obj, "prop", JSVAL_VOID,
          26                 :                             nativeGet, JS_StrictPropertyStub,
          27                 :                             JSPROP_SHARED));
          28                 :
          29               1 :     EXEC("'use strict';                                     \n"
          30                 :          "var error, passed = false;                        \n"
          31                 :          "try                                               \n"
          32                 :          "{                                                 \n"
          33                 :          "  this.globalProp.prop = 42;                      \n"
          34                 :          "  throw new Error('setting property succeeded!'); \n"
          35                 :          "}                                                 \n"
          36                 :          "catch (e)                                         \n"
          37                 :          "{                                                 \n"
          38                 :          "  error = e;                                      \n"
          39                 :          "  if (e instanceof TypeError)                     \n"
          40                 :          "    passed = true;                                \n"
          41                 :          "}                                                 \n"
          42                 :          "                                                  \n"
          43                 :          "if (!passed)                                      \n"
          44                 :          "  throw error;                                    \n");
          45                 :
          46               1 :     EXEC("var error, passed = false;                        \n"
          47                 :          "try                                               \n"
          48                 :          "{                                                 \n"
          49                 :          "  this.globalProp.prop = 42;                      \n"
          50                 :          "  if (this.globalProp.prop === 17)                \n"
          51                 :          "    passed = true;                                \n"
          52                 :          "  else                                            \n"
          53                 :          "    throw new Error('bad value after set!');      \n"
          54                 :          "}                                                 \n"
          55                 :          "catch (e)                                         \n"
          56                 :          "{                                                 \n"
          57                 :          "  error = e;                                      \n"
          58                 :          "}                                                 \n"
          59                 :          "                                                  \n"
          60                 :          "if (!passed)                                      \n"
          61                 :          "  throw error;                                    \n");
          62                 :
          63               1 :     return true;
          64                 : }
          65               1 : END_TEST(testSetProperty_NativeGetterStubSetter)
          66                 :
          67               4 : BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
          68                 : {
          69                 :     // This is a JSAPI test because jsapi-test globals do not have a resolve
          70                 :     // hook and therefore can use the property cache in some cases where the
          71                 :     // shell can't.
          72               1 :     JS_ASSERT(JS_GetClass(global)->resolve == &JS_ResolveStub);
          73                 :
          74               1 :     CHECK(JS_DefineProperty(cx, global, "HOTLOOP", INT_TO_JSVAL(8), NULL, NULL, 0));
          75               1 :     EXEC("var n = 0;\n"
          76                 :          "var global = this;\n"
          77                 :          "function f() { n++; }\n"
          78                 :          "Object.defineProperty(Object.prototype, 'x', {set: f});\n"
          79                 :          "for (var i = 0; i < HOTLOOP; i++)\n"
          80                 :          "    global.x = i;\n");
          81               1 :     EXEC("if (n != HOTLOOP)\n"
          82                 :          "    throw 'FAIL';\n");
          83               1 :     return true;
          84                 : }
          85               3 : END_TEST(testSetProperty_InheritedGlobalSetter)
          86                 :

Generated by: LCOV version 1.7