Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_hthread_builtins.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Macros

#define DUK__CLASS_BITS   5
 
#define DUK__BIDX_BITS   7
 
#define DUK__STRIDX_BITS   9 /* XXX: try to optimize to 8 (would now be possible, <200 used) */
 
#define DUK__NATIDX_BITS   8
 
#define DUK__NUM_NORMAL_PROPS_BITS   6
 
#define DUK__NUM_FUNC_PROPS_BITS   6
 
#define DUK__PROP_FLAGS_BITS   3
 
#define DUK__STRING_LENGTH_BITS   8
 
#define DUK__STRING_CHAR_BITS   7
 
#define DUK__LENGTH_PROP_BITS   3
 
#define DUK__NARGS_BITS   3
 
#define DUK__PROP_TYPE_BITS   3
 
#define DUK__MAGIC_BITS   16
 
#define DUK__NARGS_VARARGS_MARKER   0x07
 
#define DUK__NO_CLASS_MARKER   0x00 /* 0 = DUK_HOBJECT_CLASS_UNUSED */
 
#define DUK__NO_BIDX_MARKER   0x7f
 
#define DUK__NO_STRIDX_MARKER   0xff
 
#define DUK__PROP_TYPE_DOUBLE   0
 
#define DUK__PROP_TYPE_STRING   1
 
#define DUK__PROP_TYPE_STRIDX   2
 
#define DUK__PROP_TYPE_BUILTIN   3
 
#define DUK__PROP_TYPE_UNDEFINED   4
 
#define DUK__PROP_TYPE_BOOLEAN_TRUE   5
 
#define DUK__PROP_TYPE_BOOLEAN_FALSE   6
 
#define DUK__PROP_TYPE_ACCESSOR   7
 

Functions

DUK_LOCAL void duk__push_stridx (duk_context *ctx, duk_bitdecoder_ctx *bd)
 
DUK_LOCAL void duk__push_string (duk_context *ctx, duk_bitdecoder_ctx *bd)
 
DUK_LOCAL void duk__push_stridx_or_string (duk_context *ctx, duk_bitdecoder_ctx *bd)
 
DUK_LOCAL void duk__push_double (duk_context *ctx, duk_bitdecoder_ctx *bd)
 
DUK_INTERNAL void duk_hthread_create_builtin_objects (duk_hthread *thr)
 
DUK_INTERNAL void duk_hthread_copy_builtin_objects (duk_hthread *thr_from, duk_hthread *thr_to)
 

Macro Definition Documentation

◆ DUK__BIDX_BITS

#define DUK__BIDX_BITS   7

◆ DUK__CLASS_BITS

#define DUK__CLASS_BITS   5

◆ DUK__LENGTH_PROP_BITS

#define DUK__LENGTH_PROP_BITS   3

◆ DUK__MAGIC_BITS

#define DUK__MAGIC_BITS   16

◆ DUK__NARGS_BITS

#define DUK__NARGS_BITS   3

◆ DUK__NARGS_VARARGS_MARKER

#define DUK__NARGS_VARARGS_MARKER   0x07

◆ DUK__NATIDX_BITS

#define DUK__NATIDX_BITS   8

◆ DUK__NO_BIDX_MARKER

#define DUK__NO_BIDX_MARKER   0x7f

◆ DUK__NO_CLASS_MARKER

#define DUK__NO_CLASS_MARKER   0x00 /* 0 = DUK_HOBJECT_CLASS_UNUSED */

◆ DUK__NO_STRIDX_MARKER

#define DUK__NO_STRIDX_MARKER   0xff

◆ DUK__NUM_FUNC_PROPS_BITS

#define DUK__NUM_FUNC_PROPS_BITS   6

◆ DUK__NUM_NORMAL_PROPS_BITS

#define DUK__NUM_NORMAL_PROPS_BITS   6

◆ DUK__PROP_FLAGS_BITS

#define DUK__PROP_FLAGS_BITS   3

◆ DUK__PROP_TYPE_ACCESSOR

#define DUK__PROP_TYPE_ACCESSOR   7

◆ DUK__PROP_TYPE_BITS

#define DUK__PROP_TYPE_BITS   3

◆ DUK__PROP_TYPE_BOOLEAN_FALSE

#define DUK__PROP_TYPE_BOOLEAN_FALSE   6

◆ DUK__PROP_TYPE_BOOLEAN_TRUE

#define DUK__PROP_TYPE_BOOLEAN_TRUE   5

◆ DUK__PROP_TYPE_BUILTIN

#define DUK__PROP_TYPE_BUILTIN   3

◆ DUK__PROP_TYPE_DOUBLE

#define DUK__PROP_TYPE_DOUBLE   0

◆ DUK__PROP_TYPE_STRIDX

#define DUK__PROP_TYPE_STRIDX   2

◆ DUK__PROP_TYPE_STRING

#define DUK__PROP_TYPE_STRING   1

◆ DUK__PROP_TYPE_UNDEFINED

#define DUK__PROP_TYPE_UNDEFINED   4

◆ DUK__STRIDX_BITS

#define DUK__STRIDX_BITS   9 /* XXX: try to optimize to 8 (would now be possible, <200 used) */

Definition at line 15 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

Referenced by duk__push_stridx().

◆ DUK__STRING_CHAR_BITS

#define DUK__STRING_CHAR_BITS   7

Definition at line 21 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

Referenced by duk__push_string().

