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

Side by Side Diff: src/factory.cc

Issue 1542963002: [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@FunctionConstructor
Patch Set: [arm64] Poke does not preserve flags with --debug-code. Created 4 years, 12 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/factory.h ('k') | src/full-codegen/arm/full-codegen-arm.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 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
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_or_bindings(*empty_fixed_array()); 1197 function->set_literals(LiteralsArray::cast(*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
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 1362 } else {
1363 } else if (!info->bound()) {
1364 int number_of_literals = info->num_literals(); 1363 int number_of_literals = info->num_literals();
1365 Handle<LiteralsArray> literals = 1364 Handle<LiteralsArray> literals =
1366 LiteralsArray::New(isolate(), handle(info->feedback_vector()), 1365 LiteralsArray::New(isolate(), handle(info->feedback_vector()),
1367 number_of_literals, pretenure); 1366 number_of_literals, pretenure);
1368 result->set_literals(*literals); 1367 result->set_literals(*literals);
1369 1368
1370 // Cache context-specific literals. 1369 // Cache context-specific literals.
1371 Handle<Context> native_context(context->native_context()); 1370 Handle<Context> native_context(context->native_context());
1372 SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context, 1371 SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context,
1373 literals); 1372 literals);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 1934
1936 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, 1935 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
1937 size_t byte_offset, 1936 size_t byte_offset,
1938 size_t byte_length) { 1937 size_t byte_length) {
1939 Handle<JSDataView> obj = NewJSDataView(); 1938 Handle<JSDataView> obj = NewJSDataView();
1940 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1939 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1941 return obj; 1940 return obj;
1942 } 1941 }
1943 1942
1944 1943
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
1945 // ES6 section 9.5.15 ProxyCreate (target, handler) 1998 // ES6 section 9.5.15 ProxyCreate (target, handler)
1946 Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target, 1999 Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target,
1947 Handle<JSReceiver> handler) { 2000 Handle<JSReceiver> handler) {
1948 // Allocate the proxy object. 2001 // Allocate the proxy object.
1949 Handle<Map> map; 2002 Handle<Map> map;
1950 if (target->IsCallable()) { 2003 if (target->IsCallable()) {
1951 if (target->IsConstructor()) { 2004 if (target->IsConstructor()) {
1952 map = Handle<Map>(isolate()->proxy_constructor_map()); 2005 map = Handle<Map>(isolate()->proxy_constructor_map());
1953 } else { 2006 } else {
1954 map = Handle<Map>(isolate()->proxy_callable_map()); 2007 map = Handle<Map>(isolate()->proxy_callable_map());
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 } 2376 }
2324 2377
2325 2378
2326 Handle<Object> Factory::ToBoolean(bool value) { 2379 Handle<Object> Factory::ToBoolean(bool value) {
2327 return value ? true_value() : false_value(); 2380 return value ? true_value() : false_value();
2328 } 2381 }
2329 2382
2330 2383
2331 } // namespace internal 2384 } // namespace internal
2332 } // namespace v8 2385 } // namespace v8
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/full-codegen/arm/full-codegen-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698