mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
8 years ago
committed by
GitHub
7 changed files with 86 additions and 6 deletions
@ -0,0 +1,40 @@ |
|||
/*===
|
|||
*** test_basic (duk_safe_call) |
|||
0: 1 0 |
|||
1: 1 0 |
|||
2: 1 1 |
|||
3: 1 1 |
|||
4: 1 1 |
|||
5: 1 0 |
|||
6: 1 0 |
|||
7: 1 1 |
|||
8: 0 0 |
|||
final top: 8 |
|||
==> rc=0, result='undefined' |
|||
===*/ |
|||
|
|||
static duk_ret_t test_basic(duk_context *ctx, void *udata) { |
|||
duk_idx_t i, n; |
|||
|
|||
(void) udata; |
|||
|
|||
duk_push_string(ctx, ""); |
|||
duk_push_string(ctx, "foo"); |
|||
duk_push_string(ctx, "\x80" "bar"); |
|||
duk_push_string(ctx, "\x81" "quux"); |
|||
duk_push_string(ctx, "\x82" "baz"); |
|||
duk_push_string(ctx, "\xc0" "quuux"); |
|||
duk_push_string(ctx, "\xfe" "quuuux"); |
|||
duk_push_string(ctx, "\xff" "quuuuux"); |
|||
|
|||
for (i = 0, n = duk_get_top(ctx) + 1; i < n; i++) { |
|||
printf("%ld: %ld %ld\n", (long) i, (long) duk_is_string(ctx, i), (long) duk_is_symbol(ctx, i)); |
|||
} |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
void test(duk_context *ctx) { |
|||
TEST_SAFE_CALL(test_basic); |
|||
} |
@ -0,0 +1,25 @@ |
|||
name: duk_is_symbol |
|||
|
|||
proto: | |
|||
duk_bool_t duk_is_symbol(duk_context *ctx, duk_idx_t idx); |
|||
|
|||
stack: | |
|||
[ ... val! ... ] |
|||
|
|||
summary: | |
|||
<p>Returns 1 if value at <code>idx</code> is a symbol, otherwise |
|||
returns 0. If <code>idx</code> is invalid, also returns 0.</p> |
|||
|
|||
<div include="symbols-are-strings.html" /> |
|||
|
|||
example: | |
|||
if (duk_is_symbol(ctx, -3)) { |
|||
/* ... */ |
|||
} |
|||
|
|||
tags: |
|||
- stack |
|||
- string |
|||
- symbol |
|||
|
|||
introduced: 2.0.0 |
@ -1,7 +1,9 @@ |
|||
<div class="note"> |
|||
Symbol values are visible in the C API as strings, e.g. <code>duk_is_string()</code> |
|||
is true (this behavior is similar to Duktape 1.x internal strings). Symbols are |
|||
still an experimental feature. For now, you can distinguish Symbols from ordinary |
|||
strings by looking at their initial byte, see |
|||
Symbol values are visible in the C API as strings so that both |
|||
<code>duk_is_symbol()</code> and <code>duk_is_string()</code> are true. |
|||
This behavior is similar to Duktape 1.x internal strings. Symbols are |
|||
still an experimental feature; for now, you can distinguish Symbols from |
|||
ordinary strings using <code><a href="#duk_is_symbol">duk_is_symbol()</a></code>. |
|||
For the internal representation, see |
|||
<a href="https://github.com/svaarala/duktape/blob/master/doc/symbols.rst">symbols.rst</a>. |
|||
</div> |
|||
|
Loading…
Reference in new issue