|
|
|
=proto
|
|
|
|
int duk_del_prop(duk_context *ctx, int obj_index);
|
|
|
|
|
|
|
|
=stack
|
|
|
|
[ ... obj! ... key! ] -> [ ... obj! ... ]
|
|
|
|
|
|
|
|
=summary
|
|
|
|
<p>Delete the property <code>key</code> of a value at <code>obj_index</code>.
|
|
|
|
<code>key</code> is removed from the stack. Return code and error throwing
|
|
|
|
behavior:</p>
|
|
|
|
<ul>
|
|
|
|
<li>If property exists and is configurable (deletable), deletes the
|
|
|
|
property and returns non-zero.</li>
|
|
|
|
<li>If property exists but is not configurable, throws an error if current
|
|
|
|
function is strict, returns 0 otherwise.</li>
|
|
|
|
<li>If property does not exist, returns non-zero (<i>not</i> 0).</li>
|
|
|
|
<li>If the value at <code>obj_index</code> is not
|
|
|
|
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-9.10">object coercible</a>,
|
|
|
|
throws an error.</li>
|
|
|
|
<li>If <code>obj_index</code> is invalid, throws an error.</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<p>The property deletion is equivalent to the Ecmascript expression:</p>
|
|
|
|
<pre class="ecmascript-code">
|
|
|
|
delete obj[key]
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>For semantics, see
|
|
|
|
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.1">Property Accessors</a>,
|
|
|
|
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.1">The delete operator</a>
|
|
|
|
and <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-8.12.7">[[Delete]] (P, Throw)</a>.
|
|
|
|
The return value and error throwing behavior mirrors the Ecmascript
|
|
|
|
<code>delete</code> operator behavior.
|
|
|
|
Both the target value and the <code>key</code> are coerced:</p>
|
|
|
|
<ul>
|
|
|
|
<li>The target value is automatically coerced to an object. However, this
|
|
|
|
object is a temporary one, so deleting its properties is not very useful.</li>
|
|
|
|
<li>The <code>key</code> argument is internally coerced to a string. There is
|
|
|
|
an internal fast path for arrays and numeric indices which avoids an
|
|
|
|
explicit string coercion, so use a numeric <code>key</code> when applicable.</p>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<div class="note">
|
|
|
|
This API call returns non-zero when the target property does not exist.
|
|
|
|
This is not very intuitive, but follows Ecmascript semantics:
|
|
|
|
<code>delete obj.nonexistent</code> also evaluates to <code>true</code>.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="note">
|
|
|
|
At the moment all Duktape/C functions are strict. When called from a
|
|
|
|
Duktape/C function, this API call thus either returns non-zero or throws
|
|
|
|
an error. However, if called outside a Duktape/C function (when the
|
|
|
|
context has an empty call stack) the API call executes in non-strict mode,
|
|
|
|
i.e. returns 0 when trying to delete a non-configurable property.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<p>If the key is a fixed string you can avoid one API call and use the
|
|
|
|
<code><a href="#duk_del_prop_string">duk_del_prop_string()</a></code> variant.
|
|
|
|
Similarly, if the key is an array index, you can use the
|
|
|
|
<code><a href="#duk_del_prop_index">duk_del_prop_index()</a></code> variant.</p>
|
|
|
|
|
|
|
|
=example
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
duk_push_string(ctx, "myProperty");
|
|
|
|
rc = duk_del_prop(ctx, -3);
|
|
|
|
printf("delete obj.myProperty -> rc=%d\n", rc);
|
|
|
|
|
|
|
|
=tags
|
|
|
|
property
|
|
|
|
|
|
|
|
=seealso
|
|
|
|
duk_del_prop_string
|
|
|
|
duk_del_prop_index
|
|
|
|
|