Check-in [4488d01cb1]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a comment header to hv3bridge.c. (CVS 1270)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4488d01cb1f9b49edd67d01c2f66fbb6f9f0d3d0
User & Date: danielk1977 2008-02-16 06:04:13
Context
2008-03-02
14:43
Minor changes to javascript debugger. (CVS 1271) check-in: 13dc246a99 user: danielk1977 tags: trunk
2008-02-16
06:04
Add a comment header to hv3bridge.c. (CVS 1270) check-in: 4488d01cb1 user: danielk1977 tags: trunk
2008-02-15
19:01
Remove a reference to one of the recently removed files. (CVS 1269) check-in: a2e4e489a3 user: danielk1977 tags: trunk
Changes

Changes to hv/hv3bridge.c.

1
























2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32

33
34
35
36
37
38
39
..
48
49
50
51
52
53
54













55
56
57
58
59
60
61
62
63
..
66
67
68
69
70
71
72











73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
...
323
324
325
326
327
328
329


330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347


348
349
350
351
352
353
354
355
356

























typedef struct BridgeObject BridgeObject;
typedef struct BridgeEnum BridgeEnum;

struct BridgeObject {
  struct SEE_object object;
  struct SEE_interpreter *i;
  struct SEE_object *pObj;
};

struct BridgeEnum {
  struct SEE_enum base;
  struct SEE_interpreter *i;
  struct SEE_enum *pEnum;
};

static struct SEE_objectclass *getBridgeVtbl();
static struct SEE_enumclass *getBridgeEnumVtbl();

/*
 *---------------------------------------------------------------------------
 *
 * createBridgeObject --
 *
 *   This is the only public interface in this file. Return a pointer to
 *   a wrapper (bridge) object that can be used in interpreter pInterp
 *   to access an object pForiegnObj that was created in interpreter
 *   pForiegnInterp.
 *
 * Results:

 *
 * Side effects:

 *
 *---------------------------------------------------------------------------
 */
struct SEE_object *
createBridgeObject(pInterp, pForiegnInterp, pForiegnObj)
    struct SEE_interpreter *pInterp;
    struct SEE_interpreter *pForiegnInterp;
................................................................................
    p->object.Prototype = 0;
    p->object.objectclass = getBridgeVtbl();
    p->i = pForiegnInterp;
    p->pObj = pForiegnObj;
    return (struct SEE_object *)p;
}














static void
copyBridgeValue(pInterp, pValue, pForiegnInterp, pForiegnValue)
    struct SEE_interpreter *pInterp;              /* Source interpreter */
    struct SEE_value *pValue;                     /* Destination value */
    struct SEE_interpreter *pForiegnInterp;       /* Source interpreter */
    struct SEE_value *pForiegnValue;              /* Source value */
{
    int eType = SEE_VALUE_GET_TYPE(pForiegnValue);

................................................................................
        SEE_SET_OBJECT(pValue, createBridgeObject(pInterp, pForiegnInterp, o));
        assert(SEE_VALUE_GET_TYPE(pValue) == eType);
    }else{
        SEE_VALUE_COPY(pValue, pForiegnValue);
    }
}












static void
handleBridgeException(pInterp, pForiegnInterp, pForiegnTry)
    struct SEE_interpreter *pInterp;
    struct SEE_interpreter *pForiegnInterp;
    SEE_try_context_t *pForiegnTry;
{
    struct SEE_value *pForiegnVal = SEE_CAUGHT(*pForiegnTry);
    if (pForiegnVal) {
        struct SEE_value exception;
        struct SEE_traceback *pTrace;
#if 1
printf("throw: ");
SEE_PrintValue(pForiegnInterp, pForiegnVal, stdout);
printf("\n");
SEE_ToString(pForiegnInterp, pForiegnVal, &exception);
SEE_PrintValue(pForiegnInterp, &exception, stdout);
printf("\n");
#endif
................................................................................
        for (pTrace = pForiegnTry->traceback; pTrace; pTrace = pTrace->prev) {
            if (!pTrace->prev) {
                pTrace->prev = pInterp->traceback;
                pInterp->traceback = pForiegnTry->traceback;
            }
        }
#endif
        copyBridgeValue(pInterp, &exception, pForiegnInterp, pForiegnVal);
        pInterp->try_location = pForiegnInterp->try_location;
        SEE_THROW(pInterp, &exception);
    }
}


static void 
................................................................................
        return;
    } else {
        SEE_try_context_t try_ctxt;
        struct SEE_value val;
        pProp = SEE_intern(p->i, pProp);
        SEE_TRY(p->i, try_ctxt) {
            SEE_OBJECT_GET(p->i, p->pObj, pProp, &val);
            copyBridgeValue(pInterp, pRes, p->i, &val);
        }
        handleBridgeException(pInterp, p->i, &try_ctxt);
    }
}

