Closed Bug 492840 Opened 16 years ago Closed 15 years ago

ES5: Implement Object.create

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.3a1

People

(Reporter: jimb, Assigned: Waldo)

References

Details

(Keywords: dev-doc-complete, Whiteboard: fixed-in-tracemonkey)

Attachments

(2 files, 2 obsolete files)

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
Blocks: 430133
No longer depends on: 430133
Assignee: general → jwalden+bmo
Attached patch Patch atop latest in bug 430133 (obsolete) — Splinter Review
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)
Attachment #402512 - Attachment is obsolete: true
Attachment #402921 - Flags: review?(jorendorff)
Attachment #402512 - Flags: review?(jorendorff)
Attachment #402921 - Attachment is obsolete: true
Attachment #402997 - Flags: review?(mrbkap)
Attachment #402921 - Flags: review?(jorendorff)
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
Blocks: es5
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
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Depends on: 573651
No longer depends on: 573651
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: