static Eina_Bool ewk_js_npobject_property_get(Ewk_JS_Object* jsObject, const char* name, Ewk_JS_Variant* value) { NPIdentifier id = _NPN_GetStringIdentifier(name); NPVariant var; bool fail = _NPN_GetProperty(0, reinterpret_cast<NPObject*>(jsObject), id, &var); if (!fail) fail = ewk_js_npvariant_to_variant(value, &var); return fail; }
bool WebBindings::getProperty(NPP npp, NPObject* object, NPIdentifier property, NPVariant* result) { return _NPN_GetProperty(npp, object, property, result); }
bool NPObjectWrapper::NPGetProperty(NPObject* obj, NPIdentifier name, NPVariant* result) { NPObject* actualObject = getObjectForCall(obj); return actualObject ? _NPN_GetProperty(0, actualObject, name, result) : false; }
static Ewk_JS_Object* ewk_js_npobject_to_object(NPObject* npObject) { NPIdentifier* values; uint32_t np_props_count; Ewk_JS_Class* cls; Ewk_JS_Object* object; Eina_Iterator* it; Ewk_JS_Property* prop; JavaScriptObject* jso; if (EINA_MAGIC_CHECK(reinterpret_cast<Ewk_JS_Object*>(npObject), EWK_JS_OBJECT_MAGIC)) return reinterpret_cast<Ewk_JS_Object*>(npObject); if (!_NPN_Enumerate(0, npObject, &values, &np_props_count)) return 0; cls = static_cast<Ewk_JS_Class*>(malloc(sizeof(Ewk_JS_Class))); if (!cls) { ERR("Could not allocate memory for ewk_js_class"); return 0; } cls->meta = 0; Ewk_JS_Default def = { ewk_js_npobject_property_set, ewk_js_npobject_property_get, ewk_js_npobject_property_del }; cls->default_prop = def; cls->methods = eina_hash_pointer_new(0); cls->properties = eina_hash_pointer_new(reinterpret_cast<Eina_Free_Cb>(ewk_js_property_free)); for (uint32_t i = 0; i < np_props_count; i++) { if (_NPN_HasProperty(0, npObject, values[i])) { NPVariant var; Ewk_JS_Property* prop = static_cast<Ewk_JS_Property*>(calloc(sizeof(Ewk_JS_Property), 1)); if (!prop) { ERR("Could not allocate memory for ewk_js_property"); goto error; } _NPN_GetProperty(0, npObject, values[i], &var); ewk_js_npvariant_to_variant(&(prop->value), &var); prop->name = _NPN_UTF8FromIdentifier(values[i]); eina_hash_add(cls->properties, values[i], prop); } } // Can't use ewk_js_object_new(cls) because it expects cls->meta to exist. object = static_cast<Ewk_JS_Object*>(malloc(sizeof(Ewk_JS_Object))); if (!object) { ERR("Could not allocate memory for ewk_js_object"); goto error; } free(values); EINA_MAGIC_SET(object, EWK_JS_OBJECT_MAGIC); object->name = 0; object->cls = cls; object->view = 0; jso = reinterpret_cast<JavaScriptObject*>(npObject); if (!strcmp("Array", jso->imp->methodTable()->className(jso->imp).ascii().data())) object->type = EWK_JS_OBJECT_ARRAY; else if (!strcmp("Function", jso->imp->methodTable()->className(jso->imp).ascii().data())) object->type = EWK_JS_OBJECT_FUNCTION; else object->type = EWK_JS_OBJECT_OBJECT; if (eina_hash_population(cls->properties) < 25) object->properties = eina_hash_string_small_new(0); else object->properties = eina_hash_string_superfast_new(0); it = eina_hash_iterator_data_new(cls->properties); EINA_ITERATOR_FOREACH(it, prop) { const char* key = prop->name; Ewk_JS_Variant* value = &prop->value; eina_hash_add(object->properties, key, value); } eina_iterator_free(it); object->base = *reinterpret_cast<JavaScriptObject*>(npObject); return object; error: ewk_js_class_free(cls); free(values); return 0; }
bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result) { return _NPN_GetProperty(npp, npobj, propertyName, result); }