static void 
Bridge_Put(pInterp, pObj, pProp, pValue, flags)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
    if (p->i == pInterp) {
        SEE_OBJECT_PUT(pInterp, p->pObj, pProp, pValue, flags);
        return;
    } else {
        SEE_try_context_t try_ctxt;
        struct SEE_value val;
        pProp = SEE_intern(p->i, pProp);
        copyBridgeValue(p->i, &val, pInterp, pValue);

        SEE_TRY(p->i, try_ctxt) {
            SEE_OBJECT_PUT(p->i, p->pObj, pProp, &val, flags);
        }
        handleBridgeException(pInterp, p->i, &try_ctxt);
    }
}

static int 
Bridge_CanPut(pInterp, pObj, pProp)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
    } else {
        int ret;
        SEE_try_context_t try_ctxt;
        pProp = SEE_intern(p->i, pProp);
        SEE_TRY(p->i, try_ctxt) {
            ret = SEE_OBJECT_DELETE(p->i, p->pObj, pProp);
        }
        handleBridgeException(pInterp, p->i, &try_ctxt);
        return ret;
    }
}

static void 
Bridge_DefaultValue(pInterp, pObj, pHint, pRes)
    struct SEE_interpreter *pInterp;
................................................................................
    struct SEE_object *pObj;
    struct SEE_value *pHint;
    struct SEE_value *pRes;
{
    BridgeObject *p = (BridgeObject *)pObj;
    struct SEE_value val;
    SEE_OBJECT_DEFAULTVALUE(p->i, p->pObj, pHint, &val);
    copyBridgeValue(pInterp, pRes, p->i, &val);
}

static struct SEE_enum *
Bridge_Enumerator(pInterp, pObj)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
{
................................................................................

        int nByte;
        int i;
        nByte = (sizeof(struct SEE_value) + sizeof(struct SEE_value *)) * argc;
        aValue = SEE_malloc(pInterp, nByte);
        apValue = (struct SEE_value **)&aValue[argc];
        for(i = 0; i < argc; i++){
            copyBridgeValue(p->i, &aValue[i], pInterp, argv[i]);
            apValue[i] = &aValue[i];
        }
        pThis = createBridgeObject(p->i, pInterp, pThis);

        SEE_TRY(p->i, try_ctxt) {
            if (isConstruct) {
                SEE_OBJECT_CONSTRUCT(p->i, p->pObj, pThis, argc, apValue, &val);
            } else {
                SEE_OBJECT_CALL(p->i, p->pObj, pThis, argc, apValue, &val);
            }
	    copyBridgeValue(pInterp, pRes, p->i, &val);
        }

        handleBridgeException(pInterp, p->i, &try_ctxt);
    }
}

static void 
Bridge_Construct(pInterp, pObj, pThis, argc, argv, pRes)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
Bridge_HasInstance(pInterp, pObj, pInstance)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
    struct SEE_value *pInstance;
{
    BridgeObject *p = (BridgeObject *)pObj;
    struct SEE_value val;
    copyBridgeValue(p->i, &val, pInterp, pInstance);
    return SEE_OBJECT_HASINSTANCE(p->i, p->pObj, &val);
}

static void *
Bridge_GetSecDomain(pInterp, pObj)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
    struct SEE_enum *pEnum;
    int *pFlags;
{
    BridgeEnum *p = (BridgeEnum *)pEnum;
    return SEE_ENUM_NEXT(p->i, p->pEnum, pFlags);
}



static struct SEE_objectclass BridgeObjectVtbl = {
    "Bridge",
    Bridge_Get,
    Bridge_Put,
    Bridge_CanPut,
    Bridge_HasProperty,
    Bridge_Delete,
    Bridge_DefaultValue,
    Bridge_Enumerator,
    Bridge_Construct,
    Bridge_Call,
    Bridge_HasInstance,
    Bridge_GetSecDomain
};
static struct SEE_objectclass *getBridgeVtbl() {
    return &BridgeObjectVtbl;
}



static struct SEE_enumclass BridgeEnumVtbl = {
  0,  /* Unused */
  BridgeEnum_Next
};

static struct SEE_enumclass *getBridgeEnumVtbl() {
    return &BridgeEnumVtbl;
}


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|
|
|



|
|
|










|
|
|
<


>


>







 







>
>
>
>
>
>
>
>
>
>
>
>
>

|







 







>
>
>
>
>
>
>
>
>
>
>

|








|







 







|







 







|

|







 







|




|







 







|







 







|







 







|










|


|







 







|







 







>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<



>
>
|
|
|
|
<
<



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
...
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403


404
405
406

