| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/api-natives.h" | 5 #include "src/api-natives.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
| 9 #include "src/lookup.h" | 9 #include "src/lookup.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 UnseededNumberDictionary::DeleteProperty(cache, entry); | 282 UnseededNumberDictionary::DeleteProperty(cache, entry); |
| 283 USE(result); | 283 USE(result); |
| 284 DCHECK(result->IsTrue()); | 284 DCHECK(result->IsTrue()); |
| 285 auto new_cache = UnseededNumberDictionary::Shrink(cache, entry); | 285 auto new_cache = UnseededNumberDictionary::Shrink(cache, entry); |
| 286 isolate->native_context()->set_template_instantiations_cache(*new_cache); | 286 isolate->native_context()->set_template_instantiations_cache(*new_cache); |
| 287 } | 287 } |
| 288 | 288 |
| 289 MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, | 289 MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, |
| 290 Handle<ObjectTemplateInfo> info, | 290 Handle<ObjectTemplateInfo> info, |
| 291 bool is_hidden_prototype) { | 291 bool is_hidden_prototype) { |
| 292 // Enter a new scope. Recursion could otherwise create a lot of handles. | |
| 293 HandleScope scope(isolate); | |
| 294 // Fast path. | 292 // Fast path. |
| 295 Handle<JSObject> result; | 293 Handle<JSObject> result; |
| 296 auto constructor = handle(info->constructor(), isolate); | |
| 297 Handle<JSFunction> cons; | |
| 298 if (constructor->IsUndefined()) { | |
| 299 cons = isolate->object_function(); | |
| 300 } else { | |
| 301 auto cons_templ = Handle<FunctionTemplateInfo>::cast(constructor); | |
| 302 ASSIGN_RETURN_ON_EXCEPTION( | |
| 303 isolate, cons, InstantiateFunction(isolate, cons_templ), JSFunction); | |
| 304 } | |
| 305 auto serial_number = handle(Smi::cast(info->serial_number()), isolate); | 294 auto serial_number = handle(Smi::cast(info->serial_number()), isolate); |
| 306 if (serial_number->value()) { | 295 if (serial_number->value()) { |
| 307 // Probe cache. | 296 // Probe cache. |
| 308 auto cache = isolate->template_instantiations_cache(); | 297 auto cache = isolate->template_instantiations_cache(); |
| 309 int entry = cache->FindEntry(static_cast<uint32_t>(serial_number->value())); | 298 int entry = cache->FindEntry(static_cast<uint32_t>(serial_number->value())); |
| 310 if (entry != UnseededNumberDictionary::kNotFound) { | 299 if (entry != UnseededNumberDictionary::kNotFound) { |
| 311 Object* boilerplate = cache->ValueAt(entry); | 300 Object* boilerplate = cache->ValueAt(entry); |
| 312 result = handle(JSObject::cast(boilerplate), isolate); | 301 result = handle(JSObject::cast(boilerplate), isolate); |
| 313 ASSIGN_RETURN_ON_EXCEPTION( | 302 ASSIGN_RETURN_ON_EXCEPTION( |
| 314 isolate, result, JSObject::DeepCopyApiBoilerplate(result), JSObject); | 303 isolate, result, JSObject::DeepCopyApiBoilerplate(result), JSObject); |
| 315 return scope.CloseAndEscape(result); | 304 return result; |
| 316 } | 305 } |
| 317 } | 306 } |
| 307 // Enter a new scope. Recursion could otherwise create a lot of handles. |
| 308 HandleScope scope(isolate); |
| 309 auto constructor = handle(info->constructor(), isolate); |
| 310 Handle<JSFunction> cons; |
| 311 if (constructor->IsUndefined()) { |
| 312 cons = isolate->object_function(); |
| 313 } else { |
| 314 auto cons_templ = Handle<FunctionTemplateInfo>::cast(constructor); |
| 315 ASSIGN_RETURN_ON_EXCEPTION( |
| 316 isolate, cons, InstantiateFunction(isolate, cons_templ), JSFunction); |
| 317 } |
| 318 auto object = isolate->factory()->NewJSObject(cons); | 318 auto object = isolate->factory()->NewJSObject(cons); |
| 319 ASSIGN_RETURN_ON_EXCEPTION( | 319 ASSIGN_RETURN_ON_EXCEPTION( |
| 320 isolate, result, | 320 isolate, result, |
| 321 ConfigureInstance(isolate, object, info, is_hidden_prototype), | 321 ConfigureInstance(isolate, object, info, is_hidden_prototype), |
| 322 JSFunction); | 322 JSFunction); |
| 323 // TODO(dcarney): is this necessary? | 323 // TODO(dcarney): is this necessary? |
| 324 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); | 324 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); |
| 325 | 325 |
| 326 if (serial_number->value()) { | 326 if (serial_number->value()) { |
| 327 CacheTemplateInstantiation(isolate, serial_number, result); | 327 CacheTemplateInstantiation(isolate, serial_number, result); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 map->set_is_callable(); | 619 map->set_is_callable(); |
| 620 map->set_is_constructor(true); | 620 map->set_is_constructor(true); |
| 621 } | 621 } |
| 622 | 622 |
| 623 DCHECK(result->shared()->IsApiFunction()); | 623 DCHECK(result->shared()->IsApiFunction()); |
| 624 return result; | 624 return result; |
| 625 } | 625 } |
| 626 | 626 |
| 627 } // namespace internal | 627 } // namespace internal |
| 628 } // namespace v8 | 628 } // namespace v8 |
| OLD | NEW |