Skip to content

Commit 93240bc

Browse files
committed
fix: sync codes.
1 parent 2144d77 commit 93240bc

File tree

22 files changed

+209
-191
lines changed

22 files changed

+209
-191
lines changed

bridge/CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ else ()
3838
add_definitions(-DENABLE_PROFILE=0)
3939
endif ()
4040

41-
if (${ENABLE_DEBUGGER})
42-
add_definitions(-DENABLE_DEBUGGER=1)
43-
endif()
44-
4541
if(NOT MSVC)
4642
if (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
4743
include(CheckIPOSupported)
@@ -53,6 +49,10 @@ if(NOT MSVC)
5349
endif()
5450
endif()
5551

52+
if (${ENABLE_DEBUGGER})
53+
add_definitions(-DENABLE_DEBUGGER=1)
54+
endif()
55+
5656
list(APPEND WEBF_PUBLIC_HEADERS
5757
${CMAKE_CURRENT_SOURCE_DIR}/include/webf_bridge.h
5858
)
@@ -105,7 +105,7 @@ list(APPEND BRIDGE_SOURCE
105105
foundation/native_value.cc
106106
foundation/native_type.cc
107107
foundation/ui_command_buffer.cc
108-
polyfill/dist/polyfill.cc
108+
polyfill/dist/polyfill.c
109109
${CMAKE_CURRENT_LIST_DIR}/third_party/dart/include/dart_api_dl.c
110110
)
111111

@@ -145,10 +145,6 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
145145
OUTPUT_VARIABLE QUICKJS_VERSION
146146
)
147147

148-
add_library(modb STATIC
149-
third_party/modp_b64/modp_b64.cc
150-
)
151-
152148
if (NOT MSVC)
153149
list(APPEND QUICK_JS_SOURCE third_party/quickjs/src/libbf.c)
154150
endif()
@@ -167,12 +163,15 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
167163
third_party/quickjs/src/core/gc.c
168164
third_party/quickjs/src/core/malloc.c
169165
third_party/quickjs/src/core/shape.c
166+
third_party/quickjs/out/dap_converter.c
167+
third_party/quickjs/out/dap_protocol.cc
168+
third_party/quickjs/out/sourcemap.c
169+
third_party/quickjs/src/core/debugger.c
170170
third_party/quickjs/src/core/parser.c
171171
third_party/quickjs/src/core/convertion.c
172172
third_party/quickjs/src/core/runtime.c
173173
third_party/quickjs/src/core/module.c
174174
third_party/quickjs/src/core/ic.c
175-
third_party/quickjs/src/core/debugger.c
176175
third_party/quickjs/src/core/builtins/js-array.c
177176
third_party/quickjs/src/core/builtins/js-async-function.c
178177
third_party/quickjs/src/core/builtins/js-async-generator.c
@@ -219,7 +218,11 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
219218
target_link_libraries(quickjs mimalloc-static)
220219
endif()
221220

221+
target_link_libraries(quickjs modb)
222+
222223
target_include_directories(quickjs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/include)
224+
target_include_directories(quickjs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/out)
225+
target_include_directories(quickjs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/modp_b64/include)
223226

224227
if (MSVC)
225228
target_include_directories(quickjs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/compat/win32/pthreads)

bridge/bindings/qjs/atomic_string.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (C) 2022-present The WebF authors. All rights reserved.
44
*/
55

6-
#include <vector>
76
#include "atomic_string.h"
87
#include <algorithm>
98
#include <vector>

bridge/core/executing_context_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,6 @@ TEST(ContextData, constructorName) {
365365
};
366366
auto bridge = TEST_init(errorHandler);
367367
const char* code = "console.assert(Object.getPrototypeOf(window).constructor.name === 'Window')";
368-
bridge->evaluateScript(code, strlen(code), "file://", 0);
368+
bridge->page()->evaluateScript(code, strlen(code), "file://", 0);
369369
EXPECT_EQ(errorHandlerExecuted, false);
370370
}

bridge/core/frame/console_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TEST(Console, debugInspect) {
2929
};
3030
auto bridge = TEST_init();
3131
const char* code = "function f() { console.log(123); } f();";
32-
bridge->evaluateScript(code, strlen(code), "/tmp/index.js", 0);
32+
bridge->page()->evaluateScript(code, strlen(code), "/tmp/index.js", 0);
3333
EXPECT_EQ(logExecuted, true);
3434
}
3535

