MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fx_Object_create

Function fx_Object_create

xs/sources/xsObject.c:520–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518}
519
520void fx_Object_create(txMachine* the)
521{
522 txSlot* instance;
523 txSlot* properties;
524 txSlot* at;
525 txSlot* property;
526 txFlag mask;
527 if ((mxArgc < 1) || ((mxArgv(0)->kind != XS_NULL_KIND) && (mxArgv(0)->kind != XS_REFERENCE_KIND)))
528 mxTypeError("invalid prototype");
529 if (mxArgv(0)->kind == XS_NULL_KIND)
530 fxNewInstance(the);
531 else {
532 mxPushSlot(mxArgv(0));
533 fxNewHostInstance(the);
534 }
535 mxPullSlot(mxResult);
536 instance = fxGetInstance(the, mxResult);
537 if ((mxArgc > 1) && (mxArgv(1)->kind != XS_UNDEFINED_KIND)) {
538 properties = fxToInstance(the, mxArgv(1));
539 at = fxNewInstance(the);
540 mxBehaviorOwnKeys(the, properties, XS_EACH_NAME_FLAG | XS_EACH_SYMBOL_FLAG, at);
541 mxPushUndefined();
542 property = the->stack;
543 while ((at = at->next)) {
544 if (mxBehaviorGetOwnProperty(the, properties, at->value.at.id, at->value.at.index, property) && !(property->flag & XS_DONT_ENUM_FLAG)) {
545 mxPushReference(properties);
546 mxGetAll(at->value.at.id, at->value.at.index);
547 mask = fxDescriptorToSlot(the, the->stack);
548 if (!mxBehaviorDefineOwnProperty(the, instance, at->value.at.id, at->value.at.index, the->stack, mask))
549 mxTypeError("invalid descriptor");
550 mxPop();
551 }
552 }
553 mxPop();
554 mxPop();
555 }
556}
557
558void fx_Object_defineProperties(txMachine* the)
559{

Callers

nothing calls this directly

Calls 5

fxNewInstanceFunction · 0.85
fxNewHostInstanceFunction · 0.85
fxGetInstanceFunction · 0.85
fxToInstanceFunction · 0.85
fxDescriptorToSlotFunction · 0.85

Tested by

no test coverage detected