Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value methods to assert value kind #50

Merged
merged 7 commits into from
Dec 21, 2020
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
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: CI

on: [push, pull_request, workflow_dispatch]
on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
test:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Value methods for checking value kind (is string, number, array etc)
- C formatting via `clang-format` to aid future development

## [v0.3.0]
Expand Down
290 changes: 280 additions & 10 deletions v8go.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,294 @@ void ContextDispose(ContextPtr ptr) {

/********** Value **********/

#define LOCAL_VALUE(ptr) \
m_value* val = static_cast<m_value*>(ptr); \
m_ctx* ctx = val->ctx_ptr; \
Isolate* iso = ctx->iso; \
Locker locker(iso); \
Isolate::Scope isolate_scope(iso); \
HandleScope handle_scope(iso); \
Context::Scope context_scope(ctx->ptr.Get(iso)); \
Local<Value> value = val->ptr.Get(iso);

void ValueDispose(ValuePtr ptr) {
delete static_cast<m_value*>(ptr);
}

const char* ValueToString(ValuePtr ptr) {
m_value* val = static_cast<m_value*>(ptr);
m_ctx* ctx = val->ctx_ptr;
Isolate* iso = ctx->iso;
LOCAL_VALUE(ptr);
String::Utf8Value utf8(iso, value);
return CopyString(utf8);
}

Locker locker(iso);
Isolate::Scope isolate_scope(iso);
HandleScope handle_scope(iso);
Context::Scope context_scope(ctx->ptr.Get(iso));
int ValueIsUndefined(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsUndefined();
}

Local<Value> value = val->ptr.Get(iso);
String::Utf8Value utf8(iso, value);
int ValueIsNull(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsNull();
}

return CopyString(utf8);
int ValueIsNullOrUndefined(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsNullOrUndefined();
}

int ValueIsTrue(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsTrue();
}

int ValueIsFalse(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsFalse();
}

int ValueIsName(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsName();
}

int ValueIsString(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsString();
}

int ValueIsSymbol(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsSymbol();
}

int ValueIsFunction(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsFunction();
}

int ValueIsObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsObject();
}

int ValueIsBigInt(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsBigInt();
}

int ValueIsBoolean(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsBoolean();
}

int ValueIsNumber(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsNumber();
}

int ValueIsExternal(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsExternal();
}

int ValueIsInt32(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsInt32();
}

int ValueIsUint32(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsUint32();
}

int ValueIsDate(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsDate();
}

int ValueIsArgumentsObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsArgumentsObject();
}

int ValueIsBigIntObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsBigIntObject();
}

int ValueIsNumberObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsNumberObject();
}

int ValueIsStringObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsStringObject();
}

int ValueIsSymbolObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsSymbolObject();
}

int ValueIsNativeError(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsNativeError();
}

int ValueIsRegExp(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsRegExp();
}

int ValueIsAsyncFunction(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsAsyncFunction();
}

int ValueIsGeneratorFunction(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsGeneratorFunction();
}

int ValueIsGeneratorObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsGeneratorObject();
}

int ValueIsPromise(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsPromise();
}

int ValueIsMap(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsMap();
}

int ValueIsSet(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsSet();
}

int ValueIsMapIterator(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsMapIterator();
}

int ValueIsSetIterator(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsSetIterator();
}

int ValueIsWeakMap(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsWeakMap();
}

int ValueIsWeakSet(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsWeakSet();
}

int ValueIsArray(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsArray();
}

int ValueIsArrayBuffer(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsArrayBuffer();
}

int ValueIsArrayBufferView(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsArrayBufferView();
}

int ValueIsTypedArray(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsTypedArray();
}

int ValueIsUint8Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsUint8Array();
}

int ValueIsUint8ClampedArray(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsUint8ClampedArray();
}

int ValueIsInt8Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsInt8Array();
}

int ValueIsUint16Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsUint16Array();
}

int ValueIsInt16Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsInt16Array();
}

int ValueIsUint32Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsUint32Array();
}

int ValueIsInt32Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsInt32Array();
}

