code; if (info->call_code()->IsCallHandlerInfo() && CallHandlerInfo::cast(info->call_code())->fast_handler()->IsCode()) { code = isolate->builtins()->HandleFastApiCall(); } else { code = isolate->builtins()->HandleApiCall(); } bool is_constructor = !info->remove_prototype(); Handle result = isolate->factory()->NewSharedFunctionInfo(name, code, is_constructor); if (is_constructor) { result->SetConstructStub(*isolate->builtins()->JSConstructStubApi()); } result->set_length(info->length()); if (class_name->IsString()) result->set_instance_class_name(*class_name); result->set_api_func_data(*info); result->DontAdaptArguments(); DCHECK(result->IsApiFunction()); info->set_shared_function_info(*result); return result; } bool FunctionTemplateInfo::IsTemplateFor(Map* map) { // There is a constraint on the object; check. if (!map->IsJSObjectMap()) return false; // Fetch the constructor function of the object. Object* cons_obj = map->GetConstructor(); if (!cons_obj->IsJSFunction()) return false; JSFunction* fun = JSFunction::cast(cons_obj); // Iterate through the chain of inheriting function templates to // see if the required one occurs. for (Object* type = fun->shared()->function_data(); type->IsFunctionTemplateInfo(); type = FunctionTemplateInfo::cast(type)->parent_template()) { if (type == this) return true; } // Didn't find the required type in the inheritance chain. return false; } // static Handle TemplateList::New(Isolate* isolate, int size) { Handle list = isolate->factory()->NewFixedArray(kLengthIndex + size); list->set(kLengthIndex, Smi::kZero); return Handle::cast(list); } // static Handle TemplateList::Add(Isolate* isolate, Handle list, Handle value) { STATIC_ASSERT(kFirstElementIndex == 1); int index = list->length() + 1; Handle fixed_array = Handle::cast(list); fixed_array = FixedArray::SetAndGrow(fixed_array, index, value); fixed_array->set(kLengthIndex, Smi::FromInt(index)); return Handle::cast(fixed_array); } // static MaybeHandle JSObject::New(Handle constructor, Handle new_target, Handle site) { // If called through new, new.target can be: // - a subclass of constructor, // - a proxy wrapper around constructor, or // - the constructor itself. // If called through Reflect.construct, it's guaranteed to be a constructor. Isolate* const isolate = constructor->GetIsolate(); DCHECK(constructor->IsConstructor()); DCHECK(new_target->IsConstructor()); DCHECK(!constructor->has_initial_map() || constructor->initial_map()->instance_type() != JS_FUNCTION_TYPE); Handle initial_map; ASSIGN_RETURN_ON_EXCEPTION( isolate, initial_map, JSFunction::GetDerivedMap(isolate, constructor, new_target), JSObject); Handle result = isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); isolate->counters()->constructed_objects()->Increment(); isolate->counters()->constructed_objects_runtime()->Increment(); return result; } void JSObject::EnsureWritableFastElements(Handle object) { DCHECK(object->HasFastSmiOrObjectElements() || object->HasFastStringWrapperElements()); FixedArray* raw_elems = FixedArray::cast(object->elements()); Heap* heap = object->GetHeap(); if (raw_elems->map() != heap->fixed_cow_array_map()) return; Isolate* isolate = heap->isolate(); Handle elems(raw_elems, isolate); Handle writable_elems = isolate->factory()->CopyFixedArrayWithMap( elems, isolate->factory()->fixed_array_map()); object->set_elements(*writable_elems); isolate->counters()->cow_arrays_converted()->Increment(); } // ES6 9.5.1 // static MaybeHandle JSProxy::GetPrototype(Handle proxy) { Isolate* isolate = proxy->GetIsolate(); Handle trap_name = isolate->factory()->getPrototypeOf_string(); STACK_CHECK(isolate, MaybeHandle()); // 1. Let handler be the value of the [[ProxyHandler]] internal slot. // 2. If handler is null, throw a TypeError exception. // 3. Assert: Type(handler) is Object. // 4. Let target be the value of the [[ProxyTarget]] internal slot. if (proxy->IsRevoked()) { THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kProxyRevoked, trap_name), Object); } Handle target(proxy->target(), isolate); Handle