From 59552a5cb40ac682d1c9d13bbfc50b9493b14488 Mon Sep 17 00:00:00 2001 From: Mathieu Hofman Date: Sun, 8 Jan 2023 22:50:20 +0000 Subject: [PATCH] Revert "XS: compartment proposal update" Reverts VirtualModuleRecord -> ModuleSource rename This reverts commit 222e094b3aeb3afa202d5429a09b77283214cb03 --- xs/sources/xsAll.h | 19 ++++++----- xs/sources/xsCommon.c | 2 +- xs/sources/xsCommon.h | 2 +- xs/sources/xsModule.c | 70 ++++++++++++++++++++--------------------- xs/sources/xsSnapshot.c | 12 +++---- xs/tools/xslStrip.c | 10 +++--- 6 files changed, 57 insertions(+), 58 deletions(-) diff --git a/xs/sources/xsAll.h b/xs/sources/xsAll.h index 735e7d947d..320dfe24d2 100644 --- a/xs/sources/xsAll.h +++ b/xs/sources/xsAll.h @@ -1792,13 +1792,12 @@ mxExport void fx_Compartment_prototype_evaluate(txMachine* the); mxExport void fx_Compartment_prototype_import(txMachine* the); mxExport void fx_Compartment_prototype_importNow(txMachine* the); -mxExport void fx_ModuleSource(txMachine* the); -mxExport void fx_ModuleSource_prototype_get_bindings(txMachine* the); -mxExport void fx_ModuleSource_prototype_get_needsImport(txMachine* the); -mxExport void fx_ModuleSource_prototype_get_needsImportMeta(txMachine* the); - -mxExport void fxExecuteVirtualModuleSource(txMachine* the); -mxExport void fxExecuteVirtualModuleSourceImport(txMachine* the); +mxExport void fx_StaticModuleRecord(txMachine* the); +mxExport void fx_StaticModuleRecord_import(txMachine* the); +mxExport void fx_StaticModuleRecord_initialize(txMachine* the); +mxExport void fx_StaticModuleRecord_prototype_get_bindings(txMachine* the); +mxExport void fx_StaticModuleRecord_prototype_get_needsImport(txMachine* the); +mxExport void fx_StaticModuleRecord_prototype_get_needsImportMeta(txMachine* the); /* xsLockdown.c */ #ifdef mxLockdown @@ -2458,7 +2457,7 @@ enum { mxSharedArrayBufferPrototypeStackIndex, mxBigIntPrototypeStackIndex, mxCompartmentPrototypeStackIndex, - mxModuleSourcePrototypeStackIndex, + mxStaticModuleRecordPrototypeStackIndex, mxWeakRefPrototypeStackIndex, mxFinalizationRegistryPrototypeStackIndex, @@ -2569,7 +2568,7 @@ enum { #define mxRegExpConstructor the->stackPrototypes[-1 - _RegExp] #define mxSetConstructor the->stackPrototypes[-1 - _Set] #define mxSharedArrayBufferConstructor the->stackPrototypes[-1 - _SharedArrayBuffer] -#define mxModuleSourceConstructor the->stackPrototypes[-1 - _ModuleSource] +#define mxStaticModuleRecordConstructor the->stackPrototypes[-1 - _StaticModuleRecord] #define mxStringConstructor the->stackPrototypes[-1 - _String] #define mxSymbolConstructor the->stackPrototypes[-1 - _Symbol] #define mxSyntaxErrorConstructor the->stackPrototypes[-1 - _SyntaxError] @@ -2630,7 +2629,7 @@ enum { #define mxSharedArrayBufferPrototype the->stackPrototypes[-1 - mxSharedArrayBufferPrototypeStackIndex] #define mxBigIntPrototype the->stackPrototypes[-1 - mxBigIntPrototypeStackIndex] #define mxCompartmentPrototype the->stackPrototypes[-1 - mxCompartmentPrototypeStackIndex] -#define mxModuleSourcePrototype the->stackPrototypes[-1 - mxModuleSourcePrototypeStackIndex] +#define mxStaticModuleRecordPrototype the->stackPrototypes[-1 - mxStaticModuleRecordPrototypeStackIndex] #define mxWeakRefPrototype the->stackPrototypes[-1 - mxWeakRefPrototypeStackIndex] #define mxFinalizationRegistryPrototype the->stackPrototypes[-1 - mxFinalizationRegistryPrototypeStackIndex] diff --git a/xs/sources/xsCommon.c b/xs/sources/xsCommon.c index 749e535f81..bd6161cc92 100644 --- a/xs/sources/xsCommon.c +++ b/xs/sources/xsCommon.c @@ -1260,7 +1260,6 @@ const txString gxIDStrings[XS_ID_COUNT] = { "JSON", "Map", "Math", - "ModuleSource", "Number", "Object", "Promise", @@ -1271,6 +1270,7 @@ const txString gxIDStrings[XS_ID_COUNT] = { "RegExp", "Set", "SharedArrayBuffer", + "StaticModuleRecord", "String", "Symbol", "SyntaxError", diff --git a/xs/sources/xsCommon.h b/xs/sources/xsCommon.h index 629faa8b7a..f16f47456d 100644 --- a/xs/sources/xsCommon.h +++ b/xs/sources/xsCommon.h @@ -683,7 +683,6 @@ enum { _JSON, _Map, _Math, - _ModuleSource, _Number, _Object, _Promise, @@ -694,6 +693,7 @@ enum { _RegExp, _Set, _SharedArrayBuffer, + _StaticModuleRecord, _String, _Symbol, _SyntaxError, diff --git a/xs/sources/xsModule.c b/xs/sources/xsModule.c index 84747c33f7..0501c03548 100644 --- a/xs/sources/xsModule.c +++ b/xs/sources/xsModule.c @@ -92,8 +92,8 @@ static txBoolean fxModuleSetPrototype(txMachine* the, txSlot* instance, txSlot* static txSlot* fxCheckCompartmentInstance(txMachine* the, txSlot* slot); static void fxPrepareCompartmentFunction(txMachine* the, txSlot* program, txSlot* instance); -static txSlot* fxCheckModuleSourceInstance(txMachine* the, txSlot* slot); -static txSlot* fxNewModuleSourceInstance(txMachine* the); +static txSlot* fxCheckStaticModuleRecordInstance(txMachine* the, txSlot* slot); +static txSlot* fxNewStaticModuleRecordInstance(txMachine* the); const txBehavior ICACHE_FLASH_ATTR gxModuleBehavior = { fxModuleGetProperty, @@ -127,7 +127,7 @@ enum { #define mxIsModule(THE_SLOT) \ (((THE_SLOT)->next) && ((THE_SLOT)->next->flag & XS_INTERNAL_FLAG) && ((THE_SLOT)->next->kind == XS_MODULE_KIND)) -#define mxIsModuleSource(THE_SLOT) \ +#define mxIsStaticModuleRecord(THE_SLOT) \ (((THE_SLOT)->next) && ((THE_SLOT)->next->flag & XS_INTERNAL_FLAG) && ((THE_SLOT)->next->kind == XS_MODULE_SOURCE_KIND)) #define mxModuleInstanceStatus(MODULE) ((MODULE)->next->next->ID) @@ -198,13 +198,13 @@ void fxBuildModule(txMachine* the) mxPush(mxObjectPrototype); slot = fxLastProperty(the, fxNewObjectInstance(the)); - slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_ModuleSource_prototype_get_bindings), C_NULL, mxID(_bindings), XS_DONT_ENUM_FLAG); - // slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_ModuleSource_prototype_get_needsImport), C_NULL, mxID(_needsImport), XS_DONT_ENUM_FLAG); - // slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_ModuleSource_prototype_get_needsImportMeta), C_NULL, mxID(_needsImportMeta), XS_DONT_ENUM_FLAG); - slot = fxNextStringXProperty(the, slot, "ModuleSource", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); - mxModuleSourcePrototype = *the->stack; - slot = fxBuildHostConstructor(the, mxCallback(fx_ModuleSource), 1, mxID(_ModuleSource)); - mxModuleSourceConstructor = *the->stack; + slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_StaticModuleRecord_prototype_get_bindings), C_NULL, mxID(_bindings), XS_DONT_ENUM_FLAG); + // slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_StaticModuleRecord_prototype_get_needsImport), C_NULL, mxID(_needsImport), XS_DONT_ENUM_FLAG); + // slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_StaticModuleRecord_prototype_get_needsImportMeta), C_NULL, mxID(_needsImportMeta), XS_DONT_ENUM_FLAG); + slot = fxNextStringXProperty(the, slot, "StaticModuleRecord", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG); + mxStaticModuleRecordPrototype = *the->stack; + slot = fxBuildHostConstructor(the, mxCallback(fx_StaticModuleRecord), 1, mxID(_StaticModuleRecord)); + mxStaticModuleRecordConstructor = *the->stack; mxPop(); } @@ -411,7 +411,7 @@ void fxExecuteModulesRejected(txMachine* the) fxExecuteModules(the, queue); } -void fxExecuteVirtualModuleSource(txMachine* the) +void fx_StaticModuleRecord_initialize(txMachine* the) { txSlot* instance = mxFunction->value.reference; txSlot* function = fxLastProperty(the, instance); @@ -419,7 +419,7 @@ void fxExecuteVirtualModuleSource(txMachine* the) txSlot* module = home->value.home.module; txSlot* internal = mxModuleInstanceInternal(module); txSlot* meta = mxModuleInstanceMeta(module); - txSlot* closures = mxFunctionInstanceCode(instance)->value.callback.closures; + txSlot* closures = mxFunctionInstanceCode(instance)->value.code.closures; txSlot* property; if (mxIsUndefined(function)) return; @@ -438,7 +438,7 @@ void fxExecuteVirtualModuleSource(txMachine* the) /* ARGUMENTS */ mxPushReference(closures); if (internal->flag & XS_IMPORT_FLAG) { - function = fxNewHostFunction(the, fxExecuteVirtualModuleSourceImport, 1, XS_NO_ID); + function = fxNewHostFunction(the, fx_StaticModuleRecord_import, 1, XS_NO_ID); mxFunctionInstanceHome(function)->value.home.module = module; } else @@ -1110,7 +1110,7 @@ void fxLoadVirtualModuleNamespace(txMachine* the, txSlot* object, txSlot* module mxPullSlot(mxModuleInstanceExports(module)); } -void fxLoadVirtualModuleSource_disabled(txMachine* the, txSlot* record, txSlot* instance) +void fxLoadVirtualStaticModuleRecord_disabled(txMachine* the, txSlot* record, txSlot* instance) { txSlot* slot; txSlot* function; @@ -1119,13 +1119,13 @@ void fxLoadVirtualModuleSource_disabled(txMachine* the, txSlot* record, txSlot* txSlot* transfer; mxPushSlot(record); - mxGetID(fxID(the, "execute")); + mxGetID(fxID(the, "initialize")); slot = the->stack; if (!mxIsUndefined(slot)) { if (!fxIsCallable(the, slot)) - mxTypeError("execute is no function"); + mxTypeError("initialize is no function"); } - function = fxNewHostFunction(the, fxExecuteVirtualModuleSource, 0, XS_NO_ID); + function = fxNewHostFunction(the, fx_StaticModuleRecord_initialize, 0, XS_NO_ID); property = mxFunctionInstanceHome(function); property->value.home.object = fxToInstance(the, record); property->value.home.module = instance; @@ -1649,7 +1649,7 @@ void fxMapModuleDescriptor(txMachine* the, txSlot* realm, txID moduleID, txSlot* mxPop(); // property; mxPushSlot(descriptor); - mxGetID(fxID(the, "source")); + mxGetID(fxID(the, "record")); property = the->stack; if (!mxIsUndefined(property)) { if ((property->kind == XS_STRING_KIND) || (property->kind == XS_STRING_X_KIND)) { @@ -1663,9 +1663,9 @@ void fxMapModuleDescriptor(txMachine* the, txSlot* realm, txID moduleID, txSlot* goto done; } if (!mxIsReference(property)) - mxTypeError("descriptor.source is no object"); - if (!mxIsModuleSource(property->value.reference)) - mxTypeError("descriptor.source is no module source"); + mxTypeError("descriptor.record is no object"); + if (!mxIsStaticModuleRecord(property->value.reference)) + mxTypeError("descriptor.record is no static module record"); fxDuplicateModuleTransfers(the, property, module); goto importMeta; } @@ -2866,7 +2866,7 @@ void fx_Compartment_prototype_importNow(txMachine* the) mxPullSlot(mxResult); } -txSlot* fxCheckModuleSourceInstance(txMachine* the, txSlot* slot) +txSlot* fxCheckStaticModuleRecordInstance(txMachine* the, txSlot* slot) { if (slot->kind == XS_REFERENCE_KIND) { txSlot* instance = slot->value.reference; @@ -2874,11 +2874,11 @@ txSlot* fxCheckModuleSourceInstance(txMachine* the, txSlot* slot) return instance; } } - mxTypeError("this is no ModuleSource instance"); + mxTypeError("this is no StaticModuleRecord instance"); return C_NULL; } -txSlot* fxNewModuleSourceInstance(txMachine* the) +txSlot* fxNewStaticModuleRecordInstance(txMachine* the) { txSlot* instance; txSlot* slot; @@ -2914,7 +2914,7 @@ txSlot* fxNewModuleSourceInstance(txMachine* the) return instance; } -void fxExecuteVirtualModuleSourceImport(txMachine* the) +void fx_StaticModuleRecord_import(txMachine* the) { txSlot* instance = mxFunction->value.reference; txSlot* home = mxFunctionInstanceHome(instance); @@ -2925,17 +2925,17 @@ void fxExecuteVirtualModuleSourceImport(txMachine* the) mxPullSlot(mxResult); } -void fx_ModuleSource(txMachine* the) +void fx_StaticModuleRecord(txMachine* the) { txSlot* instance; txSlot* slot; txStringStream stream; txScript* script; if (mxIsUndefined(mxTarget)) - mxTypeError("call: ModuleSource"); + mxTypeError("call: StaticModuleRecord"); mxPushSlot(mxTarget); - fxGetPrototypeFromConstructor(the, &mxModuleSourcePrototype); - instance = fxNewModuleSourceInstance(the); + fxGetPrototypeFromConstructor(the, &mxStaticModuleRecordPrototype); + instance = fxNewStaticModuleRecordInstance(the); mxPullSlot(mxResult); if (mxArgc == 0) mxPushUndefined(); @@ -2955,9 +2955,9 @@ void fx_ModuleSource(txMachine* the) mxPop(); } -void fx_ModuleSource_prototype_get_bindings(txMachine* the) +void fx_StaticModuleRecord_prototype_get_bindings(txMachine* the) { - txSlot* record = fxCheckModuleSourceInstance(the, mxThis); + txSlot* record = fxCheckStaticModuleRecordInstance(the, mxThis); txSlot* resultInstance; txSlot* resultArray; txSlot* resultItem; @@ -3071,17 +3071,17 @@ void fx_ModuleSource_prototype_get_bindings(txMachine* the) fxCacheArray(the, resultInstance); } -void fx_ModuleSource_prototype_get_needsImport(txMachine* the) +void fx_StaticModuleRecord_prototype_get_needsImport(txMachine* the) { - txSlot* record = fxCheckModuleSourceInstance(the, mxThis); + txSlot* record = fxCheckStaticModuleRecordInstance(the, mxThis); txFlag flag = mxModuleInstanceInternal(record)->flag; mxResult->value.boolean = (flag & XS_IMPORT_FLAG) ? 1 : 0; mxResult->kind = XS_BOOLEAN_KIND; } -void fx_ModuleSource_prototype_get_needsImportMeta(txMachine* the) +void fx_StaticModuleRecord_prototype_get_needsImportMeta(txMachine* the) { - txSlot* record = fxCheckModuleSourceInstance(the, mxThis); + txSlot* record = fxCheckStaticModuleRecordInstance(the, mxThis); txFlag flag = mxModuleInstanceInternal(record)->flag; mxResult->value.boolean = (flag & XS_IMPORT_META_FLAG) ? 1 : 0; mxResult->kind = XS_BOOLEAN_KIND; diff --git a/xs/sources/xsSnapshot.c b/xs/sources/xsSnapshot.c index fe264585c9..1dfa2236de 100644 --- a/xs/sources/xsSnapshot.c +++ b/xs/sources/xsSnapshot.c @@ -317,10 +317,6 @@ static txCallback gxCallbacks[mxCallbacksLength] = { fx_Math_tan, fx_Math_tanh, fx_Math_trunc, - fx_ModuleSource, - fx_ModuleSource_prototype_get_bindings, - // fx_ModuleSource_prototype_get_needsImport, - // fx_ModuleSource_prototype_get_needsImportMeta, fx_Number_isFinite, fx_Number_isInteger, fx_Number_isNaN, @@ -435,6 +431,12 @@ static txCallback gxCallbacks[mxCallbacksLength] = { fx_SharedArrayBuffer_prototype_slice, fx_SharedArrayBuffer, fx_species_get, + fx_StaticModuleRecord, + fx_StaticModuleRecord_import, + fx_StaticModuleRecord_initialize, + fx_StaticModuleRecord_prototype_get_bindings, + // fx_StaticModuleRecord_prototype_get_needsImport, + // fx_StaticModuleRecord_prototype_get_needsImportMeta, fx_String_fromCharCode, fx_String_fromCodePoint, fx_String_prototype_at, @@ -542,8 +544,6 @@ static txCallback gxCallbacks[mxCallbacksLength] = { fxArrayLengthSetter, fxExecuteModulesFulfilled, fxExecuteModulesRejected, - fxExecuteVirtualModuleSource, - fxExecuteVirtualModuleSourceImport, fxInitializeRegExp, fxLoadModulesFulfilled, fxLoadModulesRejected, diff --git a/xs/tools/xslStrip.c b/xs/tools/xslStrip.c index 075624e8ef..831573c4a6 100644 --- a/xs/tools/xslStrip.c +++ b/xs/tools/xslStrip.c @@ -182,10 +182,6 @@ void fxStripCallbacks(txLinker* linker, txMachine* the) fxStripCallback(linker, fx_Map); else if (!c_strcmp(name, "Math")) fxUnuseSymbol(linker, mxID(_Math)); - else if (!c_strcmp(name, "ModuleSource")) { - fxStripCallback(linker, fx_ModuleSource); - fxStripCallback(linker, fx_ModuleSource_prototype_get_bindings); - } else if (!c_strcmp(name, "Promise")) { fxStripCallback(linker, fx_AsyncFromSyncIterator_prototype_next); fxStripCallback(linker, fx_AsyncFromSyncIterator_prototype_return); @@ -220,6 +216,10 @@ void fxStripCallbacks(txLinker* linker, txMachine* the) fxStripCallback(linker, fx_Set); else if (!c_strcmp(name, "SharedArrayBuffer")) fxStripCallback(linker, fx_SharedArrayBuffer); + else if (!c_strcmp(name, "StaticModuleRecord")) { + fxStripCallback(linker, fx_StaticModuleRecord); + fxStripCallback(linker, fx_StaticModuleRecord_prototype_get_bindings); + } else if (!c_strcmp(name, "Uint8Array")) { fxUnuseSymbol(linker, mxID(_Uint8Array)); fxStripCallback(linker, fx_Uint8Array); @@ -245,7 +245,7 @@ void fxStripCallbacks(txLinker* linker, txMachine* the) else if (!c_strcmp(name, "eval")) { fxStripCallback(linker, fx_Compartment_prototype_evaluate); fxStripCallback(linker, fx_Function); - fxStripCallback(linker, fx_ModuleSource); + fxStripCallback(linker, fx_StaticModuleRecord); fxStripCallback(linker, fx_eval); fxUnuseCode(XS_CODE_ARGUMENTS_SLOPPY); fxUnuseCode(XS_CODE_EVAL);