Skip to content

Commit

Permalink
fix: #25
Browse files Browse the repository at this point in the history
  • Loading branch information
HarlonWang committed Nov 9, 2022
1 parent 5632e51 commit a026271
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
23 changes: 17 additions & 6 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,28 @@ QuickJSContext context = QuickJSContext.create();
context.evaluate("var a = 1 + 2;");
```

### 支持的 Java 类型
以下的 Java 类型可以直接转换到 JavaScript 中使用:
### 支持的类型

#### 以下基础类型,Java 和 JavaScript 可以直接互转使用
- `boolean`
- `int`
- `int`
- `double`
- `String`
- `null`
- `null`

#### JS 对象类型的互转
- `JSObject` 代表一个 JavaScript 对象
- `JSFunction` 代表一个 JavaScript 方法
- `JSArray` 代表一个 JavaScript 数组


#### 关于 Long 类型
因为 JavaScript 里没有对应 Java 的 Long 类型,所以,Long 类型的转换比较特殊。
- 从 Java 可以直接传 Long 值到 JavaScript,会转为 Int64 位。
- 从 JavaScript 传值到 Java 转为为 Long 类型,需要借助 Double 类型,示例如下:
```Java
((Double)target).longValue());
```

### 属性设置
Java

Expand Down Expand Up @@ -173,4 +184,4 @@ console.log('age:' + age); // 18

- [quickjs-java](https://github.com/cashapp/quickjs-java)
- [quack](https://github.com/koush/quack)
- [quickjs-android](https://github.com/taoweiji/quickjs-android)
- [quickjs-android](https://github.com/taoweiji/quickjs-android)
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,28 @@ QuickJSContext context = QuickJSContext.create();
context.evaluate("var a = 1 + 2;");
```

### Supported Java Types
Currently, the following Java types are supported with JavaScript:
### Supported Types

#### Java and JavaScript can directly convert to each other for the following basic types
- `boolean`
- `int` when calling JavaScript from Java.
- `double`
- `String`
- `null`

#### Mutual conversion of JS object types
- `JSObject` represents a JavaScript object
- `JSFunction` represents a JavaScript function
- `JSArray` represents a JavaScript Array


#### About Long Type
Because there is no Long type corresponding to Java in JavaScript, the conversion of Long type is special.
- Long value can be directly transferred from Java to JavaScript, which will be converted to Int64 bit。
- To convert a value from JavaScript to Java into a Long type, you need to use the Double type, as shown in the following example:
```Java
((Double)target).longValue());
```

### Set Property
Java

Expand Down

0 comments on commit a026271

Please sign in to comment.