bridge/polyfill/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"main": "dist/index.js",
55
"scripts": {
66
"build": "cross-env NODE_ENV=development rollup --config rollup.config.js && npm run mainToC && npm run testToC && npm run sourceMapToC",
7-
"build:release": "cross-env NODE_ENV=production rollup --config rollup.config.js && npm run mainToC && npm run testToC",
8-
"mainToC": "node scripts/js_to_c.js -s ../dist/main.js -o ../dist",
9-
"testToC": "node scripts/js_to_c.js -s ../dist/test.js -o ../dist -n TestFramework",
7+
"build:release": "cross-env NODE_ENV=production rollup --config rollup.config.js && npm run mainToC && npm run testToC && npm run sourceMapToC",
8+
"mainToC": "node scripts/js_to_c.js -s ./dist/main.js -o ./dist",
9+
"testToC": "node scripts/js_to_c.js -s ./dist/test.js -o ./dist -n TestFramework",
1010
"sourceMapToC": "node scripts/js_to_c.js -s ./dist/sourcemap.js -o ../third_party/quickjs/out -n SourceMap"
1111
},
1212
"dependencies": {
@@ -15,12 +15,12 @@
1515
"event-emitter": "^0.3.5",
1616
"expect": "^25.1.0",
1717
"qjsc": "^0.2.11",
18-
"source-map": "^0.7.4",
18+
"source-map": "^0.6.1",
1919
"ts-jest": "^24.3.0",
2020
"tslib": "^1.11.2"
2121
},
2222
"devDependencies": {
23-
"@rollup/plugin-commonjs": "^18.0.0",
23+
"@rollup/plugin-commonjs": "^18.1.0",
2424
"@rollup/plugin-node-resolve": "^7.1.3",
2525
"@rollup/plugin-replace": "^2.3.2",
2626
"@rollup/plugin-typescript": "^4.1.1",

bridge/scripts/code_generator/bin/code_generator.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { TemplateType } = require('../dist/ts_types/types');
1313
const { generatorIDLSource } = require('../dist/ts_types/idl/generator');
1414
const { generatorDAP } = require('../dist/ts_types/dap/generator');
1515
const { generateDAPSource } = require('../dist/ts_types/dap/generateSource');
16-
const { generateUnionTypes, generateUnionTypeFileName } = require('../dist/idl/generateUnionTypes')
16+
const { generateUnionTypes, generateUnionTypeFileName } = require('../dist/ts_types/idl/generateUnionTypes')
1717
const { generateJSONTemplate } = require('../dist/json/generator');
1818
const { generateNamesInstaller } = require("../dist/json/generator");
1919
const { union } = require("lodash");
@@ -68,7 +68,7 @@ function genCodeFromTypeDefine() {
6868
// Analyze all files first.
6969
for (let i = 0; i < blobs.length; i ++) {
7070
let b = blobs[i];
71-
analyzer(b, definedPropertyCollector, TemplateType[type.toUpperCase()], dapInfoCollector, unionTypeCollector);
71+
analyzer(b, definedPropertyCollector, unionTypeCollector, TemplateType[type.toUpperCase()], dapInfoCollector);
7272
}
7373

7474
for (let i = 0; i < blobs.length; i ++) {
@@ -94,18 +94,20 @@ function genCodeFromTypeDefine() {
9494
writeFileIfChanged(genFilePath + '.cc', result.source);
9595
}
9696

97-
let unionTypes = Array.from(unionTypeCollector.types);
98-
unionTypes.forEach(union => {
99-
union.sort((p, n) => {
100-
if (typeof p.value === 'string') return 1;
101-
return -(n.value - p.value);
102-
})
103-
});
104-
for(let i = 0; i < unionTypes.length; i ++) {
105-
let result = generateUnionTypes(unionTypes[i]);
106-
let filename = generateUnionTypeFileName(unionTypes[i]);
107-
wirteFileIfChanged(path.join(dist, filename) + '.h', result.header);
108-
wirteFileIfChanged(path.join(dist, filename) + '.cc', result.source);
97+
if (type.toUpperCase() === TemplateType[TemplateType.IDL]) {
98+
let unionTypes = Array.from(unionTypeCollector.types);
99+
unionTypes.forEach(union => {
100+
union.sort((p, n) => {
101+
if (typeof p.value === 'string') return 1;
102+
return -(n.value - p.value);
103+
})
104+
});
105+
for(let i = 0; i < unionTypes.length; i ++) {
106+
let result = generateUnionTypes(unionTypes[i]);
107+
let filename = generateUnionTypeFileName(unionTypes[i]);
108+
writeFileIfChanged(path.join(dist, filename) + '.h', result.header);
109+
writeFileIfChanged(path.join(dist, filename) + '.cc', result.source);
110+
}
109111
}
110112
}
111113

@@ -205,8 +207,8 @@ class UnionTypeCollector {
205207
}
206208

207209
let definedPropertyCollector = new DefinedPropertyCollector();
208-
let dapInfoCollector = new DAPInfoCollector();
209210
let unionTypeCollector = new UnionTypeCollector();
211+
let dapInfoCollector = new DAPInfoCollector();
210212
let names_needs_install = new Set();
211213

212214
genCodeFromTypeDefine();

bridge/scripts/code_generator/src/ts_types/analyzer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
ParameterMode,
1212
PropsDeclaration,
1313
} from './idl/declaration';
14-
import {isUnionType} from "./idl/generateSource";
1514
import {TemplateType} from "./types";
15+
import {isUnionType} from "./idl/generateSource";
1616

1717
interface DefinedPropertyCollector {
1818
properties: Set<string>;
@@ -24,7 +24,6 @@ export interface UnionTypeCollector {
2424
types: Set<ParameterType[]>;
2525
}
2626

27-
export function analyzer(blob: IDLBlob, definedPropertyCollector: DefinedPropertyCollector, unionTypeCollector: UnionTypeCollector) {
2827
export interface DAPInfoCollector {
2928
requests: Set<ClassObject>;
3029
events: Set<ClassObject>;
@@ -34,10 +33,10 @@ export interface DAPInfoCollector {
3433
others: Set<ClassObject>;
3534
}
3635

37-
export function analyzer(blob: IDLBlob, definedPropertyCollector: DefinedPropertyCollector, type: TemplateType, dapInfoCollector: DAPInfoCollector) {
36+
export function analyzer(blob: IDLBlob, definedPropertyCollector: DefinedPropertyCollector, unionTypeCollector: UnionTypeCollector, templateType: TemplateType, dapInfoCollector: DAPInfoCollector) {
3837
let code = blob.raw;
3938
const sourceFile = ts.createSourceFile(blob.source, blob.raw, ScriptTarget.ES2020);
40-
blob.objects = sourceFile.statements.map(statement => walkProgram(blob, statement, definedPropertyCollector, unionTypeCollector, dapInfoCollector)).filter(o => {
39+
blob.objects = sourceFile.statements.map(statement => walkProgram(blob, statement, definedPropertyCollector, unionTypeCollector, templateType, dapInfoCollector)).filter(o => {
4140
return o instanceof ClassObject || o instanceof FunctionObject;
4241
}) as (FunctionObject | ClassObject)[];
4342
}

bridge/scripts/code_generator/src/ts_types/dap/generateHeader.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ function readDAPTemplate(name: string) {
1111
}
1212

1313

14-
export function generateDAPMembersTypes(type: ParameterType[], mode: ParameterMode, typeName: string): string {
14+
export function generateDAPMembersTypes(type: ParameterType, mode: ParameterMode, typeName: string): string {
1515
function generateCTypeFromType(t: ParameterType) {
16-
switch (t) {
16+
switch (t.value) {
1717
case FunctionArgumentType.int64: {
1818
return 'int64_t';
1919
}
@@ -33,23 +33,19 @@ export function generateDAPMembersTypes(type: ParameterType[], mode: ParameterMo
3333
return '';
3434
}
3535

36-
let isNormalType = generateCTypeFromType(type[0]);
36+
let isNormalType = generateCTypeFromType(type);
3737
if (isNormalType) {
3838
return isNormalType;
3939
}
4040

41-
if (typeof type[0] == 'string') {
41+
if (typeof type.value == 'string') {
4242
if (mode.keyword) {
4343
return 'const char*';
4444
}
4545

4646
return 'struct ' + type.value + '*';
4747
}
4848

49-
if (type.length > 1) {
50-
return `size_t ${typeName}Len;\n ${generateCTypeFromType(type[1])}*`
51-
}
52-
5349
if (type.isArray) {
5450
let arrayType = generateDAPMembersTypes(type.value as ParameterType, mode, typeName);
5551
let hasNoPointer = arrayType != 'const char*' && arrayType.indexOf('*') >= 0;

bridge/scripts/code_generator/src/ts_types/dap/generateSource.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ function getTypeName(type: ParameterType) {
138138
function generatePropParser(prop: PropsDeclaration, externalInitialize: string[], info: DAPInfoCollector): string | null {
139139
function wrapOptional(code: string) {
140140
function generateUnInitializeValue(): string {
141-
if (prop.type[0] === FunctionArgumentType.dom_string) {
141+
if (prop.type.value === FunctionArgumentType.dom_string) {
142142
callCode = `args->${prop.name} = NULL;`;
143-
} else if (prop.type[0] === FunctionArgumentType.double) {
143+
} else if (prop.type.value === FunctionArgumentType.double) {
144144
callCode = `args->${prop.name} = 0.0;`;
145-
} else if (prop.type[0] === FunctionArgumentType.int64) {
145+
} else if (prop.type.value === FunctionArgumentType.int64) {
146146
callCode = `args->${prop.name} = 0;`
147-
} else if (prop.type[0] === FunctionArgumentType.boolean) {
147+
} else if (prop.type.value === FunctionArgumentType.boolean) {
148148
callCode = `args->${prop.name} = 0;`
149149
} else {
150150
callCode = `args->${prop.name} = NULL;`;
@@ -161,16 +161,8 @@ function generatePropParser(prop: PropsDeclaration, externalInitialize: string[]
161161

162162
const typeKind = getTypeKind(prop.type);
163163
let callCode = '';
164-
if (prop.type[0] === FunctionArgumentType.dom_string) {
165-
callCode = `args->${prop.name} = get_property_string_copy(ctx, arguments, "${prop.name}");`;
166-
} else if (prop.type[0] === FunctionArgumentType.double) {
167-
callCode = `args->${prop.name} = get_property_float64(ctx, arguments, "${prop.name}");`;
168-
} else if (prop.type[0] === FunctionArgumentType.int64) {
169-
callCode = `args->${prop.name} = get_property_int64(ctx, arguments, "${prop.name}");`
170-
} else if (prop.type[0] === FunctionArgumentType.boolean) {
171-
callCode = `args->${prop.name} = get_property_boolean(ctx, arguments, "${prop.name}");`
172-
} else {
173-
let targetTypes = Array.from(info.others).find(o => o.name === prop.type[0]);
164+
if (typeKind === PropTypeKind.normal || typeKind === PropTypeKind.normalArray) {
165+
const isArray = prop.type.isArray;
174166

175167
let value = prop.type.value;
176168
if (isArray) {
@@ -212,9 +204,9 @@ function generatePropParser(prop: PropsDeclaration, externalInitialize: string[]
212204

213205
function generateMemberInit(prop: PropsDeclaration, externalInitialize: string[], info: DAPInfoCollector): string {
214206
let initCode = '';
215-
if (prop.type[0] === FunctionArgumentType.boolean) {
207+
if (prop.type.value === FunctionArgumentType.boolean) {
216208
initCode = `body->${prop.name} = 0;`;
217-
} else if (prop.type[0] === FunctionArgumentType.int64 || prop.type[0] === FunctionArgumentType.double) {
209+
} else if (prop.type.value === FunctionArgumentType.int64 || prop.type.value === FunctionArgumentType.double) {
218210
initCode = `body->${prop.name} = 0;`;
219211
} else {
220212
initCode = `body->${prop.name} = NULL;`;
@@ -225,10 +217,9 @@ function generateMemberInit(prop: PropsDeclaration, externalInitialize: string[]
225217
return initCode;
226218
}
227219

228-
function generateMemberStringifyCode(prop: PropsDeclaration, bodyName: string, externalInitialize: string[], info: DAPInfoCollector): string {
229-
function wrapIf(code: string) {
230-
if (prop.type[0] === FunctionArgumentType.dom_string || typeof prop.type[0] === 'string') {
231-
return `if (${bodyName}->${prop.name} != NULL) {
220+
function wrapIf(code: string, expression: string, type: ParameterType) {
221+
if (type.value === FunctionArgumentType.dom_string || typeof type.value === 'string') {
222+
return `if (${expression} != NULL) {
232223
${code}
233224
}`;
234225
} else if (type.value === FunctionArgumentType.double || type.value === FunctionArgumentType.int64) {
@@ -242,13 +233,13 @@ function generateMemberStringifyCode(prop: PropsDeclaration, bodyName: string, e
242233
function generateMemberStringifyCode(prop: PropsDeclaration, bodyName: string, externalInitialize: string[], info: DAPInfoCollector): string {
243234

244235
function generateQuickJSInitFromType(type: ParameterType) {
245-
if (type === FunctionArgumentType.double) {
236+
if (type.value === FunctionArgumentType.double) {
246237
return `JS_NewFloat64`;
247-
} else if (type === FunctionArgumentType.dom_string) {
238+
} else if (type.value === FunctionArgumentType.dom_string) {
248239
return `JS_NewString`;
249-
} else if (type === FunctionArgumentType.int64) {
240+
} else if (type.value === FunctionArgumentType.int64) {
250241
return `JS_NewInt64`;
251-
} else if (type === FunctionArgumentType.boolean) {
242+
} else if (type.value === FunctionArgumentType.boolean) {
252243
return `JS_NewBool`;
253244
} else {
254245
let targetTypes = Array.from(info.others).find(o => o.name === type.value);
@@ -262,33 +253,42 @@ function generateMemberStringifyCode(prop: PropsDeclaration, bodyName: string, e
262253

263254
function genCallCode(type: ParameterType, prop: PropsDeclaration) {
264255
let callCode = '';
265-
if (type === FunctionArgumentType.int64) {
256+
if (type.value === FunctionArgumentType.int64) {
266257
callCode = `JS_SetPropertyStr(ctx, object, "${prop.name}", ${generateQuickJSInitFromType(type)}(ctx, ${bodyName}->${prop.name}));`;
267-
} else if (type === FunctionArgumentType.boolean) {
258+
} else if (type.value === FunctionArgumentType.boolean) {
268259
callCode = `JS_SetPropertyStr(ctx, object, "${prop.name}", ${generateQuickJSInitFromType(type)}(ctx, ${bodyName}->${prop.name}));`;
269-
} else if (type === FunctionArgumentType.dom_string) {
260+
} else if (type.value === FunctionArgumentType.dom_string) {
270261
callCode = `JS_SetPropertyStr(ctx, object, "${prop.name}", ${generateQuickJSInitFromType(type)}(ctx, ${bodyName}->${prop.name}));`;
271-
} else if (type === FunctionArgumentType.double) {
262+
} else if (type.value === FunctionArgumentType.double) {
272263
callCode = `JS_SetPropertyStr(ctx, object, "${prop.name}", ${generateQuickJSInitFromType(type)}(ctx, ${bodyName}->${prop.name}));`;
273264
} else {
274-
if (type === FunctionArgumentType.array) {
265+
if (type.isArray) {
266+
let isReference = typeof (prop.type.value as ParameterType).value === 'string';
267+
let arrCallCode = `JS_SetPropertyUint32(ctx, arr, i, ${generateQuickJSInitFromType(prop.type.value as ParameterType)}(ctx, ${isReference ? '&' : ''}${bodyName}->${prop.name}[i]));`;
268+
const typeKind = getTypeKind(type);
269+
if (prop.optional && typeKind === PropTypeKind.normalArray) {
270+
arrCallCode = `if (${bodyName}->${prop.name} != NULL) {
271+
${arrCallCode}
272+
}`;
273+
}
274+
275275
callCode = `JSValue arr = JS_NewArray(ctx);
276276
for(int i = 0; i < ${bodyName}->${prop.name}Len; i ++) {
277277
${arrCallCode}
278278
}
279279
JS_SetPropertyStr(ctx, object, "${prop.name}", arr);`
280280
} else {
281-
let targetTypes = Array.from(info.others).find(o => o.name === type);
281+
let targetTypes = Array.from(info.others).find(o => o.name === type.value);
282282
if (targetTypes) {
283283
generateTypeStringify(targetTypes, prop.name, info, externalInitialize);
284-
callCode = `JS_SetPropertyStr(ctx, object, "${prop.name}", stringify_property_${type}(ctx, ${bodyName}->${prop.name}));`
284+
callCode = `JS_SetPropertyStr(ctx, object, "${prop.name}", stringify_property_${type.value}(ctx, ${bodyName}->${prop.name}));`
285285
}
286286
}
287287
}
288288
return callCode;
289289
}
290290

291-
let callCode = genCallCode(prop.type[0], prop);
291+
let callCode = genCallCode(prop.type, prop);
292292

293293
return addIndent(prop.optional ? wrapIf(callCode, `${bodyName}->${prop.name}`, prop.type) : callCode, 2);
294294
}

bridge/scripts/code_generator/src/ts_types/idl/declaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ParameterBaseType, ParameterType} from "../analyzer";
1+
import {ParameterType} from "../analyzer";
22

33
export enum FunctionArgumentType {
44
// Basic types

0 commit comments

Comments
 (0)