mirrored from https://chromium.googlesource.com/v8/v8.git
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
objects.h
3632 lines (2947 loc) · 128 KB
/
objects.h
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 2006-2008 Google 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:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * 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.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "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 THE COPYRIGHT
// OWNER 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.
#ifndef V8_OBJECTS_H_
#define V8_OBJECTS_H_
#include "builtins.h"
#include "code-stubs.h"
#include "smart-pointer.h"
#include "unicode-inl.h"
//
// All object types in the V8 JavaScript are described in this file.
//
// Inheritance hierarchy:
// - Object
// - Smi (immediate small integer)
// - Failure (immediate for marking failed operation)
// - HeapObject (superclass for everything allocated in the heap)
// - JSObject
// - JSArray
// - JSFunction
// - GlobalObject
// - JSGlobalObject
// - JSBuiltinsObject
// - JSValue
// - Script
// - Array
// - ByteArray
// - FixedArray
// - HashTable
// - Dictionary
// - SymbolTable
// - Context
// - GlobalContext
// - String
// - SeqString
// - AsciiString
// - TwoByteString
// - ConsString
// - SlicedString
// - ExternalString
// - ExternalAsciiString
// - ExternalTwoByteString
// - HeapNumber
// - Code
// - Map
// - Oddball
// - Proxy
// - SharedFunctionInfo
// - Struct
// - AccessorInfo
// - AccessCheckInfo
// - InterceptorInfo
// - CallHandlerInfo
// - FunctionTemplateInfo
// - ObjectTemplateInfo
// - SignatureInfo
// - TypeSwitchInfo
// - DebugInfo
// - BreakPointInfo
//
// Formats of Object*:
// Smi: [31 bit signed int] 0
// HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
// Failure: [30 bit signed int] 11
// Ecma-262 3rd 8.6.1
enum PropertyAttributes {
NONE = v8::None,
READ_ONLY = v8::ReadOnly,
DONT_ENUM = v8::DontEnum,
DONT_DELETE = v8::DontDelete,
INTERCEPTED = 1 << 3,
ABSENT = 16 // Used in runtime to indicate a property is absent.
};
namespace v8 { namespace internal {
// PropertyDetails captures type and attributes for a property.
// They are used both in property dictionaries and instance descriptors.
class PropertyDetails BASE_EMBEDDED {
public:
PropertyDetails(PropertyAttributes attributes,
PropertyType type,
int index = 0) {
ASSERT(TypeField::is_valid(type));
ASSERT(AttributesField::is_valid(attributes));
ASSERT(IndexField::is_valid(index));
value_ = TypeField::encode(type)
| AttributesField::encode(attributes)
| IndexField::encode(index);
ASSERT(type == this->type());
ASSERT(attributes == this->attributes());
ASSERT(index == this->index());
}
// Conversion for storing details as Object*.
inline PropertyDetails(Smi* smi);
inline Smi* AsSmi();
PropertyType type() { return TypeField::decode(value_); }
bool IsTransition() {
PropertyType t = type();
ASSERT(t != INTERCEPTOR);
if (t == MAP_TRANSITION || t == CONSTANT_TRANSITION) return true;
return false;
}
PropertyAttributes attributes() { return AttributesField::decode(value_); }
int index() { return IndexField::decode(value_); }
static bool IsValidIndex(int index) { return IndexField::is_valid(index); }
bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; }
bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; }
bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; }
// Bit fields in value_ (type, shift, size). Must be public so the
// constants can be embedded in generated code.
class TypeField: public BitField<PropertyType, 0, 3> {};
class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
class IndexField: public BitField<uint32_t, 6, 32-6> {};
static const int kInitialIndex = 1;
private:
uint32_t value_;
};
// All Maps have a field instance_type containing a InstanceType.
// It describes the type of the instances.
//
// As an example, a JavaScript object is a heap object and its map
// instance_type is JS_OBJECT_TYPE.
//
// The names of the string instance types are intended to systematically
// mirror their encoding in the instance_type field of the map. The length
// (SHORT, MEDIUM, or LONG) is always mentioned. The default encoding is
// considered TWO_BYTE. It is not mentioned in the name. ASCII encoding is
// mentioned explicitly in the name. Likewise, the default representation is
// considered sequential. It is not mentioned in the name. The other
// representations (eg, CONS, SLICED, EXTERNAL) are explicitly mentioned.
// Finally, the string is either a SYMBOL_TYPE (if it is a symbol) or a
// STRING_TYPE (if it is not a symbol).
//
// NOTE: The following things are some that depend on the string types having
// instance_types that are less than those of all other types:
// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
// Object::IsString.
//
// NOTE: Everything following JS_OBJECT_TYPE is considered a
// JSObject for GC purposes. The first four entries here have typeof
// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
#define INSTANCE_TYPE_LIST(V) \
V(SHORT_SYMBOL_TYPE) \
V(MEDIUM_SYMBOL_TYPE) \
V(LONG_SYMBOL_TYPE) \
V(SHORT_ASCII_SYMBOL_TYPE) \
V(MEDIUM_ASCII_SYMBOL_TYPE) \
V(LONG_ASCII_SYMBOL_TYPE) \
V(SHORT_CONS_SYMBOL_TYPE) \
V(MEDIUM_CONS_SYMBOL_TYPE) \
V(LONG_CONS_SYMBOL_TYPE) \
V(SHORT_CONS_ASCII_SYMBOL_TYPE) \
V(MEDIUM_CONS_ASCII_SYMBOL_TYPE) \
V(LONG_CONS_ASCII_SYMBOL_TYPE) \
V(SHORT_SLICED_SYMBOL_TYPE) \
V(MEDIUM_SLICED_SYMBOL_TYPE) \
V(LONG_SLICED_SYMBOL_TYPE) \
V(SHORT_SLICED_ASCII_SYMBOL_TYPE) \
V(MEDIUM_SLICED_ASCII_SYMBOL_TYPE) \
V(LONG_SLICED_ASCII_SYMBOL_TYPE) \
V(SHORT_EXTERNAL_SYMBOL_TYPE) \
V(MEDIUM_EXTERNAL_SYMBOL_TYPE) \
V(LONG_EXTERNAL_SYMBOL_TYPE) \
V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
V(MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE) \
V(LONG_EXTERNAL_ASCII_SYMBOL_TYPE) \
V(SHORT_STRING_TYPE) \
V(MEDIUM_STRING_TYPE) \
V(LONG_STRING_TYPE) \
V(SHORT_ASCII_STRING_TYPE) \
V(MEDIUM_ASCII_STRING_TYPE) \
V(LONG_ASCII_STRING_TYPE) \
V(SHORT_CONS_STRING_TYPE) \
V(MEDIUM_CONS_STRING_TYPE) \
V(LONG_CONS_STRING_TYPE) \
V(SHORT_CONS_ASCII_STRING_TYPE) \
V(MEDIUM_CONS_ASCII_STRING_TYPE) \
V(LONG_CONS_ASCII_STRING_TYPE) \
V(SHORT_SLICED_STRING_TYPE) \
V(MEDIUM_SLICED_STRING_TYPE) \
V(LONG_SLICED_STRING_TYPE) \
V(SHORT_SLICED_ASCII_STRING_TYPE) \
V(MEDIUM_SLICED_ASCII_STRING_TYPE) \
V(LONG_SLICED_ASCII_STRING_TYPE) \
V(SHORT_EXTERNAL_STRING_TYPE) \
V(MEDIUM_EXTERNAL_STRING_TYPE) \
V(LONG_EXTERNAL_STRING_TYPE) \
V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
V(MEDIUM_EXTERNAL_ASCII_STRING_TYPE) \
V(LONG_EXTERNAL_ASCII_STRING_TYPE) \
V(LONG_PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
\
V(MAP_TYPE) \
V(HEAP_NUMBER_TYPE) \
V(FIXED_ARRAY_TYPE) \
V(CODE_TYPE) \
V(ODDBALL_TYPE) \
V(PROXY_TYPE) \
V(BYTE_ARRAY_TYPE) \
V(FILLER_TYPE) \
\
V(ACCESSOR_INFO_TYPE) \
V(ACCESS_CHECK_INFO_TYPE) \
V(INTERCEPTOR_INFO_TYPE) \
V(SHARED_FUNCTION_INFO_TYPE) \
V(CALL_HANDLER_INFO_TYPE) \
V(FUNCTION_TEMPLATE_INFO_TYPE) \
V(OBJECT_TEMPLATE_INFO_TYPE) \
V(SIGNATURE_INFO_TYPE) \
V(TYPE_SWITCH_INFO_TYPE) \
V(DEBUG_INFO_TYPE) \
V(BREAK_POINT_INFO_TYPE) \
V(SCRIPT_TYPE) \
\
V(JS_OBJECT_TYPE) \
V(JS_GLOBAL_OBJECT_TYPE) \
V(JS_BUILTINS_OBJECT_TYPE) \
V(JS_VALUE_TYPE) \
V(JS_ARRAY_TYPE) \
\
V(JS_FUNCTION_TYPE) \
// Since string types are not consecutive, this macro is used to
// iterate over them.
#define STRING_TYPE_LIST(V) \
V(SHORT_SYMBOL_TYPE, TwoByteString::kHeaderSize, short_symbol) \
V(MEDIUM_SYMBOL_TYPE, TwoByteString::kHeaderSize, medium_symbol) \
V(LONG_SYMBOL_TYPE, TwoByteString::kHeaderSize, long_symbol) \
V(SHORT_ASCII_SYMBOL_TYPE, AsciiString::kHeaderSize, short_ascii_symbol) \
V(MEDIUM_ASCII_SYMBOL_TYPE, AsciiString::kHeaderSize, medium_ascii_symbol) \
V(LONG_ASCII_SYMBOL_TYPE, AsciiString::kHeaderSize, long_ascii_symbol) \
V(SHORT_CONS_SYMBOL_TYPE, ConsString::kSize, short_cons_symbol) \
V(MEDIUM_CONS_SYMBOL_TYPE, ConsString::kSize, medium_cons_symbol) \
V(LONG_CONS_SYMBOL_TYPE, ConsString::kSize, long_cons_symbol) \
V(SHORT_CONS_ASCII_SYMBOL_TYPE, ConsString::kSize, short_cons_ascii_symbol) \
V(MEDIUM_CONS_ASCII_SYMBOL_TYPE, ConsString::kSize, medium_cons_ascii_symbol)\
V(LONG_CONS_ASCII_SYMBOL_TYPE, ConsString::kSize, long_cons_ascii_symbol) \
V(SHORT_SLICED_SYMBOL_TYPE, SlicedString::kSize, short_sliced_symbol) \
V(MEDIUM_SLICED_SYMBOL_TYPE, SlicedString::kSize, medium_sliced_symbol) \
V(LONG_SLICED_SYMBOL_TYPE, SlicedString::kSize, long_sliced_symbol) \
V(SHORT_SLICED_ASCII_SYMBOL_TYPE, \
SlicedString::kSize, \
short_sliced_ascii_symbol) \
V(MEDIUM_SLICED_ASCII_SYMBOL_TYPE, \
SlicedString::kSize, \
medium_sliced_ascii_symbol) \
V(LONG_SLICED_ASCII_SYMBOL_TYPE, \
SlicedString::kSize, \
long_sliced_ascii_symbol) \
V(SHORT_EXTERNAL_SYMBOL_TYPE, \
ExternalTwoByteString::kSize, \
short_external_symbol) \
V(MEDIUM_EXTERNAL_SYMBOL_TYPE, \
ExternalTwoByteString::kSize, \
medium_external_symbol) \
V(LONG_EXTERNAL_SYMBOL_TYPE, \
ExternalTwoByteString::kSize, \
long_external_symbol) \
V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
ExternalAsciiString::kSize, \
short_external_ascii_symbol) \
V(MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE, \
ExternalAsciiString::kSize, \
medium_external_ascii_symbol) \
V(LONG_EXTERNAL_ASCII_SYMBOL_TYPE, \
ExternalAsciiString::kSize, \
long_external_ascii_symbol) \
V(SHORT_STRING_TYPE, TwoByteString::kHeaderSize, short_string) \
V(MEDIUM_STRING_TYPE, TwoByteString::kHeaderSize, medium_string) \
V(LONG_STRING_TYPE, TwoByteString::kHeaderSize, long_string) \
V(SHORT_ASCII_STRING_TYPE, AsciiString::kHeaderSize, short_ascii_string) \
V(MEDIUM_ASCII_STRING_TYPE, AsciiString::kHeaderSize, medium_ascii_string) \
V(LONG_ASCII_STRING_TYPE, AsciiString::kHeaderSize, long_ascii_string) \
V(SHORT_CONS_STRING_TYPE, ConsString::kSize, short_cons_string) \
V(MEDIUM_CONS_STRING_TYPE, ConsString::kSize, medium_cons_string) \
V(LONG_CONS_STRING_TYPE, ConsString::kSize, long_cons_string) \
V(SHORT_CONS_ASCII_STRING_TYPE, ConsString::kSize, short_cons_ascii_string) \
V(MEDIUM_CONS_ASCII_STRING_TYPE, ConsString::kSize, medium_cons_ascii_string)\
V(LONG_CONS_ASCII_STRING_TYPE, ConsString::kSize, long_cons_ascii_string) \
V(SHORT_SLICED_STRING_TYPE, SlicedString::kSize, short_sliced_string) \
V(MEDIUM_SLICED_STRING_TYPE, SlicedString::kSize, medium_sliced_string) \
V(LONG_SLICED_STRING_TYPE, SlicedString::kSize, long_sliced_string) \
V(SHORT_SLICED_ASCII_STRING_TYPE, \
SlicedString::kSize, \
short_sliced_ascii_string) \
V(MEDIUM_SLICED_ASCII_STRING_TYPE, \
SlicedString::kSize, \
medium_sliced_ascii_string) \
V(LONG_SLICED_ASCII_STRING_TYPE, \
SlicedString::kSize, \
long_sliced_ascii_string) \
V(SHORT_EXTERNAL_STRING_TYPE, \
ExternalTwoByteString::kSize, \
short_external_string) \
V(MEDIUM_EXTERNAL_STRING_TYPE, \
ExternalTwoByteString::kSize, \
medium_external_string) \
V(LONG_EXTERNAL_STRING_TYPE, \
ExternalTwoByteString::kSize, \
long_external_string) \
V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
ExternalAsciiString::kSize, \
short_external_ascii_string) \
V(MEDIUM_EXTERNAL_ASCII_STRING_TYPE, \
ExternalAsciiString::kSize, \
medium_external_ascii_string) \
V(LONG_EXTERNAL_ASCII_STRING_TYPE, \
ExternalAsciiString::kSize, \
long_external_ascii_string)
// A struct is a simple object a set of object-valued fields. Including an
// object type in this causes the compiler to generate most of the boilerplate
// code for the class including allocation and garbage collection routines,
// casts and predicates. All you need to define is the class, methods and
// object verification routines. Easy, no?
//
// Note that for subtle reasons related to the ordering or numerical values of
// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
// manually.
#define STRUCT_LIST(V) \
V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
V(SIGNATURE_INFO, SignatureInfo, signature_info) \
V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
V(DEBUG_INFO, DebugInfo, debug_info) \
V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \
V(SCRIPT, Script, script)
// We use the full 8 bits of the instance_type field to encode heap object
// instance types. The high-order bit (bit 7) is set if the object is not a
// string, and cleared if it is a string.
const uint32_t kIsNotStringMask = 0x80;
const uint32_t kStringTag = 0x0;
const uint32_t kNotStringTag = 0x80;
// If bit 7 is clear, bits 5 and 6 are the string's size (short, medium, or
// long).
const uint32_t kStringSizeMask = 0x60;
const uint32_t kShortStringTag = 0x0;
const uint32_t kMediumStringTag = 0x20;
const uint32_t kLongStringTag = 0x40;
// If bit 7 is clear, bit 4 indicates that the string is a symbol (if set) or
// not (if cleared).
const uint32_t kIsSymbolMask = 0x10;
const uint32_t kNotSymbolTag = 0x0;
const uint32_t kSymbolTag = 0x10;
// If bit 7 is clear, and the string representation is a sequential string,
// then bit 3 indicates whether the string consists of two-byte characters or
// one-byte characters.
const uint32_t kStringEncodingMask = 0x8;
const uint32_t kTwoByteStringTag = 0x0;
const uint32_t kAsciiStringTag = 0x8;
// If bit 7 is clear, the low-order 3 bits indicate the representation
// of the string.
const uint32_t kStringRepresentationMask = 0x07;
enum StringRepresentationTag {
kSeqStringTag = 0x0,
kConsStringTag = 0x1,
kSlicedStringTag = 0x2,
kExternalStringTag = 0x3
};
enum InstanceType {
SHORT_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kSeqStringTag,
MEDIUM_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kSeqStringTag,
LONG_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kSeqStringTag,
SHORT_ASCII_SYMBOL_TYPE =
kShortStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag,
MEDIUM_ASCII_SYMBOL_TYPE =
kMediumStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag,
LONG_ASCII_SYMBOL_TYPE =
kLongStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag,
SHORT_CONS_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kConsStringTag,
MEDIUM_CONS_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kConsStringTag,
LONG_CONS_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kConsStringTag,
SHORT_CONS_ASCII_SYMBOL_TYPE =
kShortStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag,
MEDIUM_CONS_ASCII_SYMBOL_TYPE =
kMediumStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag,
LONG_CONS_ASCII_SYMBOL_TYPE =
kLongStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag,
SHORT_SLICED_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kSlicedStringTag,
MEDIUM_SLICED_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kSlicedStringTag,
LONG_SLICED_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kSlicedStringTag,
SHORT_SLICED_ASCII_SYMBOL_TYPE =
kShortStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag,
MEDIUM_SLICED_ASCII_SYMBOL_TYPE =
kMediumStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag,
LONG_SLICED_ASCII_SYMBOL_TYPE =
kLongStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag,
SHORT_EXTERNAL_SYMBOL_TYPE =
kShortStringTag | kSymbolTag | kExternalStringTag,
MEDIUM_EXTERNAL_SYMBOL_TYPE =
kMediumStringTag | kSymbolTag | kExternalStringTag,
LONG_EXTERNAL_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kExternalStringTag,
SHORT_EXTERNAL_ASCII_SYMBOL_TYPE =
kShortStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag,
MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE =
kMediumStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag,
LONG_EXTERNAL_ASCII_SYMBOL_TYPE =
kLongStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag,
SHORT_STRING_TYPE = kShortStringTag | kSeqStringTag,
MEDIUM_STRING_TYPE = kMediumStringTag | kSeqStringTag,
LONG_STRING_TYPE = kLongStringTag | kSeqStringTag,
SHORT_ASCII_STRING_TYPE = kShortStringTag | kAsciiStringTag | kSeqStringTag,
MEDIUM_ASCII_STRING_TYPE = kMediumStringTag | kAsciiStringTag | kSeqStringTag,
LONG_ASCII_STRING_TYPE = kLongStringTag | kAsciiStringTag | kSeqStringTag,
SHORT_CONS_STRING_TYPE = kShortStringTag | kConsStringTag,
MEDIUM_CONS_STRING_TYPE = kMediumStringTag | kConsStringTag,
LONG_CONS_STRING_TYPE = kLongStringTag | kConsStringTag,
SHORT_CONS_ASCII_STRING_TYPE =
kShortStringTag | kAsciiStringTag | kConsStringTag,
MEDIUM_CONS_ASCII_STRING_TYPE =
kMediumStringTag | kAsciiStringTag | kConsStringTag,
LONG_CONS_ASCII_STRING_TYPE =
kLongStringTag | kAsciiStringTag | kConsStringTag,
SHORT_SLICED_STRING_TYPE = kShortStringTag | kSlicedStringTag,
MEDIUM_SLICED_STRING_TYPE = kMediumStringTag | kSlicedStringTag,
LONG_SLICED_STRING_TYPE = kLongStringTag | kSlicedStringTag,
SHORT_SLICED_ASCII_STRING_TYPE =
kShortStringTag | kAsciiStringTag | kSlicedStringTag,
MEDIUM_SLICED_ASCII_STRING_TYPE =
kMediumStringTag | kAsciiStringTag | kSlicedStringTag,
LONG_SLICED_ASCII_STRING_TYPE =
kLongStringTag | kAsciiStringTag | kSlicedStringTag,
SHORT_EXTERNAL_STRING_TYPE = kShortStringTag | kExternalStringTag,
MEDIUM_EXTERNAL_STRING_TYPE = kMediumStringTag | kExternalStringTag,
LONG_EXTERNAL_STRING_TYPE = kLongStringTag | kExternalStringTag,
SHORT_EXTERNAL_ASCII_STRING_TYPE =
kShortStringTag | kAsciiStringTag | kExternalStringTag,
MEDIUM_EXTERNAL_ASCII_STRING_TYPE =
kMediumStringTag | kAsciiStringTag | kExternalStringTag,
LONG_EXTERNAL_ASCII_STRING_TYPE =
kLongStringTag | kAsciiStringTag | kExternalStringTag,
LONG_PRIVATE_EXTERNAL_ASCII_STRING_TYPE = LONG_EXTERNAL_ASCII_STRING_TYPE,
MAP_TYPE = kNotStringTag,
HEAP_NUMBER_TYPE,
FIXED_ARRAY_TYPE,
CODE_TYPE,
ODDBALL_TYPE,
PROXY_TYPE,
BYTE_ARRAY_TYPE,
FILLER_TYPE,
SMI_TYPE,
ACCESSOR_INFO_TYPE,
ACCESS_CHECK_INFO_TYPE,
INTERCEPTOR_INFO_TYPE,
SHARED_FUNCTION_INFO_TYPE,
CALL_HANDLER_INFO_TYPE,
FUNCTION_TEMPLATE_INFO_TYPE,
OBJECT_TEMPLATE_INFO_TYPE,
SIGNATURE_INFO_TYPE,
TYPE_SWITCH_INFO_TYPE,
DEBUG_INFO_TYPE,
BREAK_POINT_INFO_TYPE,
SCRIPT_TYPE,
JS_OBJECT_TYPE,
JS_GLOBAL_OBJECT_TYPE,
JS_BUILTINS_OBJECT_TYPE,
JS_VALUE_TYPE,
JS_ARRAY_TYPE,
JS_FUNCTION_TYPE,
// Pseudo-types
FIRST_NONSTRING_TYPE = MAP_TYPE,
FIRST_TYPE = 0x0,
LAST_TYPE = JS_FUNCTION_TYPE,
// Boundaries for testing the type is a JavaScript "object". Note that
// function objects are not counted as objects, even though they are
// implemented as such; only values whose typeof is "object" are included.
FIRST_JS_OBJECT_TYPE = JS_OBJECT_TYPE,
LAST_JS_OBJECT_TYPE = JS_ARRAY_TYPE
};
enum CompareResult {
LESS = -1,
EQUAL = 0,
GREATER = 1,
NOT_EQUAL = GREATER
};
#define DECL_BOOLEAN_ACCESSORS(name) \
inline bool name(); \
inline void set_##name(bool value); \
#define DECL_ACCESSORS(name, type) \
inline type* name(); \
inline void set_##name(type* value);
class StringStream;
class ObjectVisitor;
struct ValueInfo : public Malloced {
ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { }
InstanceType type;
Object* ptr;
const char* str;
double number;
};
// A template-ized version of the IsXXX functions.
template <class C> static inline bool Is(Object* obj);
// Object is the abstract superclass for all classes in the
// object hierarchy.
// Object does not use any virtual functions to avoid the
// allocation of the C++ vtable.
// Since Smi and Failure are subclasses of Object no
// data members can be present in Object.
class Object BASE_EMBEDDED {
public:
// Type testing.
inline bool IsSmi();
inline bool IsHeapObject();
inline bool IsHeapNumber();
inline bool IsString();
inline bool IsSeqString();
inline bool IsAsciiString();
inline bool IsTwoByteString();
inline bool IsConsString();
inline bool IsSlicedString();
inline bool IsExternalString();
inline bool IsExternalAsciiString();
inline bool IsExternalTwoByteString();
inline bool IsShortString();
inline bool IsMediumString();
inline bool IsLongString();
inline bool IsSymbol();
inline bool IsNumber();
inline bool IsByteArray();
inline bool IsFailure();
inline bool IsRetryAfterGC();
inline bool IsException();
inline bool IsJSObject();
inline bool IsMap();
inline bool IsFixedArray();
inline bool IsDescriptorArray();
inline bool IsContext();
inline bool IsGlobalContext();
inline bool IsJSFunction();
inline bool IsCode();
inline bool IsOddball();
inline bool IsSharedFunctionInfo();
inline bool IsJSValue();
inline bool IsProxy();
inline bool IsBoolean();
inline bool IsJSArray();
inline bool IsHashTable();
inline bool IsDictionary();
inline bool IsSymbolTable();
inline bool IsPrimitive();
inline bool IsGlobalObject();
inline bool IsJSGlobalObject();
inline bool IsJSBuiltinsObject();
inline bool IsUndetectableObject();
inline bool IsAccessCheckNeeded();
// Returns true if this object is an instance of the specified
// function template.
bool IsInstanceOf(FunctionTemplateInfo* type);
inline bool IsStruct();
#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
#undef DECLARE_STRUCT_PREDICATE
// Oddball testing.
INLINE(bool IsUndefined());
INLINE(bool IsTheHole());
INLINE(bool IsNull());
INLINE(bool IsTrue());
INLINE(bool IsFalse());
// Extract the number.
inline double Number();
Object* ToObject(); // ECMA-262 9.9.
Object* ToBoolean(); // ECMA-262 9.2.
// Convert to a JSObject if needed.
// global_context is used when creating wrapper object.
Object* ToObject(Context* global_context);
// Converts this to a Smi if possible.
// Failure is returned otherwise.
inline Object* ToSmi();
void Lookup(String* name, LookupResult* result);
// Property access.
inline Object* GetProperty(String* key);
inline Object* GetProperty(String* key, PropertyAttributes* attributes);
Object* GetPropertyWithReceiver(Object* receiver,
String* key,
PropertyAttributes* attributes);
Object* GetProperty(Object* receiver,
LookupResult* result,
String* key,
PropertyAttributes* attributes);
Object* GetPropertyWithCallback(Object* receiver,
Object* structure,
String* name,
Object* holder);
inline Object* GetElement(uint32_t index);
Object* GetElementWithReceiver(Object* receiver, uint32_t index);
// Return the object's prototype (might be Heap::null_value()).
Object* GetPrototype();
// Returns true if this is a JSValue containing a string and the index is
// < the length of the string. Used to implement [] on strings.
inline bool IsStringObjectWithCharacterAt(uint32_t index);
#ifdef DEBUG
// Prints this object with details.
void Print();
void PrintLn();
// Verifies the object.
void Verify();
// Verify a pointer is a valid object pointer.
static void VerifyPointer(Object* p);
#endif
// Prints this object without details.
void ShortPrint();
// Prints this object without details to a message accumulator.
void ShortPrint(StringStream* accumulator);
// Casting: This cast is only needed to satisfy macros in objects-inl.h.
static Object* cast(Object* value) { return value; }
// Layout description.
static const int kSize = 0; // Object does not take up any space.
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
};
// Smi represents integer Numbers that can be stored in 31 bits.
// Smis are immediate which means they are NOT allocated in the heap.
// The this pointer has the following format: [31 bit signed int] 0
// Smi stands for small integer.
class Smi: public Object {
public:
// Returns the integer value.
inline int value();
// Convert a value to a Smi object.
static inline Smi* FromInt(int value);
// Returns whether value can be represented in a Smi.
static inline bool IsValid(int value);
// Casting.
static inline Smi* cast(Object* object);
// Dispatched behavior.
void SmiPrint();
void SmiPrint(StringStream* accumulator);
#ifdef DEBUG
void SmiVerify();
#endif
// Min and max limits for Smi values.
static const int kMinValue = -(1 << (kBitsPerPointer - (kSmiTagSize + 1)));
static const int kMaxValue = (1 << (kBitsPerPointer - (kSmiTagSize + 1))) - 1;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
};
// Failure is used for reporing out of memory situations and
// propagating exceptions through the runtime system. Failure objects
// are transient and cannot occur as part of the objects graph.
//
// Failures are a single word, encoded as follows:
// +-------------------------+---+--+--+
// |rrrrrrrrrrrrrrrrrrrrrrrrr|sss|tt|11|
// +-------------------------+---+--+--+
//
// The low two bits, 0-1, are the failure tag, 11. The next two bits,
// 2-3, are a failure type tag 'tt' with possible values:
// 00 RETRY_AFTER_GC
// 01 EXCEPTION
// 10 INTERNAL_ERROR
// 11 OUT_OF_MEMORY_EXCEPTION
//
// The next three bits, 4-6, are an allocation space tag 'sss'. The
// allocation space tag is 000 for all failure types except
// RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are
// (the encoding is found in globals.h):
// 000 NEW_SPACE
// 001 OLD_SPACE
// 010 CODE_SPACE
// 011 MAP_SPACE
// 100 LO_SPACE
//
// The remaining bits is the number of words requested by the
// allocation request that failed, and is zeroed except for
// RETRY_AFTER_GC failures. The 25 bits (on a 32 bit platform) gives
// a representable range of 2^27 bytes (128MB).
// Failure type tag info.
const int kFailureTypeTagSize = 2;
const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
class Failure: public Object {
public:
// RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
enum Type {
RETRY_AFTER_GC = 0,
EXCEPTION = 1, // Returning this marker tells the real exception
// is in Top::pending_exception.
INTERNAL_ERROR = 2,
OUT_OF_MEMORY_EXCEPTION = 3
};
inline Type type() const;
// Returns the space that needs to be collected for RetryAfterGC failures.
inline AllocationSpace allocation_space() const;
// Returns the number of bytes requested (up to the representable maximum)
// for RetryAfterGC failures.
inline int requested() const;
inline bool IsInternalError() const;
inline bool IsOutOfMemoryException() const;
static Failure* RetryAfterGC(int requested_bytes, AllocationSpace space);
static inline Failure* Exception();
static inline Failure* InternalError();
static inline Failure* OutOfMemoryException();
// Casting.
static inline Failure* cast(Object* object);
// Dispatched behavior.
void FailurePrint();
void FailurePrint(StringStream* accumulator);
#ifdef DEBUG
void FailureVerify();
#endif
private:
inline int value() const;
static inline Failure* Construct(Type type, int value = 0);
DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
};
// HeapObject is the superclass for all classes describing heap allocated
// objects.
class HeapObject: public Object {
public:
// [map]: contains a Map which contains the objects reflective information.
inline Map* map();
inline void set_map(Map* value);
// Converts an address to a HeapObject pointer.
static inline HeapObject* FromAddress(Address address);
// Returns the address of this HeapObject.
inline Address address();
// Iterates over pointers contained in the object (including the Map)
void Iterate(ObjectVisitor* v);
// Iterates over all pointers contained in the object except the
// first map pointer. The object type is given in the first
// parameter. This function does not access the map pointer in the
// object, and so is safe to call while the map pointer is modified.
void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
// This method only applies to struct objects. Iterates over all the fields
// of this struct.
void IterateStructBody(int object_size, ObjectVisitor* v);
// Copy the body from the 'from' object to this.
// Please note the two object must have the same map prior to the call.
inline void CopyBody(JSObject* from);
// Returns the heap object's size in bytes
inline int Size();
// Given a heap object's map pointer, returns the heap size in bytes
// Useful when the map pointer field is used for other purposes.
// GC internal.
inline int SizeFromMap(Map* map);
static inline Object* GetHeapObjectField(HeapObject* obj, int index);
// Casting.
static inline HeapObject* cast(Object* obj);
// Dispatched behavior.
void HeapObjectShortPrint(StringStream* accumulator);
#ifdef DEBUG
void HeapObjectPrint();
void HeapObjectVerify();
inline void VerifyObjectField(int offset);
void PrintHeader(const char* id);
// Verify a pointer is a valid HeapObject pointer that points to object
// areas in the heap.
static void VerifyHeapPointer(Object* p);
#endif
// Layout description.
// First field in a heap object is map.
static const int kMapOffset = Object::kSize;
static const int kSize = kMapOffset + kPointerSize;
protected:
// helpers for calling an ObjectVisitor to iterate over pointers in the
// half-open range [start, end) specified as integer offsets
inline void IteratePointers(ObjectVisitor* v, int start, int end);
// as above, for the single element at "offset"
inline void IteratePointer(ObjectVisitor* v, int offset);
// Computes the object size from the map.
// Should only be used from SizeFromMap.
int SlowSizeFromMap(Map* map);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
};
// The HeapNumber class describes heap allocated numbers that cannot be
// represented in a Smi (small integer)
class HeapNumber: public HeapObject {
public:
// [value]: number value.
inline double value();
inline void set_value(double value);
// Casting.
static inline HeapNumber* cast(Object* obj);
// Dispatched behavior.
Object* HeapNumberToBoolean();
void HeapNumberPrint();
void HeapNumberPrint(StringStream* accumulator);
#ifdef DEBUG
void HeapNumberVerify();
#endif
// Layout description.
static const int kValueOffset = HeapObject::kSize;
static const int kSize = kValueOffset + kDoubleSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
};
// The JSObject describes real heap allocated JavaScript objects with
// properties.
// Note that the map of JSObject changes during execution to enable inline
// caching.
class JSObject: public HeapObject {
public:
// [properties]: Backing storage for properties.
DECL_ACCESSORS(properties, FixedArray)
inline void initialize_properties();
// [elements]: The elements in the fast case.
DECL_ACCESSORS(elements, HeapObject)
inline void initialize_elements();
// Accessors for properties.
inline bool HasFastProperties();
// Do we want to keep the elements in fast case when increasing the
// capacity?
bool KeepInFastCase(int new_capacity);
// Accessors for slow properties
inline Dictionary* property_dictionary(); // asserts !HasFastProperties
inline Dictionary* element_dictionary(); // asserts !HasFastElements
Object* SetProperty(String* key,
Object* value,
PropertyAttributes attributes);
Object* SetProperty(LookupResult* result,
String* key,
Object* value,
PropertyAttributes attributes);
Object* SetPropertyWithFailedAccessCheck(LookupResult* result,
String* name,
Object* value);
Object* SetPropertyWithCallback(Object* structure,
String* name,
Object* value,
JSObject* holder);
Object* SetPropertyWithInterceptor(String* name,
Object* value,
PropertyAttributes attributes);
Object* SetPropertyPostInterceptor(String* name,
Object* value,
PropertyAttributes attributes);
Object* IgnoreAttributesAndSetLocalProperty(String* key,
Object* value);
Object* SetLazyProperty(LookupResult* result,
String* name,
Object* value,
PropertyAttributes attributes);
// Returns the class name ([[Class]] property in the specification).
String* class_name();
// Retrieve interceptors.
InterceptorInfo* GetNamedInterceptor();
InterceptorInfo* GetIndexedInterceptor();
inline PropertyAttributes GetPropertyAttribute(String* name);
PropertyAttributes GetPropertyAttributeWithReceiver(JSObject* receiver,
String* name);
PropertyAttributes GetLocalPropertyAttribute(String* name);
Object* DefineAccessor(String* name, bool is_getter, JSFunction* fun,
PropertyAttributes attributes);
Object* LookupAccessor(String* name, bool is_getter);
// Used from Object::GetProperty().
Object* GetPropertyWithFailedAccessCheck(Object* receiver,
LookupResult* result,
String* name);
Object* GetPropertyWithInterceptor(JSObject* receiver,