Please note, this is a STATIC archive of website from 03 Nov 2016, does not collect or store any user information, there is no "phishing" involved.


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.


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.


If a class has the JSCLASS_IS_EXTENDED bit set in its JSClass.flags and has a non-null JSExtendedClass.wrappedObject, then objects of that class may be wrappers. In a few cases the JavaScript engine will pretend the wrapper isn't there, instead operating on the object it wraps. In these cases the engine calls the JSExtendedClass.wrappedObject callback to get the wrapped object. Most classes do not implement wrappedObject.

The specific cases where this happens are:

  • The default toString method returns a string that contains the name of the wrapped object's class rather than the wrapper's class.
  • In typeof expressions and in JS_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.eval unwraps.
  • A wrapper object that wraps an Array is considered an array for the purpose of Array.prototype.concat and Array.concat (which treat array arguments differently from other arguments, per ECMA 262-3 §

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).

Document Tags and Contributors

 Contributors to this page: fscholz, arai, Jorend
 Last updated by: fscholz,