From 2c8d1c1ba9a6adf7770863fc84b0257ea05f7116 Mon Sep 17 00:00:00 2001 From: Roger Chapman Date: Sat, 19 Dec 2020 19:54:35 +1100 Subject: [PATCH 1/6] Value methods to assert value kind --- v8go.cc | 58 ++++++++--- v8go.h | 6 ++ value.go | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++ value_test.go | 36 +++++++ 4 files changed, 365 insertions(+), 13 deletions(-) diff --git a/v8go.cc b/v8go.cc index b393dfb1..58cc9727 100644 --- a/v8go.cc +++ b/v8go.cc @@ -200,26 +200,58 @@ void ContextDispose(ContextPtr ptr) { /********** Value **********/ +#define LOCAL_VALUE(ptr) \ + m_value* val = static_cast(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 = val->ptr.Get(iso); + void ValueDispose(ValuePtr ptr) { - delete static_cast(ptr); + delete static_cast(ptr); } const char* ValueToString(ValuePtr ptr) { - m_value* val = static_cast(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(ptr); + String::Utf8Value utf8(iso, value); - Local value = val->ptr.Get(iso); - String::Utf8Value utf8(iso, value); - - return CopyString(utf8); + return CopyString(utf8); } +int ValueIsUndefined(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsUndefined() ? 1 : 0; +} + +int ValueIsNull(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsNull() ? 1 : 0; +} + +int ValueIsNullOrUndefined(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsNullOrUndefined() ? 1 : 0; +} + +int ValueIsTrue(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsTrue() ? 1 : 0; +} + +int ValueIsFalse(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsFalse() ? 1 : 0; +} + +int ValueIsString(ValuePtr ptr) { + LOCAL_VALUE(ptr); + + return value->IsString() ? 1 : 0; +} + /********** Version **********/ diff --git a/v8go.h b/v8go.h index 378482df..e8b737e6 100644 --- a/v8go.h +++ b/v8go.h @@ -47,6 +47,12 @@ extern RtnValue RunScript(ContextPtr ctx_ptr, const char* source, const char* or 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 ValueIsString(ValuePtr ptr); const char* Version(); diff --git a/value.go b/value.go index 5130821e..19caffa9 100644 --- a/value.go +++ b/value.go @@ -22,6 +22,284 @@ func (v *Value) String() string { return C.GoString(s) } +// IsUndefined returns true if this value is the undefined value. See ECMA-262 4.3.10. +func (v *Value) IsUndefined() bool { + return C.ValueIsUndefined(v.ptr) > 0 +} + +// IsNull returns true if this value is the null value. See ECMA-262 4.3.11. +func (v *Value) IsNull() bool { + return C.ValueIsNull(v.ptr) > 0 +} + +// IsNullOrUndefined returns true if this value is either the null or the undefined value. +// See ECMA-262 4.3.11. and 4.3.12 +// This is equivalent to `value == null` in JS. +func (v *Value) IsNullOrUndefined() bool { + return C.ValueIsNullOrUndefined(v.ptr) > 0 +} + +// IsTrue returns true if this value is true. +// This is not the same as `BooleanValue()`. The latter performs a conversion to boolean, +// i.e. the result of `Boolean(value)` in JS, whereas this checks `value === true`. +func (v *Value) IsTrue() bool { + return C.ValueIsTrue(v.ptr) > 0 +} + +// IsFalse returns true if this value is false. +// This is not the same as `!BooleanValue()`. The latter performs a conversion to boolean, +// i.e. the result of `!Boolean(value)` in JS, whereas this checks `value === false`. +func (v *Value) IsFalse() bool { + return C.ValueIsFalse(v.ptr) > 0 +} + +// IsName returns true if this value is a symbol or a string. +// This is equivalent to `typeof value === 'string' || typeof value === 'symbol'` in JS. +func (v *Value) IsName() bool { + panic("not implemented") +} + +// IsString returns true if this value is an instance of the String type. See ECMA-262 8.4. +// This is equivalent to `typeof value === 'string'` in JS. +func (v *Value) IsString() bool { + return C.ValueIsString(v.ptr) > 0 +} + +// IsSymbol returns true if this value is a symbol. +// This is equivalent to `typeof value === 'symbol'` in JS. +func (v *Value) IsSymbol() bool { + panic("not implemented") +} + +// IsFunction returns true if this value is a function. +// This is equivalent to `typeof value === 'function'` in JS. +func (v *Value) IsFunction() bool { + panic("not implemented") +} + +// IsObject returns true if this value is an object. +func (v *Value) IsObject() bool { + panic("not implemented") +} + +// IsBigInt returns true if this value is a bigint. +// This is equivalent to `typeof value === 'bigint'` in JS. +func (v *Value) IsBigInt() bool { + panic("not implemented") +} + +// IsBoolean returns true if this value is boolean. +// This is equivalent to `typeof value === 'boolean'` in JS. +func (v *Value) IsBoolean() bool { + panic("not implemented") +} + +// IsNumber returns true if this value is a number. +// This is equivalent to `typeof value === 'number'` in JS. +func (v *Value) IsNumber() bool { + panic("not implemented") +} + +// IsExternal returns true if this value is an `External` object. +func (v *Value) IsExternal() bool { + panic("not implemented") +} + +// IsInt32 returns true if this value is a 32-bit signed integer. +func (v *Value) IsInt32() bool { + panic("not implemented") +} + +// IsUint32 returns true if this value is a 32-bit unsigned integer. +func (v *Value) IsUint32() bool { + panic("not implemented") +} + +// IsDate returns true if this value is a `Date`. +func (v *Value) IsDate() bool { + panic("not implemented") +} + +// IsArgumentsObject returns true if this value is an Arguments object. +func (v *Value) IsArgumentsObject() bool { + panic("not implemented") +} + +// IsBigIntObject returns true if this value is a BigInt object. +func (v *Value) IsBigIntObject() bool { + panic("not implemented") +} + +// IsNumberObject returns true if this value is a `Number` object. +func (v *Value) IsNumberObject() bool { + panic("not implemented") +} + +// IsStringObject returns true if this value is a `String` object. +func (v *Value) IsStringObject() bool { + panic("not implemented") +} + +// IsSymbolObject returns true if this value is a `Symbol` object. +func (v *Value) IsSymbolObject() bool { + panic("not implemented") +} + +// IsNativeError returns true if this value is a NativeError. +func (v *Value) IsNativeError() bool { + panic("not implemented") +} + +// IsRegExp returns true if this value is a `RegExp`. +func (v *Value) IsRegExp() bool { + panic("not implemented") +} + +// IsAsyncFunc returns true if this value is an async function. +func (v *Value) IsAsyncFunc() bool { + panic("not implemented") +} + +// Is IsGeneratorFunc returns true if this value is a Generator function. +func (v *Value) IsGeneratorFunc() bool { + panic("not implemented") +} + +// IsGeneratorObject returns true if this value is a Generator object (iterator). +func (v *Value) IsGeneratorObject() bool { + panic("not implemented") +} + +// IsPromise returns true if this value is a `Promise`. +func (v *Value) IsPromise() bool { + panic("not implemented") +} + +// IsMap returns true if this value is a `Map`. +func (v *Value) IsMap() bool { + panic("not implemented") +} + +// IsSet returns true if this value is a `Set`. +func (v *Value) IsSet() bool { + panic("not implemented") +} + +// IsMapIterator returns true if this value is a `Map` Iterator. +func (v *Value) IsMapIterator() bool { + panic("not implemented") +} + +// IsSetIterator returns true if this value is a `Set` Iterator. +func (v *Value) IsSetIterator() bool { + panic("not implemented") +} + +// IsWeakMap returns true if this value is a `WeakMap`. +func (v *Value) IsWeakMap() bool { + panic("not implemented") +} + +// IsWeakSet returns true if this value is a `WeakSet`. +func (v *Value) IsWeakSet() bool { + panic("not implemented") +} + +// IsArrayBuffer returns true if this value is an `ArrayBuffer`. +func (v *Value) IsArrayBuffer() bool { + panic("not implemented") +} + +// IsArrayBufferView returns true if this value is an `ArrayBufferView`. +func (v *Value) IsArrayBufferView() bool { + panic("not implemented") +} + +// IsTypedArray returns true if this value is one of TypedArrays. +func (v *Value) IsTypedArray() bool { + panic("not implemented") +} + +// IsUint8Array returns true if this value is an `Uint8Array`. +func (v *Value) IsUint8Array() bool { + panic("not implemented") +} + +// IsUint8ClampedArray returns true if this value is an `Uint8ClampedArray`. +func (v *Value) IsUint8ClampedArray() bool { + panic("not implemented") +} + +// IsInt8Array returns true if this value is an `Int8Array`. +func (v *Value) IsInt8Array() bool { + panic("not implemented") +} + +// IsUint16Array returns true if this value is an `Uint16Array`. +func (v *Value) IsUint16Array() bool { + panic("not implemented") +} + +// IsInt16Array returns true if this value is an `Int16Array`. +func (v *Value) IsInt16Array() bool { + panic("not implemented") +} + +// IsUint32Array returns true if this value is an `Uint32Array`. +func (v *Value) IsUint32Array() bool { + panic("not implemented") +} + +// IsInt32Array returns true if this value is an `Int32Array`. +func (v *Value) IsInt32Array() bool { + panic("not implemented") +} + +// IsFloat32Array returns true if this value is a `Float32Array`. +func (v *Value) IsFloat32Array() bool { + panic("not implemented") +} + +// IsFloat64Array returns true if this value is a `Float64Array`. +func (v *Value) IsFloat64Array() bool { + panic("not implemented") +} + +// IsBigInt64Array returns true if this value is a `BigInt64Array`. +func (v *Value) IsBigInt64Array() bool { + panic("not implemented") +} + +// IsBigUint64Array returns true if this value is a BigUint64Array`. +func (v *Value) IsBigUint64Array() bool { + panic("not implemented") +} + +// IsDataView returns true if this value is a `DataView`. +func (v *Value) IsDataView() bool { + panic("not implemented") +} + +// IsSharedArrayBuffer returns true if this value is a `SharedArrayBuffer`. +func (v *Value) IsSharedArrayBuffer() bool { + panic("not implemented") +} + +// IsProxy returns true if this value is a JavaScript `Proxy`. +func (v *Value) IsProxy() bool { + panic("not implemented") +} + +// IsWasmModuleObject returns true if this value is a `WasmModuleObject`. +func (v *Value) IsWasmModuleObject() bool { + panic("not implemented") +} + +// IsModuleNamespaceObject returns true if the value is a `Module` Namespace `Object`. +func (v *Value) IsModuleNamespaceObject() bool { + panic("not implemented") +} + func (v *Value) finalizer() { C.ValueDispose(v.ptr) v.ptr = nil diff --git a/value_test.go b/value_test.go index 59c099ef..82be972b 100644 --- a/value_test.go +++ b/value_test.go @@ -1,6 +1,8 @@ package v8go_test import ( + "reflect" + "runtime" "testing" "rogchap.com/v8go" @@ -32,3 +34,37 @@ func TestValueString(t *testing.T) { }) } } + +func TestValueIsXXX(t *testing.T) { + t.Parallel() + iso, _ := v8go.NewIsolate() + var tests = []struct { + source string + assert func(*v8go.Value) bool + }{ + {"", (*v8go.Value).IsUndefined}, + {"let v; v", (*v8go.Value).IsUndefined}, + {"let v = null; v", (*v8go.Value).IsNull}, + {"let v; v", (*v8go.Value).IsNullOrUndefined}, + {"let v = null; v", (*v8go.Value).IsNullOrUndefined}, + {"let v = true; v", (*v8go.Value).IsTrue}, + {"let v = false; v", (*v8go.Value).IsFalse}, + {`"double quote"`, (*v8go.Value).IsString}, + {"'single quote'", (*v8go.Value).IsString}, + {"`string litral`", (*v8go.Value).IsString}, + } + for _, tt := range tests { + tt := tt + t.Run(tt.source, func(t *testing.T) { + t.Parallel() + ctx, _ := v8go.NewContext(iso) + val, err := ctx.RunScript(tt.source, "test.js") + if err != nil { + t.Fatalf("failed to run script: %v", err) + } + if !tt.assert(val) { + t.Errorf("value is false for %s", runtime.FuncForPC(reflect.ValueOf(tt.assert).Pointer()).Name()) + } + }) + } +} From 40421fdd77421373e24b50473a1ba309f6c5dee0 Mon Sep 17 00:00:00 2001 From: Roger Chapman Date: Mon, 21 Dec 2020 11:00:19 +1100 Subject: [PATCH 2/6] add other value is methods --- v8go.cc | 240 +++++++++++++++++++++++++++++++++++++++++++++++++- v8go.h | 48 ++++++++++ value.go | 119 +++++++++++++------------ value_test.go | 88 +++++++++++++++++- 4 files changed, 435 insertions(+), 60 deletions(-) diff --git a/v8go.cc b/v8go.cc index 58cc9727..23ebeb45 100644 --- a/v8go.cc +++ b/v8go.cc @@ -246,12 +246,250 @@ int ValueIsFalse(ValuePtr ptr) { return value->IsFalse() ? 1 : 0; } -int ValueIsString(ValuePtr ptr) { +int ValueIsName(ValuePtr ptr) { LOCAL_VALUE(ptr); + return value->IsName() ? 1 : 0; +} +int ValueIsString(ValuePtr ptr) { + LOCAL_VALUE(ptr); return value->IsString() ? 1 : 0; } +int ValueIsSymbol(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsSymbol() ? 1 : 0; +} + +int ValueIsFunction(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsFunction() ? 1 : 0; +} + +int ValueIsObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsObject() ? 1 : 0; +} + +int ValueIsBigInt(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsBigInt() ? 1 : 0; +} + +int ValueIsBoolean(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsBoolean() ? 1 : 0; +} + +int ValueIsNumber(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsNumber() ? 1 : 0; +} + +int ValueIsExternal(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsExternal() ? 1 : 0; +} + +int ValueIsInt32(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsInt32() ? 1 : 0; +} + +int ValueIsUint32(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsUint32() ? 1 : 0; +} + +int ValueIsDate(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsDate() ? 1 : 0; +} + +int ValueIsArgumentsObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsArgumentsObject() ? 1 : 0; +} + +int ValueIsBigIntObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsBigIntObject() ? 1 : 0; +} + +int ValueIsNumberObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsNumberObject() ? 1 : 0; +} + +int ValueIsStringObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsStringObject() ? 1 : 0; +} + +int ValueIsSymbolObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsSymbolObject() ? 1 : 0; +} + +int ValueIsNativeError(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsNativeError() ? 1 : 0; +} + +int ValueIsRegExp(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsRegExp() ? 1 : 0; +} + +int ValueIsAsyncFunction(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsAsyncFunction() ? 1 : 0; +} + +int ValueIsGeneratorFunction(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsGeneratorFunction() ? 1 : 0; +} + +int ValueIsGeneratorObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsGeneratorObject() ? 1 : 0; +} + +int ValueIsPromise(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsPromise() ? 1 : 0; +} + +int ValueIsMap(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsMap() ? 1 : 0; +} + +int ValueIsSet(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsSet() ? 1 : 0; +} + +int ValueIsMapIterator(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsMapIterator() ? 1 : 0; +} + +int ValueIsSetIterator(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsSetIterator() ? 1 : 0; +} + +int ValueIsWeakMap(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsWeakMap() ? 1 : 0; +} + +int ValueIsWeakSet(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsWeakSet() ? 1 : 0; +} + +int ValueIsArray(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsArray() ? 1 : 0; +} + +int ValueIsArrayBuffer(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsArrayBuffer() ? 1 : 0; +} + +int ValueIsArrayBufferView(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsArrayBufferView() ? 1 : 0; +} + +int ValueIsTypedArray(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsTypedArray() ? 1 : 0; +} + +int ValueIsUint8Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsUint8Array() ? 1 : 0; +} + +int ValueIsUint8ClampedArray(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsUint8ClampedArray() ? 1 : 0; +} + +int ValueIsInt8Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsInt8Array() ? 1 : 0; +} + +int ValueIsUint16Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsUint16Array() ? 1 : 0; +} + +int ValueIsInt16Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsInt16Array() ? 1 : 0; +} + +int ValueIsUint32Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsUint32Array() ? 1 : 0; +} + +int ValueIsInt32Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsInt32Array() ? 1 : 0; +} + +int ValueIsFloat32Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsFloat32Array() ? 1 : 0; +} + +int ValueIsFloat64Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsFloat64Array() ? 1 : 0; +} + +int ValueIsBigInt64Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsBigInt64Array() ? 1 : 0; +} + +int ValueIsBigUint64Array(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsBigUint64Array() ? 1 : 0; +} + +int ValueIsDataView(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsDataView() ? 1 : 0; +} + +int ValueIsSharedArrayBuffer(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsSharedArrayBuffer() ? 1 : 0; +} + +int ValueIsProxy(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsProxy() ? 1 : 0; +} + +int ValueIsWasmModuleObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsWasmModuleObject() ? 1 : 0; +} + +int ValueIsModuleNamespaceObject(ValuePtr ptr) { + LOCAL_VALUE(ptr); + return value->IsModuleNamespaceObject() ? 1 : 0; +} /********** Version **********/ diff --git a/v8go.h b/v8go.h index e8b737e6..0b4a826f 100644 --- a/v8go.h +++ b/v8go.h @@ -52,7 +52,55 @@ 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(); diff --git a/value.go b/value.go index 19caffa9..ec91e5bc 100644 --- a/value.go +++ b/value.go @@ -24,280 +24,289 @@ func (v *Value) String() string { // IsUndefined returns true if this value is the undefined value. See ECMA-262 4.3.10. func (v *Value) IsUndefined() bool { - return C.ValueIsUndefined(v.ptr) > 0 + return C.ValueIsUndefined(v.ptr) != 0 } // IsNull returns true if this value is the null value. See ECMA-262 4.3.11. func (v *Value) IsNull() bool { - return C.ValueIsNull(v.ptr) > 0 + return C.ValueIsNull(v.ptr) != 0 } // IsNullOrUndefined returns true if this value is either the null or the undefined value. // See ECMA-262 4.3.11. and 4.3.12 // This is equivalent to `value == null` in JS. func (v *Value) IsNullOrUndefined() bool { - return C.ValueIsNullOrUndefined(v.ptr) > 0 + return C.ValueIsNullOrUndefined(v.ptr) != 0 } // IsTrue returns true if this value is true. // This is not the same as `BooleanValue()`. The latter performs a conversion to boolean, // i.e. the result of `Boolean(value)` in JS, whereas this checks `value === true`. func (v *Value) IsTrue() bool { - return C.ValueIsTrue(v.ptr) > 0 + return C.ValueIsTrue(v.ptr) != 0 } // IsFalse returns true if this value is false. // This is not the same as `!BooleanValue()`. The latter performs a conversion to boolean, // i.e. the result of `!Boolean(value)` in JS, whereas this checks `value === false`. func (v *Value) IsFalse() bool { - return C.ValueIsFalse(v.ptr) > 0 + return C.ValueIsFalse(v.ptr) != 0 } // IsName returns true if this value is a symbol or a string. // This is equivalent to `typeof value === 'string' || typeof value === 'symbol'` in JS. func (v *Value) IsName() bool { - panic("not implemented") + return C.ValueIsName(v.ptr) != 0 } // IsString returns true if this value is an instance of the String type. See ECMA-262 8.4. // This is equivalent to `typeof value === 'string'` in JS. func (v *Value) IsString() bool { - return C.ValueIsString(v.ptr) > 0 + return C.ValueIsString(v.ptr) != 0 } // IsSymbol returns true if this value is a symbol. // This is equivalent to `typeof value === 'symbol'` in JS. func (v *Value) IsSymbol() bool { - panic("not implemented") + return C.ValueIsSymbol(v.ptr) != 0 } // IsFunction returns true if this value is a function. // This is equivalent to `typeof value === 'function'` in JS. func (v *Value) IsFunction() bool { - panic("not implemented") + return C.ValueIsFunction(v.ptr) != 0 } // IsObject returns true if this value is an object. func (v *Value) IsObject() bool { - panic("not implemented") + return C.ValueIsObject(v.ptr) != 0 } // IsBigInt returns true if this value is a bigint. // This is equivalent to `typeof value === 'bigint'` in JS. func (v *Value) IsBigInt() bool { - panic("not implemented") + return C.ValueIsBigInt(v.ptr) != 0 } // IsBoolean returns true if this value is boolean. // This is equivalent to `typeof value === 'boolean'` in JS. func (v *Value) IsBoolean() bool { - panic("not implemented") + return C.ValueIsBoolean(v.ptr) != 0 } // IsNumber returns true if this value is a number. // This is equivalent to `typeof value === 'number'` in JS. func (v *Value) IsNumber() bool { - panic("not implemented") + return C.ValueIsNumber(v.ptr) != 0 } // IsExternal returns true if this value is an `External` object. func (v *Value) IsExternal() bool { - panic("not implemented") + // TODO(rogchap): requires test case + return C.ValueIsExternal(v.ptr) != 0 } // IsInt32 returns true if this value is a 32-bit signed integer. func (v *Value) IsInt32() bool { - panic("not implemented") + return C.ValueIsInt32(v.ptr) != 0 } // IsUint32 returns true if this value is a 32-bit unsigned integer. func (v *Value) IsUint32() bool { - panic("not implemented") + return C.ValueIsUint32(v.ptr) != 0 } // IsDate returns true if this value is a `Date`. func (v *Value) IsDate() bool { - panic("not implemented") + return C.ValueIsDate(v.ptr) != 0 } // IsArgumentsObject returns true if this value is an Arguments object. func (v *Value) IsArgumentsObject() bool { - panic("not implemented") + return C.ValueIsArgumentsObject(v.ptr) != 0 } // IsBigIntObject returns true if this value is a BigInt object. func (v *Value) IsBigIntObject() bool { - panic("not implemented") + return C.ValueIsBigIntObject(v.ptr) != 0 } // IsNumberObject returns true if this value is a `Number` object. func (v *Value) IsNumberObject() bool { - panic("not implemented") + return C.ValueIsNumberObject(v.ptr) != 0 } // IsStringObject returns true if this value is a `String` object. func (v *Value) IsStringObject() bool { - panic("not implemented") + return C.ValueIsStringObject(v.ptr) != 0 } // IsSymbolObject returns true if this value is a `Symbol` object. func (v *Value) IsSymbolObject() bool { - panic("not implemented") + return C.ValueIsSymbolObject(v.ptr) != 0 } // IsNativeError returns true if this value is a NativeError. func (v *Value) IsNativeError() bool { - panic("not implemented") + return C.ValueIsNativeError(v.ptr) != 0 } // IsRegExp returns true if this value is a `RegExp`. func (v *Value) IsRegExp() bool { - panic("not implemented") + return C.ValueIsRegExp(v.ptr) != 0 } // IsAsyncFunc returns true if this value is an async function. -func (v *Value) IsAsyncFunc() bool { - panic("not implemented") +func (v *Value) IsAsyncFunction() bool { + return C.ValueIsAsyncFunction(v.ptr) != 0 } // Is IsGeneratorFunc returns true if this value is a Generator function. -func (v *Value) IsGeneratorFunc() bool { - panic("not implemented") +func (v *Value) IsGeneratorFunction() bool { + return C.ValueIsGeneratorFunction(v.ptr) != 0 } // IsGeneratorObject returns true if this value is a Generator object (iterator). func (v *Value) IsGeneratorObject() bool { - panic("not implemented") + return C.ValueIsGeneratorObject(v.ptr) != 0 } // IsPromise returns true if this value is a `Promise`. func (v *Value) IsPromise() bool { - panic("not implemented") + return C.ValueIsPromise(v.ptr) != 0 } // IsMap returns true if this value is a `Map`. func (v *Value) IsMap() bool { - panic("not implemented") + return C.ValueIsMap(v.ptr) != 0 } // IsSet returns true if this value is a `Set`. func (v *Value) IsSet() bool { - panic("not implemented") + return C.ValueIsSet(v.ptr) != 0 } // IsMapIterator returns true if this value is a `Map` Iterator. func (v *Value) IsMapIterator() bool { - panic("not implemented") + return C.ValueIsMapIterator(v.ptr) != 0 } // IsSetIterator returns true if this value is a `Set` Iterator. func (v *Value) IsSetIterator() bool { - panic("not implemented") + return C.ValueIsSetIterator(v.ptr) != 0 } // IsWeakMap returns true if this value is a `WeakMap`. func (v *Value) IsWeakMap() bool { - panic("not implemented") + return C.ValueIsWeakMap(v.ptr) != 0 } // IsWeakSet returns true if this value is a `WeakSet`. func (v *Value) IsWeakSet() bool { - panic("not implemented") + return C.ValueIsWeakSet(v.ptr) != 0 +} + +// IsArray returns true if this value is an array. +// Note that it will return false for a `Proxy` of an array. +func (v *Value) IsArray() bool { + return C.ValueIsArray(v.ptr) != 0 } // IsArrayBuffer returns true if this value is an `ArrayBuffer`. func (v *Value) IsArrayBuffer() bool { - panic("not implemented") + return C.ValueIsArrayBuffer(v.ptr) != 0 } // IsArrayBufferView returns true if this value is an `ArrayBufferView`. func (v *Value) IsArrayBufferView() bool { - panic("not implemented") + return C.ValueIsArrayBufferView(v.ptr) != 0 } // IsTypedArray returns true if this value is one of TypedArrays. func (v *Value) IsTypedArray() bool { - panic("not implemented") + return C.ValueIsTypedArray(v.ptr) != 0 } // IsUint8Array returns true if this value is an `Uint8Array`. func (v *Value) IsUint8Array() bool { - panic("not implemented") + return C.ValueIsUint8Array(v.ptr) != 0 } // IsUint8ClampedArray returns true if this value is an `Uint8ClampedArray`. func (v *Value) IsUint8ClampedArray() bool { - panic("not implemented") + return C.ValueIsUint8ClampedArray(v.ptr) != 0 } // IsInt8Array returns true if this value is an `Int8Array`. func (v *Value) IsInt8Array() bool { - panic("not implemented") + return C.ValueIsInt8Array(v.ptr) != 0 } // IsUint16Array returns true if this value is an `Uint16Array`. func (v *Value) IsUint16Array() bool { - panic("not implemented") + return C.ValueIsUint16Array(v.ptr) != 0 } // IsInt16Array returns true if this value is an `Int16Array`. func (v *Value) IsInt16Array() bool { - panic("not implemented") + return C.ValueIsInt16Array(v.ptr) != 0 } // IsUint32Array returns true if this value is an `Uint32Array`. func (v *Value) IsUint32Array() bool { - panic("not implemented") + return C.ValueIsUint32Array(v.ptr) != 0 } // IsInt32Array returns true if this value is an `Int32Array`. func (v *Value) IsInt32Array() bool { - panic("not implemented") + return C.ValueIsInt32Array(v.ptr) != 0 } // IsFloat32Array returns true if this value is a `Float32Array`. func (v *Value) IsFloat32Array() bool { - panic("not implemented") + return C.ValueIsFloat32Array(v.ptr) != 0 } // IsFloat64Array returns true if this value is a `Float64Array`. func (v *Value) IsFloat64Array() bool { - panic("not implemented") + return C.ValueIsFloat64Array(v.ptr) != 0 } // IsBigInt64Array returns true if this value is a `BigInt64Array`. func (v *Value) IsBigInt64Array() bool { - panic("not implemented") + return C.ValueIsBigInt64Array(v.ptr) != 0 } // IsBigUint64Array returns true if this value is a BigUint64Array`. func (v *Value) IsBigUint64Array() bool { - panic("not implemented") + return C.ValueIsBigUint64Array(v.ptr) != 0 } // IsDataView returns true if this value is a `DataView`. func (v *Value) IsDataView() bool { - panic("not implemented") + return C.ValueIsDataView(v.ptr) != 0 } // IsSharedArrayBuffer returns true if this value is a `SharedArrayBuffer`. func (v *Value) IsSharedArrayBuffer() bool { - panic("not implemented") + return C.ValueIsSharedArrayBuffer(v.ptr) != 0 } // IsProxy returns true if this value is a JavaScript `Proxy`. func (v *Value) IsProxy() bool { - panic("not implemented") + return C.ValueIsProxy(v.ptr) != 0 } // IsWasmModuleObject returns true if this value is a `WasmModuleObject`. func (v *Value) IsWasmModuleObject() bool { - panic("not implemented") + // TODO(rogchap): requires test case + return C.ValueIsWasmModuleObject(v.ptr) != 0 } // IsModuleNamespaceObject returns true if the value is a `Module` Namespace `Object`. func (v *Value) IsModuleNamespaceObject() bool { - panic("not implemented") + // TODO(rogchap): requires test case + return C.ValueIsModuleNamespaceObject(v.ptr) != 0 } func (v *Value) finalizer() { diff --git a/value_test.go b/value_test.go index 82be972b..d9fc3b1d 100644 --- a/value_test.go +++ b/value_test.go @@ -44,14 +44,94 @@ func TestValueIsXXX(t *testing.T) { }{ {"", (*v8go.Value).IsUndefined}, {"let v; v", (*v8go.Value).IsUndefined}, - {"let v = null; v", (*v8go.Value).IsNull}, + {"null", (*v8go.Value).IsNull}, {"let v; v", (*v8go.Value).IsNullOrUndefined}, {"let v = null; v", (*v8go.Value).IsNullOrUndefined}, - {"let v = true; v", (*v8go.Value).IsTrue}, - {"let v = false; v", (*v8go.Value).IsFalse}, + {"true", (*v8go.Value).IsTrue}, + {"false", (*v8go.Value).IsFalse}, + {"'name'", (*v8go.Value).IsName}, + {"Symbol()", (*v8go.Value).IsName}, {`"double quote"`, (*v8go.Value).IsString}, {"'single quote'", (*v8go.Value).IsString}, - {"`string litral`", (*v8go.Value).IsString}, + {"`string literal`", (*v8go.Value).IsString}, + {"Symbol()", (*v8go.Value).IsSymbol}, + {"Symbol('foo')", (*v8go.Value).IsSymbol}, + {"() => {}", (*v8go.Value).IsFunction}, + {"function v() {}; v", (*v8go.Value).IsFunction}, + {"const v = function() {}; v", (*v8go.Value).IsFunction}, + {"console.log", (*v8go.Value).IsFunction}, + {"Object", (*v8go.Value).IsFunction}, + {"class Foo {}; Foo", (*v8go.Value).IsFunction}, + {"class Foo { bar() {} }; (new Foo()).bar", (*v8go.Value).IsFunction}, + {"function* v(){}; v", (*v8go.Value).IsFunction}, + {"async function v(){}; v", (*v8go.Value).IsFunction}, + {"Object()", (*v8go.Value).IsObject}, + {"new Object", (*v8go.Value).IsObject}, + {"var v = {}; v", (*v8go.Value).IsObject}, + {"10n", (*v8go.Value).IsBigInt}, + {"BigInt(1)", (*v8go.Value).IsBigInt}, + {"true", (*v8go.Value).IsBoolean}, + {"false", (*v8go.Value).IsBoolean}, + {"Boolean()", (*v8go.Value).IsBoolean}, + {"(new Boolean).valueOf()", (*v8go.Value).IsBoolean}, + {"1", (*v8go.Value).IsNumber}, + {"1.1", (*v8go.Value).IsNumber}, + {"1_1", (*v8go.Value).IsNumber}, + {".1", (*v8go.Value).IsNumber}, + {"2e4", (*v8go.Value).IsNumber}, + {"0x2", (*v8go.Value).IsNumber}, + {"NaN", (*v8go.Value).IsNumber}, + {"Infinity", (*v8go.Value).IsNumber}, + {"Number(1)", (*v8go.Value).IsNumber}, + {"(new Number()).valueOf()", (*v8go.Value).IsNumber}, + {"1", (*v8go.Value).IsInt32}, + {"-1", (*v8go.Value).IsInt32}, + {"1", (*v8go.Value).IsUint32}, + {"new Date", (*v8go.Value).IsDate}, + {"function foo(){ return arguments }; foo()", (*v8go.Value).IsArgumentsObject}, + {"Object(1n)", (*v8go.Value).IsBigIntObject}, + {"Object(1)", (*v8go.Value).IsNumberObject}, + {"new Number", (*v8go.Value).IsNumberObject}, + {"new String", (*v8go.Value).IsStringObject}, + {"Object('')", (*v8go.Value).IsStringObject}, + {"Object(Symbol())", (*v8go.Value).IsSymbolObject}, + {"Error()", (*v8go.Value).IsNativeError}, + {"TypeError()", (*v8go.Value).IsNativeError}, + {"SyntaxError()", (*v8go.Value).IsNativeError}, + {"/./", (*v8go.Value).IsRegExp}, + {"RegExp()", (*v8go.Value).IsRegExp}, + {"async function v(){}; v", (*v8go.Value).IsAsyncFunction}, + {"let v = async () => {}; v", (*v8go.Value).IsAsyncFunction}, + {"function* v(){}; v", (*v8go.Value).IsGeneratorFunction}, + {"function* v(){}; v()", (*v8go.Value).IsGeneratorObject}, + {"new Promise(()=>{})", (*v8go.Value).IsPromise}, + {"new Map", (*v8go.Value).IsMap}, + {"new Set", (*v8go.Value).IsSet}, + {"(new Map).entries()", (*v8go.Value).IsMapIterator}, + {"(new Set).entries()", (*v8go.Value).IsSetIterator}, + {"new WeakMap", (*v8go.Value).IsWeakMap}, + {"new WeakSet", (*v8go.Value).IsWeakSet}, + {"new Array", (*v8go.Value).IsArray}, + {"Array()", (*v8go.Value).IsArray}, + {"[]", (*v8go.Value).IsArray}, + {"new ArrayBuffer", (*v8go.Value).IsArrayBuffer}, + {"new Int8Array", (*v8go.Value).IsArrayBufferView}, + {"new Int8Array", (*v8go.Value).IsTypedArray}, + {"new Uint32Array", (*v8go.Value).IsTypedArray}, + {"new Uint8Array", (*v8go.Value).IsUint8Array}, + {"new Uint8ClampedArray", (*v8go.Value).IsUint8ClampedArray}, + {"new Int8Array", (*v8go.Value).IsInt8Array}, + {"new Uint16Array", (*v8go.Value).IsUint16Array}, + {"new Int16Array", (*v8go.Value).IsInt16Array}, + {"new Uint32Array", (*v8go.Value).IsUint32Array}, + {"new Int32Array", (*v8go.Value).IsInt32Array}, + {"new Float32Array", (*v8go.Value).IsFloat32Array}, + {"new Float64Array", (*v8go.Value).IsFloat64Array}, + {"new BigInt64Array", (*v8go.Value).IsBigInt64Array}, + {"new BigUint64Array", (*v8go.Value).IsBigUint64Array}, + {"new DataView(new ArrayBuffer)", (*v8go.Value).IsDataView}, + {"new SharedArrayBuffer", (*v8go.Value).IsSharedArrayBuffer}, + {"new Proxy({},{})", (*v8go.Value).IsProxy}, } for _, tt := range tests { tt := tt From 2c45b9f352b3bdfe5855641f8dd0af25a8e72108 Mon Sep 17 00:00:00 2001 From: Roger Chapman Date: Mon, 21 Dec 2020 11:02:30 +1100 Subject: [PATCH 3/6] add to changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03ed0ca5..96b45ec3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ 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) + ## [v0.3.0] ### Added From 61a87e89f9d03e37a8031602da82441209049b87 Mon Sep 17 00:00:00 2001 From: Roger Chapman Date: Mon, 21 Dec 2020 11:06:34 +1100 Subject: [PATCH 4/6] fix CI to only trigger one set of test runs on a PR --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 71866e99..1beba0b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,11 @@ name: CI -on: [push, pull_request, workflow_dispatch] +on: + push: + branches: + - master + pull_request: + workflow_dispatch: jobs: test: From b2bd68ef40727b005cde351bb420f7d9d93e6aab Mon Sep 17 00:00:00 2001 From: Roger Chapman Date: Mon, 21 Dec 2020 12:01:27 +1100 Subject: [PATCH 5/6] simplify the C++ code --- v8go.cc | 108 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/v8go.cc b/v8go.cc index 23ebeb45..ba659c53 100644 --- a/v8go.cc +++ b/v8go.cc @@ -223,272 +223,272 @@ const char* ValueToString(ValuePtr ptr) { int ValueIsUndefined(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsUndefined() ? 1 : 0; + return value->IsUndefined(); } int ValueIsNull(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsNull() ? 1 : 0; + return value->IsNull(); } int ValueIsNullOrUndefined(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsNullOrUndefined() ? 1 : 0; + return value->IsNullOrUndefined(); } int ValueIsTrue(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsTrue() ? 1 : 0; + return value->IsTrue(); } int ValueIsFalse(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsFalse() ? 1 : 0; + return value->IsFalse(); } int ValueIsName(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsName() ? 1 : 0; + return value->IsName(); } int ValueIsString(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsString() ? 1 : 0; + return value->IsString(); } int ValueIsSymbol(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsSymbol() ? 1 : 0; + return value->IsSymbol(); } int ValueIsFunction(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsFunction() ? 1 : 0; + return value->IsFunction(); } int ValueIsObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsObject() ? 1 : 0; + return value->IsObject(); } int ValueIsBigInt(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsBigInt() ? 1 : 0; + return value->IsBigInt(); } int ValueIsBoolean(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsBoolean() ? 1 : 0; + return value->IsBoolean(); } int ValueIsNumber(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsNumber() ? 1 : 0; + return value->IsNumber(); } int ValueIsExternal(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsExternal() ? 1 : 0; + return value->IsExternal(); } int ValueIsInt32(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsInt32() ? 1 : 0; + return value->IsInt32(); } int ValueIsUint32(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsUint32() ? 1 : 0; + return value->IsUint32(); } int ValueIsDate(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsDate() ? 1 : 0; + return value->IsDate(); } int ValueIsArgumentsObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsArgumentsObject() ? 1 : 0; + return value->IsArgumentsObject(); } int ValueIsBigIntObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsBigIntObject() ? 1 : 0; + return value->IsBigIntObject(); } int ValueIsNumberObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsNumberObject() ? 1 : 0; + return value->IsNumberObject(); } int ValueIsStringObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsStringObject() ? 1 : 0; + return value->IsStringObject(); } int ValueIsSymbolObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsSymbolObject() ? 1 : 0; + return value->IsSymbolObject(); } int ValueIsNativeError(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsNativeError() ? 1 : 0; + return value->IsNativeError(); } int ValueIsRegExp(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsRegExp() ? 1 : 0; + return value->IsRegExp(); } int ValueIsAsyncFunction(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsAsyncFunction() ? 1 : 0; + return value->IsAsyncFunction(); } int ValueIsGeneratorFunction(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsGeneratorFunction() ? 1 : 0; + return value->IsGeneratorFunction(); } int ValueIsGeneratorObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsGeneratorObject() ? 1 : 0; + return value->IsGeneratorObject(); } int ValueIsPromise(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsPromise() ? 1 : 0; + return value->IsPromise(); } int ValueIsMap(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsMap() ? 1 : 0; + return value->IsMap(); } int ValueIsSet(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsSet() ? 1 : 0; + return value->IsSet(); } int ValueIsMapIterator(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsMapIterator() ? 1 : 0; + return value->IsMapIterator(); } int ValueIsSetIterator(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsSetIterator() ? 1 : 0; + return value->IsSetIterator(); } int ValueIsWeakMap(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsWeakMap() ? 1 : 0; + return value->IsWeakMap(); } int ValueIsWeakSet(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsWeakSet() ? 1 : 0; + return value->IsWeakSet(); } int ValueIsArray(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsArray() ? 1 : 0; + return value->IsArray(); } int ValueIsArrayBuffer(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsArrayBuffer() ? 1 : 0; + return value->IsArrayBuffer(); } int ValueIsArrayBufferView(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsArrayBufferView() ? 1 : 0; + return value->IsArrayBufferView(); } int ValueIsTypedArray(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsTypedArray() ? 1 : 0; + return value->IsTypedArray(); } int ValueIsUint8Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsUint8Array() ? 1 : 0; + return value->IsUint8Array(); } int ValueIsUint8ClampedArray(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsUint8ClampedArray() ? 1 : 0; + return value->IsUint8ClampedArray(); } int ValueIsInt8Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsInt8Array() ? 1 : 0; + return value->IsInt8Array(); } int ValueIsUint16Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsUint16Array() ? 1 : 0; + return value->IsUint16Array(); } int ValueIsInt16Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsInt16Array() ? 1 : 0; + return value->IsInt16Array(); } int ValueIsUint32Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsUint32Array() ? 1 : 0; + return value->IsUint32Array(); } int ValueIsInt32Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsInt32Array() ? 1 : 0; + return value->IsInt32Array(); } int ValueIsFloat32Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsFloat32Array() ? 1 : 0; + return value->IsFloat32Array(); } int ValueIsFloat64Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsFloat64Array() ? 1 : 0; + return value->IsFloat64Array(); } int ValueIsBigInt64Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsBigInt64Array() ? 1 : 0; + return value->IsBigInt64Array(); } int ValueIsBigUint64Array(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsBigUint64Array() ? 1 : 0; + return value->IsBigUint64Array(); } int ValueIsDataView(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsDataView() ? 1 : 0; + return value->IsDataView(); } int ValueIsSharedArrayBuffer(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsSharedArrayBuffer() ? 1 : 0; + return value->IsSharedArrayBuffer(); } int ValueIsProxy(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsProxy() ? 1 : 0; + return value->IsProxy(); } int ValueIsWasmModuleObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsWasmModuleObject() ? 1 : 0; + return value->IsWasmModuleObject(); } int ValueIsModuleNamespaceObject(ValuePtr ptr) { LOCAL_VALUE(ptr); - return value->IsModuleNamespaceObject() ? 1 : 0; + return value->IsModuleNamespaceObject(); } /********** Version **********/ From 3c1fcaec78e7d739f193796a909a0bd0776e4ef8 Mon Sep 17 00:00:00 2001 From: Roger Chapman Date: Mon, 21 Dec 2020 20:06:12 +1100 Subject: [PATCH 6/6] remove whitespace EOL --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1beba0b0..20fb0615 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: CI -on: +on: push: branches: - master