File indexing completed on 2024-05-19 04:42:03

0001 #!/usr/bin/env python3
0002 # -*- coding: utf-8 -*-
0003 #
0004 # SPDX-FileCopyrightText: 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
0005 #
0006 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 
0008 from jsgenerator import *
0009 
0010 # Print the license of the generated file (the same as the one of this file)
0011 print("""/*
0012     SPDX-FileCopyrightText: 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
0013 
0014     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0015 */
0016 """)
0017 
0018 _mixed = '_mixed'       # This variable does not exist and will therefore yield the type "mixed"
0019 _string = '""'
0020 _bool = 'true'
0021 _int = '1'
0022 _float = '1.0'
0023 _array = '[]'
0024 _void = ''
0025 
0026 # Fundamental objects (section 19)
0027 _object = 'new Object()'
0028 _function = 'function(){}'
0029 _date = 'new Date()'
0030 _regexp = 'new RegExp()'
0031 _regexp_match = '{index: 1, input: "", length: 1}'
0032 _map = 'new Map()'
0033 _set = 'new Set()'
0034 _arraybuffer = 'new ArrayBuffer()'
0035 _dataview = 'new DataView()'
0036 _iterator = '{next: function() {}, done: true, value: _mixed}'
0037 _promise = 'new Promise()'
0038 
0039 Module().members(
0040 Class('Object').members(
0041     F(_object, 'assign', ('target', _object), ('sources', _mixed)),
0042     F(_object, 'create', ('O', _object), ('properties', _object)),
0043     F(_object, 'defineProperties', ('O', _object), ('properties', _object)),
0044     F(_object, 'defineProperty', ('O', _object), ('property', _string), ('attributes', _object)),
0045     F(_object, 'freeze', ('O', _object)),
0046     F(_object, 'getOwnPropertyDescriptor', ('O', _object), ('property', _string)),
0047     F(_array, 'getOwnPropertyNames', ('O', _object)),
0048     F(_array, 'getOwnPropertySymbols', ('O', _object)),
0049     F(_object, 'getPrototypeOf', ('O', _object)),
0050     F(_bool, 'is', ('a', _mixed), ('b', _mixed)),
0051     F(_bool, 'isExtensible', ('O', _object)),
0052     F(_bool, 'isFrozen', ('O', _object)),
0053     F(_bool, 'isSealed', ('O', _object)),
0054     F(_iterator, 'keys', ('O', _object)),
0055     F(_object, 'preventExtensions', ('O', _object)),
0056     F(_object, 'seal', ('O', _object)),
0057     F(_object, 'setPrototypeOf', ('O', _object), ('proto', _object)),
0058 
0059     Var(_function, 'constructor'),
0060     F(_object, 'hasOwnProperty', ('property', _string)),
0061     F(_bool, 'isPrototypeOf', ('object', _object)),
0062     F(_bool, 'propertyIsEnumerable', ('property', _string)),
0063     F(_string, 'toLocaleString'),
0064     F(_string, 'toString'),
0065 ),
0066 
0067 Class('Function').members(
0068     Var(_int, 'length'),
0069     F(_mixed, 'apply', ('thisArg', _object), ('arguments', _array)),
0070     F(_function, 'bind', ('thisArg', _object), ('arguments', _mixed)),
0071     F(_mixed, 'call', ('thisArg', _object), ('arguments', _mixed)),
0072     F(_function, 'toMethod', ('newHome', _object), ('methodName', _string)),
0073     Var(_string, 'name')
0074 ),
0075 
0076 Class('Boolean', ('value', _bool)).members(
0077     F(_bool, 'valueOf'),
0078 ),
0079 
0080 # 19.4 (Symbol) skipped for now because it is far too internal
0081 Class('Error', ('message', _string)).members(
0082     Var(_string, 'message'),
0083     Var(_string, 'name'),
0084 ),
0085 
0086 Class('EvalError').prototype('Error'),
0087 Class('RangeError').prototype('Error'),
0088 Class('ReferenceError').prototype('Error'),
0089 Class('SyntaxError').prototype('Error'),
0090 Class('TypeError').prototype('Error'),
0091 Class('URIError').prototype('Error'),
0092 
0093 # 19.5.6 (NativeError) skipped because it seems too internal
0094 
0095 # Numbers and dates (section 20)
0096 Class('Number', ('value', _float)).members(
0097     Var(_float, 'EPSILON'),
0098     F(_bool, 'isFinite', ('number', _float)),
0099     F(_bool, 'isInteger', ('number', _int)),
0100     F(_bool, 'isNaN', ('number', _float)),
0101     F(_bool, 'isSafeInteger', ('number', _int)),
0102     Var(_int, 'MAX_SAFE_INTEGER'),
0103     Var(_float, 'MAX_VALUE'),
0104     Var(_float, 'NaN'),
0105     Var(_float, 'NEGATIVE_INFINITY'),
0106     Var(_int, 'MIN_SAFE_INTEGER'),
0107     Var(_float, 'MIN_VALUE'),
0108     F(_float, 'parseFloat', ('string', _string)),
0109     F(_int, 'parseInt', ('string', _string), ('radix', _int)),
0110     Var(_float, 'POSITIVE_INFINITY'),
0111     F(_string, 'toExponential', ('fractionDigits', _int)),
0112     F(_string, 'toFixed', ('fractionDigits', _int)),
0113     F(_string, 'toPrecision', ('precision', _int)),
0114     F(_float, 'valueOf'),
0115 ),
0116 
0117 Struct('Math').members(
0118     Var(_float, 'E'),
0119     Var(_float, 'LN10'),
0120     Var(_float, 'LOG10E'),
0121     Var(_float, 'LN2'),
0122     Var(_float, 'PI'),
0123     Var(_float, 'SQRT1_2'),
0124     Var(_float, 'SQRT2'),
0125     F(_float, 'abs', ('x', _float)),
0126     F(_float, 'acos', ('x', _float)),
0127     F(_float, 'acosh', ('x', _float)),
0128     F(_float, 'asin', ('x', _float)),
0129     F(_float, 'asinh', ('x', _float)),
0130     F(_float, 'atan', ('x', _float)),
0131     F(_float, 'atanh', ('x', _float)),
0132     F(_float, 'atan2', ('x', _float), ('y', _float)),
0133     F(_float, 'cbrt', ('x', _float)),
0134     F(_int, 'ceil', ('x', _float)),
0135     F(_int, 'clz32', ('x', _int)),
0136     F(_float, 'cos', ('x', _float)),
0137     F(_float, 'cosh', ('x', _float)),
0138     F(_float, 'exp', ('x', _float)),
0139     F(_float, 'expm1', ('x', _float)),
0140     F(_int, 'floor', ('x', _float)),
0141     F(_int, 'fround', ('x', _float)),
0142     F(_float, 'hypot', ('a', _float), ('b', _float)),
0143     F(_int, 'imul', ('x', _int), ('y', _int)),
0144     F(_float, 'log', ('x', _float)),
0145     F(_float, 'log1p', ('x', _float)),
0146     F(_float, 'log10', ('x', _float)),
0147     F(_float, 'log2', ('x', _float)),
0148     F(_float, 'max', ('a', _float), ('b', _float)),
0149     F(_float, 'min', ('a', _float), ('b', _float)),
0150     F(_float, 'pow', ('x', _float), ('y', _float)),
0151     F(_float, 'random'),
0152     F(_int, 'round', ('x', _float)),
0153     F(_int, 'sign', ('x', _float)),
0154     F(_float, 'sin', ('x', _float)),
0155     F(_float, 'sinh', ('x', _float)),
0156     F(_float, 'sqrt', ('x', _float)),
0157     F(_float, 'tan', ('x', _float)),
0158     F(_float, 'tanh', ('x', _float)),
0159     F(_int, 'trunc', ('x', _float)),
0160 ),
0161 
0162 Class('Date', ('year', _int), ('month', _int), ('date', _int), ('hours', _int), ('minutes', _int), ('seconds', _int), ('ms', _int)).members(
0163     F(_date, 'now'),
0164     F(_date, 'parse', ('string', _string)),
0165     F(_date, 'UTC', ('year', _int), ('month', _int), ('date', _int), ('hours', _int), ('minutes', _int), ('seconds', _int), ('ms', _int)),
0166     F(_int, 'getDate'),
0167     F(_int, 'getDay'),
0168     F(_int, 'getFullYear'),
0169     F(_int, 'getHours'),
0170     F(_int, 'getMilliseconds'),
0171     F(_int, 'getMinutes'),
0172     F(_int, 'getMonth'),
0173     F(_int, 'getSeconds'),
0174     F(_int, 'getTime'),
0175     F(_int, 'getTimezoneOffset'),
0176     F(_int, 'getUTCDate'),
0177     F(_int, 'getUTCDay'),
0178     F(_int, 'getUTCFullYear'),
0179     F(_int, 'getUTCHours'),
0180     F(_int, 'getUTCMilliseconds'),
0181     F(_int, 'getUTCMinutes'),
0182     F(_int, 'getUTCMonth'),
0183     F(_int, 'getUTCSeconds'),
0184     F(_int, 'setDate', ('date', _int)),
0185     F(_int, 'setFullYear', ('year', _int), ('month', _int), ('date', _int)),
0186     F(_int, 'setHours', ('hours', _int), ('minutes', _int), ('seconds', _int), ('ms', _int)),
0187     F(_int, 'setMilliseconds', ('ms', _int)),
0188     F(_int, 'setMinutes', ('min', _int), ('sec', _int), ('ms', _int)),
0189     F(_int, 'setMonth', ('month', _int), ('date', _int)),
0190     F(_int, 'setSeconds', ('sec', _int), ('ms', _int)),
0191     F(_int, 'setTime', ('time', _int)),
0192     F(_int, 'setUTCDate', ('date', _int)),
0193     F(_int, 'setUTCFullYear', ('year', _int), ('month', _int), ('date', _int)),
0194     F(_int, 'setUTCHours', ('hours', _int), ('minutes', _int), ('seconds', _int), ('ms', _int)),
0195     F(_int, 'setUTCMilliseconds', ('ms', _int)),
0196     F(_int, 'setUTCMinutes', ('min', _int), ('sec', _int), ('ms', _int)),
0197     F(_int, 'setUTCMonth', ('month', _int), ('date', _int)),
0198     F(_int, 'setUTCSeconds', ('sec', _int), ('ms', _int)),
0199     F(_string, 'toDateString'),
0200     F(_string, 'toISOString'),
0201     F(_string, 'toJSON', ('key', _string)),
0202     F(_string, 'toLocaleDateString'),
0203     F(_string, 'toLocaleTimeString'),
0204     F(_string, 'toTimeString'),
0205     F(_string, 'toUTCString'),
0206     F(_int, 'valueOf'),
0207 ),
0208 
0209 # Text Processing (section 21)
0210 Class('String', ('value', _mixed)).members(
0211     F(_string, 'fromCharCode', ('code', _int)),
0212     F(_string, 'fromCodePoint', ('code', _int)),
0213     F(_string, 'raw', ('callSize', _mixed)),
0214     F(_string, 'charAt', ('pos', _int)),
0215     F(_int, 'charCodeAt', ('pos', _int)),
0216     F(_int, 'codePointAt', ('pos', _int)),
0217     F(_string, 'concat', ('other', _string)),
0218     F(_bool, 'contains', ('searchString', _string), ('position', _int)),
0219     F(_bool, 'endsWith', ('searchString', _string), ('endPosition', _int)),
0220     F(_int, 'indexOf', ('searchString', _string), ('position', _int)),
0221     F(_int, 'lastIndexOf', ('searchString', _string), ('position', _int)),
0222     F(_int, 'localeCompare', ('other', _string)),
0223     F(_regexp_match, 'match', ('regexp', _regexp)),
0224     F(_string, 'normalize', ('form', _string)),
0225     F(_string, 'repeat', ('count', _int)),
0226     F(_string, 'replace', ('searchValue', _string), ('replaceValue', _string)),
0227     F(_int, 'search', ('regexp', _regexp)),
0228     F(_string, 'slice', ('start', _int), ('end', _int)),
0229     F(_array, 'split', ('separator', _string), ('limit', _int)),
0230     F(_bool, 'startsWith', ('searchString', _string), ('position', _int)),
0231     F(_string, 'substring', ('start', _int), ('end', _int)),
0232     F(_string, 'toLocaleLowerCase'),
0233     F(_string, 'toLocaleUpperCase'),
0234     F(_string, 'toLowerCase'),
0235     F(_string, 'toUpperCase'),
0236     F(_string, 'trim'),
0237     F(_string, 'valueOf'),
0238     Var(_int, 'length'),
0239 ),
0240 
0241 Class('RegExp', ('pattern', _string), ('flags', _string)).members(
0242     F(_void, 'compile'),
0243     F(_array, 'exec', ('string', _string)),
0244     Var(_bool, 'ingoreCase'),
0245     F(_regexp_match, 'match', ('string', _string)),
0246     Var(_bool, 'multiline'),
0247     F(_string, 'replace', ('string', _string), ('replaceValue', _string)),
0248     F(_int, 'search', ('string', _string)),
0249     Var(_string, 'source'),
0250     F(_array, 'split', ('string', _string), ('limit', _int)),
0251     Var(_bool, 'sticky'),
0252     F(_bool, 'test', ('string', _string)),
0253     Var(_bool, 'unicode'),
0254     Var(_int, 'lastIndex'),
0255     Var(_string, 'lastMatch'),
0256 ),
0257 
0258 # Array Objects (section 22)
0259 Class('Array', ('len', _int)).members(
0260     F(_array, 'from', ('arrayLike', _mixed), ('mapfn', _function), ('thisArg', _object)),
0261     F(_bool, 'isArray', ('arg', _mixed)),
0262     F(_array, 'of', ('items', _mixed)),
0263     F(_array, 'concat', ('other', _array)),
0264     F(_array, 'copyWithin', ('target', _int), ('start', _int), ('end', _int)),
0265     F(_iterator, 'entries'),
0266     F(_bool, 'every', ('callbackfn', _function), ('thisArg', _object)),
0267     F(_array, 'fill', ('value', _mixed), ('start', _int), ('end', _int)),
0268     F(_array, 'filter', ('callbackfn', _function), ('thisArg', _object)),
0269     F(_mixed, 'find', ('predicate', _function), ('thisArg', _object)),
0270     F(_int, 'findIndex', ('predicate', _function), ('thisArg', _object)),
0271     F(_void, 'forEach', ('callbackfn', _function), ('thisArg', _object)),
0272     F(_int, 'indexOf', ('searchElement', _mixed), ('fromIndex', _int)),
0273     F(_string, 'join', ('separator', _string)),
0274     F(_int, 'lastIndexOf', ('searchElement', _mixed), ('fromIndex', _int)),
0275     F(_array, 'map', ('callbackfn', _function), ('thisArg', _object)),
0276     F(_mixed, 'pop'),
0277     F(_int, 'push', ('element', _mixed)),
0278     F(_mixed, 'reduce', ('callbackfn', _function), ('initialValue', _mixed)),
0279     F(_mixed, 'reduceRight', ('callbackfn', _function), ('initialValue', _mixed)),
0280     F(_array, 'reverse'),
0281     F(_mixed, 'shift'),
0282     F(_array, 'slice', ('start', _int), ('end', _int)),
0283     F(_bool, 'some', ('callbackfn', _function), ('thisArg', _object)),
0284     F(_array, 'sort', ('comparefn', _function)),
0285     F(_array, 'splice', ('start', _int), ('deleteCount', _int), ('items', _mixed)),
0286     F(_string, 'substr', ('start', _int), ('length', _int)),
0287     F(_int, 'unshift', ('items', _mixed)),
0288     F(_iterator, 'values'),
0289     Var(_int, 'length'),
0290 ),
0291 
0292 # Keyed Collection (section 23)
0293 Class('Map', ('iterable', _mixed)).members(
0294     F(_void, 'clear'),
0295     F(_bool, 'delete', ('key', _mixed)),
0296     F(_iterator, 'entries'),
0297     F(_void, 'forEach', ('callbackfn', _function), ('thisArg', _object)),
0298     F(_mixed, 'get', ('key', _mixed)),
0299     F(_bool, 'has', ('key', _mixed)),
0300     F(_map, 'set', ('key', _mixed), ('value', _mixed)),
0301     Var(_int, 'size'),
0302     F(_iterator, 'values'),
0303 ),
0304 
0305 Class('Set', ('iterable', _mixed)).members(
0306     F(_set, 'add', ('value', _mixed)),
0307     F(_void, 'clear'),
0308     F(_bool, 'delete', ('value', _mixed)),
0309     F(_iterator, 'entries'),
0310     F(_void, 'forEach', ('callbackfn', _function), ('thisArg', _object)),
0311     F(_bool, 'has', ('value', _mixed)),
0312     Var(_int, 'size'),
0313     F(_iterator, 'values'),
0314 ),
0315 
0316 Class('WeakMap', ('iterable', _mixed)).members(
0317     F(_void, 'clear'),
0318     F(_bool, 'delete', ('key', _mixed)),
0319     F(_mixed, 'get', ('key', _mixed)),
0320     F(_bool, 'has', ('key', _mixed)),
0321     F(_map, 'set', ('key', _mixed), ('value', _mixed)),
0322 ),
0323 
0324 Class('WeakSet', ('iterable', _mixed)).members(
0325     F(_set, 'add', ('value', _mixed)),
0326     F(_void, 'clear'),
0327     F(_bool, 'delete', ('value', _mixed)),
0328     F(_bool, 'has', ('value', _mixed)),
0329 ),
0330 
0331 # Structured Data (section 24)
0332 Class('ArrayBuffer', ('length', _int)).members(
0333     F(_bool, 'isView', ('arg', _mixed)),
0334     Var(_int, 'byteLength'),
0335     F(_arraybuffer, 'slice', ('start', _int), ('end', _int)),
0336 ),
0337 
0338 Class('DataView', ('buffer', _arraybuffer), ('byteOffset', _int), ('byteLength', _int)).members(
0339     Var(_dataview, 'buffer'),
0340     Var(_int, 'byteLength'),
0341     Var(_int, 'byteOffset'),
0342     F(_float, 'getFloat32', ('byteOffset', _int), ('littleEndian', _bool)),
0343     F(_float, 'getFloat64', ('byteOffset', _int), ('littleEndian', _bool)),
0344     F(_int, 'getInt8', ('byteOffset', _int)),
0345     F(_int, 'getInt16', ('byteOffset', _int), ('littleEndian', _bool)),
0346     F(_int, 'getInt32', ('byteOffset', _int), ('littleEndian', _bool)),
0347     F(_int, 'getUInt8', ('byteOffset', _int)),
0348     F(_int, 'getUInt16', ('byteOffset', _int), ('littleEndian', _bool)),
0349     F(_int, 'getUInt32', ('byteOffset', _int), ('littleEndian', _bool)),
0350     F(_void, 'setFloat32', ('byteOffset', _int), ('value', _float), ('littleEndian', _bool)),
0351     F(_void, 'setFloat64', ('byteOffset', _int), ('value', _float), ('littleEndian', _bool)),
0352     F(_void, 'setInt8', ('byteOffset', _int), ('value', _int)),
0353     F(_void, 'setInt16', ('byteOffset', _int), ('value', _int), ('littleEndian', _bool)),
0354     F(_void, 'setInt32', ('byteOffset', _int), ('value', _int), ('littleEndian', _bool)),
0355     F(_void, 'setUInt8', ('byteOffset', _int), ('value', _int)),
0356     F(_void, 'setUInt16', ('byteOffset', _int), ('value', _int), ('littleEndian', _bool)),
0357     F(_void, 'setUInt32', ('byteOffset', _int), ('value', _int), ('littleEndian', _bool)),
0358 ),
0359 
0360 Struct('JSON').members(
0361     F(_mixed, 'parse', ('text', _string), ('reviver', _function)),
0362     F(_string, 'stringify', ('value', _mixed), ('replacer', _function), ('space', _string)),
0363 ),
0364 
0365 # Control Abstraction Objects (section 25)
0366 Class('Promise', ('executor', _function)).members(
0367     F(_void, 'all', ('iterable', _array)),
0368     F(_void, 'race', ('iterable', _array)),
0369     F(_promise, 'resolve', ('x', _mixed)),
0370     F(_void, 'catch', ('onRejected', _function)),
0371     F(_void, 'then', ('onFulfilled', _function), ('onRejected', _function)),
0372 ),
0373 
0374 Struct('Reflect').members(
0375     F(_mixed, 'apply', ('target', _function), ('thisArgument', _object), ('argumentList', _array)),
0376     F(_object, 'construct', ('target', _function), ('argumentList', _array)),
0377     F(_void, 'deleteProperty', ('target', _object), ('propertyKey', _string)),
0378     F(_iterator, 'enumerate', ('target', _object)),
0379     F(_mixed, 'get', ('target', _object), ('propertyKey', _string), ('receiver', _object)),
0380     F(_bool, 'has', ('target', _object), ('propertyKey', _string)),
0381     F(_array, 'ownKeys', ('target', _object)),
0382     F(_void, 'set', ('target', _object), ('propertyKey', _string), ('value', _mixed), ('receiver', _object)),
0383 ),
0384 
0385 *[Class(a + 'Array', ('length', _int)).prototype('Array').members(
0386     Var(_mixed, 'buffer'),
0387     Var(_int, 'byteLength'),
0388     Var(_int, 'byteOffset'),
0389     F(_array, 'subarray', ('begin', _int), ('end', _int)),
0390     Var(_int, 'BYTES_PER_ELEMENT'),
0391 ) for a in ['Int8', 'Uint8', 'Uint8Clamped', 'Int16', 'Uint16', 'Int32', 'Uint32', 'Float32', 'Float64']]
0392 ).print()
0393 # Realm, Loader and Proxy not described for now