/*
 * OVERVIEW:
 *
 *   This file contains the implementation of the "bridge" object. A bridge
 *   object is used when one SEE interpreter needs to access an object that
 *   was created by another SEE interpreter.
 *  
 *     struct SEE_interpreter *pInterp1 = <....>;
 *     struct SEE_interpreter *pInterp2 = <....>;
 *     struct SEE_object *pObj;
 *     BridgeObject *pBridge; 
 *  
 *     pObj = (struct SEE_object *)SEE_native_new(pInterp1);
 *     pBridge = createBridgeObject(pInterp2, pInterp1, pObj);
 *  
 *   After running the above fragment, object pObj may only be used by
 *   interpreter pInterp1. Object pBridge, which behaves the same way
 *   in all respects, may be accessed by interpreter pInterp2.
 *
 *   This file is part of the Hv3 web-browser. But it is really generic
 *   code that can be used by any program that needs to share objects
 *   between SEE interpreters.
 */

typedef struct BridgeObject BridgeObject;
typedef struct BridgeEnum BridgeEnum;

struct BridgeObject {
    struct SEE_object object;
    struct SEE_interpreter *i;
    struct SEE_object *pObj;
};

struct BridgeEnum {
    struct SEE_enum base;
    struct SEE_interpreter *i;
    struct SEE_enum *pEnum;
};

static struct SEE_objectclass *getBridgeVtbl();
static struct SEE_enumclass *getBridgeEnumVtbl();

/*
 *---------------------------------------------------------------------------
 *
 * createBridgeObject --
 *
 *   This is the only public interface in this file. Create a a wrapper
 *   (bridge) object that can be used in interpreter pInterp to access an
 *   object pForiegnObj that was created in interpreter pForiegnInterp.

 *
 * Results:
 *   Pointer to new heap allocated bridge object.
 *
 * Side effects:
 *   None.
 *
 *---------------------------------------------------------------------------
 */
struct SEE_object *
createBridgeObject(pInterp, pForiegnInterp, pForiegnObj)
    struct SEE_interpreter *pInterp;
    struct SEE_interpreter *pForiegnInterp;
................................................................................
    p->object.Prototype = 0;
    p->object.objectclass = getBridgeVtbl();
    p->i = pForiegnInterp;
    p->pObj = pForiegnObj;
    return (struct SEE_object *)p;
}

/*
 *---------------------------------------------------------------------------
 *
 * bridgeCopyValue --
 *
 *   This function is used to transfer SEE values between interpreters.
 *
 * Results:
 *
 * Side effects:
 *
 *---------------------------------------------------------------------------
 */
static void
bridgeCopyValue(pInterp, pValue, pForiegnInterp, pForiegnValue)
    struct SEE_interpreter *pInterp;              /* Source interpreter */
    struct SEE_value *pValue;                     /* Destination value */
    struct SEE_interpreter *pForiegnInterp;       /* Source interpreter */
    struct SEE_value *pForiegnValue;              /* Source value */
{
    int eType = SEE_VALUE_GET_TYPE(pForiegnValue);

................................................................................
        SEE_SET_OBJECT(pValue, createBridgeObject(pInterp, pForiegnInterp, o));
        assert(SEE_VALUE_GET_TYPE(pValue) == eType);
    }else{
        SEE_VALUE_COPY(pValue, pForiegnValue);
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * bridgeHandleException --
 *
 * Results:
 *
 * Side effects:
 *
 *---------------------------------------------------------------------------
 */
static void
bridgeHandleException(pInterp, pForiegnInterp, pForiegnTry)
    struct SEE_interpreter *pInterp;
    struct SEE_interpreter *pForiegnInterp;
    SEE_try_context_t *pForiegnTry;
{
    struct SEE_value *pForiegnVal = SEE_CAUGHT(*pForiegnTry);
    if (pForiegnVal) {
        struct SEE_value exception;
        struct SEE_traceback *pTrace;
#if 0
printf("throw: ");
SEE_PrintValue(pForiegnInterp, pForiegnVal, stdout);
printf("\n");
SEE_ToString(pForiegnInterp, pForiegnVal, &exception);
SEE_PrintValue(pForiegnInterp, &exception, stdout);
printf("\n");
#endif
................................................................................
        for (pTrace = pForiegnTry->traceback; pTrace; pTrace = pTrace->prev) {
            if (!pTrace->prev) {
                pTrace->prev = pInterp->traceback;
                pInterp->traceback = pForiegnTry->traceback;
            }
        }
#endif
        bridgeCopyValue(pInterp, &exception, pForiegnInterp, pForiegnVal);
        pInterp->try_location = pForiegnInterp->try_location;
        SEE_THROW(pInterp, &exception);
    }
}


static void 
................................................................................
        return;
    } else {
        SEE_try_context_t try_ctxt;
        struct SEE_value val;
        pProp = SEE_intern(p->i, pProp);
        SEE_TRY(p->i, try_ctxt) {
            SEE_OBJECT_GET(p->i, p->pObj, pProp, &val);
            bridgeCopyValue(pInterp, pRes, p->i, &val);
        }
        bridgeHandleException(pInterp, p->i, &try_ctxt);
    }
}

