forked from yorkie/rust.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.rs
64 lines (55 loc) · 1.92 KB
/
os.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#![allow(non_snake_case)]
use std::env;
use util::v8;
extern {
fn utils_is_big_endian() -> bool;
}
extern fn tmpdir(arguments: v8::FunctionCallbackInfo) {
let dir = env::temp_dir();
let val = v8::String::NewFromUtf8(dir.to_str().unwrap());
arguments.GetReturnValue().Set(val);
}
extern fn homedir(arguments: v8::FunctionCallbackInfo) {
let dir = env::home_dir();
let val = v8::String::NewFromUtf8(dir.unwrap().to_str().unwrap());
arguments.GetReturnValue().Set(val);
}
extern fn endianness(arguments: v8::FunctionCallbackInfo) {
let isBig: bool;
unsafe {
isBig = utils_is_big_endian();
}
if isBig == true {
arguments.GetReturnValue().Set(v8::String::NewFromUtf8("BE"));
} else {
arguments.GetReturnValue().Set(v8::String::NewFromUtf8("BE"));
}
}
extern fn ostype(arguments: v8::FunctionCallbackInfo) {
let val = env::consts::FAMILY;
arguments.GetReturnValue().Set(v8::String::NewFromUtf8(val));
}
extern fn platform(arguments: v8::FunctionCallbackInfo) {
let val = env::consts::OS;
arguments.GetReturnValue().Set(v8::String::NewFromUtf8(val));
}
extern fn arch(arguments: v8::FunctionCallbackInfo) {
let val = env::consts::ARCH;
arguments.GetReturnValue().Set(v8::String::NewFromUtf8(val));
}
pub fn Init() -> v8::Object {
let exports = v8::Object::New();
exports.Set(v8::String::NewFromUtf8("tmpdir"),
v8::FunctionTemplate::New(tmpdir).GetFunction());
exports.Set(v8::String::NewFromUtf8("homedir"),
v8::FunctionTemplate::New(homedir).GetFunction());
exports.Set(v8::String::NewFromUtf8("endianness"),
v8::FunctionTemplate::New(endianness).GetFunction());
exports.Set(v8::String::NewFromUtf8("type"),
v8::FunctionTemplate::New(ostype).GetFunction());
exports.Set(v8::String::NewFromUtf8("platform"),
v8::FunctionTemplate::New(platform).GetFunction());
exports.Set(v8::String::NewFromUtf8("arch"),
v8::FunctionTemplate::New(arch).GetFunction());
return exports;
}