The default bug view has changed. See this FAQ.

ES5: Implement Object.create

RESOLVED FIXED in mozilla1.9.3a1

Status

()

Core
JavaScript Engine
RESOLVED FIXED
8 years ago
7 years ago

People

(Reporter: jimb, Assigned: Waldo)

Tracking

({dev-doc-complete})

Trunk
mozilla1.9.3a1
dev-doc-complete
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(2 attachments, 2 obsolete attachments)

(Reporter)

Description

8 years ago
Object.create is specified by 15.2.3.5 in the ES5 draft:
http://wiki.ecmascript.org/doku.php?id=es3.1:es3.1_proposal_working_draft
(Reporter)

Updated

8 years ago
Blocks: 430133
No longer depends on: 430133
Assignee: general → jwalden+bmo
Created attachment 402512 [details] [diff] [review]
Patch atop latest in bug 430133

This doesn't provide any new functionality, but newborn-proto-setting capability is an important step toward removing __proto__ support at some (likely distant) time in the future.
Attachment #402512 - Flags: review?(jorendorff)
Created attachment 402921 [details] [diff] [review]
Give a better error message for Object.create(2), one other uber-nit
Attachment #402512 - Attachment is obsolete: true
Attachment #402921 - Flags: review?(jorendorff)
Attachment #402512 - Flags: review?(jorendorff)
Created attachment 402997 [details] [diff] [review]
Updated atop latest patch in bug 430133, add another test or two
Attachment #402921 - Attachment is obsolete: true
Attachment #402997 - Flags: review?(mrbkap)
Attachment #402921 - Flags: review?(jorendorff)

Comment 4

8 years ago
Waldo, please fix the test to call reportCompare() and update ecma_5/Object/jstests.list to remove the skip. Thanks.
Comment on attachment 402997 [details] [diff] [review]
Updated atop latest patch in bug 430133, add another test or two

>+MSG_DEF(JSMSG_NOT_OBJECT_OR_NULL,     244, 0, JSEXN_TYPEERR, "value is not null or an object")

You can use JSMSG_UNEXPECTED_TYPE with type being "null or an object" instead of adding a new message here.

>diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp
>--- a/js/src/jsobj.cpp
>+++ b/js/src/jsobj.cpp
>@@ -2673,16 +2673,80 @@ obj_defineProperties(JSContext* cx, uint
>     for (size_t i = 0; i < len; i++) {
>         if (!DefineProperty(cx, obj, (*descs)[i], true, dummy))
>             return JS_FALSE;
>     }
> 
>     return JS_TRUE;
> }
> 
>+/* ES5 15.2.3.5: Object.create(O [, Properties]) */
>+static JSBool
>+obj_create(JSContext *cx, uintN argc, jsval *vp)
>+{
>+    jsval v = argc == 0 ? JSVAL_VOID : vp[2];

Nit: parentheses around argc == 0.

>+    if (argc < 1 || !JSVAL_IS_OBJECT(v)) {

The argc < 1 in this check is redundant with the above assignment (especially since we assign a non-object to v if argc is less than 1). I guess it's a little tricky, but I'd say to remove the redundant test.

>+    /*
>+     * Notwithstanding that Object.create seems more likely to be in run-once
>+     * code than performance-critical code, JS_GetScopeChain(cx) is going to
>+     * throw us off trace -- is there an alternative?

Hmm, so js_NewObjectWithGivenProto will use the parent of the prototype (if it's not null) if parent is null. You could use that if the given prototype is non-null. I don't know what we want the lexical scope of these objects to be. Parented to the prototype object's parent (which may be a different lexical scope)? Always parented to the static scope of Object.create? I assume the spec is silent on this issue because it doesn't address the possibility of multiple global objects...
Attachment #402997 - Flags: review?(mrbkap) → review+
(reversing dependency on Object.defineProperty, whose patch this patch depends on)
No longer blocks: 430133
Depends on: 430133
Created attachment 417018 [details] [diff] [review]
Unbitrotted, possibly with previous comments addressed, atop and waiting upon bug 430133
http://hg.mozilla.org/tracemonkey/rev/9a24406ddbe7
http://hg.mozilla.org/tracemonkey/rev/aa8a6d3b5dc8
http://hg.mozilla.org/tracemonkey/rev/8cb0a325a704
Blocks: 445494
Status: NEW → ASSIGNED
Whiteboard: fixed-in-tracemonkey
Target Milestone: --- → mozilla1.9.3a1
I wrote up a little bit here, but we certainly need to make the information more visible than simply buried in the JS reference:

https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Object/create
Keywords: dev-doc-needed

Comment 10

7 years ago
http://hg.mozilla.org/mozilla-central/rev/9a24406ddbe7
Status: ASSIGNED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED
Depends on: 573651
Keywords: dev-doc-needed → dev-doc-complete

Updated

7 years ago
No longer depends on: 573651
You need to log in before you can comment on or make changes to this bug.