Obsolete since JavaScript 1.8.5
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
This article covers features introduced in SpiderMonkey 1.8
Callback for objects that wrap other objects.
Syntax
typedef JSObject * (*JSObjectOp)(JSContext *cx, JSObject *obj);
| Name | Type | Description | 
|---|---|---|
| cx | JSContext * | The context in which the object is being unwrapped. | 
| obj | JSObject * | The object to unwrap. | 
Description
If a class has the JSCLASS_IS_EXTENDED bit set in its JSClass.flags and has a non-null JSExtendedClass.wrappedObjectJSExtendedClass.wrappedObject callback to get the wrapped object. Most classes do not implement wrappedObject.
The specific cases where this happens are:
- The default toStringmethod returns a string that contains the name of the wrapped object's class rather than the wrapper's class.
- In typeofexpressions and inJS_TypeOfValue, the type of the wrapped object is returned. (The result may be"object","function", or"xml".)
- When assigning to __proto__or__parent__from script, the JavaScript engine checks to see if the assignment would produce a cycle. If so, it fails with an exception. When walking the chain to do this check, wrappers are automatically unwrapped.
- A wrapper object is strictly equal to the object it wraps, in the sense of ===and!==. Two wrapper objects that wrap the same object are also strictly equal.
- Object.prototype.evalunwraps.
- A wrapper object that wraps an Array is considered an array for the purpose of Array.prototype.concatandArray.concat(which treat array arguments differently from other arguments, per ECMA 262-3 §15.4.4.4).
The wrappedObject callback implementation must never fail. If it returns null or obj, then the JS engine treats the object as though it were not a wrapper.
Wrapper objects typically have no prototype, do not allow setting __proto__, and inherit properties from the wrapped object rather than the prototype chain (see JSNewResolveOp).