Commit e7bd43c3 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Cleanup native methods creation in js/intl.js.

This CL replaces usages of utils.InstallFunctions and utils.InstallGetter()
with the DEFINE_METHOD* macros that ensure that the native function is
created in proper form from the beginning. Thus the function will not
require further reconfiguring like adding a computed name or removing of
'prototype' property.

This CL is one of a series of cleanup CL which are the preliminary steps for
improving function closures creation.

Bug: v8:6459
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: I667d70fae12a2f50d0fe18d958b6520110b4b573
Reviewed-on: https://chromium-review.googlesource.com/548075
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46278}
parent f9e0322a
This diff is collapsed.
......@@ -99,6 +99,11 @@ macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
# To avoid ES2015 Function name inference.
macro ANONYMOUS_FUNCTION(fn) = (0, (fn));
macro DEFINE_METHODS_LEN(obj, class_def, len) = %DefineMethodsInternal(obj, class class_def, len);
macro DEFINE_METHOD_LEN(obj, method_def, len) = %DefineMethodsInternal(obj, class { method_def }, len);
macro DEFINE_METHODS(obj, class_def) = DEFINE_METHODS_LEN(obj, class_def, -1);
macro DEFINE_METHOD(obj, method_def) = DEFINE_METHOD_LEN(obj, method_def, -1);
# Constants. The compiler constant folds them.
define INFINITY = (1/0);
define UNDEFINED = (void 0);
......
......@@ -130,7 +130,6 @@ RUNTIME_FUNCTION(Runtime_FunctionSetLength) {
CONVERT_ARG_CHECKED(JSFunction, fun, 0);
CONVERT_SMI_ARG_CHECKED(length, 1);
CHECK((length & 0xC0000000) == 0xC0000000 || (length & 0xC0000000) == 0x0);
fun->shared()->set_length(length);
return isolate->heap()->undefined_value();
}
......
......@@ -917,6 +917,64 @@ RUNTIME_FUNCTION(Runtime_CopyDataPropertiesWithExcludedProperties) {
return *target;
}
namespace {
inline void TrySetNative(Handle<Object> maybe_func) {
if (!maybe_func->IsJSFunction()) return;
JSFunction::cast(*maybe_func)->shared()->set_native(true);
}
inline void TrySetNativeAndLength(Handle<Object> maybe_func, int length) {
if (!maybe_func->IsJSFunction()) return;
SharedFunctionInfo* shared = JSFunction::cast(*maybe_func)->shared();
shared->set_native(true);
if (length >= 0) {
shared->set_length(length);
}
}
} // namespace
RUNTIME_FUNCTION(Runtime_DefineMethodsInternal) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());
CHECK(isolate->bootstrapper()->IsActive());
CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, source_class, 1);
CONVERT_SMI_ARG_CHECKED(length, 2);
DCHECK(source_class->prototype()->IsJSObject());
Handle<JSObject> source(JSObject::cast(source_class->prototype()), isolate);
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
KeyAccumulator::GetKeys(source, KeyCollectionMode::kOwnOnly,
ALL_PROPERTIES,
GetKeysConversion::kConvertToString));
for (int i = 0; i < keys->length(); ++i) {
Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
if (*key == isolate->heap()->constructor_string()) continue;
PropertyDescriptor descriptor;
Maybe<bool> did_get_descriptor =
JSReceiver::GetOwnPropertyDescriptor(isolate, source, key, &descriptor);
CHECK(did_get_descriptor.FromJust());
if (descriptor.has_value()) {
TrySetNativeAndLength(descriptor.value(), length);
} else {
if (descriptor.has_get()) TrySetNative(descriptor.get());
if (descriptor.has_set()) TrySetNative(descriptor.set());
}
Maybe<bool> success = JSReceiver::DefineOwnProperty(
isolate, target, key, &descriptor, Object::DONT_THROW);
CHECK(success.FromJust());
}
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) {
HandleScope scope(isolate);
DCHECK_EQ(4, args.length());
......
......@@ -428,6 +428,7 @@ namespace internal {
F(CopyDataPropertiesWithExcludedProperties, -1 /* >= 1 */, 1) \
F(DefineGetterPropertyUnchecked, 4, 1) \
F(DefineSetterPropertyUnchecked, 4, 1) \
F(DefineMethodsInternal, 3, 1) \
F(ToObject, 1, 1) \
F(ToPrimitive, 1, 1) \
F(ToPrimitive_Number, 1, 1) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment