OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
11 #include "src/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
12 #include "src/compiler.h" | 12 #include "src/compiler.h" |
13 #include "src/conversions.h" | 13 #include "src/conversions.h" |
14 #include "src/isolate-inl.h" | 14 #include "src/isolate-inl.h" |
15 #include "src/macro-assembler.h" | 15 #include "src/macro-assembler.h" |
16 #include "src/objects/frame-array-inl.h" | 16 #include "src/objects/frame-array-inl.h" |
17 #include "src/objects/module-info.h" | 17 #include "src/objects/module-info.h" |
18 #include "src/objects/scope-info.h" | 18 #include "src/objects/scope-info.h" |
19 #include "src/string-builder.h" | |
19 | 20 |
20 namespace v8 { | 21 namespace v8 { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 | 24 |
24 // Calls the FUNCTION_CALL function and retries it up to three times | 25 // Calls the FUNCTION_CALL function and retries it up to three times |
25 // to guarantee that any allocations performed during the call will | 26 // to guarantee that any allocations performed during the call will |
26 // succeed if there's enough memory. | 27 // succeed if there's enough memory. |
27 // | 28 // |
28 // Warning: Do not use the identifiers __object__, __maybe_object__, | 29 // Warning: Do not use the identifiers __object__, __maybe_object__, |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 return iterator; | 903 return iterator; |
903 } | 904 } |
904 | 905 |
905 Handle<Symbol> Factory::NewSymbol() { | 906 Handle<Symbol> Factory::NewSymbol() { |
906 CALL_HEAP_FUNCTION( | 907 CALL_HEAP_FUNCTION( |
907 isolate(), | 908 isolate(), |
908 isolate()->heap()->AllocateSymbol(), | 909 isolate()->heap()->AllocateSymbol(), |
909 Symbol); | 910 Symbol); |
910 } | 911 } |
911 | 912 |
913 MaybeHandle<Symbol> Factory::NewSymbol(Handle<Object> name) { | |
914 DCHECK(name->IsString() || name->IsUndefined(isolate())); | |
915 Handle<Symbol> symbol = NewSymbol(); | |
916 if (name->IsString()) { | |
917 // Compute the descriptive string for the {symbol}. | |
918 Handle<String> descriptive_string; | |
919 IncrementalStringBuilder builder(isolate()); | |
920 builder.AppendCString("Symbol("); | |
921 builder.AppendString(Handle<String>::cast(name)); | |
922 builder.AppendCharacter(')'); | |
923 ASSIGN_RETURN_ON_EXCEPTION(isolate(), descriptive_string, builder.Finish(), | |
924 Symbol); | |
925 | |
926 // Make sure those strings are flattened. | |
927 name = String::Flatten(Handle<String>::cast(name), TENURED); | |
928 descriptive_string = String::Flatten(descriptive_string, TENURED); | |
929 | |
930 symbol->set_name(String::cast(*name)); | |
931 symbol->set_descriptive_string(String::cast(*descriptive_string)); | |
Igor Sheludko
2017/05/23 07:08:23
String::cast is not necessary here.
Benedikt Meurer
2017/05/23 08:37:39
Done.
| |
932 } | |
933 return symbol; | |
934 } | |
912 | 935 |
913 Handle<Symbol> Factory::NewPrivateSymbol() { | 936 Handle<Symbol> Factory::NewPrivateSymbol() { |
Igor Sheludko
2017/05/23 07:08:23
Is this method still used?
Benedikt Meurer
2017/05/23 08:37:39
Yes.
| |
914 Handle<Symbol> symbol = NewSymbol(); | 937 Handle<Symbol> symbol = NewSymbol(); |
915 symbol->set_is_private(true); | 938 symbol->set_is_private(true); |
916 return symbol; | 939 return symbol; |
917 } | 940 } |
918 | 941 |
942 MaybeHandle<Symbol> Factory::NewPrivateSymbol(Handle<Object> name) { | |
943 Handle<Symbol> symbol; | |
944 ASSIGN_RETURN_ON_EXCEPTION(isolate(), symbol, NewSymbol(name), Symbol); | |
945 symbol->set_is_private(true); | |
946 return symbol; | |
947 } | |
948 | |
919 Handle<JSPromise> Factory::NewJSPromise() { | 949 Handle<JSPromise> Factory::NewJSPromise() { |
920 Handle<JSFunction> constructor( | 950 Handle<JSFunction> constructor( |
921 isolate()->native_context()->promise_function(), isolate()); | 951 isolate()->native_context()->promise_function(), isolate()); |
922 DCHECK(constructor->has_initial_map()); | 952 DCHECK(constructor->has_initial_map()); |
923 Handle<Map> map(constructor->initial_map(), isolate()); | 953 Handle<Map> map(constructor->initial_map(), isolate()); |
924 | 954 |
925 DCHECK(!map->is_prototype_map()); | 955 DCHECK(!map->is_prototype_map()); |
926 Handle<JSObject> promise_obj = NewJSObjectFromMap(map); | 956 Handle<JSObject> promise_obj = NewJSObjectFromMap(map); |
927 Handle<JSPromise> promise = Handle<JSPromise>::cast(promise_obj); | 957 Handle<JSPromise> promise = Handle<JSPromise>::cast(promise_obj); |
928 promise->set_status(v8::Promise::kPending); | 958 promise->set_status(v8::Promise::kPending); |
(...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2952 Handle<AccessorInfo> prototype = | 2982 Handle<AccessorInfo> prototype = |
2953 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2983 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
2954 Descriptor d = Descriptor::AccessorConstant( | 2984 Descriptor d = Descriptor::AccessorConstant( |
2955 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2985 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
2956 map->AppendDescriptor(&d); | 2986 map->AppendDescriptor(&d); |
2957 } | 2987 } |
2958 } | 2988 } |
2959 | 2989 |
2960 } // namespace internal | 2990 } // namespace internal |
2961 } // namespace v8 | 2991 } // namespace v8 |
OLD | NEW |