◆ DUK__STRING_LENGTH_BITS

#define DUK__STRING_LENGTH_BITS   8

Definition at line 20 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

Referenced by duk__push_string().

Function Documentation

◆ duk__push_double()

DUK_LOCAL void duk__push_double ( duk_context * ctx,
duk_bitdecoder_ctx * bd )

Definition at line 195 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

195 {
198
199 for (i = 0; i < 8; i++) {
200 /* Encoding endianness must match target memory layout,
201 * build scripts and genbuiltins.py must ensure this.
202 */
203 du.uc[i] = (duk_uint8_t) duk_bd_decode(bd, 8);
204 }
205
206 duk_push_number(ctx, du.d); /* push operation normalizes NaNs */
207}
unsigned int duk_small_uint_t
DUK_EXTERNAL void duk_push_number(duk_context *ctx, duk_double_t val)
DUK_INTERNAL_DECL duk_int32_t duk_bd_decode(duk_bitdecoder_ctx *ctx, duk_small_int_t bits)

References duk_double_union::d, duk_bd_decode(), duk_push_number(), and duk_double_union::uc.

Referenced by duk_hthread_create_builtin_objects().

◆ duk__push_stridx()

DUK_LOCAL void duk__push_stridx ( duk_context * ctx,
duk_bitdecoder_ctx * bd )

◆ duk__push_stridx_or_string()

DUK_LOCAL void duk__push_stridx_or_string ( duk_context * ctx,
duk_bitdecoder_ctx * bd )

Definition at line 188 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

188 {
189 if (duk_bd_decode_flag(bd)) {
190 duk__push_string(ctx, bd);
191 } else {
192 duk__push_stridx(ctx, bd);
193 }
194}
DUK_INTERNAL_DECL duk_small_int_t duk_bd_decode_flag(duk_bitdecoder_ctx *ctx)
DUK_LOCAL void duk__push_stridx(duk_context *ctx, duk_bitdecoder_ctx *bd)
DUK_LOCAL void duk__push_string(duk_context *ctx, duk_bitdecoder_ctx *bd)

References duk__push_stridx(), duk__push_string(), and duk_bd_decode_flag().

Referenced by duk_hthread_create_builtin_objects().

◆ duk__push_string()

DUK_LOCAL void duk__push_string ( duk_context * ctx,
duk_bitdecoder_ctx * bd )

Definition at line 176 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

176 {
179 duk_uint8_t *p;
180
182 p = (duk_uint8_t *) duk_push_fixed_buffer(ctx, n);
183 for (i = 0; i < n; i++) {
184 *p++ = (duk_uint8_t) duk_bd_decode(bd, DUK__STRING_CHAR_BITS);
185 }
186 duk_to_string(ctx, -1);
187}
DUK_EXTERNAL const char * duk_to_string(duk_context *ctx, duk_idx_t index)
#define duk_push_fixed_buffer(ctx, size)

References DUK__STRING_CHAR_BITS, DUK__STRING_LENGTH_BITS, duk_bd_decode(), duk_push_fixed_buffer, and duk_to_string().

Referenced by duk__push_stridx_or_string(), and duk_hthread_create_builtin_objects().

◆ duk_hthread_copy_builtin_objects()

DUK_INTERNAL void duk_hthread_copy_builtin_objects ( duk_hthread * thr_from,
duk_hthread * thr_to )

Definition at line 828 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

828 {
830
831 for (i = 0; i < DUK_NUM_BUILTINS; i++) {
832 thr_to->builtins[i] = thr_from->builtins[i];
833 DUK_HOBJECT_INCREF_ALLOWNULL(thr_to, thr_to->builtins[i]); /* side effect free */
834 }
835}
#define DUK_HOBJECT_INCREF_ALLOWNULL(thr, h)
duk_hobject * builtins[DUK_NUM_BUILTINS]

References duk_hthread::builtins, DUK_HOBJECT_INCREF_ALLOWNULL, and DUK_NUM_BUILTINS.

◆ duk_hthread_create_builtin_objects()

DUK_INTERNAL void duk_hthread_create_builtin_objects ( duk_hthread * thr)

Definition at line 209 of file duktape-1.8.0/src-separate/duk_hthread_builtins.c.