static void 
Bridge_Put(pInterp, pObj, pProp, pValue, flags)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
    if (p->i == pInterp) {
        SEE_OBJECT_PUT(pInterp, p->pObj, pProp, pValue, flags);
        return;
    } else {
        SEE_try_context_t try_ctxt;
        struct SEE_value val;
        pProp = SEE_intern(p->i, pProp);
        bridgeCopyValue(p->i, &val, pInterp, pValue);

        SEE_TRY(p->i, try_ctxt) {
            SEE_OBJECT_PUT(p->i, p->pObj, pProp, &val, flags);
        }
        bridgeHandleException(pInterp, p->i, &try_ctxt);
    }
}

static int 
Bridge_CanPut(pInterp, pObj, pProp)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
    } else {
        int ret;
        SEE_try_context_t try_ctxt;
        pProp = SEE_intern(p->i, pProp);
        SEE_TRY(p->i, try_ctxt) {
            ret = SEE_OBJECT_DELETE(p->i, p->pObj, pProp);
        }
        bridgeHandleException(pInterp, p->i, &try_ctxt);
        return ret;
    }
}

static void 
Bridge_DefaultValue(pInterp, pObj, pHint, pRes)
    struct SEE_interpreter *pInterp;
................................................................................
    struct SEE_object *pObj;
    struct SEE_value *pHint;
    struct SEE_value *pRes;
{
    BridgeObject *p = (BridgeObject *)pObj;
    struct SEE_value val;
    SEE_OBJECT_DEFAULTVALUE(p->i, p->pObj, pHint, &val);
    bridgeCopyValue(pInterp, pRes, p->i, &val);
}

static struct SEE_enum *
Bridge_Enumerator(pInterp, pObj)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
{
................................................................................

        int nByte;
        int i;
        nByte = (sizeof(struct SEE_value) + sizeof(struct SEE_value *)) * argc;
        aValue = SEE_malloc(pInterp, nByte);
        apValue = (struct SEE_value **)&aValue[argc];
        for(i = 0; i < argc; i++){
            bridgeCopyValue(p->i, &aValue[i], pInterp, argv[i]);
            apValue[i] = &aValue[i];
        }
        pThis = createBridgeObject(p->i, pInterp, pThis);

        SEE_TRY(p->i, try_ctxt) {
            if (isConstruct) {
                SEE_OBJECT_CONSTRUCT(p->i, p->pObj, pThis, argc, apValue, &val);
            } else {
                SEE_OBJECT_CALL(p->i, p->pObj, pThis, argc, apValue, &val);
            }
	    bridgeCopyValue(pInterp, pRes, p->i, &val);
        }

        bridgeHandleException(pInterp, p->i, &try_ctxt);
    }
}

static void 
Bridge_Construct(pInterp, pObj, pThis, argc, argv, pRes)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
Bridge_HasInstance(pInterp, pObj, pInstance)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
    struct SEE_value *pInstance;
{
    BridgeObject *p = (BridgeObject *)pObj;
    struct SEE_value val;
    bridgeCopyValue(p->i, &val, pInterp, pInstance);
    return SEE_OBJECT_HASINSTANCE(p->i, p->pObj, &val);
}

static void *
Bridge_GetSecDomain(pInterp, pObj)
    struct SEE_interpreter *pInterp;
    struct SEE_object *pObj;
................................................................................
    struct SEE_enum *pEnum;
    int *pFlags;
{
    BridgeEnum *p = (BridgeEnum *)pEnum;
    return SEE_ENUM_NEXT(p->i, p->pEnum, pFlags);
}

/* Return a pointer to the bridge object vtbl */
static struct SEE_objectclass *getBridgeVtbl() {
    static struct SEE_objectclass BridgeObjectVtbl = {
        "Bridge",
        Bridge_Get,
        Bridge_Put,
        Bridge_CanPut,
        Bridge_HasProperty,
        Bridge_Delete,
        Bridge_DefaultValue,
        Bridge_Enumerator,
        Bridge_Construct,
        Bridge_Call,
        Bridge_HasInstance,
        Bridge_GetSecDomain
    };

    return &BridgeObjectVtbl;
}

/* Return a pointer to the bridge object enumerator vtbl */
static struct SEE_enumclass *getBridgeEnumVtbl() {
    static struct SEE_enumclass BridgeEnumVtbl = {
        0,  /* Unused */
        BridgeEnum_Next
    };


    return &BridgeEnumVtbl;
}