mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 15:21:26 -05:00
feat(std/node) Endianness (#3833)
This commit is contained in:
parent
de5c099b47
commit
3de9540ac6
2 changed files with 19 additions and 10 deletions
|
@ -19,6 +19,7 @@
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
import { notImplemented } from "./_utils.ts";
|
import { notImplemented } from "./_utils.ts";
|
||||||
|
import { EOL as fsEOL } from "../fs/eol.ts";
|
||||||
|
|
||||||
const SEE_GITHUB_ISSUE = "See https://github.com/denoland/deno/issues/3802";
|
const SEE_GITHUB_ISSUE = "See https://github.com/denoland/deno/issues/3802";
|
||||||
|
|
||||||
|
@ -96,9 +97,17 @@ export function cpus(): CPUCoreInfo[] {
|
||||||
notImplemented(SEE_GITHUB_ISSUE);
|
notImplemented(SEE_GITHUB_ISSUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Not yet implemented */
|
/**
|
||||||
|
* Returns a string identifying the endianness of the CPU for which the Deno
|
||||||
|
* binary was compiled. Possible values are 'BE' for big endian and 'LE' for
|
||||||
|
* little endian.
|
||||||
|
**/
|
||||||
export function endianness(): "BE" | "LE" {
|
export function endianness(): "BE" | "LE" {
|
||||||
notImplemented(SEE_GITHUB_ISSUE);
|
// Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView#Endianness
|
||||||
|
const buffer = new ArrayBuffer(2);
|
||||||
|
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
|
||||||
|
// Int16Array uses the platform's endianness.
|
||||||
|
return new Int16Array(buffer)[0] === 256 ? "LE" : "BE";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Not yet implemented */
|
/** Not yet implemented */
|
||||||
|
@ -201,7 +210,7 @@ export const constants = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EOL = Deno.build.os == "win" ? "\r\n" : "\n";
|
export const EOL = Deno.build.os == "win" ? fsEOL.CRLF : fsEOL.LF;
|
||||||
|
|
||||||
const validateInt32 = (
|
const validateInt32 = (
|
||||||
value: number,
|
value: number,
|
||||||
|
|
|
@ -154,6 +154,13 @@ test({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
name: "Endianness is determined",
|
||||||
|
fn() {
|
||||||
|
assert(["LE", "BE"].includes(os.endianness()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Method is currently implemented correctly for windows but not for any other os
|
// Method is currently implemented correctly for windows but not for any other os
|
||||||
test({
|
test({
|
||||||
name: "Load average is an array of 3 numbers",
|
name: "Load average is an array of 3 numbers",
|
||||||
|
@ -187,13 +194,6 @@ test({
|
||||||
Error,
|
Error,
|
||||||
"Not implemented"
|
"Not implemented"
|
||||||
);
|
);
|
||||||
assertThrows(
|
|
||||||
() => {
|
|
||||||
os.endianness();
|
|
||||||
},
|
|
||||||
Error,
|
|
||||||
"Not implemented"
|
|
||||||
);
|
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => {
|
() => {
|
||||||
os.freemem();
|
os.freemem();
|
||||||
|
|
Loading…
Add table
Reference in a new issue