209 {
210 duk_context *ctx = (duk_context *) thr;
211 duk_bitdecoder_ctx bd_ctx;
212 duk_bitdecoder_ctx *bd = &bd_ctx; /* convenience */
213 duk_hobject *h;
214 duk_small_uint_t i, j;
215
216 DUK_D(DUK_DPRINT("INITBUILTINS BEGIN: DUK_NUM_BUILTINS=%d, DUK_NUM_BUILTINS_ALL=%d", (int) DUK_NUM_BUILTINS, (int) DUK_NUM_ALL_BUILTINS));
217
218 DUK_MEMZERO(&bd_ctx, sizeof(bd_ctx));
219 bd->data = (const duk_uint8_t *) duk_builtins_data;
220 bd->length = (duk_size_t) DUK_BUILTINS_DATA_LENGTH;
221
222 /*
223 * First create all built-in bare objects on the empty valstack.
224 *
225 * Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
226 * stack indices matching their eventual thr->builtins[] index.
227 *
228 * Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
229 * will exist on the value stack during init but won't be placed
230 * into thr->builtins[]. These are objects referenced in some way
231 * from thr->builtins[] roots but which don't need to be indexed by
232 * Duktape through thr->builtins[] (e.g. user custom objects).
233 */
234
236
237 DUK_DD(DUK_DDPRINT("create empty built-ins"));
238 DUK_ASSERT_TOP(ctx, 0);
239 for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) {
240 duk_small_uint_t class_num;
241 duk_small_int_t len = -1; /* must be signed */
242
244 len = (duk_small_int_t) duk_bd_decode_flagged(bd, DUK__LENGTH_PROP_BITS, (duk_int32_t) -1 /*def_value*/);
245
246 if (class_num == DUK_HOBJECT_CLASS_FUNCTION) {
247 duk_small_uint_t natidx;
248 duk_int_t c_nargs; /* must hold DUK_VARARGS */
249 duk_c_function c_func;
250 duk_int16_t magic;
251
252 DUK_DDD(DUK_DDDPRINT("len=%ld", (long) len));
253 DUK_ASSERT(len >= 0);
254
256 c_func = duk_bi_native_functions[natidx];
257
258 c_nargs = (duk_small_uint_t) duk_bd_decode_flagged(bd, DUK__NARGS_BITS, len /*def_value*/);
259 if (c_nargs == DUK__NARGS_VARARGS_MARKER) {
260 c_nargs = DUK_VARARGS;
261 }
262
263 /* XXX: set magic directly here? (it could share the c_nargs arg) */
264 duk_push_c_function_noexotic(ctx, c_func, c_nargs);
265
266 h = duk_require_hobject(ctx, -1);
267 DUK_ASSERT(h != NULL);
268
269 /* Currently all built-in native functions are strict.
270 * duk_push_c_function() now sets strict flag, so
271 * assert for it.
272 */
274
275 /* XXX: function properties */
276
277 /* Built-in 'name' is not writable by default. Function '.name'
278 * is writable to allow user code to set a '.name' on a native
279 * function.
280 */
283 -2,
287
288 /* Almost all global level Function objects are constructable
289 * but not all: Function.prototype is a non-constructable,
290 * callable Function.
291 */
292 if (duk_bd_decode_flag(bd)) {
294 } else {
296 }
297
298 /* Cast converts magic to 16-bit signed value */
299 magic = (duk_int16_t) duk_bd_decode_flagged(bd, DUK__MAGIC_BITS, 0 /*def_value*/);
300 ((duk_hnativefunction *) h)->magic = magic;
301 } else {
302 /* XXX: ARRAY_PART for Array prototype? */
303
306 -1); /* no prototype or class yet */
307
308 h = duk_require_hobject(ctx, -1);
309 DUK_ASSERT(h != NULL);
310 }
311
312 DUK_HOBJECT_SET_CLASS_NUMBER(h, class_num);
313
314 if (i < DUK_NUM_BUILTINS) {
315 thr->builtins[i] = h;
316 DUK_HOBJECT_INCREF(thr, &h->hdr);
317 }
318
319 if (len >= 0) {
320 /*
321 * For top-level objects, 'length' property has the following
322 * default attributes: non-writable, non-enumerable, non-configurable
323 * (E5 Section 15).
324 *
325 * However, 'length' property for Array.prototype has attributes
326 * expected of an Array instance which are different: writable,
327 * non-enumerable, non-configurable (E5 Section 15.4.5.2).
328 *
329 * This is currently determined implicitly based on class; there are
330 * no attribute flags in the init data.
331 */
332
333 duk_push_int(ctx, len);
335 -2,
337 (class_num == DUK_HOBJECT_CLASS_ARRAY ? /* only Array.prototype matches */
339 }
340
341 /* enable exotic behaviors last */
342
343 if (class_num == DUK_HOBJECT_CLASS_ARRAY) {
345 }
346 if (class_num == DUK_HOBJECT_CLASS_STRING) {
348 }
349
350 /* some assertions */
351
353 /* DUK_HOBJECT_FLAG_CONSTRUCTABLE varies */
356 /* DUK_HOBJECT_FLAG_NATIVEFUNCTION varies */
358 DUK_ASSERT(!DUK_HOBJECT_HAS_ARRAY_PART(h)); /* currently, even for Array.prototype */
359 /* DUK_HOBJECT_FLAG_STRICT varies */
360 DUK_ASSERT(!DUK_HOBJECT_HAS_NATIVEFUNCTION(h) || /* all native functions have NEWENV */
365 /* DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies */
366 /* DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies */
368
369 DUK_DDD(DUK_DDDPRINT("created built-in %ld, class=%ld, length=%ld", (long) i, (long) class_num, (long) len));
370 }
371
372 /*
373 * Then decode the builtins init data (see genbuiltins.py) to
374 * init objects
375 */
376
377 DUK_DD(DUK_DDPRINT("initialize built-in object properties"));
378 for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) {
381
382 DUK_DDD(DUK_DDDPRINT("initializing built-in object at index %ld", (long) i));
383 h = duk_require_hobject(ctx, i);
384 DUK_ASSERT(h != NULL);
385
387 if (t != DUK__NO_BIDX_MARKER) {
388 DUK_DDD(DUK_DDDPRINT("set internal prototype: built-in %ld", (long) t));
390 }
391
393 if (t != DUK__NO_BIDX_MARKER) {
394 /* 'prototype' property for all built-in objects (which have it) has attributes:
395 * [[Writable]] = false,
396 * [[Enumerable]] = false,
397 * [[Configurable]] = false
398 */
399 DUK_DDD(DUK_DDDPRINT("set external prototype: built-in %ld", (long) t));
401 }
402
404 if (t != DUK__NO_BIDX_MARKER) {
405 /* 'constructor' property for all built-in objects (which have it) has attributes:
406 * [[Writable]] = true,
407 * [[Enumerable]] = false,
408 * [[Configurable]] = true
409 */
410 DUK_DDD(DUK_DDDPRINT("set external constructor: built-in %ld", (long) t));
412 }
413
414 /* normal valued properties */
416 DUK_DDD(DUK_DDDPRINT("built-in object %ld, %ld normal valued properties", (long) i, (long) num));
417 for (j = 0; j < num; j++) {
418 duk_small_uint_t prop_flags;
419
421
422 /*
423 * Property attribute defaults are defined in E5 Section 15 (first
424 * few pages); there is a default for all properties and a special
425 * default for 'length' properties. Variation from the defaults is
426 * signaled using a single flag bit in the bitstream.
427 */
428
429 if (duk_bd_decode_flag(bd)) {
431 } else {
432 prop_flags = DUK_PROPDESC_FLAGS_WC;
433 }
434
436
437 DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld",
438 (long) i, (long) j, duk_get_tval(ctx, -1), (unsigned long) prop_flags, (long) t));
439
440 switch (t) {
442 duk__push_double(ctx, bd);
443 break;
444 }
446 duk__push_string(ctx, bd);
447 break;
448 }
450 duk__push_stridx(ctx, bd);
451 break;
452 }
454 duk_small_uint_t bidx;
455
458 duk_dup(ctx, (duk_idx_t) bidx);
459 break;
460 }
463 break;
464 }
466 duk_push_true(ctx);
467 break;
468 }
470 duk_push_false(ctx);
471 break;
472 }
476 duk_c_function c_func_getter;
477 duk_c_function c_func_setter;
478
479 /* XXX: this is a bit awkward because there is no exposed helper
480 * in the API style, only this internal helper.
481 */
482 DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx",
483 (long) i, duk_get_tval(ctx, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) prop_flags));
484
485 c_func_getter = duk_bi_native_functions[natidx_getter];
486 c_func_setter = duk_bi_native_functions[natidx_setter];
487 duk_push_c_function_noconstruct_noexotic(ctx, c_func_getter, 0); /* always 0 args */
488 duk_push_c_function_noconstruct_noexotic(ctx, c_func_setter, 1); /* always 1 arg */
489
490 /* XXX: magic for getter/setter? use duk_def_prop()? */
491
492 DUK_ASSERT((prop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */
493
494 prop_flags |= DUK_PROPDESC_FLAG_ACCESSOR; /* accessor flag not encoded explicitly */
496 duk_require_hobject(ctx, i),
497 duk_get_hstring(ctx, -3),
498 duk_require_hobject(ctx, -2),
499 duk_require_hobject(ctx, -1),
500 prop_flags);
501 duk_pop_3(ctx); /* key, getter and setter, now reachable through object */
502 goto skip_value;
503 }
504 default: {
505 /* exhaustive */
507 }
508 }
509
510 DUK_ASSERT((prop_flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0);
511 duk_xdef_prop(ctx, i, prop_flags);
512
513 skip_value:
514 continue; /* avoid empty label at the end of a compound statement */
515 }
516
517 /* native function properties */
519 DUK_DDD(DUK_DDDPRINT("built-in object %ld, %ld function valued properties", (long) i, (long) num));
520 for (j = 0; j < num; j++) {
521 duk_hstring *h_key;
522 duk_small_uint_t natidx;
523 duk_int_t c_nargs; /* must hold DUK_VARARGS */
524 duk_small_uint_t c_length;
525 duk_int16_t magic;
526 duk_c_function c_func;
527 duk_hnativefunction *h_func;
528#if defined(DUK_USE_LIGHTFUNC_BUILTINS)
529 duk_small_int_t lightfunc_eligible;
530#endif
531
533 h_key = duk_get_hstring(ctx, -1);
534 DUK_ASSERT(h_key != NULL);
535 DUK_UNREF(h_key);
537
539 c_nargs = (duk_int_t) duk_bd_decode_flagged(bd, DUK__NARGS_BITS, (duk_int32_t) c_length /*def_value*/);
540 if (c_nargs == DUK__NARGS_VARARGS_MARKER) {
541 c_nargs = DUK_VARARGS;
542 }
543
544 c_func = duk_bi_native_functions[natidx];
545
546 DUK_DDD(DUK_DDDPRINT("built-in %ld, function-valued property %ld, key %!O, natidx %ld, length %ld, nargs %ld",
547 (long) i, (long) j, (duk_heaphdr *) h_key, (long) natidx, (long) c_length,
548 (c_nargs == DUK_VARARGS ? (long) -1 : (long) c_nargs)));
549
550 /* Cast converts magic to 16-bit signed value */
551 magic = (duk_int16_t) duk_bd_decode_flagged(bd, DUK__MAGIC_BITS, 0);
552
553#if defined(DUK_USE_LIGHTFUNC_BUILTINS)
554 lightfunc_eligible =
555 ((c_nargs >= DUK_LFUNC_NARGS_MIN && c_nargs <= DUK_LFUNC_NARGS_MAX) || (c_nargs == DUK_VARARGS)) &&
556 (c_length <= DUK_LFUNC_LENGTH_MAX) &&
557 (magic >= DUK_LFUNC_MAGIC_MIN && magic <= DUK_LFUNC_MAGIC_MAX);
558
559 if (h_key == DUK_HTHREAD_STRING_EVAL(thr) ||
560 h_key == DUK_HTHREAD_STRING_YIELD(thr) ||
561 h_key == DUK_HTHREAD_STRING_RESUME(thr) ||
562 h_key == DUK_HTHREAD_STRING_REQUIRE(thr)) {
563 /* These functions have trouble working as lightfuncs.
564 * Some of them have specific asserts and some may have
565 * additional properties (e.g. 'require.id' may be written).
566 */
567 DUK_D(DUK_DPRINT("reject as lightfunc: key=%!O, i=%d, j=%d", (duk_heaphdr *) h_key, (int) i, (int) j));
568 lightfunc_eligible = 0;
569 }
570
571 if (lightfunc_eligible) {
572 duk_tval tv_lfunc;
573 duk_small_uint_t lf_nargs = (c_nargs == DUK_VARARGS ? DUK_LFUNC_NARGS_VARARGS : c_nargs);
574 duk_small_uint_t lf_flags = DUK_LFUNC_FLAGS_PACK(magic, c_length, lf_nargs);
575 DUK_TVAL_SET_LIGHTFUNC(&tv_lfunc, c_func, lf_flags);
576 duk_push_tval(ctx, &tv_lfunc);
577 DUK_D(DUK_DPRINT("built-in function eligible as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld -> %!iT", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic, duk_get_tval(ctx, -1)));
578 goto lightfunc_skip;
579 }
580
581 DUK_D(DUK_DPRINT("built-in function NOT ELIGIBLE as light function: i=%d, j=%d c_length=%ld, c_nargs=%ld, magic=%ld", (int) i, (int) j, (long) c_length, (long) c_nargs, (long) magic));
582#endif /* DUK_USE_LIGHTFUNC_BUILTINS */
583
584 /* [ (builtin objects) name ] */
585
586 duk_push_c_function_noconstruct_noexotic(ctx, c_func, c_nargs);
587 h_func = duk_require_hnativefunction(ctx, -1);
588 DUK_UNREF(h_func);
589
590 /* Currently all built-in native functions are strict.
591 * This doesn't matter for many functions, but e.g.
592 * String.prototype.charAt (and other string functions)
593 * rely on being strict so that their 'this' binding is
594 * not automatically coerced.
595 */
597
598 /* No built-in functions are constructable except the top
599 * level ones (Number, etc).
600 */
602
603 /* XXX: any way to avoid decoding magic bit; there are quite
604 * many function properties and relatively few with magic values.
605 */
606 h_func->magic = magic;
607
608 /* [ (builtin objects) name func ] */
609
610 duk_push_int(ctx, c_length);
612
613 duk_dup(ctx, -2);
615
616 /* XXX: other properties of function instances; 'arguments', 'caller'. */
617
618 DUK_DD(DUK_DDPRINT("built-in object %ld, function property %ld -> %!T",
619 (long) i, (long) j, (duk_tval *) duk_get_tval(ctx, -1)));
620
621 /* [ (builtin objects) name func ] */
622
623 /*
624 * The default property attributes are correct for all
625 * function valued properties of built-in objects now.
626 */
627
628#if defined(DUK_USE_LIGHTFUNC_BUILTINS)
629 lightfunc_skip:
630#endif
631
633
634 /* [ (builtin objects) ] */
635 }
636 }
637
638 /*
639 * Special post-tweaks, for cases not covered by the init data format.
640 *
641 * - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
642 * toGMTString is required to have the same Function object as
643 * toUTCString in E5 Section B.2.6. Note that while Smjs respects
644 * this, V8 does not (the Function objects are distinct).
645 *
646 * - Make DoubleError non-extensible.
647 *
648 * - Add info about most important effective compile options to Duktape.
649 *
650 * - Possibly remove some properties (values or methods) which are not
651 * desirable with current feature options but are not currently
652 * conditional in init data.
653 */
654
657
659 DUK_ASSERT(h != NULL);
661
662#if !defined(DUK_USE_ES6_OBJECT_PROTO_PROPERTY)
663 DUK_DD(DUK_DDPRINT("delete Object.prototype.__proto__ built-in which is not enabled in features"));
665#endif
666
667#if !defined(DUK_USE_ES6_OBJECT_SETPROTOTYPEOF)
668 DUK_DD(DUK_DDPRINT("delete Object.setPrototypeOf built-in which is not enabled in features"));
670#endif
671
672 /* XXX: relocate */
673 duk_push_string(ctx,
674 /* Endianness indicator */
675#if defined(DUK_USE_INTEGER_LE)
676 "l"
677#elif defined(DUK_USE_INTEGER_BE)
678 "b"
679#elif defined(DUK_USE_INTEGER_ME) /* integer mixed endian not really used now */
680 "m"
681#else
682 "?"
683#endif
684#if defined(DUK_USE_DOUBLE_LE)
685 "l"
686#elif defined(DUK_USE_DOUBLE_BE)
687 "b"
688#elif defined(DUK_USE_DOUBLE_ME)
689 "m"
690#else
691 "?"
692#endif
693 " "
694 /* Packed or unpacked tval */
695#if defined(DUK_USE_PACKED_TVAL)
696 "p"
697#else
698 "u"
699#endif
700#if defined(DUK_USE_FASTINT)
701 "f"
702#endif
703 " "
704 /* Low memory options */
705#if defined(DUK_USE_STRTAB_CHAIN)
706 "c" /* chain */
707#elif defined(DUK_USE_STRTAB_PROBE)
708 "p" /* probe */
709#else
710 "?"
711#endif
712#if !defined(DUK_USE_HEAPPTR16) && !defined(DUK_DATAPTR16) && !defined(DUK_FUNCPTR16)
713 "n"
714#endif
715#if defined(DUK_USE_HEAPPTR16)
716 "h"
717#endif
718#if defined(DUK_USE_DATAPTR16)
719 "d"
720#endif
721#if defined(DUK_USE_FUNCPTR16)
722 "f"
723#endif
724#if defined(DUK_USE_REFCOUNT16)
725 "R"
726#endif
727#if defined(DUK_USE_STRHASH16)
728 "H"
729#endif
730#if defined(DUK_USE_STRLEN16)
731 "S"
732#endif
733#if defined(DUK_USE_BUFLEN16)
734 "B"
735#endif
736#if defined(DUK_USE_OBJSIZES16)
737 "O"
738#endif
739#if defined(DUK_USE_LIGHTFUNC_BUILTINS)
740 "L"
741#endif
742#if defined(DUK_USE_ROM_STRINGS) || defined(DUK_USE_ROM_OBJECTS)
743 /* XXX: This won't be shown in practice now
744 * because this code is not run when builtins
745 * are in ROM.
746 */
747 "Z"
748#endif
749 " "
750 /* Object property allocation layout */
751#if defined(DUK_USE_HOBJECT_LAYOUT_1)
752 "p1"
753#elif defined(DUK_USE_HOBJECT_LAYOUT_2)
754 "p2"
755#elif defined(DUK_USE_HOBJECT_LAYOUT_3)
756 "p3"
757#else
758 "p?"
759#endif
760 " "
761 /* Alignment guarantee */
762#if (DUK_USE_ALIGN_BY == 4)
763 "a4"
764#elif (DUK_USE_ALIGN_BY == 8)
765 "a8"
766#elif (DUK_USE_ALIGN_BY == 1)
767 "a1"
768#else
769#error invalid DUK_USE_ALIGN_BY
770#endif
771 " "
772 /* Architecture, OS, and compiler strings */
774 " "
776 " "
779
780 /*
781 * InitJS code - Ecmascript code evaluated from a built-in source
782 * which provides e.g. backward compatibility. User can also provide
783 * JS code to be evaluated at startup.
784 */
785
786#ifdef DUK_USE_BUILTIN_INITJS
787 /* XXX: compression */
788 DUK_DD(DUK_DDPRINT("running built-in initjs"));
789 duk_eval_string(ctx, (const char *) duk_initjs_data); /* initjs data is NUL terminated */
790 duk_pop(ctx);
791#endif /* DUK_USE_BUILTIN_INITJS */
792
793#ifdef DUK_USE_USER_INITJS
794 /* XXX: compression (as an option) */
795 DUK_DD(DUK_DDPRINT("running user initjs"));
796 duk_eval_string_noresult(ctx, (const char *) DUK_USE_USER_INITJS);
797#endif /* DUK_USE_USER_INITJS */
798
799 /*
800 * Since built-ins are not often extended, compact them.
801 */
802
803 DUK_DD(DUK_DDPRINT("compact built-ins"));
804 for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) {
806 }
807
808 DUK_D(DUK_DPRINT("INITBUILTINS END"));
809
810#ifdef DUK_USE_DDPRINT
811 for (i = 0; i < DUK_NUM_ALL_BUILTINS; i++) {
812 DUK_DD(DUK_DDPRINT("built-in object %ld after initialization and compacting: %!@iO",
813 (long) i, (duk_heaphdr *) duk_require_hobject(ctx, i)));
814 }
815#endif
816
817 /*
818 * Pop built-ins from stack: they are now INCREF'd and
819 * reachable from the builtins[] array or indirectly
820 * through builtins[].
821 */
822
823 duk_set_top(ctx, 0);
824 DUK_ASSERT_TOP(ctx, 0);
825}
duk_int_fast32_t duk_int_t
#define DUK_MEMZERO(p, n)
DUK_INTERNAL_DECL void duk_push_c_function_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs)
DUK_EXTERNAL const char * duk_push_string(duk_context *ctx, const char *str)
DUK_INTERNAL_DECL duk_hobject * duk_require_hobject(duk_context *ctx, duk_idx_t index)
#define DUK_HOBJECT_HAS_BOUND(h)
DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx)
DUK_EXTERNAL void duk_push_true(duk_context *ctx)
DUK_INTERNAL const duk_uint8_t duk_initjs_data[204]
#define DUK_STRIDX_TO_UTC_STRING
#define DUK_LFUNC_NARGS_MAX
#define DUK_DELPROP_FLAG_THROW
#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h)
#define DUK_BIDX_OBJECT_PROTOTYPE
DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags)
#define DUK_BIDX_DOUBLE_ERROR
DUK_INTERNAL_DECL void duk_push_c_function_noconstruct_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs)
#define DUK_LFUNC_LENGTH_MAX
#define DUK_STRIDX_TO_GMT_STRING
#define DUK_HOBJECT_HAS_CREATEARGS(h)
#define DUK_BIDX_FUNCTION_PROTOTYPE
#define DUK_PROPDESC_FLAGS_NONE
#define DUK_HTHREAD_STRING___PROTO__(thr)
#define DUK_HOBJECT_CLASS_FUNCTION
DUK_EXTERNAL void duk_require_stack(duk_context *ctx, duk_idx_t extra)
DUK_INTERNAL_DECL void duk_hobject_define_accessor_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_hobject *getter, duk_hobject *setter, duk_small_uint_t propflags)
#define DUK_HOBJECT_CLASS_ARRAY
#define DUK_STRIDX_CONSTRUCTOR
#define DUK_PROPDESC_FLAG_ACCESSOR
#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h)
#define DUK_HTHREAD_STRING_YIELD(thr)
#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p)
DUK_INTERNAL_DECL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj)
#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h)
DUK_EXTERNAL void duk_push_int(duk_context *ctx, duk_int_t val)
DUK_EXTERNAL void duk_pop_3(duk_context *ctx)
#define DUK_LFUNC_MAGIC_MIN
DUK_INTERNAL const duk_c_function duk_bi_native_functions[149]
#define DUK_HOBJECT_SET_STRICT(h)
#define DUK_LFUNC_NARGS_VARARGS
DUK_INTERNAL_DECL duk_int32_t duk_bd_decode_flagged(duk_bitdecoder_ctx *ctx, duk_small_int_t bits, duk_int32_t def_value)
#define DUK_HTHREAD_STRING_RESUME(thr)
#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h)
DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags)
#define DUK_HOBJECT_HAS_ARRAY_PART(h)
#define DUK_LFUNC_FLAGS_PACK(magic, length, nargs)
DUK_EXTERNAL void duk_set_top(duk_context *ctx, duk_idx_t index)
DUK_EXTERNAL void duk_dup(duk_context *ctx, duk_idx_t from_index)
#define DUK_HTHREAD_STRING_EVAL(thr)
DUK_INTERNAL_DECL void duk_push_tval(duk_context *ctx, duk_tval *tv)
#define DUK_HOBJECT_HAS_NATIVEFUNCTION(h)
#define DUK_HOBJECT_HAS_THREAD(h)
DUK_EXTERNAL void duk_push_undefined(duk_context *ctx)
#define DUK_HTHREAD_STRING_REQUIRE(thr)
#define DUK_PROPDESC_FLAGS_WC
#define DUK_PROPDESC_FLAG_WRITABLE
#define DUK_ASSERT_TOP(ctx, n)
DUK_EXTERNAL void duk_push_false(duk_context *ctx)
#define DUK_HOBJECT_FLAG_EXTENSIBLE
DUK_INTERNAL_DECL duk_idx_t duk_push_object_helper(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx)
#define DUK_BIDX_OBJECT_CONSTRUCTOR
#define DUK_HOBJECT_HAS_NEWENV(h)
#define DUK_LFUNC_NARGS_MIN
#define DUK_HOBJECT_INCREF(thr, h)
DUK_EXTERNAL void duk_pop(duk_context *ctx)
#define DUK_TVAL_SET_LIGHTFUNC(tv, fp, flags)
#define DUK_HOBJECT_HAS_ENVRECCLOSED(h)
#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h)
#define DUK_LFUNC_MAGIC_MAX
DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_context *ctx, duk_idx_t obj_index, duk_small_int_t stridx, duk_small_uint_t desc_flags)
#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h)
DUK_INTERNAL_DECL duk_hstring * duk_get_hstring(duk_context *ctx, duk_idx_t index)
DUK_INTERNAL_DECL duk_hnativefunction * duk_require_hnativefunction(duk_context *ctx, duk_idx_t index)
#define DUK_HOBJECT_HAS_EXTENSIBLE(h)
#define DUK_HOBJECT_CLASS_STRING
#define DUK_HOBJECT_HAS_STRICT(h)
#define DUK_HOBJECT_SET_CLASS_NUMBER(h, v)
#define DUK_BIDX_DATE_PROTOTYPE
#define DUK_HOBJECT_HAS_COMPILEDFUNCTION(h)
#define DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr)
DUK_INTERNAL_DECL duk_tval * duk_get_tval(duk_context *ctx, duk_idx_t index)
#define DUK_HOBJECT_HAS_NAMEBINDING(h)
DUK_INTERNAL_DECL void duk_xdef_prop(duk_context *ctx, duk_idx_t obj_index, duk_small_uint_t desc_flags)
#define duk_eval_string(ctx, src)
duk_ret_t(* duk_c_function)(duk_context *ctx)
#define duk_eval_string_noresult(ctx, src)
DUK_LOCAL void duk__push_stridx_or_string(duk_context *ctx, duk_bitdecoder_ctx *bd)
DUK_LOCAL void duk__push_double(duk_context *ctx, duk_bitdecoder_ctx *bd)
#define NULL
Definition gmacros.h:924
static void error(LoadState *S, const char *why)

