close
Skip to content

Implicitly inherit from Object - #2559

Merged
dcodeIO merged 7 commits into
mainfrom
extend-object
Nov 14, 2022
Merged

Implicitly inherit from Object#2559
dcodeIO merged 7 commits into
mainfrom
extend-object

Conversation

@dcodeIO

@dcodeIO dcodeIO commented Nov 12, 2022

Copy link
Copy Markdown
Member

Classes that are not unmanaged and don't extend other classes now implicitly extend Object. As a result, the type Object can be used to reference and pass along any normal class instance.

let obj: Object = new Anything();
function fn(arg: Object): void {
  if (arg instanceof Anything) {
    ...
  }
}
fn(new Anything());

Note: Does not apply to basic value types like i32, which are not objects.

With Object becoming the general base class, a breaking change to constant class ids was necessary, in that foundational classes move one up. Relevant for external integration with the runtime, where these ids may be hardcoded.

Class New id Old id
Object 0 dynamic
ArrayBuffer 1 0
String 2 1
...
  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

CountBleck added a commit to CountBleck/assemblyscript-website that referenced this pull request Nov 12, 2022
The class IDs for ArrayBuffer and String have now been incremented by 1.
@dcodeIO
dcodeIO marked this pull request as ready for review November 13, 2022 06:36
@jtenner

jtenner commented Nov 14, 2022

Copy link
Copy Markdown
Contributor

Thank you for this! I was able to test the branch with as-pect and it works after I made some coding changes. I also needed to use the new loader because the runtime type ids changed. Other than that, everything looks good to me!

@dcodeIO
dcodeIO merged commit 688dcd2 into main Nov 14, 2022
dcodeIO pushed a commit to AssemblyScript/website that referenced this pull request Nov 14, 2022
@HerrCai0907
HerrCai0907 deleted the extend-object branch October 17, 2023 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants