-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix subclassing support and new object creation in Temporal.*.from #232
Comments
I agree with the suggestions by @littledan and will be fixing this alongside #230 in a new PR. In the meantime, @Ms2ger @pipobscure @ljharb I'd love to hear your thoughts on this. |
I agree with both of the two bullet points in the OP. |
Relevant comment from the duplicate: sffc>
|
As per #231 and #237, we're only doing casting in with(), which is covered by ToPartialDate, etc., and plus() and minus(), which are covered by ToLimitedDuration(). We also decided somewhere else (can't remember where) that from() converts any non-Object to a String. So the plan described in the top comment becomes a bit simpler, we don't actually need a casting method. |
I have a work in progress for this, but it's going to collide with the test262 work that @Ms2ger is doing, so I'll put it on pause for now. |
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
@Ms2ger My work in progress is at https://github.com/tc39/proposal-temporal/tree/232-from-cloning, feel free to reorganize the commits however you like. |
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Effectively, this makes Temporal.Foo.from(aFoo) clone the object instead of returning the same object. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
Absolute and TimeZone cannot take property bags, so they are different from the rest, but in general the idea is to call ToX(arg) if Type(arg) is Object, and XFromString(ToString(arg)) if not. Reorganize from() to clone the object Each type's from() method now calls a new abstract operation, ToFooRecord, which takes a property bag (which can be the actual type) and returns a Record with the appropriate slots. If the argument isn't an object, then from() calls ParseFooString directly. We delete the FooFromString operations, and in most cases the ToFoo operations unless there is a method somewhere in the API that actually needs the casting behaviour (including returning the original object if it's of the correct type.) Reorganizes the abstract operations in the polyfill to match the abstract operations in the spec a bit more. Closes: #232.
I think this was fixed by #502 some while ago. |
A couple issues with these
from
methods:from
methods, this is logically a way to construct a new object that's based on an existing one, and not a cast; it will always create a new instance (just likeArray.from
does applied to an Array). However, the logic in the polyfill and spec text will not create a new instance if it's provided an existing instance of the same class.I'd suggest refactoring the implementation of
from
and casting in general as follows:from
method (when applied on something that's not a String) will call this new abstract algorithm, and then constructthis
with the resultfrom
method (with the original constructor as the new.target). [I don't mean to literally invoke Construct but rather use these algorithm steps, deduplicated into an abstract algorithm.]The text was updated successfully, but these errors were encountered: