Skip to content
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e1150fb
Address sanitizer
CedricGuillemet Oct 29, 2025
a569011
template parameter
CedricGuillemet Oct 29, 2025
f0308c8
default values
CedricGuillemet Oct 29, 2025
41d85d3
JNI sanitizer
CedricGuillemet Oct 29, 2025
7ef0e14
android image with asan
CedricGuillemet Oct 29, 2025
657a9ee
ASAN from android ndk
CedricGuillemet Nov 4, 2025
5a23a08
macos13
CedricGuillemet Nov 4, 2025
fddf441
up android extensions
CedricGuillemet Nov 4, 2025
6e9c40d
implicit instantiation of undefined template
CedricGuillemet Nov 4, 2025
e552838
casting u16
CedricGuillemet Nov 4, 2025
032df9e
macos14
CedricGuillemet Nov 4, 2025
f27f623
up ios simulator
CedricGuillemet Nov 4, 2025
7abc893
PR feedback
CedricGuillemet Nov 5, 2025
dda689a
mangled names
CedricGuillemet Nov 5, 2025
eda3414
syntax
CedricGuillemet Nov 5, 2025
f0594ca
copy/paste
CedricGuillemet Nov 5, 2025
ced60d1
typo
CedricGuillemet Nov 5, 2025
1979429
more on name demangle
CedricGuillemet Nov 5, 2025
871fbd8
namespace test
CedricGuillemet Nov 5, 2025
1738f3b
yet another namespace test
CedricGuillemet Nov 5, 2025
14afcdc
once more
CedricGuillemet Nov 5, 2025
8f53e65
recursive call
CedricGuillemet Nov 5, 2025
49e7870
revert namespace tweaks
CedricGuillemet Nov 6, 2025
f1d3e31
Merge branch 'main' of https://github.com/BabylonJS/JsRuntimeHost int…
CedricGuillemet Nov 6, 2025
f1cba24
use clang for sanitizer
CedricGuillemet Nov 6, 2025
1f56b79
sanitizer
CedricGuillemet Nov 6, 2025
fc90f72
kick build
CedricGuillemet Nov 7, 2025
14d1a39
something is wrong with jsc
CedricGuillemet Nov 7, 2025
3faa15d
casting maybe?
CedricGuillemet Nov 7, 2025
3ea8de8
false positive
CedricGuillemet Nov 7, 2025
a2d6080
yet another test
CedricGuillemet Nov 7, 2025
32f147e
disable asan
CedricGuillemet Nov 7, 2025
23d57b6
fix template attribute
CedricGuillemet Nov 7, 2025
12d5cf9
check finite
CedricGuillemet Nov 7, 2025
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
30 changes: 26 additions & 4 deletions .github/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ schedules:

variables:
- name: ndkVersion
value: 25.2.9519653
value: 28.2.13676358

jobs:
# WIN32
Expand Down Expand Up @@ -85,6 +85,13 @@ jobs:
vmImage: 'macOS-latest'
xCodeVersion: 16.4

- template: jobs/macos.yml
parameters:
name: 'macOS_Xcode164_Sanitizers'
vmImage: 'macOS-latest'
xCodeVersion: 16.4
enableSanitizers: true

# iOS
- template: jobs/ios.yml
parameters:
Expand All @@ -96,9 +103,24 @@ jobs:
- template: jobs/ios.yml
parameters:
name: 'iOS_Xcode152'
vmImage: 'macOS-13'
vmImage: 'macOS-14'
xCodeVersion: 15.2
simulator: 'iPhone 14'
simulator: 'iPhone 15'

# Linux
- template: jobs/linux.yml
- template: jobs/linux.yml
parameters:
name: Ubuntu_gcc

- template: jobs/linux.yml
parameters:
name: Ubuntu_clang
cc: clang
cxx: clang++

- template: jobs/linux.yml
parameters:
name: Ubuntu_Sanitizers_clang
enableSanitizers: true
cc: clang
cxx: clang++
4 changes: 3 additions & 1 deletion .github/jobs/android.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
parameters:
- name: name
type: string
default: ''
- name: jsEngine
type: string
default: ''

jobs:
- job: ${{parameters.name}}
timeoutInMinutes: 30

pool:
vmImage: macos-13
vmImage: macos-14

steps:
- script: |
Expand Down
18 changes: 15 additions & 3 deletions .github/jobs/linux.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
parameters:
name: ''
enableSanitizers: false
cc: gcc
cxx: g++

jobs:
- job: ubuntu
- job: ${{parameters.name}}
timeoutInMinutes: 15

pool:
vmImage: ubuntu-latest

variables:
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }}

