This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathJSDollarVM.cpp
More file actions
3556 lines (3013 loc) · 137 KB
/
JSDollarVM.cpp
File metadata and controls
3556 lines (3013 loc) · 137 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
/*
* Copyright (C) 2015-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSDollarVM.h"
#include "ArrayPrototype.h"
#include "BuiltinNames.h"
#include "CodeBlock.h"
#include "ControlFlowProfiler.h"
#include "DOMAttributeGetterSetter.h"
#include "DOMJITGetterSetter.h"
#include "Debugger.h"
#include "FrameTracers.h"
#include "FunctionCodeBlock.h"
#include "GetterSetter.h"
#include "JSArray.h"
#include "JSCInlines.h"
#include "JSONObject.h"
#include "JSString.h"
#include "Options.h"
#include "Parser.h"
#include "ProbeContext.h"
#include "ShadowChicken.h"
#include "Snippet.h"
#include "SnippetParams.h"
#include "TypeProfiler.h"
#include "TypeProfilerLog.h"
#include "VMInspector.h"
#include "WasmCapabilities.h"
#include <unicode/uversion.h>
#include <wtf/Atomics.h>
#include <wtf/CPUTime.h>
#include <wtf/DataLog.h>
#include <wtf/Language.h>
#include <wtf/ProcessID.h>
#include <wtf/StringPrintStream.h>
#include <wtf/unicode/icu/ICUHelpers.h>
#if ENABLE(WEBASSEMBLY)
#include "JSWebAssemblyHelpers.h"
#include "WasmStreamingParser.h"
#endif
using namespace JSC;
IGNORE_WARNINGS_BEGIN("frame-address")
extern "C" void ctiMasmProbeTrampoline();
namespace JSC {
// This class is only here as a simple way to grant JSDollarVM friend privileges
// to all the classes that it needs special access to.
class JSDollarVMHelper {
public:
JSDollarVMHelper(VM& vm)
: m_vm(vm)
{ }
void updateVMStackLimits() { return m_vm.updateStackLimits(); };
VM& m_vm;
};
} // namespace JSC
namespace {
static JSC_DECLARE_HOST_FUNCTION(functionDOMJITGetterComplexEnableException);
static JSC_DECLARE_HOST_FUNCTION(functionDOMJITFunctionObjectWithTypeCheck);
static JSC_DECLARE_HOST_FUNCTION(functionDOMJITCheckJSCastObjectWithTypeCheck);
// We must RELEASE_ASSERT(Options::useDollarVM()) in all JSDollarVM functions
// that are non-trivial at an eye's glance. This includes (but is not limited to):
// constructors
// create() factory
// createStructure() factory
// finishCreation()
// HOST_CALL or operation functions
// Constructors and methods of utility and test classes
// lambda functions
//
// The way to do this RELEASE_ASSERT is with the DollarVMAssertScope below.
//
// The only exception are some constexpr constructors used for instantiating
// globals (since these must have trivial constructors) e.g. DOMJITAttribute.
// Instead, these constructors should always be ALWAYS_INLINE.
class JSDollarVMCallFrame : public JSNonFinalObject {
using Base = JSNonFinalObject;
public:
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
JSDollarVMCallFrame(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static JSDollarVMCallFrame* create(JSGlobalObject* globalObject, CallFrame* callFrame, unsigned requestedFrameIndex)
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
Structure* structure = createStructure(vm, globalObject, jsNull());
JSDollarVMCallFrame* frame = new (NotNull, allocateCell<JSDollarVMCallFrame>(vm.heap)) JSDollarVMCallFrame(vm, structure);
frame->finishCreation(vm, callFrame, requestedFrameIndex);
return frame;
}
void finishCreation(VM& vm, CallFrame* callFrame, unsigned requestedFrameIndex)
{
DollarVMAssertScope assertScope;
Base::finishCreation(vm);
auto addProperty = [&] (VM& vm, const char* name, JSValue value) {
DollarVMAssertScope assertScope;
JSDollarVMCallFrame::addProperty(vm, name, value);
};
unsigned frameIndex = 0;
bool isValid = false;
callFrame->iterate(vm, [&] (StackVisitor& visitor) {
DollarVMAssertScope assertScope;
if (frameIndex++ != requestedFrameIndex)
return StackVisitor::Continue;
addProperty(vm, "name", jsString(vm, visitor->functionName()));
if (visitor->callee().isCell())
addProperty(vm, "callee", visitor->callee().asCell());
CodeBlock* codeBlock = visitor->codeBlock();
if (codeBlock) {
addProperty(vm, "codeBlock", codeBlock);
addProperty(vm, "unlinkedCodeBlock", codeBlock->unlinkedCodeBlock());
addProperty(vm, "executable", codeBlock->ownerExecutable());
}
isValid = true;
return StackVisitor::Done;
});
addProperty(vm, "valid", jsBoolean(isValid));
}
DECLARE_INFO;
private:
void addProperty(VM& vm, const char* name, JSValue value)
{
DollarVMAssertScope assertScope;
Identifier identifier = Identifier::fromString(vm, name);
putDirect(vm, identifier, value);
}
};
const ClassInfo JSDollarVMCallFrame::s_info = { "CallFrame", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDollarVMCallFrame) };
class ElementHandleOwner;
class Root;
class Element : public JSNonFinalObject {
public:
Element(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
typedef JSNonFinalObject Base;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
Root* root() const { return m_root.get(); }
void setRoot(VM& vm, Root* root) { m_root.set(vm, this, root); }
static Element* create(VM& vm, JSGlobalObject* globalObject, Root* root)
{
DollarVMAssertScope assertScope;
Structure* structure = createStructure(vm, globalObject, jsNull());
Element* element = new (NotNull, allocateCell<Element>(vm.heap)) Element(vm, structure);
element->finishCreation(vm, root);
return element;
}
void finishCreation(VM&, Root*);
static void visitChildren(JSCell* cell, SlotVisitor& visitor)
{
DollarVMAssertScope assertScope;
Element* thisObject = jsCast<Element*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_root);
}
static ElementHandleOwner* handleOwner();
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
DECLARE_INFO;
private:
WriteBarrier<Root> m_root;
};
class ElementHandleOwner final : public WeakHandleOwner {
WTF_MAKE_FAST_ALLOCATED;
public:
bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) final
{
DollarVMAssertScope assertScope;
if (UNLIKELY(reason))
*reason = "JSC::Element is opaque root";
Element* element = jsCast<Element*>(handle.slot()->asCell());
return visitor.containsOpaqueRoot(element->root());
}
};
class Root final : public JSDestructibleObject {
public:
using Base = JSDestructibleObject;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.destructibleObjectSpace;
}
Root(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
Element* element()
{
return m_element.get();
}
void setElement(Element* element)
{
DollarVMAssertScope assertScope;
Weak<Element> newElement(element, Element::handleOwner());
m_element.swap(newElement);
}
static Root* create(VM& vm, JSGlobalObject* globalObject)
{
DollarVMAssertScope assertScope;
Structure* structure = createStructure(vm, globalObject, jsNull());
Root* root = new (NotNull, allocateCell<Root>(vm.heap)) Root(vm, structure);
root->finishCreation(vm);
return root;
}
DECLARE_INFO;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static void visitChildren(JSCell* thisObject, SlotVisitor& visitor)
{
DollarVMAssertScope assertScope;
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.addOpaqueRoot(thisObject);
}
private:
Weak<Element> m_element;
};
class SimpleObject : public JSNonFinalObject {
public:
SimpleObject(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
typedef JSNonFinalObject Base;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static SimpleObject* create(VM& vm, JSGlobalObject* globalObject)
{
DollarVMAssertScope assertScope;
Structure* structure = createStructure(vm, globalObject, jsNull());
SimpleObject* simpleObject = new (NotNull, allocateCell<SimpleObject>(vm.heap)) SimpleObject(vm, structure);
simpleObject->finishCreation(vm);
return simpleObject;
}
static void visitChildren(JSCell* cell, SlotVisitor& visitor)
{
DollarVMAssertScope assertScope;
SimpleObject* thisObject = jsCast<SimpleObject*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(thisObject->m_hiddenValue);
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
JSValue hiddenValue()
{
return m_hiddenValue.get();
}
void setHiddenValue(VM& vm, JSValue value)
{
ASSERT(value.isCell());
m_hiddenValue.set(vm, this, value);
}
static CallData getConstructData(JSCell*)
{
CallData constructData;
constructData.type = CallData::Type::Native;
constructData.native.function = callHostFunctionAsConstructor;
return constructData;
}
DECLARE_INFO;
private:
WriteBarrier<JSC::Unknown> m_hiddenValue;
};
class ImpureGetter : public JSNonFinalObject {
public:
ImpureGetter(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
typedef JSNonFinalObject Base;
static constexpr unsigned StructureFlags = Base::StructureFlags | JSC::GetOwnPropertySlotIsImpure | JSC::OverridesGetOwnPropertySlot;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static ImpureGetter* create(VM& vm, Structure* structure, JSObject* delegate)
{
DollarVMAssertScope assertScope;
ImpureGetter* getter = new (NotNull, allocateCell<ImpureGetter>(vm.heap)) ImpureGetter(vm, structure);
getter->finishCreation(vm, delegate);
return getter;
}
void finishCreation(VM& vm, JSObject* delegate)
{
DollarVMAssertScope assertScope;
Base::finishCreation(vm);
if (delegate)
m_delegate.set(vm, this, delegate);
}
static bool getOwnPropertySlot(JSObject* object, JSGlobalObject* globalObject, PropertyName name, PropertySlot& slot)
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
ImpureGetter* thisObject = jsCast<ImpureGetter*>(object);
if (thisObject->m_delegate) {
if (thisObject->m_delegate->getPropertySlot(globalObject, name, slot))
return true;
RETURN_IF_EXCEPTION(scope, false);
}
return Base::getOwnPropertySlot(object, globalObject, name, slot);
}
static void visitChildren(JSCell* cell, SlotVisitor& visitor)
{
DollarVMAssertScope assertScope;
ASSERT_GC_OBJECT_INHERITS(cell, info());
Base::visitChildren(cell, visitor);
ImpureGetter* thisObject = jsCast<ImpureGetter*>(cell);
visitor.append(thisObject->m_delegate);
}
void setDelegate(VM& vm, JSObject* delegate)
{
m_delegate.set(vm, this, delegate);
}
private:
WriteBarrier<JSObject> m_delegate;
};
static JSC_DECLARE_CUSTOM_GETTER(customGetterValueGetter);
static JSC_DECLARE_CUSTOM_GETTER(customGetterAcessorGetter);
class CustomGetter : public JSNonFinalObject {
public:
CustomGetter(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
typedef JSNonFinalObject Base;
static constexpr unsigned StructureFlags = Base::StructureFlags | JSC::OverridesGetOwnPropertySlot;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static CustomGetter* create(VM& vm, Structure* structure)
{
DollarVMAssertScope assertScope;
CustomGetter* getter = new (NotNull, allocateCell<CustomGetter>(vm.heap)) CustomGetter(vm, structure);
getter->finishCreation(vm);
return getter;
}
static bool getOwnPropertySlot(JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName, PropertySlot& slot)
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
CustomGetter* thisObject = jsCast<CustomGetter*>(object);
if (propertyName == PropertyName(Identifier::fromString(vm, "customGetter"))) {
slot.setCacheableCustom(thisObject, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum, customGetterValueGetter);
return true;
}
if (propertyName == PropertyName(Identifier::fromString(vm, "customGetterAccessor"))) {
slot.setCacheableCustom(thisObject, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::CustomAccessor, customGetterAcessorGetter);
return true;
}
return JSObject::getOwnPropertySlot(thisObject, globalObject, propertyName, slot);
}
};
JSC_DEFINE_CUSTOM_GETTER(customGetterValueGetter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, PropertyName))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
CustomGetter* thisObject = jsDynamicCast<CustomGetter*>(vm, JSValue::decode(thisValue));
if (!thisObject)
return throwVMTypeError(globalObject, scope);
bool shouldThrow = thisObject->get(globalObject, PropertyName(Identifier::fromString(vm, "shouldThrow"))).toBoolean(globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
if (shouldThrow)
return throwVMTypeError(globalObject, scope);
return JSValue::encode(jsNumber(100));
}
JSC_DEFINE_CUSTOM_GETTER(customGetterAcessorGetter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, PropertyName))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSObject* thisObject = jsDynamicCast<JSObject*>(vm, JSValue::decode(thisValue));
if (!thisObject)
return throwVMTypeError(globalObject, scope);
bool shouldThrow = thisObject->get(globalObject, PropertyName(Identifier::fromString(vm, "shouldThrow"))).toBoolean(globalObject);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
if (shouldThrow)
return throwVMTypeError(globalObject, scope);
return JSValue::encode(jsNumber(100));
}
static JSC_DECLARE_CUSTOM_GETTER(runtimeArrayLengthGetter);
class RuntimeArray : public JSArray {
public:
typedef JSArray Base;
static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | OverridesAnyFormOfGetPropertyNames;
IGNORE_WARNINGS_BEGIN("unused-const-variable")
static constexpr bool needsDestruction = false;
IGNORE_WARNINGS_END
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static RuntimeArray* create(JSGlobalObject* globalObject, CallFrame* callFrame)
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
Structure* structure = createStructure(vm, globalObject, createPrototype(vm, globalObject));
RuntimeArray* runtimeArray = new (NotNull, allocateCell<RuntimeArray>(vm.heap)) RuntimeArray(globalObject, structure);
runtimeArray->finishCreation(globalObject, callFrame);
vm.heap.addFinalizer(runtimeArray, destroy);
return runtimeArray;
}
~RuntimeArray() { }
static void destroy(JSCell* cell)
{
DollarVMAssertScope assertScope;
static_cast<RuntimeArray*>(cell)->RuntimeArray::~RuntimeArray();
}
static bool getOwnPropertySlot(JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName, PropertySlot& slot)
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
RuntimeArray* thisObject = jsCast<RuntimeArray*>(object);
if (propertyName == vm.propertyNames->length) {
slot.setCacheableCustom(thisObject, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum, runtimeArrayLengthGetter);
return true;
}
Optional<uint32_t> index = parseIndex(propertyName);
if (index && index.value() < thisObject->getLength()) {
slot.setValue(thisObject, PropertyAttribute::DontDelete | PropertyAttribute::DontEnum, jsNumber(thisObject->m_vector[index.value()]));
return true;
}
return JSObject::getOwnPropertySlot(thisObject, globalObject, propertyName, slot);
}
static bool getOwnPropertySlotByIndex(JSObject* object, JSGlobalObject* globalObject, unsigned index, PropertySlot& slot)
{
DollarVMAssertScope assertScope;
RuntimeArray* thisObject = jsCast<RuntimeArray*>(object);
if (index < thisObject->getLength()) {
slot.setValue(thisObject, PropertyAttribute::DontDelete | PropertyAttribute::DontEnum, jsNumber(thisObject->m_vector[index]));
return true;
}
return JSObject::getOwnPropertySlotByIndex(thisObject, globalObject, index, slot);
}
static NO_RETURN_DUE_TO_CRASH bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&)
{
RELEASE_ASSERT_NOT_REACHED();
}
static NO_RETURN_DUE_TO_CRASH bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&)
{
RELEASE_ASSERT_NOT_REACHED();
}
unsigned getLength() const { return m_vector.size(); }
DECLARE_INFO;
static ArrayPrototype* createPrototype(VM&, JSGlobalObject* globalObject)
{
DollarVMAssertScope assertScope;
return globalObject->arrayPrototype();
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(DerivedArrayType, StructureFlags), info(), ArrayClass);
}
protected:
void finishCreation(JSGlobalObject* globalObject, CallFrame* callFrame)
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
Base::finishCreation(vm);
ASSERT(inherits(vm, info()));
for (size_t i = 0; i < callFrame->argumentCount(); i++)
m_vector.append(callFrame->argument(i).toInt32(globalObject));
}
private:
RuntimeArray(JSGlobalObject* globalObject, Structure* structure)
: JSArray(globalObject->vm(), structure, nullptr)
{
DollarVMAssertScope assertScope;
}
Vector<int> m_vector;
};
JSC_DEFINE_CUSTOM_GETTER(runtimeArrayLengthGetter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, PropertyName))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
RuntimeArray* thisObject = jsDynamicCast<RuntimeArray*>(vm, JSValue::decode(thisValue));
if (!thisObject)
return throwVMTypeError(globalObject, scope);
return JSValue::encode(jsNumber(thisObject->getLength()));
}
static const struct CompactHashIndex staticCustomAccessorTableIndex[2] = {
{ 0, -1 },
{ -1, -1 },
};
static JSC_DECLARE_CUSTOM_GETTER(testStaticAccessorGetter);
static JSC_DECLARE_CUSTOM_SETTER(testStaticAccessorPutter);
JSC_DEFINE_CUSTOM_GETTER(testStaticAccessorGetter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, PropertyName))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
JSObject* thisObject = jsDynamicCast<JSObject*>(vm, JSValue::decode(thisValue));
RELEASE_ASSERT(thisObject);
if (JSValue result = thisObject->getDirect(vm, PropertyName(Identifier::fromString(vm, "testField"))))
return JSValue::encode(result);
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_CUSTOM_SETTER(testStaticAccessorPutter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, EncodedJSValue value))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
JSObject* thisObject = jsDynamicCast<JSObject*>(vm, JSValue::decode(thisValue));
RELEASE_ASSERT(thisObject);
return thisObject->putDirect(vm, PropertyName(Identifier::fromString(vm, "testField")), JSValue::decode(value));
}
static const struct HashTableValue staticCustomAccessorTableValues[1] = {
{ "testStaticAccessor", static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(testStaticAccessorGetter), (intptr_t)static_cast<PutPropertySlot::PutValueFunc>(testStaticAccessorPutter) } },
};
static const struct HashTable staticCustomAccessorTable =
{ 1, 1, true, nullptr, staticCustomAccessorTableValues, staticCustomAccessorTableIndex };
class StaticCustomAccessor : public JSNonFinalObject {
using Base = JSNonFinalObject;
public:
StaticCustomAccessor(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
static constexpr unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable | OverridesGetOwnPropertySlot;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static StaticCustomAccessor* create(VM& vm, Structure* structure)
{
DollarVMAssertScope assertScope;
StaticCustomAccessor* accessor = new (NotNull, allocateCell<StaticCustomAccessor>(vm.heap)) StaticCustomAccessor(vm, structure);
accessor->finishCreation(vm);
return accessor;
}
static bool getOwnPropertySlot(JSObject* thisObject, JSGlobalObject* globalObject, PropertyName propertyName, PropertySlot& slot)
{
if (String(propertyName.uid()) == "thinAirCustomGetter") {
slot.setCacheableCustom(thisObject, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::CustomAccessor, testStaticAccessorGetter);
return true;
}
return JSNonFinalObject::getOwnPropertySlot(thisObject, globalObject, propertyName, slot);
}
};
static JSC_DECLARE_CUSTOM_GETTER(testStaticValueGetter);
static JSC_DECLARE_CUSTOM_SETTER(testStaticValuePutter);
JSC_DEFINE_CUSTOM_GETTER(testStaticValueGetter, (JSGlobalObject*, EncodedJSValue, PropertyName))
{
DollarVMAssertScope assertScope;
return JSValue::encode(jsUndefined());
}
JSC_DEFINE_CUSTOM_SETTER(testStaticValuePutter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, EncodedJSValue value))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
JSObject* thisObject = jsDynamicCast<JSObject*>(vm, JSValue::decode(thisValue));
RELEASE_ASSERT(thisObject);
return thisObject->putDirect(vm, PropertyName(Identifier::fromString(vm, "testStaticValue")), JSValue::decode(value));
}
static const struct CompactHashIndex staticCustomValueTableIndex[2] = {
{ 0, -1 },
{ -1, -1 },
};
static const struct HashTableValue staticCustomValueTableValues[1] = {
{ "testStaticValue", static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(testStaticValueGetter), (intptr_t)static_cast<PutPropertySlot::PutValueFunc>(testStaticValuePutter) } },
};
static const struct HashTable staticCustomValueTable =
{ 1, 1, true, nullptr, staticCustomValueTableValues, staticCustomValueTableIndex };
class StaticCustomValue : public JSNonFinalObject {
using Base = JSNonFinalObject;
public:
StaticCustomValue(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
static constexpr unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static StaticCustomValue* create(VM& vm, Structure* structure)
{
DollarVMAssertScope assertScope;
StaticCustomValue* accessor = new (NotNull, allocateCell<StaticCustomValue>(vm.heap)) StaticCustomValue(vm, structure);
accessor->finishCreation(vm);
return accessor;
}
};
class ObjectDoingSideEffectPutWithoutCorrectSlotStatus : public JSNonFinalObject {
using Base = JSNonFinalObject;
public:
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
ObjectDoingSideEffectPutWithoutCorrectSlotStatus(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
static ObjectDoingSideEffectPutWithoutCorrectSlotStatus* create(VM& vm, Structure* structure)
{
DollarVMAssertScope assertScope;
ObjectDoingSideEffectPutWithoutCorrectSlotStatus* accessor = new (NotNull, allocateCell<ObjectDoingSideEffectPutWithoutCorrectSlotStatus>(vm.heap)) ObjectDoingSideEffectPutWithoutCorrectSlotStatus(vm, structure);
accessor->finishCreation(vm);
return accessor;
}
static bool put(JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
{
DollarVMAssertScope assertScope;
auto* thisObject = jsCast<ObjectDoingSideEffectPutWithoutCorrectSlotStatus*>(cell);
auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm());
auto* string = value.toString(globalObject);
RETURN_IF_EXCEPTION(throwScope, false);
RELEASE_AND_RETURN(throwScope, Base::put(thisObject, globalObject, propertyName, string, slot));
}
};
class DOMJITNode : public JSNonFinalObject {
public:
DOMJITNode(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
typedef JSNonFinalObject Base;
static constexpr unsigned StructureFlags = Base::StructureFlags;
template<typename CellType, SubspaceAccess>
static CompleteSubspace* subspaceFor(VM& vm)
{
return &vm.cellSpace;
}
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(JSC::JSType(LastJSCObjectType + 1), StructureFlags), info());
}
#if ENABLE(JIT)
static Ref<Snippet> checkSubClassSnippet()
{
DollarVMAssertScope assertScope;
Ref<Snippet> snippet = Snippet::create();
snippet->setGenerator([=] (CCallHelpers& jit, SnippetParams& params) {
DollarVMAssertScope assertScope;
CCallHelpers::JumpList failureCases;
failureCases.append(jit.branchIfNotType(params[0].gpr(), JSC::JSType(LastJSCObjectType + 1)));
return failureCases;
});
return snippet;
}
#endif
static DOMJITNode* create(VM& vm, Structure* structure)
{
DollarVMAssertScope assertScope;
DOMJITNode* getter = new (NotNull, allocateCell<DOMJITNode>(vm.heap)) DOMJITNode(vm, structure);
getter->finishCreation(vm);
return getter;
}
int32_t value() const
{
return m_value;
}
static ptrdiff_t offsetOfValue() { return OBJECT_OFFSETOF(DOMJITNode, m_value); }
private:
int32_t m_value { 42 };
};
static JSC_DECLARE_CUSTOM_GETTER(domJITGetterCustomGetter);
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(domJITGetterSlowCall, EncodedJSValue, (JSGlobalObject*, void*));
class DOMJITGetter : public DOMJITNode {
public:
DOMJITGetter(VM& vm, Structure* structure)
: Base(vm, structure)
{
DollarVMAssertScope assertScope;
}
DECLARE_INFO;
typedef DOMJITNode Base;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
DollarVMAssertScope assertScope;
return Structure::create(vm, globalObject, prototype, TypeInfo(JSC::JSType(LastJSCObjectType + 1), StructureFlags), info());
}
static DOMJITGetter* create(VM& vm, Structure* structure)
{
DollarVMAssertScope assertScope;
DOMJITGetter* getter = new (NotNull, allocateCell<DOMJITGetter>(vm.heap)) DOMJITGetter(vm, structure);
getter->finishCreation(vm);
return getter;
}
class DOMJITAttribute : public DOMJIT::GetterSetter {
public:
ALWAYS_INLINE constexpr DOMJITAttribute()
: DOMJIT::GetterSetter(
domJITGetterCustomGetter,
#if ENABLE(JIT)
&callDOMGetter,
#else
nullptr,
#endif
SpecInt32Only)
{
}
#if ENABLE(JIT)
static Ref<DOMJIT::CallDOMGetterSnippet> callDOMGetter()
{
DollarVMAssertScope assertScope;
Ref<DOMJIT::CallDOMGetterSnippet> snippet = DOMJIT::CallDOMGetterSnippet::create();
snippet->requireGlobalObject = true;
snippet->setGenerator([=] (CCallHelpers& jit, SnippetParams& params) {
DollarVMAssertScope assertScope;
JSValueRegs results = params[0].jsValueRegs();
GPRReg domGPR = params[1].gpr();
GPRReg globalObjectGPR = params[2].gpr();
params.addSlowPathCall(jit.jump(), jit, domJITGetterSlowCall, results, globalObjectGPR, domGPR);
return CCallHelpers::JumpList();
});
return snippet;
}
#endif
};
private:
void finishCreation(VM&);
};
static const DOMJITGetter::DOMJITAttribute DOMJITGetterDOMJIT;
void DOMJITGetter::finishCreation(VM& vm)
{
DollarVMAssertScope assertScope;
Base::finishCreation(vm);
const DOMJIT::GetterSetter* domJIT = &DOMJITGetterDOMJIT;
auto* customGetterSetter = DOMAttributeGetterSetter::create(vm, domJIT->getter(), nullptr, DOMAttributeAnnotation { DOMJITNode::info(), domJIT });
putDirectCustomAccessor(vm, Identifier::fromString(vm, "customGetter"), customGetterSetter, PropertyAttribute::ReadOnly | PropertyAttribute::CustomAccessor);
}
JSC_DEFINE_CUSTOM_GETTER(domJITGetterCustomGetter, (JSGlobalObject* globalObject, EncodedJSValue thisValue, PropertyName))
{
DollarVMAssertScope assertScope;
VM& vm = globalObject->vm();
DOMJITNode* thisObject = jsDynamicCast<DOMJITNode*>(vm, JSValue::decode(thisValue));
ASSERT(thisObject);