int ValueIsFloat32Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsFloat32Array();
}

int ValueIsFloat64Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsFloat64Array();
}

int ValueIsBigInt64Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsBigInt64Array();
}

int ValueIsBigUint64Array(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsBigUint64Array();
}

int ValueIsDataView(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsDataView();
}

int ValueIsSharedArrayBuffer(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsSharedArrayBuffer();
}

int ValueIsProxy(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsProxy();
}

int ValueIsWasmModuleObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsWasmModuleObject();
}

int ValueIsModuleNamespaceObject(ValuePtr ptr) {
LOCAL_VALUE(ptr);
return value->IsModuleNamespaceObject();
}

/********** Version **********/
Expand Down
54 changes: 54 additions & 0 deletions v8go.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,60 @@ extern RtnValue RunScript(ContextPtr ctx_ptr,

extern void ValueDispose(ValuePtr ptr);
const char* ValueToString(ValuePtr ptr);
int ValueIsUndefined(ValuePtr ptr);
int ValueIsNull(ValuePtr ptr);
int ValueIsNullOrUndefined(ValuePtr ptr);
int ValueIsTrue(ValuePtr ptr);
int ValueIsFalse(ValuePtr ptr);
int ValueIsName(ValuePtr ptr);
int ValueIsString(ValuePtr ptr);
int ValueIsSymbol(ValuePtr ptr);
int ValueIsFunction(ValuePtr ptr);
int ValueIsObject(ValuePtr ptr);
int ValueIsBigInt(ValuePtr ptr);
int ValueIsBoolean(ValuePtr ptr);
int ValueIsNumber(ValuePtr ptr);
int ValueIsExternal(ValuePtr ptr);
int ValueIsInt32(ValuePtr ptr);
int ValueIsUint32(ValuePtr ptr);
int ValueIsDate(ValuePtr ptr);
int ValueIsArgumentsObject(ValuePtr ptr);
int ValueIsBigIntObject(ValuePtr ptr);
int ValueIsNumberObject(ValuePtr ptr);
int ValueIsStringObject(ValuePtr ptr);
int ValueIsSymbolObject(ValuePtr ptr);
int ValueIsNativeError(ValuePtr ptr);
int ValueIsRegExp(ValuePtr ptr);
int ValueIsAsyncFunction(ValuePtr ptr);
int ValueIsGeneratorFunction(ValuePtr ptr);
int ValueIsGeneratorObject(ValuePtr ptr);
int ValueIsPromise(ValuePtr ptr);
int ValueIsMap(ValuePtr ptr);
int ValueIsSet(ValuePtr ptr);
int ValueIsMapIterator(ValuePtr ptr);
int ValueIsSetIterator(ValuePtr ptr);
int ValueIsWeakMap(ValuePtr ptr);
int ValueIsWeakSet(ValuePtr ptr);
int ValueIsArray(ValuePtr ptr);
int ValueIsArrayBuffer(ValuePtr ptr);
int ValueIsArrayBufferView(ValuePtr ptr);
int ValueIsTypedArray(ValuePtr ptr);
int ValueIsUint8Array(ValuePtr ptr);
int ValueIsUint8ClampedArray(ValuePtr ptr);
int ValueIsInt8Array(ValuePtr ptr);
int ValueIsUint16Array(ValuePtr ptr);
int ValueIsInt16Array(ValuePtr ptr);
int ValueIsUint32Array(ValuePtr ptr);
int ValueIsInt32Array(ValuePtr ptr);
int ValueIsFloat32Array(ValuePtr ptr);
int ValueIsFloat64Array(ValuePtr ptr);
int ValueIsBigInt64Array(ValuePtr ptr);
int ValueIsBigUint64Array(ValuePtr ptr);
int ValueIsDataView(ValuePtr ptr);
int ValueIsSharedArrayBuffer(ValuePtr ptr);
int ValueIsProxy(ValuePtr ptr);
int ValueIsWasmModuleObject(ValuePtr ptr);
int ValueIsModuleNamespaceObject(ValuePtr ptr);

const char* Version();

Expand Down
Loading