JS_DeleteProperty2

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_DeleteProperty2
  • Revision title: JS_DeleteProperty2
  • Revision id: 138475
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment no wording changes; page display name changed to 'JS_DeleteProperty2'

Revision Content

{{ Jsapi_ref_header("JS_DeleteProperty2") }}

Removes a specified property from an object.

Syntax

JSBool JS_DeleteProperty2(JSContext *cx, JSObject *obj,
    const char *name, jsval *rval);

JSBool JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen, jsval *rval);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{ Jsapi-requires-request() }}
obj JSObject * Object from which to delete a property.
name const char * or const jschar * Name of the property to delete.
namelen size_t (only in JS_DeleteUCProperty2) The length of name in characters; or -1 to indicate that name is null-terminated.
rval jsval * Out parameter. *rval receives the stored value of the deleted property.

Description

JS_DeleteProperty2 removes a specified property, name, from an object, obj, and assigns the final stored value of the deleted property to *rval. If an object references a property belonging to a prototype, the property is removed from the object, but not from the prototype. If deletion is successful, JS_DeleteProperty2 returns JS_TRUE. Otherwise it returns JS_FALSE.

JS_DeleteUCProperty2 is the Unicode version of the function.

Notes

Per the ECMA standard, these functions remove read-only properties from objects as long as those properties are not also permanent.

For JavaScript 1.2 and earlier, if JS_DeleteProperty2 or JS_DeleteUCProperty2 fails because the property to be deleted is permanent, it reports the error before returning JS_FALSE. For JavaScript 1.3, the attempt is silently ignored. In both these cases, *rval will receive the stored value of the property that was not deleted.

To remove all properties from an object, call JS_ClearScope.

See Also

{{ LXRSearch("ident", "i", "JS_DeleteProperty2") }}
{{ LXRSearch("ident", "i", "JS_DeleteUCProperty2") }}

JS_ClearScope, JS_DefineProperty, JS_DefinePropertyWithTinyId, JS_DeleteProperty, JS_GetProperty, JS_LookupProperty, JS_PropertyStub, JS_SetProperty

Revision Source

<p>{{ Jsapi_ref_header("JS_DeleteProperty2") }}
</p><p>Removes a specified property from an object.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_DeleteProperty2</strong>(<a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/JSObject" title="en/JSObject">JSObject</a> *obj,
    const char *name, <a href="/en/jsval" title="en/jsval">jsval</a> *rval);

<a href="/en/JSBool" title="en/JSBool">JSBool</a> <strong>JS_DeleteUCProperty2</strong>(<a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/JSObject" title="en/JSObject">JSObject</a> *obj,
    const <a href="/en/jschar" title="en/jschar">jschar</a> *name, size_t namelen, <a href="/en/jsval" title="en/jsval">jsval</a> *rval);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>Pointer to a JS context from which to derive runtime information.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="/en/JSObject" title="en/JSObject">JSObject</a> *</code></td>
<td>Object from which to delete a property.</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>const char *</code> <em>or</em> <code>const <a href="/en/jschar" title="en/jschar">jschar</a> *</code></td>
<td>Name of the property to delete.</td>
</tr>
<tr>
<td><code>namelen</code></td>
<td><code>size_t</code></td>
<td><em>(only in <code>JS_DeleteUCProperty2</code>)</em> The length of <code>name</code> in characters; or <code>-1</code> to indicate that <code>name</code> is null-terminated.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code><a href="/en/jsval" title="en/jsval">jsval</a> *</code></td>
<td>Out parameter. <code>*rval</code> receives the <a href="/en/JSAPI/Stored_value" title="en/JSAPI/Stored_value">stored value</a> of the deleted property.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_DeleteProperty2</code> removes a specified property, <code>name</code>, from an object, <code>obj</code>, and assigns the final <a href="/en/JSAPI/Stored_value" title="en/JSAPI/Stored_value">stored value</a> of the deleted property to <code>*rval</code>. If an object references a property belonging to a prototype, the property is removed from the object, but not from the prototype. If deletion is successful, <code>JS_DeleteProperty2</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code>.
</p><p><code>JS_DeleteUCProperty2</code> is the Unicode version of the function.
</p>
<h3 name="Notes"> Notes </h3>
<p>Per the ECMA standard, these functions remove read-only properties from objects as long as those properties are not also permanent.
</p><p>For JavaScript 1.2 and earlier, if <code>JS_DeleteProperty2</code> or <code>JS_DeleteUCProperty2</code> fails because the property to be deleted is permanent, it reports the error before returning <code>JS_FALSE</code>. For JavaScript 1.3, the attempt is silently ignored. In both these cases, <code>*rval</code> will receive the stored value of the property that was not deleted.
</p><p>To remove all properties from an object, call <code><a href="/en/JS_ClearScope" title="en/JS_ClearScope">JS_ClearScope</a></code>.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_DeleteProperty2") }}<br>
{{ LXRSearch("ident", "i", "JS_DeleteUCProperty2") }}
</p><p><a href="/en/JS_ClearScope" title="en/JS_ClearScope">JS_ClearScope</a>,
<a href="/en/JS_DefineProperty" title="en/JS_DefineProperty">JS_DefineProperty</a>,
<a href="/en/JS_DefinePropertyWithTinyId" title="en/JS_DefinePropertyWithTinyId">JS_DefinePropertyWithTinyId</a>,
<a href="/en/JS_DeleteProperty" title="en/JS_DeleteProperty">JS_DeleteProperty</a>,
<a href="/en/JS_GetProperty" title="en/JS_GetProperty">JS_GetProperty</a>,
<a href="/en/JS_LookupProperty" title="en/JS_LookupProperty">JS_LookupProperty</a>,
<a href="/en/JS_PropertyStub" title="en/JS_PropertyStub">JS_PropertyStub</a>,
<a href="/en/JS_SetProperty" title="en/JS_SetProperty">JS_SetProperty</a>
</p>
Revert to this revision