Compare Revisions

JSAPI Cookbook

Revision 233961:

Revision 233961 by Jorend on

Revision 74040:

Revision 74040 by Jorend on

Title:
JSAPI Cookbook
JSAPI Cookbook
Slug:
SpiderMonkey/JSAPI_Cookbook
SpiderMonkey/JSAPI_Cookbook
Content:

Revision 233961
Revision 74040
n13    <h2>n13    <h2 id="Basics">
n16    <h3>n16    <h3 id="Finding_the_global_object">
n37    <h3>n37    <h3 id="Defining_a_function">
n66    <h3>n66    <h3 id="Creating_an_Array">
n79    <h3>n79    <h3 id="Creating_an_Object">
n92    <h3>n92    <h3 id="Constructing_an_object_with_new">
n143    <h3>n143    <h3 id="Calling_a_global_JS_function">
n160    <h3>n160    <h3 id="Calling_a_JS_function_via_a_local_variable">
n176    <h3 name="Returning_an_integer">n176    <h3 id="Returning_an_integer" name="Returning_an_integer">
n192    <h3 name="Returning_a_floating-point_number">n192    <h3 id="Returning_a_floating-point_number" name="Returning_a_
 >floating-point_number">
n204    <h2 name="Exception_handling">n204    <h2 id="Exception_handling" name="Exception_handling">
n207    <h3 name="throw">n207    <h3 id="throw" name="throw">
n276    <h3 name="catch">n276    <h3 id="catch" name="catch">
n307    <h3 name="finally">n307    <h3 id="finally" name="finally">
n378    <h2 name="Object_properties">n378    <h2 id="Object_properties" name="Object_properties">
n381    <h3 name="Getting_a_property">n381    <h3 id="Getting_a_property" name="Getting_a_property">
n417    <h3 name="Setting_a_property">n417    <h3 id="Setting_a_property" name="Setting_a_property">
n433    <h3 name="Checking_for_a_property">n433    <h3 id="Checking_for_a_property" name="Checking_for_a_propert
 >y">
n456    <h3>n456    <h3 id="Defining_a_constant_property">
n483    <h3>n483    <h3 id="Defining_a_property_with_a_getter_and_setter">
n506    <h3>n506    <h3 id="Defining_a_read-only_property_with_only_a_getter">
n525    <h2 name="Prototypes">n525    <h2 id="Prototypes" name="Prototypes">
n528    <h3>n528    <h3 id="Defining_a_native_read-only_property_on_the_String.pr
 >ototype">
n534                                                   enumerable: trn534                                                   enumerable: tr
>ue});  <br>>ue});  
n544// get the String object from the current context global objectn544// Get the String constructor from the global object.
545if (!JS_GetProperty(cx, JS_GetGlobalObject(cx), "String", &amp;va545if (!JS_GetProperty(cx, global, "String", &amp;val))
>l)) { 
n547}n547if (JSVAL_IS_PRIMITIVE(val))
548 548    return ThrowError(cx, global, "String is not an object", __FI
 >LE__, __LINE__);
549// check if String is an object
550if (!JSVAL_IS_OBJECT(val)) {
551    return JS_FALSE;
552}
553 
nn551// Get String.prototype.
556if (!JS_GetProperty(cx, string, "prototype", &amp;val)) {552if (!JS_GetProperty(cx, string, "prototype", &amp;val))
557    return JS_FALSE;
558}
559 
560// check if the String.prototype is an object too
561if (!JSVAL_IS_OBJECT(val)) {
562        return JS_FALSE;553    return JS_FALSE;
563}554if (JSVAL_IS_PRIMITIVE(val))
564 555    return ThrowError(cx, global, "String.prototype is not an obj
 >ect", __FILE__, __LINE__);
n567// and now we can add some new functionality to all the stringsn558// ...and now we can add some new functionality to all strings.
568JS_DefineProperty(cx, string_prototype, "md5sum", JSVAL_VOID, Get559if (!JS_DefineProperty(cx, string_prototype, "md5sum", JSVAL_VOID
>MD5Func, NULL, JSPROP_READONLY | JSPROP_ENUMERATE));>, GetMD5Func, NULL,
560                       JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS | 
 >JSPROP_ENUMERATE))
561    return JS_FALSE;
t570    <h2 name="Wanted">t563    <h2 id="Wanted" name="Wanted">

Back to History