LCOV - code coverage report
Current view: directory - js/src/jsapi-tests - testBug604087.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 41 39 95.1 %
Date: 2012-06-02 Functions: 15 12 80.0 %

       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                 :  * Tests JS_TransplantObject
       5                 :  */
       6                 : 
       7                 : #include "tests.h"
       8                 : #include "jsobj.h"
       9                 : #include "jswrapper.h"
      10                 : 
      11                 : struct OuterWrapper : js::Wrapper
      12               1 : {
      13               1 :     OuterWrapper() : Wrapper(0) {}
      14                 : 
      15               2 :     virtual bool isOuterWindow() {
      16               2 :         return true;
      17                 :     }
      18                 : 
      19                 :     static OuterWrapper singleton;
      20                 : };
      21                 : 
      22                 : OuterWrapper
      23               1 : OuterWrapper::singleton;
      24                 : 
      25                 : static JSObject *
      26               3 : wrap(JSContext *cx, JSObject *toWrap, JSObject *target)
      27                 : {
      28               6 :     JSAutoEnterCompartment ac;
      29               3 :     if (!ac.enter(cx, target))
      30               0 :         return NULL;
      31                 : 
      32               3 :     JSObject *wrapper = toWrap;
      33               3 :     if (!JS_WrapObject(cx, &wrapper))
      34               0 :         return NULL;
      35               3 :     return wrapper;
      36                 : }
      37                 : 
      38                 : static JSObject *
      39               3 : PreWrap(JSContext *cx, JSObject *scope, JSObject *obj, unsigned flags)
      40                 : {
      41               3 :     JS_GC(cx);
      42               3 :     return obj;
      43                 : }
      44                 : 
      45                 : static JSObject *
      46               3 : Wrap(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent, unsigned flags)
      47                 : {
      48               3 :     return js::Wrapper::New(cx, obj, proto, parent, &js::CrossCompartmentWrapper::singleton);
      49                 : }
      50                 : 
      51               4 : BEGIN_TEST(testBug604087)
      52                 : {
      53                 :     JSObject *outerObj = js::Wrapper::New(cx, global, global->getProto(), global,
      54               1 :                                           &OuterWrapper::singleton);
      55               1 :     JSObject *compartment2 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
      56               1 :     JSObject *compartment3 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
      57               1 :     JSObject *compartment4 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
      58                 : 
      59               1 :     JSObject *c2wrapper = wrap(cx, outerObj, compartment2);
      60               1 :     CHECK(c2wrapper);
      61               1 :     js::SetProxyExtra(c2wrapper, 0, js::Int32Value(2));
      62                 : 
      63               1 :     JSObject *c3wrapper = wrap(cx, outerObj, compartment3);
      64               1 :     CHECK(c3wrapper);
      65               1 :     js::SetProxyExtra(c3wrapper, 0, js::Int32Value(3));
      66                 : 
      67               1 :     JSObject *c4wrapper = wrap(cx, outerObj, compartment4);
      68               1 :     CHECK(c4wrapper);
      69               1 :     js::SetProxyExtra(c4wrapper, 0, js::Int32Value(4));
      70               1 :     compartment4 = c4wrapper = NULL;
      71                 : 
      72                 :     JSObject *next;
      73                 :     {
      74               2 :         JSAutoEnterCompartment ac;
      75               1 :         CHECK(ac.enter(cx, compartment2));
      76                 :         next = js::Wrapper::New(cx, compartment2, compartment2->getProto(), compartment2,
      77               1 :                                 &OuterWrapper::singleton);
      78               1 :         CHECK(next);
      79                 :     }
      80                 : 
      81               1 :     JS_SetWrapObjectCallbacks(JS_GetRuntime(cx), Wrap, PreWrap);
      82               1 :     CHECK(JS_TransplantObject(cx, outerObj, next));
      83               1 :     return true;
      84                 : }
      85               3 : END_TEST(testBug604087)

Generated by: LCOV version 1.7