steps:
- script: |
sudo apt-get update
sudo apt-get install libjavascriptcoregtk-4.1-dev libcurl4-openssl-dev ninja-build
sudo apt-get install libjavascriptcoregtk-4.1-dev libcurl4-openssl-dev ninja-build clang
displayName: 'Install packages'

- script: cmake -B Build/ubuntu -GNinja -D CMAKE_BUILD_TYPE=RelWithDebInfo
- script: |
export CC=${{parameters.cc}}
export CXX=${{parameters.cxx}}
cmake -B Build/ubuntu -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo -D ENABLE_SANITIZERS=$(SANITIZER_FLAG) -D CMAKE_C_COMPILER=${{parameters.cc}} -D CMAKE_CXX_COMPILER=${{parameters.cxx}}
displayName: 'Configure CMake'

- script: |
Expand Down
6 changes: 5 additions & 1 deletion .github/jobs/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
name: ''
vmImage: ''
xCodeVersion: ''
enableSanitizers: false

jobs:
- job: ${{parameters.name}}
Expand All @@ -10,13 +11,16 @@ jobs:
pool:
vmImage: ${{parameters.vmImage}}

variables:
SANITIZER_FLAG: ${{ coalesce(replace(format('{0}', parameters.enableSanitizers), 'True', 'ON'), 'OFF') }}

steps:
- script: |
sudo xcode-select --switch /Applications/Xcode_${{parameters.xCodeVersion}}.app/Contents/Developer
displayName: 'Select Xcode ${{parameters.xCodeVersion}}'

- script: |
cmake -B Build/macOS -GXcode
cmake -B Build/macOS -G Xcode -D ENABLE_SANITIZERS=$(SANITIZER_FLAG)
displayName: 'Configure CMake'

- task: Xcode@5
Expand Down
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FetchContent_Declare(arcana.cpp
GIT_TAG c726dbe58713eda65bfb139c257093c43479b894)
FetchContent_Declare(AndroidExtensions
GIT_REPOSITORY https://github.com/bghgary/AndroidExtensions.git
GIT_TAG 7d88a601fda9892791e7b4e994e375e049615688)
GIT_TAG 24370fff52a03ef43dcf5e5fcb8b84338b779a05)
FetchContent_Declare(asio
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
GIT_TAG f693a3eb7fe72a5f19b975289afc4f437d373d9c)
Expand Down Expand Up @@ -73,6 +73,31 @@ option(JSRUNTIMEHOST_POLYFILL_ABORT_CONTROLLER "Include JsRuntimeHost Polyfills
option(JSRUNTIMEHOST_POLYFILL_WEBSOCKET "Include JsRuntimeHost Polyfill WebSocket." ON)
option(JSRUNTIMEHOST_POLYFILL_BLOB "Include JsRuntimeHost Polyfill Blob." ON)

# Sanitizers
option(ENABLE_SANITIZERS "Enable AddressSanitizer and UBSan" OFF)

if(ENABLE_SANITIZERS)
set(ENABLE_RTTI ON CACHE BOOL "" FORCE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(SANITIZERS "address,undefined")
# Check for Clang since vptr and fdsan are Clang-specific
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND SANITIZERS "vptr")
# FDSan only works on Android builds with Clang

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure it doesn't work with linux (and macOS) as well? is it an issue with clang version in default Ubuntu 24.x and Xcode pre-26? if that's the actual case, can this check be specific about the clang version instead of the OS/platform?

if (ANDROID)
list(APPEND SANITIZERS "fdsan")
endif()
endif()

string(JOIN "," SANITIZER_FLAGS ${SANITIZERS})

add_compile_options(-fsanitize=${SANITIZER_FLAGS} -fno-omit-frame-pointer)
add_link_options(-fsanitize=${SANITIZER_FLAGS})
else()
message(WARNING "Sanitizers not supported on this compiler.")
endif()
endif()

# --------------------------------------------------

FetchContent_MakeAvailable_With_Message(arcana.cpp)
Expand Down
7 changes: 3 additions & 4 deletions Core/AppRuntime/V8Inspector/Source/V8InspectorAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,9 @@ namespace Babylon
}
v8::Local<v8::String> string_value = v8::Local<v8::String>::Cast(value);
int len = string_value->Length();
std::basic_string<uint16_t> buffer(len, '\0');
string_value->Write(v8::Isolate::GetCurrent(), &buffer[0], 0, len);
return v8_inspector::StringBuffer::create(
v8_inspector::StringView(buffer.data(), len));
std::basic_string<char16_t> buffer(len, '\0');
string_value->Write(v8::Isolate::GetCurrent(), reinterpret_cast<uint16_t*>(&buffer[0]), 0, len); // Write expects uint16_t* but the template parameter is char16_t
return v8_inspector::StringBuffer::create(v8_inspector::StringView(reinterpret_cast<uint16_t*>(buffer.data()), len));
}

