Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: src/contexts.h

Issue 1306993003: Call JS functions via native context instead of js builtins object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | src/contexts.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_CONTEXTS_H_ 5 #ifndef V8_CONTEXTS_H_
6 #define V8_CONTEXTS_H_ 6 #define V8_CONTEXTS_H_
7 7
8 #include "src/heap/heap.h" 8 #include "src/heap/heap.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 // Heap-allocated activation contexts. 67 // Heap-allocated activation contexts.
68 // 68 //
69 // Contexts are implemented as FixedArray objects; the Context 69 // Contexts are implemented as FixedArray objects; the Context
70 // class is a convenience interface casted on a FixedArray object. 70 // class is a convenience interface casted on a FixedArray object.
71 // 71 //
72 // Note: Context must have no virtual functions and Context objects 72 // Note: Context must have no virtual functions and Context objects
73 // must always be allocated via Heap::AllocateContext() or 73 // must always be allocated via Heap::AllocateContext() or
74 // Factory::NewContext. 74 // Factory::NewContext.
75 75
76 #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \
77 V(CONCAT_ITERABLE_TO_ARRAY_INDEX, JSFunction, concat_iterable_to_array) \
78 V(GET_TEMPLATE_CALL_SITE_INDEX, JSFunction, get_template_call_site) \
79 V(MAKE_RANGE_ERROR_INDEX, JSFunction, make_range_error) \
80 V(MAKE_TYPE_ERROR_INDEX, JSFunction, make_type_error) \
81 V(NON_NUMBER_TO_NUMBER_INDEX, JSFunction, non_number_to_number) \
82 V(NON_STRING_TO_STRING_INDEX, JSFunction, non_string_to_string) \
83 V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \
84 V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \
85 V(SPREAD_ARGUMENTS_INDEX, JSFunction, spread_arguments) \
86 V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable) \
87 V(TO_LENGTH_FUN_INDEX, JSFunction, to_length_fun) \
88 V(TO_NAME_INDEX, JSFunction, to_name) \
89 V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun) \
90 V(TO_PRIMITIVE_INDEX, JSFunction, to_primitive) \
91 V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun)
92
76 #define NATIVE_CONTEXT_IMPORTED_FIELDS(V) \ 93 #define NATIVE_CONTEXT_IMPORTED_FIELDS(V) \
77 V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \ 94 V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
78 V(CREATE_DATE_FUN_INDEX, JSFunction, create_date_fun) \ 95 V(CREATE_DATE_FUN_INDEX, JSFunction, create_date_fun) \
96 V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
97 V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \
98 V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap) \
79 V(ERROR_FUNCTION_INDEX, JSFunction, error_function) \ 99 V(ERROR_FUNCTION_INDEX, JSFunction, error_function) \
80 V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \ 100 V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \
81 V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \ 101 V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \
82 V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \ 102 V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \
83 V(JSON_SERIALIZE_ADAPTER_INDEX, JSFunction, json_serialize_adapter) \ 103 V(JSON_SERIALIZE_ADAPTER_INDEX, JSFunction, json_serialize_adapter) \
84 V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \ 104 V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \
85 V(MAP_DELETE_METHOD_INDEX, JSFunction, map_delete) \ 105 V(MAP_DELETE_METHOD_INDEX, JSFunction, map_delete) \
86 V(MAP_FROM_ARRAY_INDEX, JSFunction, map_from_array) \ 106 V(MAP_FROM_ARRAY_INDEX, JSFunction, map_from_array) \
87 V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \ 107 V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \
88 V(MAP_HAS_METHOD_INDEX, JSFunction, map_has) \ 108 V(MAP_HAS_METHOD_INDEX, JSFunction, map_has) \
(...skipping 15 matching lines...) Expand all
104 V(OBSERVERS_ENQUEUE_SPLICE_INDEX, JSFunction, observers_enqueue_splice) \ 124 V(OBSERVERS_ENQUEUE_SPLICE_INDEX, JSFunction, observers_enqueue_splice) \
105 V(OBSERVERS_NOTIFY_CHANGE_INDEX, JSFunction, observers_notify_change) \ 125 V(OBSERVERS_NOTIFY_CHANGE_INDEX, JSFunction, observers_notify_change) \
106 V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \ 126 V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \
107 V(PROMISE_CHAIN_INDEX, JSFunction, promise_chain) \ 127 V(PROMISE_CHAIN_INDEX, JSFunction, promise_chain) \
108 V(PROMISE_CREATE_INDEX, JSFunction, promise_create) \ 128 V(PROMISE_CREATE_INDEX, JSFunction, promise_create) \
109 V(PROMISE_HAS_USER_DEFINED_REJECT_HANDLER_INDEX, JSFunction, \ 129 V(PROMISE_HAS_USER_DEFINED_REJECT_HANDLER_INDEX, JSFunction, \
110 promise_has_user_defined_reject_handler) \ 130 promise_has_user_defined_reject_handler) \
111 V(PROMISE_REJECT_INDEX, JSFunction, promise_reject) \ 131 V(PROMISE_REJECT_INDEX, JSFunction, promise_reject) \
112 V(PROMISE_RESOLVE_INDEX, JSFunction, promise_resolve) \ 132 V(PROMISE_RESOLVE_INDEX, JSFunction, promise_resolve) \
113 V(PROMISE_THEN_INDEX, JSFunction, promise_then) \ 133 V(PROMISE_THEN_INDEX, JSFunction, promise_then) \
134 V(PROXY_ENUMERATE_INDEX, JSFunction, proxy_enumerate) \
114 V(RANGE_ERROR_FUNCTION_INDEX, JSFunction, range_error_function) \ 135 V(RANGE_ERROR_FUNCTION_INDEX, JSFunction, range_error_function) \
115 V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \ 136 V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \
116 V(SET_ADD_METHOD_INDEX, JSFunction, set_add) \ 137 V(SET_ADD_METHOD_INDEX, JSFunction, set_add) \
117 V(SET_DELETE_METHOD_INDEX, JSFunction, set_delete) \ 138 V(SET_DELETE_METHOD_INDEX, JSFunction, set_delete) \
118 V(SET_FROM_ARRAY_INDEX, JSFunction, set_from_array) \ 139 V(SET_FROM_ARRAY_INDEX, JSFunction, set_from_array) \
119 V(SET_HAS_METHOD_INDEX, JSFunction, set_has) \ 140 V(SET_HAS_METHOD_INDEX, JSFunction, set_has) \
120 V(STACK_OVERFLOW_BOILERPLATE_INDEX, JSObject, stack_overflow_boilerplate) \ 141 V(STACK_OVERFLOW_BOILERPLATE_INDEX, JSObject, stack_overflow_boilerplate) \
121 V(SYNTAX_ERROR_FUNCTION_INDEX, JSFunction, syntax_error_function) \ 142 V(SYNTAX_ERROR_FUNCTION_INDEX, JSFunction, syntax_error_function) \
122 V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \ 143 V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \
123 to_complete_property_descriptor) \ 144 to_complete_property_descriptor) \
124 V(TO_DETAIL_STRING_FUN_INDEX, JSFunction, to_detail_string_fun) \ 145 V(TO_DETAIL_STRING_FUN_INDEX, JSFunction, to_detail_string_fun) \
125 V(TO_INTEGER_FUN_INDEX, JSFunction, to_integer_fun) \ 146 V(TO_INTEGER_FUN_INDEX, JSFunction, to_integer_fun) \
126 V(TO_LENGTH_FUN_INDEX, JSFunction, to_length_fun) \
127 V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun) \
128 V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun) \
129 V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \ 147 V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \
130 V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function) 148 V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function)
131 149
132 #define NATIVE_CONTEXT_IMPORTED_FIELDS_FOR_PROXY(V) \
133 V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
134 V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \
135 V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap) \
136 V(PROXY_ENUMERATE_INDEX, JSFunction, proxy_enumerate)
137
138 #define NATIVE_CONTEXT_FIELDS(V) \ 150 #define NATIVE_CONTEXT_FIELDS(V) \
139 V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \ 151 V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \
140 V(EMBEDDER_DATA_INDEX, FixedArray, embedder_data) \ 152 V(EMBEDDER_DATA_INDEX, FixedArray, embedder_data) \
141 /* Below is alpha-sorted */ \ 153 /* Below is alpha-sorted */ \
142 V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \ 154 V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \
143 V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \ 155 V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \
144 V(ARRAY_BUFFER_MAP_INDEX, Map, array_buffer_map) \ 156 V(ARRAY_BUFFER_MAP_INDEX, Map, array_buffer_map) \
145 V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \ 157 V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \
146 V(BOOL16X8_FUNCTION_INDEX, JSFunction, bool16x8_function) \ 158 V(BOOL16X8_FUNCTION_INDEX, JSFunction, bool16x8_function) \
147 V(BOOL32X4_FUNCTION_INDEX, JSFunction, bool32x4_function) \ 159 V(BOOL32X4_FUNCTION_INDEX, JSFunction, bool32x4_function) \
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 V(STRONG_GENERATOR_FUNCTION_MAP_INDEX, Map, strong_generator_function_map) \ 227 V(STRONG_GENERATOR_FUNCTION_MAP_INDEX, Map, strong_generator_function_map) \
216 V(STRONG_MAP_CACHE_INDEX, Object, strong_map_cache) \ 228 V(STRONG_MAP_CACHE_INDEX, Object, strong_map_cache) \
217 V(SYMBOL_FUNCTION_INDEX, JSFunction, symbol_function) \ 229 V(SYMBOL_FUNCTION_INDEX, JSFunction, symbol_function) \
218 V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \ 230 V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \
219 V(UINT16X8_FUNCTION_INDEX, JSFunction, uint16x8_function) \ 231 V(UINT16X8_FUNCTION_INDEX, JSFunction, uint16x8_function) \
220 V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \ 232 V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \
221 V(UINT32X4_FUNCTION_INDEX, JSFunction, uint32x4_function) \ 233 V(UINT32X4_FUNCTION_INDEX, JSFunction, uint32x4_function) \
222 V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \ 234 V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
223 V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \ 235 V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \
224 V(UINT8X16_FUNCTION_INDEX, JSFunction, uint8x16_function) \ 236 V(UINT8X16_FUNCTION_INDEX, JSFunction, uint8x16_function) \
225 NATIVE_CONTEXT_IMPORTED_FIELDS(V) \ 237 NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \
226 NATIVE_CONTEXT_IMPORTED_FIELDS_FOR_PROXY(V) 238 NATIVE_CONTEXT_IMPORTED_FIELDS(V)
227 239
228 // A table of all script contexts. Every loaded top-level script with top-level 240 // A table of all script contexts. Every loaded top-level script with top-level
229 // lexical declarations contributes its ScriptContext into this table. 241 // lexical declarations contributes its ScriptContext into this table.
230 // 242 //
231 // The table is a fixed array, its first slot is the current used count and 243 // The table is a fixed array, its first slot is the current used count and
232 // the subsequent slots 1..used contain ScriptContexts. 244 // the subsequent slots 1..used contain ScriptContexts.
233 class ScriptContextTable : public FixedArray { 245 class ScriptContextTable : public FixedArray {
234 public: 246 public:
235 // Conversions. 247 // Conversions.
236 static ScriptContextTable* cast(Object* context) { 248 static ScriptContextTable* cast(Object* context) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 // The native context also stores a list of all optimized code and a 481 // The native context also stores a list of all optimized code and a
470 // list of all deoptimized code, which are needed by the deoptimizer. 482 // list of all deoptimized code, which are needed by the deoptimizer.
471 void AddOptimizedCode(Code* code); 483 void AddOptimizedCode(Code* code);
472 void SetOptimizedCodeListHead(Object* head); 484 void SetOptimizedCodeListHead(Object* head);
473 Object* OptimizedCodeListHead(); 485 Object* OptimizedCodeListHead();
474 void SetDeoptimizedCodeListHead(Object* head); 486 void SetDeoptimizedCodeListHead(Object* head);
475 Object* DeoptimizedCodeListHead(); 487 Object* DeoptimizedCodeListHead();
476 488
477 Handle<Object> ErrorMessageForCodeGenerationFromStrings(); 489 Handle<Object> ErrorMessageForCodeGenerationFromStrings();
478 490
491 static int ImportedFieldIndexForName(Handle<String> name);
492 static int IntrinsicIndexForName(Handle<String> name);
493
479 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ 494 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
480 void set_##name(type* value) { \ 495 void set_##name(type* value) { \
481 DCHECK(IsNativeContext()); \ 496 DCHECK(IsNativeContext()); \
482 set(index, value); \ 497 set(index, value); \
483 } \ 498 } \
484 bool is_##name(type* value) { \ 499 bool is_##name(type* value) { \
485 DCHECK(IsNativeContext()); \ 500 DCHECK(IsNativeContext()); \
486 return type::cast(get(index)) == value; \ 501 return type::cast(get(index)) == value; \
487 } \ 502 } \
488 type* name() { \ 503 type* name() { \
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 ? STRONG_FUNCTION_MAP_INDEX 554 ? STRONG_FUNCTION_MAP_INDEX
540 : STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX; 555 : STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX;
541 } 556 }
542 557
543 return is_strong(language_mode) ? STRONG_FUNCTION_MAP_INDEX : 558 return is_strong(language_mode) ? STRONG_FUNCTION_MAP_INDEX :
544 is_strict(language_mode) ? STRICT_FUNCTION_MAP_INDEX 559 is_strict(language_mode) ? STRICT_FUNCTION_MAP_INDEX
545 : SLOPPY_FUNCTION_MAP_INDEX; 560 : SLOPPY_FUNCTION_MAP_INDEX;
546 } 561 }
547 562
548 static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize; 563 static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize;
564 static const int kNotFound = -1;
549 565
550 // GC support. 566 // GC support.
551 typedef FixedBodyDescriptor< 567 typedef FixedBodyDescriptor<
552 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor; 568 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor;
553 569
554 typedef FixedBodyDescriptor< 570 typedef FixedBodyDescriptor<
555 kHeaderSize, 571 kHeaderSize,
556 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, 572 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize,
557 kSize> MarkCompactBodyDescriptor; 573 kSize> MarkCompactBodyDescriptor;
558 574
559 private: 575 private:
560 // Unchecked access to the slots. 576 // Unchecked access to the slots.
561 Object* unchecked_previous() { return get(PREVIOUS_INDEX); } 577 Object* unchecked_previous() { return get(PREVIOUS_INDEX); }
562 578
563 #ifdef DEBUG 579 #ifdef DEBUG
564 // Bootstrapping-aware type checks. 580 // Bootstrapping-aware type checks.
565 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); 581 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid);
566 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); 582 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object);
567 #endif 583 #endif
568 584
569 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); 585 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize);
570 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); 586 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex);
571 }; 587 };
572 588
573 } } // namespace v8::internal 589 } } // namespace v8::internal
574 590
575 #endif // V8_CONTEXTS_H_ 591 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698