References duk_hthread::builtins, duk_bitdecoder_ctx::data, DUK__BIDX_BITS, DUK__CLASS_BITS, DUK__LENGTH_PROP_BITS, DUK__MAGIC_BITS, DUK__NARGS_BITS, DUK__NARGS_VARARGS_MARKER, DUK__NATIDX_BITS, DUK__NO_BIDX_MARKER, DUK__NUM_FUNC_PROPS_BITS, DUK__NUM_NORMAL_PROPS_BITS, DUK__PROP_FLAGS_BITS, DUK__PROP_TYPE_ACCESSOR, DUK__PROP_TYPE_BITS, DUK__PROP_TYPE_BOOLEAN_FALSE, DUK__PROP_TYPE_BOOLEAN_TRUE, DUK__PROP_TYPE_BUILTIN, DUK__PROP_TYPE_DOUBLE, DUK__PROP_TYPE_STRIDX, DUK__PROP_TYPE_STRING, DUK__PROP_TYPE_UNDEFINED, duk__push_double(), duk__push_stridx(), duk__push_stridx_or_string(), duk__push_string(), DUK_ASSERT, DUK_ASSERT_TOP, duk_bd_decode(), duk_bd_decode_flag(), duk_bd_decode_flagged(), duk_bi_native_functions, DUK_BIDX_DATE_PROTOTYPE, DUK_BIDX_DOUBLE_ERROR, DUK_BIDX_DUKTAPE, DUK_BIDX_FUNCTION_PROTOTYPE, DUK_BIDX_OBJECT_CONSTRUCTOR, DUK_BIDX_OBJECT_PROTOTYPE, DUK_D, DUK_DD, DUK_DDD, DUK_DDDPRINT, DUK_DDPRINT, DUK_DELPROP_FLAG_THROW, DUK_DPRINT, duk_dup(), duk_eval_string, duk_eval_string_noresult, duk_get_hstring(), duk_get_prop_stridx(), duk_get_tval(), DUK_HOBJECT_CLASS_ARRAY, DUK_HOBJECT_CLASS_FUNCTION, DUK_HOBJECT_CLASS_STRING, DUK_HOBJECT_CLEAR_CONSTRUCTABLE, DUK_HOBJECT_CLEAR_EXTENSIBLE, duk_hobject_compact_props(), duk_hobject_define_accessor_internal(), duk_hobject_delprop_raw(), DUK_HOBJECT_FLAG_EXTENSIBLE, DUK_HOBJECT_HAS_ARRAY_PART, DUK_HOBJECT_HAS_BOUND, DUK_HOBJECT_HAS_COMPILEDFUNCTION, DUK_HOBJECT_HAS_CONSTRUCTABLE, DUK_HOBJECT_HAS_CREATEARGS, DUK_HOBJECT_HAS_ENVRECCLOSED, DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS, DUK_HOBJECT_HAS_EXTENSIBLE, DUK_HOBJECT_HAS_NAMEBINDING, DUK_HOBJECT_HAS_NATIVEFUNCTION, DUK_HOBJECT_HAS_NEWENV, DUK_HOBJECT_HAS_STRICT, DUK_HOBJECT_HAS_THREAD, DUK_HOBJECT_INCREF, DUK_HOBJECT_SET_CLASS_NUMBER, DUK_HOBJECT_SET_EXOTIC_ARRAY, DUK_HOBJECT_SET_EXOTIC_STRINGOBJ, DUK_HOBJECT_SET_PROTOTYPE_UPDREF, DUK_HOBJECT_SET_STRICT, DUK_HTHREAD_STRING___PROTO__, DUK_HTHREAD_STRING_EVAL, DUK_HTHREAD_STRING_REQUIRE, DUK_HTHREAD_STRING_RESUME, DUK_HTHREAD_STRING_SET_PROTOTYPE_OF, DUK_HTHREAD_STRING_YIELD, duk_initjs_data, DUK_LFUNC_FLAGS_PACK, DUK_LFUNC_LENGTH_MAX, DUK_LFUNC_MAGIC_MAX, DUK_LFUNC_MAGIC_MIN, DUK_LFUNC_NARGS_MAX, DUK_LFUNC_NARGS_MIN, DUK_LFUNC_NARGS_VARARGS, DUK_MEMZERO, DUK_NUM_ALL_BUILTINS, DUK_NUM_BUILTINS, duk_pop(), duk_pop_3(), DUK_PROPDESC_FLAG_ACCESSOR, DUK_PROPDESC_FLAG_WRITABLE, DUK_PROPDESC_FLAGS_NONE, DUK_PROPDESC_FLAGS_W, DUK_PROPDESC_FLAGS_WC, duk_push_c_function_noconstruct_noexotic(), duk_push_c_function_noexotic(), duk_push_false(), duk_push_int(), duk_push_object_helper(), duk_push_string(), duk_push_true(), duk_push_tval(), duk_push_undefined(), duk_require_hnativefunction(), duk_require_hobject(), duk_require_stack(), duk_set_top(), DUK_STRIDX_CONSTRUCTOR, DUK_STRIDX_ENV, DUK_STRIDX_LENGTH, DUK_STRIDX_NAME, DUK_STRIDX_PROTOTYPE, DUK_STRIDX_TO_GMT_STRING, DUK_STRIDX_TO_UTC_STRING, DUK_TVAL_SET_LIGHTFUNC, DUK_UNREACHABLE, DUK_UNREF, DUK_USE_ALIGN_BY, DUK_USE_ARCH_STRING, DUK_USE_COMPILER_STRING, DUK_USE_HOBJECT_LAYOUT_2, DUK_USE_OS_STRING, DUK_USE_STRTAB_PROBE, DUK_VARARGS, duk_xdef_prop(), duk_xdef_prop_stridx(), duk_xdef_prop_stridx_builtin(), error(), duk_hobject::hdr, duk_bitdecoder_ctx::length, duk_hnativefunction::magic, and NULL.