bool AgentImpl::AppendMessage(
Expand Down
20 changes: 17 additions & 3 deletions Core/Node-API/Source/js_native_api_javascriptcore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ struct napi_callback_info__ {
};

namespace {
size_t jschar_length(const JSChar* str) {
size_t len = 0;
while (str[len] != 0) { ++len; }
return len;
}

class JSString {
public:
JSString(const JSString&) = delete;
Expand All @@ -33,7 +39,7 @@ namespace {
}

JSString(const JSChar* string, size_t length = NAPI_AUTO_LENGTH)
: _string{JSStringCreateWithCharacters(string, length == NAPI_AUTO_LENGTH ? std::char_traits<JSChar>::length(string) : length)} {
: _string{JSStringCreateWithCharacters(string, length == NAPI_AUTO_LENGTH ? jschar_length(string) : length)} {
}

~JSString() {
Expand Down Expand Up @@ -1658,9 +1664,13 @@ napi_status napi_get_value_int32(napi_env env, napi_value value, int32_t* result
CHECK_ARG(env, result);

JSValueRef exception{};
*result = static_cast<int32_t>(JSValueToNumber(env->context, ToJSValue(value), &exception));

double num = JSValueToNumber(env->context, ToJSValue(value), &exception);
CHECK_JSC(env, exception);

RETURN_STATUS_IF_FALSE(env, !std::isfinite(num), napi_number_expected);
*result = static_cast<int32_t>(num);

return napi_ok;
}

Expand All @@ -1670,9 +1680,13 @@ napi_status napi_get_value_uint32(napi_env env, napi_value value, uint32_t* resu
CHECK_ARG(env, result);

JSValueRef exception{};
*result = static_cast<uint32_t>(JSValueToNumber(env->context, ToJSValue(value), &exception));

double num = JSValueToNumber(env->context, ToJSValue(value), &exception);
CHECK_JSC(env, exception);

RETURN_STATUS_IF_FALSE(env, !std::isfinite(num), napi_number_expected);
*result = static_cast<uint32_t>(num);

return napi_ok;
}

Expand Down
10 changes: 8 additions & 2 deletions Polyfills/Blob/Source/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ namespace Babylon::Polyfills::Internal
Napi::Value Blob::ArrayBuffer(const Napi::CallbackInfo&)
{
const auto arrayBuffer = Napi::ArrayBuffer::New(Env(), m_data.size());
std::memcpy(arrayBuffer.Data(), m_data.data(), m_data.size());
if (m_data.data())
{
std::memcpy(arrayBuffer.Data(), m_data.data(), m_data.size());
}

const auto deferred = Napi::Promise::Deferred::New(Env());
deferred.Resolve(arrayBuffer);
Expand All @@ -88,7 +91,10 @@ namespace Babylon::Polyfills::Internal
Napi::Value Blob::Bytes(const Napi::CallbackInfo&)
{
const auto arrayBuffer = Napi::ArrayBuffer::New(Env(), m_data.size());
std::memcpy(arrayBuffer.Data(), m_data.data(), m_data.size());
if (m_data.data())
{
std::memcpy(arrayBuffer.Data(), m_data.data(), m_data.size());
}
const auto uint8Array = Napi::Uint8Array::New(Env(), m_data.size(), arrayBuffer, 0);

const auto deferred = Napi::Promise::Deferred::New(Env());
Expand Down
2 changes: 1 addition & 1 deletion Polyfills/URL/Source/URL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Babylon::Polyfills::Internal
{
if (env.Global().Get(JS_URL_CONSTRUCTOR_NAME).IsUndefined())
{
Napi::Function func = DefineClass(
Napi::Function func = Napi::ObjectWrap<URL>::DefineClass(
env,
JS_URL_CONSTRUCTOR_NAME,
{
Expand Down
6 changes: 6 additions & 0 deletions Tests/UnitTests/Android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(UnitTestsJNI)

if(ENABLE_SANITIZERS)
set(SANITIZERS "address,undefined")
add_compile_options(-fsanitize=${SANITIZERS} -fno-omit-frame-pointer)
add_link_options(-fsanitize=${SANITIZERS})
endif()

get_filename_component(UNIT_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../.." ABSOLUTE)
get_filename_component(TESTS_DIR "${UNIT_TESTS_DIR}/.." ABSOLUTE)
get_filename_component(REPO_ROOT_DIR "${TESTS_DIR}/.." ABSOLUTE)
Expand Down
Loading