JSDOMException.cpp
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:6k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. /****************License************************************************
  2.  * Vocalocity OpenVXI
  3.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  18.  * registered trademarks of Vocalocity, Inc. 
  19.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  20.  * by Vocalocity.
  21.  ***********************************************************************/
  22. #include "JSDOMException.hpp"
  23. #include "JSDOM.hpp"
  24. // JavaScript class definition
  25. JSClass JSDOMException::_jsClass = {
  26.   "DOMException", JSCLASS_HAS_PRIVATE,
  27.   JS_PropertyStub, JS_PropertyStub,
  28.   JSDOMException::JSGetProperty, JS_PropertyStub,
  29.   JS_EnumerateStub, JS_ResolveStub,
  30.   JS_ConvertStub, JSDOMException::JSDestructor,
  31.   0, 0, 0, 0, 
  32.   0, 0, 0, 0
  33. };
  34. // JavaScript Initialization Method
  35. JSObject *JSDOMException::JSInit(JSContext *cx, JSObject *obj) {
  36.   if (obj==NULL)
  37.     obj = JS_GetGlobalObject(cx);
  38.   jsval oldobj;
  39.   if (JS_TRUE == JS_LookupProperty(cx, obj, JSDOMException::_jsClass.name, &oldobj) && JSVAL_IS_OBJECT(oldobj))
  40.     return JSVAL_TO_OBJECT(oldobj);
  41.   return JS_InitClass(cx, obj, NULL, &JSDOMException::_jsClass,
  42.                       JSDOMException::JSConstructor, 0,
  43.                       JSDOMException::_JSPropertySpec, NULL,
  44.                       JSDOMException::_JSPropertySpec_static, NULL);
  45. }
  46. // JavaScript Constructor
  47. JSBool JSDOMException::JSConstructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
  48.   JSDOMException *p = NULL;
  49.   if (argc == 0) {
  50.     p = new JSDOMException(0);
  51.   }
  52.   else {
  53.     int code = JSVAL_TO_INT(*argv);
  54. p = new JSDOMException(code);
  55.   }
  56.   if (!p || !JS_SetPrivate(cx, obj, p)) return JS_FALSE;
  57.   p->_JSinternal.o = obj;
  58.   p->_JSinternal.c = cx;
  59.   *rval = OBJECT_TO_JSVAL(obj);
  60.   return JS_TRUE;
  61. }
  62. // JavaScript Destructor
  63. void JSDOMException::JSDestructor(JSContext *cx, JSObject *obj) {
  64.   JSDOMException *p = (JSDOMException*)JS_GetPrivate(cx, obj);
  65.   if (p) delete p;
  66. }
  67. // JavaScript Object Linking
  68. JSObject *JSDOMException::getJSObject(JSContext *cx) {
  69.   if (!cx) return NULL;
  70.   if (!_JSinternal.o) {
  71.     _JSinternal.o = newJSObject(cx);
  72.     _JSinternal.c = cx;
  73.     if (!JS_SetPrivate(cx, _JSinternal.o, this)) return NULL;
  74.   }
  75.   return _JSinternal.o;
  76. }
  77. JSObject *JSDOMException::newJSObject(JSContext *cx) {
  78.   return JS_NewObject(cx, &JSDOMException::_jsClass, NULL, NULL);
  79. }
  80. // JavaScript Variable Table
  81. JSPropertySpec JSDOMException::_JSPropertySpec[] = {
  82.     { "INDEX_SIZE_ERR", JSDOMException::JSVAR_INDEX_SIZE_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  83.     { "DOMSTRING_SIZE_ERR", JSDOMException::JSVAR_DOMSTRING_SIZE_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  84.     { "NO_MODIFICATION_ALLOWED_ERR", JSDOMException::JSVAR_NO_MODIFICATION_ALLOWED_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  85.     { "NOT_FOUND_ERR", JSDOMException::JSVAR_NOT_FOUND_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  86.     { "NOT_SUPPORTED_ERR", JSDOMException::JSVAR_NOT_SUPPORTED_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  87.     { "INVALID_STATE_ERR", JSDOMException::JSVAR_INVALID_STATE_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  88.     { "code", JSDOMException::JSVAR_code, JSPROP_ENUMERATE | JSPROP_READONLY, 0, 0},
  89. };
  90. JSPropertySpec JSDOMException::_JSPropertySpec_static[] = {
  91.     { "INDEX_SIZE_ERR", JSDOMException::JSVAR_INDEX_SIZE_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  92.     { "DOMSTRING_SIZE_ERR", JSDOMException::JSVAR_DOMSTRING_SIZE_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  93.     { "NO_MODIFICATION_ALLOWED_ERR", JSDOMException::JSVAR_NO_MODIFICATION_ALLOWED_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  94.     { "NOT_FOUND_ERR", JSDOMException::JSVAR_NOT_FOUND_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  95.     { "NOT_SUPPORTED_ERR", JSDOMException::JSVAR_NOT_SUPPORTED_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  96.     { "INVALID_STATE_ERR", JSDOMException::JSVAR_INVALID_STATE_ERR, JSPROP_ENUMERATE | JSPROP_READONLY, JSDOMException::JSGetProperty, 0},
  97.     { 0, 0, 0, 0, 0 }
  98. };
  99. // JavaScript Get Property Wrapper
  100. JSBool JSDOMException::JSGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) {
  101.    if (JSVAL_IS_INT(id)) {
  102.    
  103.    JSDOMException *priv = (JSDOMException*)JS_GetPrivate(cx, obj);
  104.       if (priv==NULL)
  105.          *vp = JSVAL_NULL;
  106.       switch(JSVAL_TO_INT(id)) {
  107.       case JSVAR_INDEX_SIZE_ERR:
  108.          *vp = __int_TO_JSVal(cx,JSDOMException::INDEX_SIZE_ERR);
  109.          break;
  110.       case JSVAR_DOMSTRING_SIZE_ERR:
  111.          *vp = __int_TO_JSVal(cx,JSDOMException::DOMSTRING_SIZE_ERR);
  112.          break;
  113.       case JSVAR_NO_MODIFICATION_ALLOWED_ERR:
  114.          *vp = __int_TO_JSVal(cx,JSDOMException::NO_MODIFICATION_ALLOWED_ERR);
  115.          break;
  116.       case JSVAR_NOT_FOUND_ERR:
  117.          *vp = __int_TO_JSVal(cx,JSDOMException::NOT_FOUND_ERR);
  118.          break;
  119.       case JSVAR_NOT_SUPPORTED_ERR:
  120.          *vp = __int_TO_JSVal(cx,JSDOMException::NOT_SUPPORTED_ERR);
  121.          break;
  122.       case JSVAR_INVALID_STATE_ERR:
  123.          *vp = __int_TO_JSVal(cx,JSDOMException::INVALID_STATE_ERR);
  124.          break;
  125.       case JSVAR_code:
  126.          if (priv)
  127.             *vp = INT_TO_JSVAL(priv->getCode());
  128.          break;
  129.       }
  130.    }
  131.    return JS_TRUE;
  132. }
  133. JSDOMException::JSDOMException(int code) : _code(code)
  134. {
  135. }
  136. int JSDOMException::getCode()
  137. {
  138.   return _code;
  139. }