Commit cff5470a authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[cleanup] Modernize creation of JSON, Math, and Intl objects

Before this patch, those builtin objects all used a strange-looking
pattern for creation that involved creating a new constructor
function (likely in order to get their ES5 [[Class]] set
appropriately).

But in modern times, with @@toStringTag as the mechanism of returning
the correct toString value, there should be no need for those extra
hoops, so simply use the Object constructor instead.

Change-Id: Id841dace26bf71f73ec25a71f1297d502438b27c
Reviewed-on: https://chromium-review.googlesource.com/533922
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45963}
parent 405fafb8
......@@ -2504,10 +2504,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- J S O N
Handle<String> name = factory->InternalizeUtf8String("JSON");
Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED);
DCHECK(json_object->IsJSObject());
Handle<JSObject> json_object =
factory->NewJSObject(isolate->object_function(), TENURED);
JSObject::AddProperty(global, name, json_object, DONT_ENUM);
SimpleInstallFunction(json_object, "parse", Builtins::kJsonParse, 2, false);
SimpleInstallFunction(json_object, "stringify", Builtins::kJsonStringify, 3,
......@@ -2520,10 +2518,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- M a t h
Handle<String> name = factory->InternalizeUtf8String("Math");
Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
Handle<JSObject> math = factory->NewJSObject(cons, TENURED);
DCHECK(math->IsJSObject());
Handle<JSObject> math =
factory->NewJSObject(isolate->object_function(), TENURED);
JSObject::AddProperty(global, name, math, DONT_ENUM);
SimpleInstallFunction(math, "abs", Builtins::kMathAbs, 1, true);
SimpleInstallFunction(math, "acos", Builtins::kMathAcos, 1, true);
......@@ -2652,10 +2648,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
#ifdef V8_INTL_SUPPORT
{ // -- I n t l
Handle<String> name = factory->InternalizeUtf8String("Intl");
Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
Handle<JSObject> intl = factory->NewJSObject(cons, TENURED);
DCHECK(intl->IsJSObject());
Handle<JSObject> intl =
factory->NewJSObject(isolate->object_function(), TENURED);
JSObject::AddProperty(global, name, intl, DONT_ENUM);
Handle<JSObject> date_time_format_prototype =
......
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