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

Side by Side Diff: src/factory.cc

Issue 270573003: Rename NewFunction without prototype to NewFunctionWithoutPrototype (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reverse argument order to be consistent Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.h ('k') | src/runtime.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 "factory.h" 5 #include "factory.h"
6 6
7 #include "conversions.h" 7 #include "conversions.h"
8 #include "isolate-inl.h" 8 #include "isolate-inl.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 10
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 Handle<SharedFunctionInfo> info, 1195 Handle<SharedFunctionInfo> info,
1196 Handle<Context> context, 1196 Handle<Context> context,
1197 PretenureFlag pretenure) { 1197 PretenureFlag pretenure) {
1198 AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE; 1198 AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE;
1199 Handle<JSFunction> result = New<JSFunction>(map, space); 1199 Handle<JSFunction> result = New<JSFunction>(map, space);
1200 InitializeFunction(result, info, context); 1200 InitializeFunction(result, info, context);
1201 return result; 1201 return result;
1202 } 1202 }
1203 1203
1204 1204
1205 Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
1206 Handle<SharedFunctionInfo> info) {
Igor Sheludko 2014/05/08 09:51:40 I think you could simplify constructors even more
1207 Handle<Context> context(isolate()->context()->native_context());
1208 return NewFunction(map, info, context);
1209 }
1210
1211
1212 Handle<JSFunction> Factory::NewFunction(Handle<String> name) {
1213 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
1214 ASSERT(info->strict_mode() == SLOPPY);
1215 return NewFunction(isolate()->sloppy_function_map(), info);
Igor Sheludko 2014/05/08 09:51:40 ... then this would be just: return NewFunction(Ne
1216 }
1217
1218
1219 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
1220 Handle<Code> code) {
1221 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
1222 info->set_code(*code);
1223 ASSERT(info->strict_mode() == SLOPPY);
1224 Handle<Map> map = isolate()->sloppy_function_without_prototype_map();
1225 return NewFunction(map, info);
Igor Sheludko 2014/05/08 09:51:40 ... this method will look like: return NewFunction
1226 }
1227
1228
1205 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1229 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1206 MaybeHandle<Code> maybe_code, 1230 Handle<Code> code,
1207 MaybeHandle<Object> maybe_prototype) { 1231 Handle<Object> prototype) {
1208 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); 1232 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
1233 info->set_code(*code);
1209 ASSERT(info->strict_mode() == SLOPPY); 1234 ASSERT(info->strict_mode() == SLOPPY);
1210 Handle<Code> code; 1235 Handle<Map> map = isolate()->sloppy_function_map();
1211 if (maybe_code.ToHandle(&code)) { 1236 Handle<JSFunction> result = NewFunction(map, info);
Igor Sheludko 2014/05/08 09:51:40 ... and this method will look like: Handle<JSFunct
1212 info->set_code(*code); 1237 result->set_prototype_or_initial_map(*prototype);
1213 }
1214 Handle<Context> context(isolate()->context()->native_context());
1215 Handle<Map> map = maybe_prototype.is_null()
1216 ? isolate()->sloppy_function_without_prototype_map()
1217 : isolate()->sloppy_function_map();
1218 Handle<JSFunction> result = NewFunction(map, info, context);
1219 Handle<Object> prototype;
1220 if (maybe_prototype.ToHandle(&prototype)) {
1221 result->set_prototype_or_initial_map(*prototype);
1222 }
1223 return result; 1238 return result;
1224 } 1239 }
1225 1240
1226 1241
1227 Handle<JSFunction> Factory::NewFunction(Handle<String> name) { 1242 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1228 return NewFunction(name, MaybeHandle<Code>(), the_hole_value()); 1243 Handle<Code> code,
1229 } 1244 Handle<Object> prototype,
1230
1231
1232 Handle<JSFunction> Factory::NewFunction(Handle<Object> prototype,
1233 Handle<String> name,
1234 InstanceType type, 1245 InstanceType type,
1235 int instance_size, 1246 int instance_size) {
1236 Handle<Code> code) {
1237 // Allocate the function 1247 // Allocate the function
1238 Handle<JSFunction> function = NewFunction(name, code, prototype); 1248 Handle<JSFunction> function = NewFunction(name, code, prototype);
1239 1249
1240 Handle<Map> initial_map = NewMap( 1250 Handle<Map> initial_map = NewMap(
1241 type, instance_size, GetInitialFastElementsKind()); 1251 type, instance_size, GetInitialFastElementsKind());
1242 if (prototype->IsTheHole() && !function->shared()->is_generator()) { 1252 if (prototype->IsTheHole() && !function->shared()->is_generator()) {
1243 prototype = NewFunctionPrototype(function); 1253 prototype = NewFunctionPrototype(function);
1244 } 1254 }
1245 initial_map->set_prototype(*prototype); 1255 initial_map->set_prototype(*prototype);
1246 function->set_initial_map(*initial_map); 1256 function->set_initial_map(*initial_map);
1247 initial_map->set_constructor(*function); 1257 initial_map->set_constructor(*function);
1248 1258
1249 return function; 1259 return function;
1250 } 1260 }
1251 1261
1252 1262
1253 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1263 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1264 Handle<Code> code,
1254 InstanceType type, 1265 InstanceType type,
1255 int instance_size, 1266 int instance_size) {
1256 Handle<Code> code) { 1267 return NewFunction(name, code, the_hole_value(), type, instance_size);
1257 return NewFunction(the_hole_value(), name, type, instance_size, code);
1258 } 1268 }
1259 1269
1260 1270
1261 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { 1271 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
1262 // Make sure to use globals from the function's context, since the function 1272 // Make sure to use globals from the function's context, since the function
1263 // can be from a different context. 1273 // can be from a different context.
1264 Handle<Context> native_context(function->context()->native_context()); 1274 Handle<Context> native_context(function->context()->native_context());
1265 Handle<Map> new_map; 1275 Handle<Map> new_map;
1266 if (function->shared()->is_generator()) { 1276 if (function->shared()->is_generator()) {
1267 // Generator prototypes can share maps since they don't have "constructor" 1277 // Generator prototypes can share maps since they don't have "constructor"
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 type = JS_GLOBAL_PROXY_TYPE; 2088 type = JS_GLOBAL_PROXY_TYPE;
2079 instance_size += JSGlobalProxy::kSize; 2089 instance_size += JSGlobalProxy::kSize;
2080 break; 2090 break;
2081 default: 2091 default:
2082 UNREACHABLE(); 2092 UNREACHABLE();
2083 type = JS_OBJECT_TYPE; // Keep the compiler happy. 2093 type = JS_OBJECT_TYPE; // Keep the compiler happy.
2084 break; 2094 break;
2085 } 2095 }
2086 2096
2087 Handle<JSFunction> result = obj->remove_prototype() 2097 Handle<JSFunction> result = obj->remove_prototype()
2088 ? NewFunction(Factory::empty_string(), code) 2098 ? NewFunctionWithoutPrototype(Factory::empty_string(), code)
2089 : NewFunction(prototype, Factory::empty_string(), 2099 : NewFunction(Factory::empty_string(), code, prototype,
2090 type, instance_size, code); 2100 type, instance_size);
2091 2101
2092 result->shared()->set_length(obj->length()); 2102 result->shared()->set_length(obj->length());
2093 Handle<Object> class_name(obj->class_name(), isolate()); 2103 Handle<Object> class_name(obj->class_name(), isolate());
2094 if (class_name->IsString()) { 2104 if (class_name->IsString()) {
2095 result->shared()->set_instance_class_name(*class_name); 2105 result->shared()->set_instance_class_name(*class_name);
2096 result->shared()->set_name(*class_name); 2106 result->shared()->set_name(*class_name);
2097 } 2107 }
2098 result->shared()->set_function_data(*obj); 2108 result->shared()->set_function_data(*obj);
2099 result->shared()->set_construct_stub(*construct_stub); 2109 result->shared()->set_construct_stub(*construct_stub);
2100 result->shared()->DontAdaptArguments(); 2110 result->shared()->DontAdaptArguments();
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 return Handle<Object>::null(); 2317 return Handle<Object>::null();
2308 } 2318 }
2309 2319
2310 2320
2311 Handle<Object> Factory::ToBoolean(bool value) { 2321 Handle<Object> Factory::ToBoolean(bool value) {
2312 return value ? true_value() : false_value(); 2322 return value ? true_value() : false_value();
2313 } 2323 }
2314 2324
2315 2325
2316 } } // namespace v8::internal 2326 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698