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/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 PretenureFlag pretenure) { | 1187 PretenureFlag pretenure) { |
1188 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; | 1188 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; |
1189 Handle<JSFunction> function = New<JSFunction>(map, space); | 1189 Handle<JSFunction> function = New<JSFunction>(map, space); |
1190 | 1190 |
1191 function->initialize_properties(); | 1191 function->initialize_properties(); |
1192 function->initialize_elements(); | 1192 function->initialize_elements(); |
1193 function->set_shared(*info); | 1193 function->set_shared(*info); |
1194 function->set_code(info->code()); | 1194 function->set_code(info->code()); |
1195 function->set_context(*context); | 1195 function->set_context(*context); |
1196 function->set_prototype_or_initial_map(*the_hole_value()); | 1196 function->set_prototype_or_initial_map(*the_hole_value()); |
1197 function->set_literals(LiteralsArray::cast(*empty_fixed_array())); | 1197 function->set_literals_or_bindings(*empty_fixed_array()); |
1198 function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER); | 1198 function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER); |
1199 isolate()->heap()->InitializeJSObjectBody(*function, *map, JSFunction::kSize); | 1199 isolate()->heap()->InitializeJSObjectBody(*function, *map, JSFunction::kSize); |
1200 return function; | 1200 return function; |
1201 } | 1201 } |
1202 | 1202 |
1203 | 1203 |
1204 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1204 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1205 Handle<String> name, | 1205 Handle<String> name, |
1206 MaybeHandle<Code> code) { | 1206 MaybeHandle<Code> code) { |
1207 Handle<Context> context(isolate()->native_context()); | 1207 Handle<Context> context(isolate()->native_context()); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 context->native_context(), BailoutId::None()); | 1352 context->native_context(), BailoutId::None()); |
1353 if (cached.code != nullptr) { | 1353 if (cached.code != nullptr) { |
1354 // Caching of optimized code enabled and optimized code found. | 1354 // Caching of optimized code enabled and optimized code found. |
1355 DCHECK(!cached.code->marked_for_deoptimization()); | 1355 DCHECK(!cached.code->marked_for_deoptimization()); |
1356 DCHECK(result->shared()->is_compiled()); | 1356 DCHECK(result->shared()->is_compiled()); |
1357 result->ReplaceCode(cached.code); | 1357 result->ReplaceCode(cached.code); |
1358 } | 1358 } |
1359 | 1359 |
1360 if (cached.literals != nullptr) { | 1360 if (cached.literals != nullptr) { |
1361 result->set_literals(cached.literals); | 1361 result->set_literals(cached.literals); |
1362 } else { | 1362 |
| 1363 } else if (!info->bound()) { |
1363 int number_of_literals = info->num_literals(); | 1364 int number_of_literals = info->num_literals(); |
1364 Handle<LiteralsArray> literals = | 1365 Handle<LiteralsArray> literals = |
1365 LiteralsArray::New(isolate(), handle(info->feedback_vector()), | 1366 LiteralsArray::New(isolate(), handle(info->feedback_vector()), |
1366 number_of_literals, pretenure); | 1367 number_of_literals, pretenure); |
1367 result->set_literals(*literals); | 1368 result->set_literals(*literals); |
1368 | 1369 |
1369 // Cache context-specific literals. | 1370 // Cache context-specific literals. |
1370 Handle<Context> native_context(context->native_context()); | 1371 Handle<Context> native_context(context->native_context()); |
1371 SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context, | 1372 SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context, |
1372 literals); | 1373 literals); |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1934 | 1935 |
1935 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, | 1936 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, |
1936 size_t byte_offset, | 1937 size_t byte_offset, |
1937 size_t byte_length) { | 1938 size_t byte_length) { |
1938 Handle<JSDataView> obj = NewJSDataView(); | 1939 Handle<JSDataView> obj = NewJSDataView(); |
1939 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); | 1940 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); |
1940 return obj; | 1941 return obj; |
1941 } | 1942 } |
1942 | 1943 |
1943 | 1944 |
1944 MaybeHandle<JSBoundFunction> Factory::NewJSBoundFunction( | |
1945 Handle<JSReceiver> target_function, Handle<Object> bound_this, | |
1946 Vector<Handle<Object>> bound_args) { | |
1947 DCHECK(target_function->IsCallable()); | |
1948 STATIC_ASSERT(Code::kMaxArguments <= FixedArray::kMaxLength); | |
1949 if (bound_args.length() >= Code::kMaxArguments) { | |
1950 THROW_NEW_ERROR(isolate(), | |
1951 NewRangeError(MessageTemplate::kTooManyArguments), | |
1952 JSBoundFunction); | |
1953 } | |
1954 | |
1955 // Determine the prototype of the {target_function}. | |
1956 Handle<Object> prototype; | |
1957 ASSIGN_RETURN_ON_EXCEPTION(isolate(), prototype, | |
1958 Object::GetPrototype(isolate(), target_function), | |
1959 JSBoundFunction); | |
1960 | |
1961 // Create the [[BoundArguments]] for the result. | |
1962 Handle<FixedArray> bound_arguments; | |
1963 if (bound_args.length() == 0) { | |
1964 bound_arguments = empty_fixed_array(); | |
1965 } else { | |
1966 bound_arguments = NewFixedArray(bound_args.length()); | |
1967 for (int i = 0; i < bound_args.length(); ++i) { | |
1968 bound_arguments->set(i, *bound_args[i]); | |
1969 } | |
1970 } | |
1971 | |
1972 // Setup the map for the JSBoundFunction instance. | |
1973 Handle<Map> map = handle( | |
1974 target_function->IsConstructor() | |
1975 ? isolate()->native_context()->bound_function_with_constructor_map() | |
1976 : isolate() | |
1977 ->native_context() | |
1978 ->bound_function_without_constructor_map(), | |
1979 isolate()); | |
1980 if (map->prototype() != *prototype) { | |
1981 map = Map::TransitionToPrototype(map, prototype, REGULAR_PROTOTYPE); | |
1982 } | |
1983 DCHECK_EQ(target_function->IsConstructor(), map->is_constructor()); | |
1984 | |
1985 // Setup the JSBoundFunction instance. | |
1986 Handle<JSBoundFunction> result = | |
1987 Handle<JSBoundFunction>::cast(NewJSObjectFromMap(map)); | |
1988 result->set_bound_target_function(*target_function); | |
1989 result->set_bound_this(*bound_this); | |
1990 result->set_bound_arguments(*bound_arguments); | |
1991 result->set_creation_context(*isolate()->native_context()); | |
1992 result->set_length(Smi::FromInt(0)); | |
1993 result->set_name(*undefined_value(), SKIP_WRITE_BARRIER); | |
1994 return result; | |
1995 } | |
1996 | |
1997 | |
1998 // ES6 section 9.5.15 ProxyCreate (target, handler) | 1945 // ES6 section 9.5.15 ProxyCreate (target, handler) |
1999 Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target, | 1946 Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target, |
2000 Handle<JSReceiver> handler) { | 1947 Handle<JSReceiver> handler) { |
2001 // Allocate the proxy object. | 1948 // Allocate the proxy object. |
2002 Handle<Map> map; | 1949 Handle<Map> map; |
2003 if (target->IsCallable()) { | 1950 if (target->IsCallable()) { |
2004 if (target->IsConstructor()) { | 1951 if (target->IsConstructor()) { |
2005 map = Handle<Map>(isolate()->proxy_constructor_map()); | 1952 map = Handle<Map>(isolate()->proxy_constructor_map()); |
2006 } else { | 1953 } else { |
2007 map = Handle<Map>(isolate()->proxy_callable_map()); | 1954 map = Handle<Map>(isolate()->proxy_callable_map()); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2376 } | 2323 } |
2377 | 2324 |
2378 | 2325 |
2379 Handle<Object> Factory::ToBoolean(bool value) { | 2326 Handle<Object> Factory::ToBoolean(bool value) { |
2380 return value ? true_value() : false_value(); | 2327 return value ? true_value() : false_value(); |
2381 } | 2328 } |
2382 | 2329 |
2383 | 2330 |
2384 } // namespace internal | 2331 } // namespace internal |
2385 } // namespace v8 | 2332 } // namespace v8 |
OLD | NEW |