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 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 } | 1229 } |
1230 | 1230 |
1231 | 1231 |
1232 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1232 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1233 Handle<String> name, | 1233 Handle<String> name, |
1234 MaybeHandle<Code> code) { | 1234 MaybeHandle<Code> code) { |
1235 Handle<Context> context(isolate()->native_context()); | 1235 Handle<Context> context(isolate()->native_context()); |
1236 Handle<SharedFunctionInfo> info = | 1236 Handle<SharedFunctionInfo> info = |
1237 NewSharedFunctionInfo(name, code, map->is_constructor()); | 1237 NewSharedFunctionInfo(name, code, map->is_constructor()); |
1238 DCHECK(is_sloppy(info->language_mode())); | 1238 DCHECK(is_sloppy(info->language_mode())); |
1239 DCHECK(!map->IsUndefined()); | 1239 DCHECK(!map->IsUndefined(isolate())); |
1240 DCHECK( | 1240 DCHECK( |
1241 map.is_identical_to(isolate()->sloppy_function_map()) || | 1241 map.is_identical_to(isolate()->sloppy_function_map()) || |
1242 map.is_identical_to(isolate()->sloppy_function_without_prototype_map()) || | 1242 map.is_identical_to(isolate()->sloppy_function_without_prototype_map()) || |
1243 map.is_identical_to( | 1243 map.is_identical_to( |
1244 isolate()->sloppy_function_with_readonly_prototype_map()) || | 1244 isolate()->sloppy_function_with_readonly_prototype_map()) || |
1245 map.is_identical_to(isolate()->strict_function_map()) || | 1245 map.is_identical_to(isolate()->strict_function_map()) || |
1246 map.is_identical_to(isolate()->strict_function_without_prototype_map()) || | 1246 map.is_identical_to(isolate()->strict_function_without_prototype_map()) || |
1247 // TODO(titzer): wasm_function_map() could be undefined here. ugly. | 1247 // TODO(titzer): wasm_function_map() could be undefined here. ugly. |
1248 (*map == context->get(Context::WASM_FUNCTION_MAP_INDEX)) || | 1248 (*map == context->get(Context::WASM_FUNCTION_MAP_INDEX)) || |
1249 map.is_identical_to(isolate()->proxy_function_map())); | 1249 map.is_identical_to(isolate()->proxy_function_map())); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 Handle<JSFunction> function = | 1295 Handle<JSFunction> function = |
1296 NewFunction(name, code, prototype, read_only_prototype, is_strict); | 1296 NewFunction(name, code, prototype, read_only_prototype, is_strict); |
1297 | 1297 |
1298 ElementsKind elements_kind = | 1298 ElementsKind elements_kind = |
1299 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; | 1299 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; |
1300 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); | 1300 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); |
1301 // TODO(littledan): Why do we have this is_generator test when | 1301 // TODO(littledan): Why do we have this is_generator test when |
1302 // NewFunctionPrototype already handles finding an appropriately | 1302 // NewFunctionPrototype already handles finding an appropriately |
1303 // shared prototype? | 1303 // shared prototype? |
1304 if (!function->shared()->is_resumable()) { | 1304 if (!function->shared()->is_resumable()) { |
1305 if (prototype->IsTheHole()) { | 1305 if (prototype->IsTheHole(isolate())) { |
1306 prototype = NewFunctionPrototype(function); | 1306 prototype = NewFunctionPrototype(function); |
1307 } else if (install_constructor) { | 1307 } else if (install_constructor) { |
1308 JSObject::AddProperty(Handle<JSObject>::cast(prototype), | 1308 JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
1309 constructor_string(), function, DONT_ENUM); | 1309 constructor_string(), function, DONT_ENUM); |
1310 } | 1310 } |
1311 } | 1311 } |
1312 | 1312 |
1313 JSFunction::SetInitialMap(function, initial_map, | 1313 JSFunction::SetInitialMap(function, initial_map, |
1314 Handle<JSReceiver>::cast(prototype)); | 1314 Handle<JSReceiver>::cast(prototype)); |
1315 | 1315 |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2213 number_string_cache()->set(hash * 2, *number); | 2213 number_string_cache()->set(hash * 2, *number); |
2214 number_string_cache()->set(hash * 2 + 1, *string); | 2214 number_string_cache()->set(hash * 2 + 1, *string); |
2215 } | 2215 } |
2216 | 2216 |
2217 | 2217 |
2218 Handle<String> Factory::NumberToString(Handle<Object> number, | 2218 Handle<String> Factory::NumberToString(Handle<Object> number, |
2219 bool check_number_string_cache) { | 2219 bool check_number_string_cache) { |
2220 isolate()->counters()->number_to_string_runtime()->Increment(); | 2220 isolate()->counters()->number_to_string_runtime()->Increment(); |
2221 if (check_number_string_cache) { | 2221 if (check_number_string_cache) { |
2222 Handle<Object> cached = GetNumberStringCache(number); | 2222 Handle<Object> cached = GetNumberStringCache(number); |
2223 if (!cached->IsUndefined()) return Handle<String>::cast(cached); | 2223 if (!cached->IsUndefined(isolate())) return Handle<String>::cast(cached); |
2224 } | 2224 } |
2225 | 2225 |
2226 char arr[100]; | 2226 char arr[100]; |
2227 Vector<char> buffer(arr, arraysize(arr)); | 2227 Vector<char> buffer(arr, arraysize(arr)); |
2228 const char* str; | 2228 const char* str; |
2229 if (number->IsSmi()) { | 2229 if (number->IsSmi()) { |
2230 int num = Handle<Smi>::cast(number)->value(); | 2230 int num = Handle<Smi>::cast(number)->value(); |
2231 str = IntToCString(num, buffer); | 2231 str = IntToCString(num, buffer); |
2232 } else { | 2232 } else { |
2233 double num = Handle<HeapNumber>::cast(number)->value(); | 2233 double num = Handle<HeapNumber>::cast(number)->value(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2319 } | 2319 } |
2320 *is_result_from_cache = true; | 2320 *is_result_from_cache = true; |
2321 if (number_of_properties == 0) { | 2321 if (number_of_properties == 0) { |
2322 // Reuse the initial map of the Object function if the literal has no | 2322 // Reuse the initial map of the Object function if the literal has no |
2323 // predeclared properties. | 2323 // predeclared properties. |
2324 return handle(context->object_function()->initial_map(), isolate()); | 2324 return handle(context->object_function()->initial_map(), isolate()); |
2325 } | 2325 } |
2326 | 2326 |
2327 int cache_index = number_of_properties - 1; | 2327 int cache_index = number_of_properties - 1; |
2328 Handle<Object> maybe_cache(context->map_cache(), isolate()); | 2328 Handle<Object> maybe_cache(context->map_cache(), isolate()); |
2329 if (maybe_cache->IsUndefined()) { | 2329 if (maybe_cache->IsUndefined(isolate())) { |
2330 // Allocate the new map cache for the native context. | 2330 // Allocate the new map cache for the native context. |
2331 maybe_cache = NewFixedArray(kMapCacheSize, TENURED); | 2331 maybe_cache = NewFixedArray(kMapCacheSize, TENURED); |
2332 context->set_map_cache(*maybe_cache); | 2332 context->set_map_cache(*maybe_cache); |
2333 } else { | 2333 } else { |
2334 // Check to see whether there is a matching element in the cache. | 2334 // Check to see whether there is a matching element in the cache. |
2335 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); | 2335 Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache); |
2336 Object* result = cache->get(cache_index); | 2336 Object* result = cache->get(cache_index); |
2337 if (result->IsWeakCell()) { | 2337 if (result->IsWeakCell()) { |
2338 WeakCell* cell = WeakCell::cast(result); | 2338 WeakCell* cell = WeakCell::cast(result); |
2339 if (!cell->cleared()) { | 2339 if (!cell->cleared()) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 } | 2394 } |
2395 | 2395 |
2396 | 2396 |
2397 Handle<Object> Factory::ToBoolean(bool value) { | 2397 Handle<Object> Factory::ToBoolean(bool value) { |
2398 return value ? true_value() : false_value(); | 2398 return value ? true_value() : false_value(); |
2399 } | 2399 } |
2400 | 2400 |
2401 | 2401 |
2402 } // namespace internal | 2402 } // namespace internal |
2403 } // namespace v8 | 2403 } // namespace v8 |
OLD | NEW |