-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIridium.txt
More file actions
1636 lines (1264 loc) · 50.9 KB
/
Iridium.txt
File metadata and controls
1636 lines (1264 loc) · 50.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=== 3JS TODO ===
1. [DONE] JS3VarDecl destructuring
(handled destructuring pattern and created a general lowering scheme)
2. [DONE] JS3Assn destructuring
(handled destructuring pattern and created a general lowering scheme)
=== Iridium Unsupported ===
1.
Input : JS3WithStatement
with (ARG) { ... }
Output : throw Error(Unsupported)
2.
Input : JS3ImportExpression
Output : throw Error(Unsupported)<-Babel does not make use of this node currently...
=== IRIDIUM ===
Progress/TODO:
============ ============ ============ ============ ============ ============ ============
JS3ImportExportNodes:
All Handled:
[] JS3ImportDeclaration
[] JS3ExportDefaultDeclaration
[] JS3NamedDeclaration
[] JS3ExportAllDeclaration
JS3AllowedBlockStatement:
Handled:
[] JS3DebuggerStatement
[] JS3ReturnStatement
[] JS3ThrowStatement
[] JS3VariableDeclaration
[] JS3FunctionDeclaration
[ERR] JS3WithStatement
[C] JS3IfStatement
[C] JS3TryStatement
[NADA] JS3EmptyStatement
[C] JS3WhileStatement
[C] JS3BreakStatement
[C] JS3ContinueStatement
[C] JS3BlockStatement
[C] JS3LabeledStatement
[C] JS3ForStatement
[C] JS3DoWhileStatement
[C] JS3SwitchStatement
[C] JS3ForInStatement
[C] JS3ForOfStatement
JS3AssnInit:
All Handled:
// AMP
[] Identifier, JS3MemberExpression
// RVals
[] JS3Literals
[] JS3RegExpLiteral
[] JS3TemplateLiteral
[] JS3TaggedTemplateExpression
[] JS3MetaProperty
[] JS3YieldExpression
[] JS3AwaitExpression
[] ThisExpression
[] JS3CallExpression
[C] JS3ContextualCallExpression
[] JS3BinaryExpression
[?C] JS3AssignmentExpression
[C] JS3ConditionalExpression
[] JS3ObjectExpression
[] JS3FunctionExpression
[] JS3ArrowFunctionExpression
[] JS3ArrayExpression
[] JS3NewExpression
[C] JS3UnaryExpression
[] JS3UpdateExpression
[C] JS3ClassExpression
// Handlers
[C] OptionalMemberExpression | OptionalCallExpression
[C] JS3AnonMemberExpression
============ ============ ============ ============ ============ ============ ============
ALL_IS = IS_Debugger | IS_Return | IS_Throw
| IS_SimpleVarDecl | IS_ArrPatVarDecl | IS_ObjPatVarDecl
| IS_FunDecl
| IS_Break | IS_LBreak
| IS_AImport | IS_BImport | IS_CImport
| IS_AExport | IS_BExport | IS_CExport | IS_DExport | IS_EExport
ALL_RVal = IV_Literals (IV_DecimalLiteral | IV_BigIntLiteral | IV_StringLiteral | IV_NumericLiteral | IV_NullLiteral | IV_BooleanLiteral)
| IV_Regexp
| IV_Templates (IV_TemplateLiteral | IV_TaggedTemplateFunctionCall)
| IV_META (IV_ModuleMeta | IV_NewTarget)
| IV_YIELD_AWAIT (IV_YIELD | IV_AWAIT)
| IV_This
| IV_Call (IV_ImportCall | IV_Call | IV_SuperCall | IV_V8IntrinsicCall)
| IV_BINOP (IV_ABINOP | IV_BBINOP | IV_CBINOP | IV_DBINOP | IV_EBINOP | IV_FBINOP)
| IV_Assignment (IS_SimpleAssn | IS_ArrPatAssn | IS_ObjPatAssn)
| IV_ConditionalExpression
| IV_ObjectExpression
| IV_FunctionExpressions (IV_FunctionExpression | IV_ArrowFunctionExpression)
| IV_ArrayExpression
| IV_NewExpression
| IV_UNOP = IV_AUNOP | IV_BUNOP | IV_CUNOP | IV_DUNOP
| IV_UpdateExpression
| IV_ClassExpression
| IV_ForInOfLoop...TODO
IV_ASSIGNABLE = ALL_RVal
| IV_Identifier
| IV_MemberExpression
| IV_ThisLookup
| IV_SuperLookup
ALL_AMP = IV_Identifier
| IV_MemberExpression
| IV_ThisLookup
| IV_SuperLookup
| IV_PrivateName
I_File = I_Program
I_Program =
[
| ALL_IS
]
=== IRIDIUM HANDLERS ===
[Statement] JS3IfStatement -> Iridium_IfStatement
[Statement] JS3TryStatement -> Iridium_TryStatement
[Expression] OptionalMemberExpression -> Iridium_OptionalChaining
[Expression] OptionalCallExpression -> Iridium_OptionalChaining
[Statement] JS3WhileStatement -> TODO
[Statement] JS3BreakStatement -> TODO
[Statement] JS3ContinueStatement -> TODO
[Statement] JS3BlockStatement -> TODO
[Statement] JS3LabeledStatement -> TODO
[Statement] JS3ForStatement -> TODO
[Statement] JS3DoWhileStatement -> TODO
[Statement] JS3SwitchStatement -> TODO
[Statement] JS3ForInStatement -> TODO
[Statement] JS3ForOfStatement -> TODO
... TODO, check handlers...
10.
Input : JS3AssignmentExpression
TRIV_KEY = Identifier | StringLiteral | NumericLiteral | BigIntLiteral | DecimalLiteral | PrivateName
a.
ID = RVal
b.
[ ID, ...ID ] = RVal
c.
{ TRIV_KEY: ID, ...ID } = RVal
Output : IS_SimpleAssnExpr | IS_ArrPatAssnExpr | IS_ObjPatAssnExpr
a.
IS_SimpleAssnExpr(ID, IRIDIUM(RVal))
b.
generatedBindings <- Set(IDs)
IS_ArrPatAssnExpr([ ID, ...ID ], IRIDIUM(RVal), generatedBindings)
c.
generatedBindings <- Set(IDs)
IS_ArrPatAssnExpr({ ID, ...ID }, IRIDIUM(RVal), generatedBindings)
11.
Input : JS3ClassDeclaration
a.
class ID {
CLASS_BODY
}
b.
class ID extends CKE {
CLASS_BODY
}
Output : IS_BaseClassDecl | IS_DerivedClassDecl
// TODO, this requires more thought
12.
Input : JS3EmptyStatement
Input : IS_EmptyStatement
13.
Input : JS3WhileStatement
while CKE {
WHILE_BODY
}
Output :
Curr <- getCurrentBB()
Test <- new BB(CKEScope)
True <- new BB(BlockScope)
PostBB <- new BB(Curr.scope)
Curr.terminal = new UnconditionalGoto(Test)
Test.terminal = new BranchTerminal(CKE_RES, True, PostBB)
True.terminal = new UnconditionalGoto(Test)
IRIDIUM(CKE, Test)
IRIDIUM(WHILE_BODY, True)
setCurrentBB(PostBB)
14.
Input : JS3BreakStatement
a. break
b. break ID
Output :
a.
Curr <- getCurrentBB()
Break <- new BB(SwitchBreak)
enclosingBreak <- getEnclosingBreakBB(null)
Curr.terminal = new UnconditionalGoto(Break)
Break.terminal = new UnconditionalGoto(enclosingBreak)
b.
Curr <- getCurrentBB()
Break <- new BB(SwitchBreak)
enclosingBreak <- getEnclosingBreakBB(ID)
Curr.terminal = new UnconditionalGoto(Break)
Break.terminal = new UnconditionalGoto(enclosingBreak)
15.
Input : JS3ContinueStatement
a. continue
b. continue ID
Output :
a.
Curr <- getCurrentBB()
Break <- new BB(SwitchBreak)
enclosingCont <- getEnclosingContinueBB(null)
Curr.terminal = new UnconditionalGoto(Break)
Break.terminal = new UnconditionalGoto(enclosingCont)
b.
Curr <- getCurrentBB()
Break <- new BB(SwitchBreak)
enclosingCont <- getEnclosingContinueBB(ID)
Curr.terminal = new UnconditionalGoto(Break)
Break.terminal = new UnconditionalGoto(enclosingCont)
16.
Input : JS3BlockStatement
{ BLOCK_BODY }
Output :
Curr <- getCurrentBB()
Body <- new BB(Block.scope)
PostBB <- new BB(Curr.scope)
Curr.terminal = new UnconditionalGoto(Body)
Body.terminal = new UnconditionalGoto(PostBB)
IRIDIUM(BLOCK_BODY, Body)
setCurrentBB(PostBB)
4.
Input : JS3UpdateExpression
(++ | --) (ID, ID.ID)
(ID, ID.ID) (++ | --)
Output : I_UPDExpr
I_UPDExpr: (++ | --) (ID, ID.ID)
I_UPDExpr: (ID, ID.ID) (++ | --)
5.
Input : JS3YieldExpression
yield
yield ID
yield JS3ContainedExprKey
Output :
I_Yield (null)
I_Yield (ID)
I_Yield (IRIDIUM(JS3ContainedExprKey))
6.
Input : JS3AwaitExpression
await ID
await JS3ContainedExprKey
Output :
I_Await (ID)
I_Await (IRIDIUM(JS3ContainedExprKey))
7.
; Contained key expressions are used to break down expressions
; that cannot be broken down in their enclosing scope.
; Iridium breaks them down into a TransparentSequenceScope
; which has a return at the last statement.
Input : JS3ContainedKeyExpr
a. Identifier
b. JS3Literals
c. yield
d. YieldExpression
e. AwaitExpression
f. JS3CallExpression
Output : I_ID | I_LIT | I_Yield | I_Await | I_TCall
a. I_ID(Identifier)
b. I_LIT(Literal)
c. I_Yield(null)
d. IRIDIUM(YieldExpression)
e. IRIDIUM(AwaitExpression)
f.
tfs <- generateTransparentFunctionScope()
for s of JS3CallExpression
tfs.push(IRIDIUM(s))
I_TCall(tfs)
* When non-function objects are transferred across realms they do no copy the realm's global properties.
* When function objects are transferred across realms they remember the realm where they were originally declared.
* ?? Exception objects get associated to the calleeRealm ??
* === Possible VM Evaluation ===
What happens to function objects that are duplicated per instance.
See, example in FunctionObject section...
It may be worth seeing what memory impact it has, if any...
=================================================================
* In JavaScript parent instances can decide if children are allowed to hold a property or not.
let Parent = {}
Object.defineProperty(Parent, "f", { value: 0, writable: false })
let Child = { __proto__: Parent }
console.log(Child.f) // 0
console.log(delete Child.f) // true <- because child object does not hold the property anyway
Child.f = 121
console.log(Child.f) // 0
Object.defineProperty(Child, "f", { value: 121, writable: false })
console.log(Child.f) // 121
=================================================================
Points-To-Analysis
=================================================================
=== Background ===
ECMAScript is an object oriented language where interconnected objects interact with each other.
Each object is a collection of key value pairs.
These key value pairs can be divided into two two logical categories.
1. Internal Slots
These slots are transparent to the user.
The are used by the specification to perform standard language operations.
Operations like as retrieval of properties, updating of properties and even function call
behaviour are all described by slots.
This makes modelling PTA for JavaScript an interesting and challenging task.
Many published works do not dig deeper into the language and perform unsound analysis.
There is a major distinction to be made here, most analysis operate on the percieved
semantics of the language.
In a more real sense, they perform "Java" like analysis on "JavaScript".
Percieved semantics are in many cases close to actual semantics, but this leaves advanced
language features unmodelled.
1. Property Retrieval
******************************************************************************
let t$1 = a.f
******************************************************************************
The percieved semantics:
******************************************************************************
// 1. Lookup the enclosing environment for "a".
// Assumption: The enclosing environment is "assumed" to always
// be a side-effect-free generic map from bindings to values.
//
// STATE/ENV = {
// var1 : ...,
// a : { p1: "boo", f: O1, ... }
// }
//
// 2. Get field f of the structure: "a : { p1: "boo", f: O1, ... }"
// Assumption: The layout of objects is Java like and property retrieval
// is free of side effects.
//
// 3. Make inference that "t$1" now points to "O1" we got from "a.f".
******************************************************************************
If we make these into algorithmic steps we can start to see whats missing.
These steps are suitable for a "Java like JavaScript subset", not JavaScript.
1. let obj <- LookupGenericEnvHashMap(PTA, "a") { // In this example we assume this returns
one concrete example, this would generally be a Set }
2. let bindingValue <- obj["f"] {
assert obj is an C/Java like Struct
if obj.f exists
return obj.f
else
return undefined
}
3. PTA' = { ...PTA, "t$1": bindingValue }
A more correct implementation might look something like this.
1.
let obj;
let objLookup = LookupEnvIsObjRecord()
If (LookupEnvIsObjRecord) {
let env = LOOKUPOBJS <- This might even be a set...
If (env is an Ordinary Object) {
If (IsDataProp(env, "a")) {
obj <- LookupGenericEnvHashMap(env, "a")
} Else {
obj <- env.[[Get]]("a") <- This behaviour might not to be normal... Side effect prone
}
} Else {
obj <- env.[[Get]]("a") <- This behaviour might not to be normal... Side effect prone
}
} else {
obj <- LookupGenericEnvHashMap(PTA, "a")
}
2. let bindingValue <- RetrievePropFromProtoObj(obj, "a") <- If the analysis does things like set attributes to objects, normal retrieval might
make the results unsound, things need to be duplicated to ensure they are applicable
to relevant objects only.
3. PTA' = { ...PTA, "t$1": bindingValue }
JavaScript semantics are more nuanced, the following examples discuss how mental models of execution
in Java are not directly transferred to modelling JavaScript.
(a) Property lookups are prone to side-effects:
******************************************************************************
let a = {
get f() { console.log("environment lookup"); return "hello"; },
set f(a) { }
}
with (a) {
console.log(f)
}
******************************************************************************
(b) Behaviour of the "this" pointer in Java and JavaScript is also very different.
******************************************************************************
class Main {
public static void main(String[] args) {
B o = new B();
o.foo();
o.boo();
}
}
class A {
int a = 10;
void boo() {
System.out.println("A:a:: " + this.a);
}
}
class B extends A {
int a = 11;
void foo() {
System.out.println("B:a:: " + this.a);
}
}
OUTPUT:
B:a:: 11
A:a:: 10
******************************************************************************
If we rewrite the same example in JavaScript the result is different:
******************************************************************************
class A {
a = 10;
boo() {
console.log("A:a:: " + this.a)
}
}
class B extends A {
a = 11;
foo() {
console.log("B:a:: " + this.a);
}
}
let o = new B();
o.foo();
o.boo();
OUTPUT:
B:a:: 11
A:a:: 11
******************************************************************************
(c) Objects created in Java "actually own the fields they create", whereas JavaScript Object
layout and behaviour is much
more nuanced.
Objects may not even create fields (that they appear to own) until their value changes.
Let us consider the following Java program:
******************************************************************************
class A {
public int a = 10;
}
class B extends A {
public int b = 11;
}
B o = new B();
System.out.println(o.a)
System.out.println(o.b)
OUTPUT:
10
11
******************************************************************************
Let us look at the Java mental model of what happens when we modify the fields of this object.
******************************************************************************
B o = new B();
// o = [10, 11] <- An Object of Type B
// | |
// A::a B::b
o.a = 100;
// o = [100, 11] <- Field "a" is mutated inplace
// | |
// A::a B::b
o.b = 111;
// o = [100, 111] <- Field "b" is mutated inplace
// | |
// A::a B::b
******************************************************************************
Now let us look at prototype-based inheritance of JavaScript which exhibits the same observable
behaviour but internally works very differently.
******************************************************************************
let A = {
a: 10
}
function B() {
this.b = 11;
}
B.prototype = A;
let o = new B();
console.log(o.a);
console.log(o.b);
OUTPUT:
10
11
******************************************************************************
Let us look at the correct JavaScript mental model of what happens when we modify the fields of this object.
******************************************************************************
let o = new B();
// A = [Ordinary]{ a: 10 }
// o = [Ordinary]{ b: 11, [[Extensible]]: true, [[Prototype]]: A } <- An Object of Type B
// | |
// b Notice the lack of allocated space for "a"
o.a = 100;
// o = [Ordinary]{ b: 11, a: 100 [[Extensible]]: true, [[Prototype]]: A } <- A new field is created now!
// | |
// b a
o.b = 111;
// o = [Ordinary]{ b: 111, a: 100 [[Extensible]]: true, [[Prototype]]: A }
// | |
// b a
******************************************************************************
I will not make any comments on which approach is better, because both have different tradeoffs.
From the above observations one can guess that Java objects are unnecessarily bulky,
while JavaScript objects are somewhat lazily constructed are likely to be slimmer in practice.
One one hand the rigid nature of Java allows static analysis to make assumptions at compile time,
no such static analysis luck is present for JavaScript.
When performing PTA for JavaScript objects it might be well worth considering what these internal slots are,
most internal slots behave exactly as one might expect while some might not.
Having knowledge of these slots and categorizing their behaviour is essential to JavaScript object modelling.
2. Property Slots
These are the slots that are directly visible to the users.
One could say these are owned by the object.
Each slot is accessible by the means of a key/binding, which can be a string or a Symbol.
Each key, maps to a corresponding property descriptor.
This property descriptor can be used to classify each property into two distinct groups.
1. Data Property
A data property behaves like a plain property, but with different rules and restrictions on properties.
[[Value]] : ECMAScript Value
[[Writable]] : Attempts to change the value using [[Set]] will fail
[[Enumerable]] : Makes the property visible to enumeration (ex: for-in loop)
[[Configurable]] : If false, you cannot
1. Delete this property
2. Change if from a data property to a accessor property
3. Change attributes (other than "changing [[Value]]" or "setting [[Writable]] to false")
2. Accessor Property
An accessor property introduces control flow to property lookup.
Depending on the operation on the property, a corresponding "get" or "set" function is called.
[[Get]] : This is
1. Function Object
2. With zero arguments
[[Set]] : This is
1. Function Object
2. One argument
3. May or may not have impact on subsequent [[Get]] calls to the prop.
[[Writable]] : Attempts to change the value using [[Set]] will fail
[[Enumerable]] : Makes the property visible to enumeration (ex: for-in loop)
[[Configurable]] : If false, you cannot
1. Delete this property
2. Change if from a data property to a accessor property
3. Change attributes (other than "changing [[Value]]" or "setting [[Writable]] to false")
=== High-Level Layout ===
type ECMAValue = Undefined
| Null
| Boolean
| String
| Symbol
| Numeric
| ECMAObject
type ECMAObject = OrdinaryObject
| OrdinaryFunctionObject
| BuiltInFunctionObject
| BoundFunctionExoticObject
| ArrayExoticObject
| StringExoticObject
| ArgumentsExoticObject
| // TODO
| // TODO
| // TODO
| ProxyExoticObject
type Record = GlobalRecord
| ScriptRecord
| ModuleRecord
| BlockScopeRecord <- Refers to simple block scope
| FunctionBlockScopeRecord <- Refers to a function scope, this is seperated from block scope as
var hoisting will happen to top of this scope instead of block scope.
This distinction comes in play at that point.
data DPair p = // TODO
; This signifies a discrete pair, not sure what to do with this yet.
; The idea is to use this to hold discrete context specific values.
; For example under context C1, value is 1 otherwise 2.
==================
=== Object Property Descriptors ===
type DataProperty = Undefined | {
Value : Set(ECMAValue)
Writable : Uninitailized |> True | False |> Any
Enumerable : Uninitailized |> True | False |> Any
Configurable : Uninitailized |> True | False |> Any
}
type AccessorProperty = Undefined | {
Get : Set(OrdinaryFunctionObject)
Set : Set(OrdinaryFunctionObject)
Writable : Uninitailized |> True | False |> Any
Enumerable : Uninitailized |> True | False |> Any
Configurable : Uninitailized |> True | False |> Any
}
=== Modelling Objects ===
// 1. Ordinary Object
type OrdinaryObject <: ECMAObject = {
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : True |> False
[[Prototype]] : Uninitailized | Null | Set(ECMAObject)
|
| Default: Object.prototype
}
type FunctionNameString = String | Symbol
type FieldInitializer = {
[[Binding]] : Uninitailized |> CONST FunctionNameString |> NON-CONST
[[Value]] : Uninitailized | Set(ECMAValue)
}
// 2. Ordinary Function Object
Some Code Examples
*****************************************************************
class Test {
static a = 101; <- Static fields and methods become part of the constructor
logA() { console.log(Test.a); }
}
let a = new Test()
a.logA() // 101
*****************************************************************
*****************************************************************
class A {
static a = 101;
logg() { console.log(B.a); }
}
class B extends A {
logA() { console.log(B.a); }
}
let a = new B()
a.logA() // 101
*****************************************************************
*****************************************************************
class Boo {
boo=1
yeah=2
hawkthua= function() { console.log("I am instantiated per object..."); }
tdoss() { console.log("I belong to the prototype and shared across instances...") }
}
Boo.prototype
$ {
$ constructor: class Boo
$ tdoss : ƒ tdoss()
$ [[Prototype]] : Object.prototype
$ }
new Boo()
$ {
$ boo : 1
$ yeah : 2
$ hawkthua : ƒ
$ [[Prototype]] : Boo.prototype
$ }
*****************************************************************
type OrdinaryFunctionObject <: ECMAObject = {
; OrdinaryObject
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : True | False |> Any
[[Prototype]] : Uninitailized | Null | Set(ECMAObject)
|
| Default: Function.prototype
; Instance Properties
; Other instance properties are mostly deprecated but may still be found in some implementations
prototype : Undefined | Set(ECMAObject)
|
| Default: new Object()
;
; In case of CClass functions, it might feel like a right place for
; initializing non-static fields, but JS instead maintains a different
; internal slots that contains Field, along with their initializer.
;
length : (
Undefined | {
[[Value]] : Uninitailized |> CONST Integer |> DPair(T) |> NON-CONST
[[Writable]] : False,
[[Enumerable]] : False,
[[Configurable]] : True
},
Undefined
)
name : (
Undefined | {
[[Value]] : Uninitailized |> CONST String |> NON-CONST
[[Writable]] : False,
[[Enumerable]] : False,
[[Configurable]] : True
},
Undefined
)
; Stuff a Function Object needs...
[[Environment]] : Record
[[PrivateEnvironment]] : PrivateEnvironmentRecord
[[FormalParameters]] : AST-Node
[[ConstructorKind]] : BASE | DERIVED
[[Realm]] : Uninitailized |> REALM
[[ThisMode]] : LEXICAL | STRICT | GLOBAL
[[Strict]] : True | False
[[HomeObject]] : Undefined | Set(ECMAObject)
[[Fields]] : Array (FieldInitializer) ; Non-static fields
[[PrivateMethods]] : Array (OrdinaryFunctionObject) ; Non-static private methods
[[ClassFieldInitializerName]] : Uninitailized |> CONST String |> NON-CONST
[[IsClassConstructor]] : Uninitailized |> True | False |> Any
}
// 3. Builtin Function Object
type BuiltInFunctionObject <: ECMAObject = {
; OrdinaryObject
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : Uninitailized |> True | False |> Any
[[Prototype]] : Undefined | Set(ECMAObject)
|
| Default: Function.prototype
; This is not a subtype of OrdinaryFunctionObject...
[[Realm]] : Uninitailized |> REALM
[[InitialName]] : Uninitailized |> NAME
}
// 4. Bound Function Exotic Object
type BoundFunctionExoticObject <: ECMAObject = {
; OrdinaryObject
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : True | False |> Any
[[Prototype]] : Uninitailized | Null | Set(ECMAObject)
|
| This becomes the [[Prototype]] of the [[BoundTargetFunction]] function object
; Instance Properties
length : (
Undefined | {
[[Value]] : Uninitailized |> CONST Integer |> DPair(T) |> NON-CONST
[[Writable]] : False,
[[Enumerable]] : False,
[[Configurable]] : True
},
Undefined
)
name : (
Undefined | {
[[Value]] : Uninitailized |> CONST String |> NON-CONST
[[Writable]] : False,
[[Enumerable]] : False,
[[Configurable]] : True
},
Undefined
)
; Constructor initializes theses...
[[BoundTargetFunction]] : OrdinaryFunctionObject
[[BoundThis]] : Uninitailized |> Set(ECMAObject)
[[BoundArguments]] : Uninitailized |> [Set(ECMAObject)]
}
// 5. Array Exotic Object
type ArrayExoticObject <: ECMAObject = {
; OrdinaryObject
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : True | False |> Any
[[Prototype]] : Uninitailized | Null | Set(ECMAObject)
|
| Default: Array.prototype
; (Possible) Analysis Meta
; [Homogenous] : Uninitailized |> Type |> DPair(T) |> ANY
; [FixedLengthArray] : Uninitailized |> KNOWN-CONST Length |> UKN-CONST Length |> UKN-NON-CONST
; Instance Properties
length : (
Undefined | {
[[Value]] : Uninitailized |> CONST Integer |> DPair(T) |> NON-CONST
[[Writable]] : False,
[[Enumerable]] : False,
[[Configurable]] : True
},
Undefined
)
}
// 6. String Exotic Object
Some Code Examples
*****************************************************************
let a = new String("ab")
a
$ {
$ 0 : "a",
$ 1 : "b",
$ length : 2
$ [[Prototype]] : String.prototype
$ }
a.toString()
$ "ab"
a[2] = "c"
a
$ {
$ 0 : "a",
$ 1 : "b",
$ 2 : "c",
$ length : 2 <-- This behaviour is different than array exotic objects
$ [[Prototype]] : String.prototype
$ }
a.toString()
$ "ab" <-- The toString implementation ignores anything greater than length
*****************************************************************
type StringExoticObject <: ECMAObject = {
; OrdinaryObject
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : Uninitailized |> True | False |> Any
[[Prototype]] : Undefined | Set(ECMAObject)
|
| Default: String.prototype
; Instance Properties
length : (
Undefined | {
[[Value]] : Uninitailized |> CONST Integer |> DPair(T) |> NON-CONST
[[Writable]] : False,
[[Enumerable]] : False,
[[Configurable]] : True
},
Undefined
)
; I believe this mirrors the [[PrimitiveValue]] slot we see on the browser.
[[StringData]] : Uninitailized |> CONST String |> NON-CONST String
}
// 7. Arguments Exotic Object
type ArgumentsExoticObject <: ECMAObject = {
; OrdinaryObject
[Binding] : (DataProperty, AccessorProperty)
[[Extensible]] : Uninitailized |> True | False |> Any
[[Prototype]] : Undefined | Set(ECMAObject)
|
| Default: Object.prototype
[[ParameterMap]] : Uninitailized |> // TODO: NOBODY KNOW WHY DIS IS LIKE IT IS
}
// 8. TODO
type TypedArrayExoticObject <: ECMAObject = {