-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat: implement native os module #1115
feat: implement native os module #1115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this
Sorry that the patterns in to copy from in the code are unclear. The newer way of writing bindings like this -- using JSC.NewFunction() should be simpler and a little faster at runtime
@@ -486,6 +486,18 @@ pub fn getImportedStyles( | |||
return JSValue.createStringArray(ctx.ptr(), styles.ptr, styles.len, true).asRef(); | |||
} | |||
|
|||
pub fn newOs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a new and better way to expose ESM modules, but most of the code hasn't been migrated to it. Have a look at ProcessModule.h.
Instead of adding a new property and writing JS wrapper code, we can directly expose the JSValue objects
@@ -0,0 +1,25 @@ | |||
function bound(obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can delete this file if we use the same way as ProcessModule.h
…forks/bun into xHyroM/feat/implement-os
Co-authored-by: Jarred Sumner <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]>
Co-authored-by: Jarred Sumner <[email protected]>
not finished |
@Jarred-Sumner everything works, tested: import os from "node:os";
for (const p of Object.getOwnPropertyNames(os)) {
if (p === "setPriority" || p === "default") continue;
if (typeof os[p] === 'function') console.log(p, os[p]());
else console.log(p, os[p]);
}
console.log(`priority ${os.getPriority()} (should be 0)`);
os.setPriority(0, 2);
console.log(`priority ${os.getPriority()} (should be 2)`);
os.setPriority(4);
console.log(`priority ${os.getPriority()} (should be 4)`);
console.log('STARTING 100 TIMES - CP');
for (let i = 0; i < 100; i++) {
os.cpus();
}
console.log('STARTING 100 TIMES - NT');
for (let i = 0; i < 100; i++) {
os.networkInterfaces();
} but you should test it on darwin :D - we cant, because VM |
awesome work @xhyrom @Fire-The-Fox |
Required before ready to review:
Must be implemented:
encoding
optionBig ❤️ for @Fire-The-Fox . He help me with cpus and networkInterfaces