jsb_pluginx_spidermonkey_specifics.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "jsb_pluginx_spidermonkey_specifics.h"
  2. namespace pluginx {
  3. js_proxy_t *_native_js_global_ht = NULL;
  4. js_proxy_t *_js_native_global_ht = NULL;
  5. std::unordered_map<std::string, js_type_class_t*> _js_global_type_map;
  6. unsigned int getHashCodeByString(const char *key)
  7. {
  8. unsigned int len = strlen(key);
  9. const char *end=key+len;
  10. unsigned int hash;
  11. for (hash = 0; key < end; key++)
  12. {
  13. hash *= 16777619;
  14. hash ^= (unsigned int) (unsigned char) toupper(*key);
  15. }
  16. return (hash);
  17. }
  18. js_proxy_t* jsb_new_proxy(void* nativeObj, JSObject* jsObj)
  19. {
  20. js_proxy_t* p;
  21. JS_NEW_PROXY(p, nativeObj, jsObj);
  22. return p;
  23. }
  24. js_proxy_t* jsb_get_native_proxy(void* nativeObj)
  25. {
  26. js_proxy_t* p;
  27. JS_GET_PROXY(p, nativeObj);
  28. return p;
  29. }
  30. js_proxy_t* jsb_get_js_proxy(JSObject* jsObj)
  31. {
  32. js_proxy_t* p;
  33. JS_GET_NATIVE_PROXY(p, jsObj);
  34. return p;
  35. }
  36. void jsb_remove_proxy(js_proxy_t* nativeProxy, js_proxy_t* jsProxy)
  37. {
  38. JS_REMOVE_PROXY(nativeProxy, jsProxy);
  39. }
  40. void get_or_create_js_obj(JSContext* cx, JS::HandleObject obj, const std::string &name, JS::MutableHandleObject jsObj)
  41. {
  42. JS::RootedValue nsval(cx);
  43. JS_GetProperty(cx, obj, name.c_str(), &nsval);
  44. if (nsval == JSVAL_VOID) {
  45. jsObj.set(JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr()));
  46. nsval = OBJECT_TO_JSVAL(jsObj);
  47. JS_SetProperty(cx, obj, name.c_str(), nsval);
  48. } else {
  49. jsObj.set(nsval.toObjectOrNull());
  50. }
  51. }
  52. } // namespace pluginx {