-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor initialize and refactor timer.
- Loading branch information
Showing
31 changed files
with
521 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2019 Alibaba Inc. All rights reserved. | ||
* Author: Kraken Team. | ||
*/ | ||
|
||
#include "member_installer.h" | ||
|
||
namespace kraken { | ||
|
||
int combinePropFlags(JSPropFlag a, JSPropFlag b) { | ||
return a | b; | ||
} | ||
int combinePropFlags(JSPropFlag a, JSPropFlag b, JSPropFlag c) { | ||
return a | b | c; | ||
} | ||
|
||
void MemberInstaller::installAttributes(JSContext* ctx, JSValue root, std::initializer_list<MemberInstaller::AttributeConfig> config) { | ||
for (auto& c : config) { | ||
JS_DefinePropertyValueStr(ctx, root, c.name, JS_DupValue(ctx, c.value), c.flag); | ||
} | ||
} | ||
|
||
int compilePropFlags(); | ||
|
||
void MemberInstaller::installFunctions(JSContext* ctx, JSValue root, std::initializer_list<FunctionConfig> config) { | ||
for (auto& c : config) { | ||
JSValue function = JS_NewCFunction(ctx, c.function, c.name, c.length); | ||
JS_DefinePropertyValueStr(ctx, root, c.name, function, c.flag); | ||
} | ||
} | ||
|
||
} // namespace kraken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2019 Alibaba Inc. All rights reserved. | ||
* Author: Kraken Team. | ||
*/ | ||
|
||
#ifndef KRAKENBRIDGE_MEMBER_INSTALLER_H | ||
#define KRAKENBRIDGE_MEMBER_INSTALLER_H | ||
|
||
#include <quickjs/quickjs.h> | ||
#include <initializer_list> | ||
|
||
namespace kraken { | ||
|
||
// Flags for object properties. | ||
enum JSPropFlag { | ||
normal = JS_PROP_NORMAL, | ||
writable = JS_PROP_WRITABLE, | ||
enumerable = JS_PROP_ENUMERABLE, | ||
configurable = JS_PROP_CONFIGURABLE | ||
}; | ||
|
||
// Combine multiple prop flags. | ||
int combinePropFlags(JSPropFlag a, JSPropFlag b); | ||
int combinePropFlags(JSPropFlag a, JSPropFlag b, JSPropFlag c); | ||
|
||
// A set of utility functions to define attributes members as ES properties. | ||
class MemberInstaller { | ||
public: | ||
struct AttributeConfig { | ||
AttributeConfig& operator=(const AttributeConfig&) = delete; | ||
const char* name; | ||
JSValue value; | ||
int flag; // Flags for object properties. | ||
}; | ||
|
||
struct FunctionConfig { | ||
FunctionConfig& operator=(const FunctionConfig&) = delete; | ||
const char* name; | ||
JSCFunction* function; | ||
size_t length; | ||
int flag; // Flags for object properties. | ||
}; | ||
|
||
static void installAttributes(JSContext* ctx, JSValue root, std::initializer_list<AttributeConfig>); | ||
static void installFunctions(JSContext* ctx, JSValue root, std::initializer_list<FunctionConfig>); | ||
}; | ||
|
||
} | ||
|
||
#endif // KRAKENBRIDGE_MEMBER_INSTALLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.