Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Coverage

on:
pull_request:
paths-ignore:
- 'docs/**'
push:
branches:
- main
paths-ignore:
- 'docs/**'

jobs:
coverage-mac-clang:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
backends: [ V8, JavaScriptCore, Lua ]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
key: build-dependencies-macos
path: |
build/ScriptXTestLibs
build/googletest-src
- name: prepare lcov
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install lcov
- name: Configure cmake
env:
SCRIPTX_TEST_FORCE_UPDATE_DEPS: ON
run: |
mkdir -p build && cd build
cmake ../test \
-DSCRIPTX_BACKEND=${{ matrix.backends }} \
-DDEVOPS_ENABLE_COVERAGE=ON \
-DCMAKE_BUILD_TYPE=DEBUG
- name: Compile UnitTests
run: |
cd build
cmake --build . -j $(sysctl -n hw.ncpu) --target UnitTests
- name: Run UnitTests
run: |
cd build && ./UnitTests
- name: Generate Coverate Data
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
run: |
cd build
lcov -c -d CMakeFiles/ -o all.info
lcov -e all.info -o coverage.info '*/ScriptX/src/*' '*/ScriptX/backend/*'

- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: './build/coverage.info'
flag-name: "Backend-${{ matrix.backends }}"
parallel: true

coverage-finish:
needs: coverage-mac-clang
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>全能的脚本引擎抽象层</p>

