home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libhook / src / hk_conf.c next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  124 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. #include "xp_core.h"
  19. #include "xp_mcom.h"
  20. #include "jsapi.h"
  21.  
  22. #include "hk_private.h"
  23.  
  24. /**********************************************
  25.  * These are to configuration functions registered
  26.  * with the new javascript HookConfig object.
  27.  * They are designed to maintain an array of the
  28.  * special hooks with simple booleans to tell
  29.  * if they already exist in the object or not.
  30.  **********************************************/
  31.  
  32.  
  33. /*
  34.  * Called when a new object is added.
  35.  * If the object is a function then we
  36.  * add it to the existence array.
  37.  * NOTE: hk_SetFunctionExistence only keeps track of those functions
  38.  *       that are known special javascript hooks.
  39.  */
  40. JSBool
  41. hk_HookObjectAddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  42. {
  43.     JSString *j_str;
  44.     char *str;
  45.  
  46.     j_str = JS_ValueToString(cx, id);
  47.     str = JS_GetStringBytes(j_str);
  48.     if (JS_TypeOfValue(cx, *vp) == JSTYPE_FUNCTION)
  49.     {
  50.         /*
  51.          * hk_SetFunctionExistence is not allowed to change
  52.          * the contents of str or the wrong function
  53.          * will be added.
  54.          */
  55.         hk_SetFunctionExistence(str, TRUE);
  56.     }
  57.  
  58.     return JS_TRUE;
  59. }
  60.  
  61.  
  62. /*
  63.  * Called when an object is deleted.
  64.  * If the object is a function then we
  65.  * delete it from the existence array.
  66.  * NOTE: hk_SetFunctionExistence only keeps track of those functions
  67.  *       that are known special javascript hooks.
  68.  */
  69. JSBool
  70. hk_HookObjectDeleteProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  71. {
  72.     JSString *j_str;
  73.     char *str;
  74.  
  75.     j_str = JS_ValueToString(cx, id);
  76.     str = JS_GetStringBytes(j_str);
  77.     if (JS_TypeOfValue(cx, *vp) == JSTYPE_FUNCTION)
  78.     {
  79.         /*
  80.          * hk_SetFunctionExistence is not allowed to change
  81.          * the contents of str or the wrong function
  82.          * will be deleted.
  83.          */
  84.         hk_SetFunctionExistence(str, FALSE);
  85.     }
  86.  
  87.     return JS_TRUE;
  88. }
  89.  
  90.  
  91. /*
  92.  * Called when an object has a new value set to it.
  93.  * The object could have been a value (like NULL) but
  94.  * now be set to a function.  The object could also have once been
  95.  * set to a function and now be set to a non-function type.
  96.  * NOTE: hk_SetFunctionExistence only keeps track of those functions
  97.  *       that are known special javascript hooks.
  98.  */
  99. JSBool
  100. hk_HookObjectSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  101. {
  102.     JSString *j_str;
  103.     char *str;
  104.  
  105.     j_str = JS_ValueToString(cx, id);
  106.     str = JS_GetStringBytes(j_str);
  107.     /*
  108.      * hk_SetFunctionExistence is not allowed to change
  109.      * the contents of str or the wrong object
  110.      * will be set.
  111.      */
  112.     if (JS_TypeOfValue(cx, *vp) == JSTYPE_FUNCTION)
  113.     {
  114.         hk_SetFunctionExistence(str, TRUE);
  115.     }
  116.     else
  117.     {
  118.         hk_SetFunctionExistence(str, FALSE);
  119.     }
  120.  
  121.     return JS_TRUE;
  122. }
  123.  
  124.