---
[![README-English](https://img.shields.io/badge/README-english-lightgreen)](README.md) [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://www.apache.org/licenses/LICENSE-2.0) [![UnitTests](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tencent/ScriptX) ![Lines of code](https://img.shields.io/tokei/lines/github/tencent/ScriptX) ![GitHub top language](https://img.shields.io/github/languages/top/tencent/ScriptX)
[![README-English](https://img.shields.io/badge/README-english-lightgreen)](README.md) [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://www.apache.org/licenses/LICENSE-2.0) [![UnitTests](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tencent/ScriptX) ![Lines of code](https://img.shields.io/tokei/lines/github/tencent/ScriptX) ![GitHub top language](https://img.shields.io/github/languages/top/tencent/ScriptX) [![Coverage Status](https://coveralls.io/repos/github/Tencent/ScriptX/badge.svg)](https://coveralls.io/github/Tencent/ScriptX)



Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

---

[![README中文](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87-lightgreen)](README-zh.md) [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://www.apache.org/licenses/LICENSE-2.0) [![UnitTests](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tencent/ScriptX) ![Lines of code](https://img.shields.io/tokei/lines/github/tencent/ScriptX) ![GitHub top language](https://img.shields.io/github/languages/top/tencent/ScriptX)
[![README中文](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87-lightgreen)](README-zh.md) [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://www.apache.org/licenses/LICENSE-2.0) [![UnitTests](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/Tencent/ScriptX/actions/workflows/unit_tests.yml) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tencent/ScriptX) ![Lines of code](https://img.shields.io/tokei/lines/github/tencent/ScriptX) ![GitHub top language](https://img.shields.io/github/languages/top/tencent/ScriptX) [![Coverage Status](https://coveralls.io/repos/github/Tencent/ScriptX/badge.svg)](https://coveralls.io/github/Tencent/ScriptX)

![ScriptX Architecture](docs/media/banner.webp)

Expand Down
1 change: 1 addition & 0 deletions backend/JavaScriptCore/JscLocalReference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Local<Unsupported> Local<Value>::asUnsupported() const {
}

bool Local<Value>::operator==(const script::Local<script::Value>& other) const {
if (isNull()) return other.isNull();
return JSValueIsStrictEqual(jsc_backend::currentEngineContextChecked(),
const_cast<JSValueRef>(val_), const_cast<JSValueRef>(other.val_));
}
Expand Down
2 changes: 1 addition & 1 deletion backend/Lua/LuaEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ bool LuaEngine::isInstanceOf(lua_State* lua, int classIndex, int selfIndex) {
}

bool LuaEngine::isInstanceOf(lua_State* lua, const void* classDefine, int selfIndex) {
if (selfIndex == 0) {
if (selfIndex == 0 || classDefine == nullptr) {
return false;
}

Expand Down
8 changes: 5 additions & 3 deletions backend/Lua/LuaHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ namespace {

int luaErrorMessageHandler(lua_State* L) {
auto msg = LuaEngine::make<Local<Value>>(1);
auto error = Object::newObject();
// set message
error.set("message", msg);
auto error = msg.isObject() ? msg.asObject() : Object::newObject();
if (!msg.isObject() || error.has("message")) {
// set message
error.set("message", msg);
}

// set stacktrace
luaL_traceback(L, L, nullptr, 1);
Expand Down
26 changes: 18 additions & 8 deletions backend/Lua/LuaLocalReference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ ValueKind Local<Value>::getKind() const {
return ValueKind::kBoolean;
} else if (type == LUA_TFUNCTION) {
return ValueKind::kFunction;
} else if (isByteBuffer()) {
return ValueKind::kByteBuffer;
} else if (type == LUA_TTABLE) {
// lua don't have array type, the are all tables
return ValueKind::kObject;
} else if (isByteBuffer()) {
return ValueKind::kByteBuffer;
} else {
return ValueKind::kUnsupported;
}
Expand All @@ -160,22 +160,32 @@ bool Local<Value>::isNull() const {
return val_ == 0 || lua_isnoneornil(lua_backend::currentLua(), val_);
}

bool Local<Value>::isString() const { return getKind() == ValueKind::kString; }
bool Local<Value>::isString() const {
return val_ != 0 && lua_type(lua_backend::currentLua(), val_) == LUA_TSTRING;
}

bool Local<Value>::isNumber() const { return getKind() == ValueKind::kNumber; }
bool Local<Value>::isNumber() const {
return val_ != 0 && lua_type(lua_backend::currentLua(), val_) == LUA_TNUMBER;
}

bool Local<Value>::isBoolean() const { return getKind() == ValueKind::kBoolean; }
bool Local<Value>::isBoolean() const {
return val_ != 0 && lua_type(lua_backend::currentLua(), val_) == LUA_TBOOLEAN;
}

bool Local<Value>::isFunction() const { return getKind() == ValueKind::kFunction; }
bool Local<Value>::isFunction() const {
return val_ != 0 && lua_type(lua_backend::currentLua(), val_) == LUA_TFUNCTION;
}

bool Local<Value>::isArray() const { return getKind() == ValueKind::kObject; }
bool Local<Value>::isArray() const { return isObject(); }

bool Local<Value>::isByteBuffer() const {
auto engine = lua_backend::currentEngine();
return engine->byteBufferDelegate_->isByteBuffer(engine, *this);
}

bool Local<Value>::isObject() const { return getKind() == ValueKind::kObject; }
bool Local<Value>::isObject() const {
return val_ != 0 && lua_type(lua_backend::currentLua(), val_) == LUA_TTABLE;
}

bool Local<Value>::isUnsupported() const { return getKind() == ValueKind::kUnsupported; }

Expand Down
74 changes: 40 additions & 34 deletions backend/V8/V8LocalReference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,44 @@

namespace script {

#define REF_IMPL_BASIC_FUNC(ValueType) \
Local<ValueType>::Local(const Local<ValueType>& copy) : val_(copy.val_) {} \
Local<ValueType>::Local(Local<ValueType>&& from) noexcept : val_(from.val_) { \
from.val_.Clear(); \
} \
Local<ValueType>::~Local() { \
assert(val_.IsEmpty() || EngineScope::currentEngine() != nullptr); \
} \
Local<ValueType>& Local<ValueType>::operator=(const Local& from) { \
if (&from != this) { \
val_ = from.val_; \
} \
return *this; \
} \
Local<ValueType>& Local<ValueType>::operator=(Local&& move) noexcept { \
if (&move != this) { \
val_ = move.val_; \
move.val_.Clear(); \
} \
return *this; \
} \
void Local<ValueType>::swap(Local& rhs) noexcept { \
if (&rhs != this) { \
std::swap(val_, rhs.val_); \
} \
} \
bool Local<ValueType>::operator==(const script::Local<script::Value>& other) const { \
return val_->StrictEquals(other.val_); \
#define REF_IMPL_BASIC_FUNC(ValueType) \
Local<ValueType>::Local(const Local<ValueType>& copy) : val_(copy.val_) {} \
Local<ValueType>::Local(Local<ValueType>&& from) noexcept : val_(from.val_) { \
from.val_.Clear(); \
} \
Local<ValueType>::~Local() { \
assert(val_.IsEmpty() || EngineScope::currentEngine() != nullptr); \
} \
Local<ValueType>& Local<ValueType>::operator=(const Local& from) { \
if (&from != this) { \
val_ = from.val_; \
} \
return *this; \
} \
Local<ValueType>& Local<ValueType>::operator=(Local&& move) noexcept { \
if (&move != this) { \
val_ = move.val_; \
move.val_.Clear(); \
} \
return *this; \
} \
void Local<ValueType>::swap(Local& rhs) noexcept { \
if (&rhs != this) { \
std::swap(val_, rhs.val_); \
} \
}

// if Local is created with null ref, it's an error
#define REF_IMPL_BASIC_NOT_VALUE(ValueType) \
Local<ValueType>::Local(InternalLocalRef v8Local) : val_(v8Local) { \
if (val_.IsEmpty() || val_->IsNullOrUndefined()) throw Exception("null reference"); \
} \
Local<String> Local<ValueType>::describe() const { return asValue().describe(); } \
std::string Local<ValueType>::describeUtf8() const { return asValue().describeUtf8(); }
#define REF_IMPL_BASIC_NOT_VALUE(ValueType) \
Local<ValueType>::Local(InternalLocalRef v8Local) : val_(v8Local) { \
if (val_.IsEmpty() || val_->IsNullOrUndefined()) throw Exception("null reference"); \
} \
Local<String> Local<ValueType>::describe() const { return asValue().describe(); } \
std::string Local<ValueType>::describeUtf8() const { return asValue().describeUtf8(); } \
bool Local<ValueType>::operator==(const script::Local<script::Value>& other) const { \
if (other.isNull()) return false; \
return val_->StrictEquals(other.val_); \
}

#define REF_IMPL_TO_VALUE(ValueType) \
Local<Value> Local<ValueType>::asValue() const { return Local<Value>(val_.As<v8::Value>()); }
Expand Down Expand Up @@ -133,6 +134,11 @@ ValueKind Local<Value>::getKind() const {
}
}

bool Local<Value>::operator==(const script::Local<script::Value>& other) const {
if (isNull()) return other.isNull();
return val_->StrictEquals(other.val_);
}

bool Local<Value>::isObject() const { return !isNull() && val_->IsObject(); }

Local<Object> Local<Value>::asObject() const {
Expand Down
1 change: 1 addition & 0 deletions backend/WebAssembly/WasmLocalReference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Local<Unsupported> Local<Value>::asUnsupported() const {
}

bool Local<Value>::operator==(const script::Local<script::Value>& other) const {
if (isNull()) return other.isNull();
return wasm_backend::Stack::equals(val_, other.val_);
}

Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 20)
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../VERSION SCRIPTX_VERSION)
project(ScriptXUnitTests VERSION ${SCRIPTX_VERSION} LANGUAGES CXX)

option(DEVOPS_ENABLE_COVERAGE "enable coverage" OFF)
option(DEVOPS_ENABLE_COVERAGE "enable code coverage" OFF)
enable_testing()

add_executable(UnitTests)
Expand All @@ -31,7 +31,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif ()

if (DEVOPS_ENABLE_COVERAGE)
# bk support gcov only
# devops support gcov only
string(APPEND CMAKE_CXX_FLAGS_DEBUG " --coverage -g3")
endif ()
endif ()
Expand Down
Loading