diff options
Diffstat (limited to 'src')
70 files changed, 1568 insertions, 494 deletions
| diff --git a/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp b/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp index 169aecad2..ec487edc9 100644 --- a/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp +++ b/src/javascript/jsc/bindings/BunGCOutputConstraint.cpp @@ -170,7 +170,7 @@ void DOMGCOutputConstraint::executeImplImpl(Visitor& visitor)              auto func = [](Visitor& visitor, HeapCell* heapCell, HeapCell::Kind) {                  SetRootMarkReasonScope rootScope(visitor, RootMarkReason::DOMGCOutput);                  JSCell* cell = static_cast<JSCell*>(heapCell); -                cell->methodTable(visitor.vm())->visitOutputConstraints(cell, visitor); +                cell->methodTable()->visitOutputConstraints(cell, visitor);              };              RefPtr<SharedTask<void(Visitor&)>> task = subspace.template forEachMarkedCellInParallel<Visitor>(func); diff --git a/src/javascript/jsc/bindings/BunStream.cpp b/src/javascript/jsc/bindings/BunStream.cpp index ee9dd3f50..2dbb53562 100644 --- a/src/javascript/jsc/bindings/BunStream.cpp +++ b/src/javascript/jsc/bindings/BunStream.cpp @@ -61,7 +61,7 @@ static WritableEvent getWritableEvent(const WTF::String& eventName)  // clang-format off  #define DEFINE_CALLBACK_FUNCTION_BODY(TypeName, ZigFunction) JSC::VM& vm = globalObject->vm(); \ -    auto* thisObject = JSC::jsDynamicCast<TypeName*>(vm, callFrame->thisValue()); \ +    auto* thisObject = JSC::jsDynamicCast<TypeName*>( callFrame->thisValue()); \      auto scope = DECLARE_THROW_SCOPE(vm); \      if (!thisObject) \          return throwVMTypeError(globalObject, scope); \ @@ -127,7 +127,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__on,      JSC::VM& vm = globalObject->vm();      auto scope = DECLARE_THROW_SCOPE(vm); -    auto thisObject = JSC::jsDynamicCast<WebCore::Readable*>(vm, callFrame->thisValue()); +    auto thisObject = JSC::jsDynamicCast<WebCore::Readable*>(callFrame->thisValue());      if (UNLIKELY(!thisObject)) {          scope.release();          JSC::throwVMTypeError(globalObject, scope); @@ -149,7 +149,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__on,      auto listener = callFrame->argument(1);      JSC::JSObject* object = listener.getObject(); -    if (UNLIKELY(!object) || !listener.isCallable(vm)) { +    if (UNLIKELY(!object) || !listener.isCallable()) {          scope.release();          return JSC::JSValue::encode(JSC::jsUndefined());      } @@ -163,7 +163,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__on,  extern "C" Bun__Readable* JSC__JSValue__getReadableStreamState(JSC__JSValue value, JSC__VM* vm)  { -    auto* thisObject = JSC::jsDynamicCast<WebCore::Readable*>(*vm, JSC::JSValue::decode(value)); +    auto* thisObject = JSC::jsDynamicCast<WebCore::Readable*>(JSC::JSValue::decode(value));      if (UNLIKELY(!thisObject)) {          return nullptr;      } @@ -171,7 +171,7 @@ extern "C" Bun__Readable* JSC__JSValue__getReadableStreamState(JSC__JSValue valu  }  extern "C" Bun__Writable* JSC__JSValue__getWritableStreamState(JSC__JSValue value, JSC__VM* vm)  { -    auto* thisObject = JSC::jsDynamicCast<WebCore::Writable*>(*vm, JSC::JSValue::decode(value)); +    auto* thisObject = JSC::jsDynamicCast<WebCore::Writable*>(JSC::JSValue::decode(value));      if (UNLIKELY(!thisObject)) {          return nullptr;      } @@ -194,7 +194,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__once,      JSC::VM& vm = globalObject->vm();      auto scope = DECLARE_THROW_SCOPE(vm); -    auto thisObject = JSC::jsDynamicCast<WebCore::Readable*>(vm, callFrame->thisValue()); +    auto thisObject = JSC::jsDynamicCast<WebCore::Readable*>(callFrame->thisValue());      if (UNLIKELY(!thisObject)) {          scope.release();          JSC::throwVMTypeError(globalObject, scope); @@ -216,7 +216,7 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__once,      auto listener = callFrame->argument(1);      JSC::JSObject* object = listener.getObject(); -    if (UNLIKELY(!object) || !listener.isCallable(vm)) { +    if (UNLIKELY(!object) || !listener.isCallable()) {          scope.release();          return JSC::JSValue::encode(JSC::jsUndefined());      } @@ -238,7 +238,7 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__on,      JSC::VM& vm = globalObject->vm();      auto scope = DECLARE_THROW_SCOPE(vm); -    auto thisObject = JSC::jsDynamicCast<WebCore::Writable*>(vm, callFrame->thisValue()); +    auto thisObject = JSC::jsDynamicCast<WebCore::Writable*>(callFrame->thisValue());      if (UNLIKELY(!thisObject)) {          scope.release();          JSC::throwVMTypeError(globalObject, scope); @@ -260,7 +260,7 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__on,      auto listener = callFrame->argument(1);      JSC::JSObject* object = listener.getObject(); -    if (UNLIKELY(!object) || !listener.isCallable(vm)) { +    if (UNLIKELY(!object) || !listener.isCallable()) {          scope.release();          return JSC::JSValue::encode(JSC::jsUndefined());      } @@ -282,7 +282,7 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__once,      JSC::VM& vm = globalObject->vm();      auto scope = DECLARE_THROW_SCOPE(vm); -    auto thisObject = JSC::jsDynamicCast<WebCore::Writable*>(vm, callFrame->thisValue()); +    auto thisObject = JSC::jsDynamicCast<WebCore::Writable*>(callFrame->thisValue());      if (UNLIKELY(!thisObject)) {          scope.release();          JSC::throwVMTypeError(globalObject, scope); @@ -304,7 +304,7 @@ static JSC_DEFINE_HOST_FUNCTION(Writable__once,      auto listener = callFrame->argument(1);      JSC::JSObject* object = listener.getObject(); -    if (UNLIKELY(!object) || !listener.isCallable(vm)) { +    if (UNLIKELY(!object) || !listener.isCallable()) {          scope.release();          return JSC::JSValue::encode(JSC::jsUndefined());      } diff --git a/src/javascript/jsc/bindings/DOMException.cpp b/src/javascript/jsc/bindings/DOMException.cpp index 232fb83fe..b3912124c 100644 --- a/src/javascript/jsc/bindings/DOMException.cpp +++ b/src/javascript/jsc/bindings/DOMException.cpp @@ -26,6 +26,7 @@   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */ +#include "root.h"  #include "DOMException.h"  #include "Exception.h" @@ -76,7 +77,7 @@ auto DOMException::description(ExceptionCode ec) -> const Description&      if (ec < WTF_ARRAY_LENGTH(descriptions))          return descriptions[ec]; -    static const Description emptyDescription { ASCIILiteral::null(), ASCIILiteral::null(), 0 }; +    static const Description emptyDescription { {}, {}, 0 };      return emptyDescription;  } diff --git a/src/javascript/jsc/bindings/IDLTypes.h b/src/javascript/jsc/bindings/IDLTypes.h index cadeea27e..96906331b 100644 --- a/src/javascript/jsc/bindings/IDLTypes.h +++ b/src/javascript/jsc/bindings/IDLTypes.h @@ -25,14 +25,15 @@  #pragma once -#include "JavaScriptCore/HandleTypes.h" -#include "JavaScriptCore/Strong.h"  #include "StringAdaptors.h" -#include "wtf/Brigand.h" -#include "wtf/StdLibExtras.h" -#include "wtf/URL.h" -#include "wtf/WallTime.h" +#include <JavaScriptCore/HandleTypes.h> +#include <JavaScriptCore/Strong.h>  #include <variant> +#include <wtf/Brigand.h> +#include <wtf/Markable.h> +#include <wtf/StdLibExtras.h> +#include <wtf/URL.h> +#include <wtf/WallTime.h>  #if ENABLE(WEBGL)  #include "WebGLAny.h" @@ -75,6 +76,14 @@ struct IDLType {      static NullableType nullValue() { return std::nullopt; }      static bool isNullValue(const NullableType& value) { return !value; }      static ImplementationType extractValueFromNullable(const NullableType& value) { return value.value(); } + +    template<typename Traits> using NullableTypeWithLessPadding = Markable<ImplementationType, Traits>; +    template<typename Traits> +    static NullableTypeWithLessPadding<Traits> nullValue() { return std::nullopt; } +    template<typename Traits> +    static bool isNullType(const NullableTypeWithLessPadding<Traits>& value) { return !value; } +    template<typename Traits> +    static ImplementationType extractValueFromNullable(const NullableTypeWithLessPadding<Traits>& value) { return value.value(); }  };  // IDLUnsupportedType is a special type that serves as a base class for currently unsupported types. @@ -149,7 +158,8 @@ template<typename StringType> struct IDLString : IDLType<StringType> {      using NullableType = StringType;      static StringType nullValue() { return StringType(); } -    static bool isNullValue(const StringType& value) { return value.isNull(); } +    static bool isNullValue(const String& value) { return value.isNull(); } +    static bool isNullValue(const AtomString& value) { return value.isNull(); }      static bool isNullValue(const UncachedString& value) { return value.string.isNull(); }      static bool isNullValue(const OwnedString& value) { return value.string.isNull(); }      static bool isNullValue(const URL& value) { return value.isNull(); } @@ -166,6 +176,10 @@ template<typename T> struct IDLLegacyNullToEmptyStringAdaptor : IDLString<String      using InnerType = T;  }; +template<typename T> struct IDLLegacyNullToEmptyAtomStringAdaptor : IDLString<AtomString> { +    using InnerType = T; +}; +  template<typename T> struct IDLAtomStringAdaptor : IDLString<AtomString> {      using InnerType = T;  }; @@ -400,4 +414,4 @@ template<typename T>  struct IsIDLArrayBufferViewAllowShared : public std::integral_constant<bool, std::is_base_of<IDLAllowSharedAdaptor<IDLArrayBufferView>, T>::value> {  }; -} // namespace WebCore +} // namespace WebCore
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/JSBuffer.cpp b/src/javascript/jsc/bindings/JSBuffer.cpp index 347dec29a..e67e39f19 100644 --- a/src/javascript/jsc/bindings/JSBuffer.cpp +++ b/src/javascript/jsc/bindings/JSBuffer.cpp @@ -73,7 +73,7 @@ bool JSBuffer__isBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSC::EncodedJS      JSC::VM& vm = lexicalGlobalObject->vm();      auto clientData = WebCore::clientData(vm); -    auto* jsBuffer = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, JSC::JSValue::decode(value)); +    auto* jsBuffer = JSC::jsDynamicCast<JSC::JSUint8Array*>(JSC::JSValue::decode(value));      if (!jsBuffer)          return false; @@ -114,7 +114,7 @@ public:          auto thisValue = callFrame.thisValue().toThis(&lexicalGlobalObject, JSC::ECMAMode::strict());          if (thisValue.isUndefinedOrNull()) { -            throwTypeError(&lexicalGlobalObject, throwScope, "Cannot convert undefined or null to object"); +            throwTypeError(&lexicalGlobalObject, throwScope, "Cannot convert undefined or null to object"_s);              return JSC::JSValue::encode(JSC::jsUndefined());          } @@ -157,7 +157,7 @@ static inline JSC::JSUint8Array* JSBuffer__bufferFromLengthAsArray(JSC::JSGlobal      auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject->vm());      if (UNLIKELY(length < 0)) { -        throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length"); +        throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length"_s);          return nullptr;      } @@ -250,7 +250,7 @@ static inline JSC::EncodedJSValue constructBufferFromStringAndEncoding(JSC::JSGl      if (callFrame->argumentCount() > 1) {          std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, callFrame->argument(1));          if (!encoded) { -            throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"); +            throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"_s);              return JSC::JSValue::encode(jsUndefined());          } @@ -336,7 +336,7 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSG      auto throwScope = DECLARE_THROW_SCOPE(vm);      auto length = callFrame->uncheckedArgument(0).toInt32(lexicalGlobalObject);      if (length < 0) { -        throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length"); +        throwRangeError(lexicalGlobalObject, throwScope, "Invalid array length"_s);          return JSValue::encode(jsUndefined());      } @@ -373,7 +373,7 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_compareBody(JSC::J      }      auto buffer = callFrame->uncheckedArgument(0); -    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, buffer); +    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(buffer);      if (UNLIKELY(!view)) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Buffer"_s);          return JSValue::encode(jsUndefined()); @@ -460,7 +460,7 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JS      }      auto arrayValue = callFrame->uncheckedArgument(0); -    auto array = JSC::jsDynamicCast<JSC::JSArray*>(vm, arrayValue); +    auto array = JSC::jsDynamicCast<JSC::JSArray*>(arrayValue);      if (!array) {          throwTypeError(lexicalGlobalObject, throwScope, "Argument must be an array"_s);          return JSValue::encode(jsUndefined()); @@ -477,7 +477,7 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JS          auto element = array->getIndex(lexicalGlobalObject, i);          RETURN_IF_EXCEPTION(throwScope, {}); -        auto* typedArray = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, element); +        auto* typedArray = JSC::jsDynamicCast<JSC::JSUint8Array*>(element);          if (!typedArray) {              throwTypeError(lexicalGlobalObject, throwScope, "Buffer.concat expects Uint8Array"_s);              return JSValue::encode(jsUndefined()); @@ -535,12 +535,12 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_toBufferBody(JSC::      }      auto buffer = callFrame->uncheckedArgument(0); -    if (!buffer.isCell() || !JSC::isTypedView(buffer.asCell()->classInfo(vm)->typedArrayStorageType)) { +    if (!buffer.isCell() || !JSC::isTypedView(buffer.asCell()->classInfo()->typedArrayStorageType)) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s);          return JSValue::encode(jsUndefined());      } -    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, buffer); +    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(buffer);      if (!view) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s); @@ -591,7 +591,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSG          return JSValue::encode(jsUndefined());      } -    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, callFrame->uncheckedArgument(0)); +    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(callFrame->uncheckedArgument(0));      if (UNLIKELY(!view)) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s); @@ -681,12 +681,12 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlob      auto buffer = callFrame->uncheckedArgument(0); -    if (!buffer.isCell() || !JSC::isTypedView(buffer.asCell()->classInfo(vm)->typedArrayStorageType)) { +    if (!buffer.isCell() || !JSC::isTypedView(buffer.asCell()->classInfo()->typedArrayStorageType)) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Uint8Array"_s);          return JSValue::encode(jsUndefined());      } -    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, buffer); +    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(buffer);      if (UNLIKELY(!view || view->isDetached())) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Uint8Array is detached"_s);          return JSValue::encode(jsUndefined()); @@ -769,7 +769,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_equalsBody(JSC::JSGl      }      auto buffer = callFrame->uncheckedArgument(0); -    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(vm, buffer); +    JSC::JSUint8Array* view = JSC::jsDynamicCast<JSC::JSUint8Array*>(buffer);      if (UNLIKELY(!view)) {          throwVMTypeError(lexicalGlobalObject, throwScope, "Expected Buffer"_s);          return JSValue::encode(jsUndefined()); @@ -866,7 +866,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob                  std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, encoding_);                  if (!encoded) { -                    throwTypeError(lexicalGlobalObject, throwScope, "Invalid encoding"); +                    throwTypeError(lexicalGlobalObject, throwScope, "Invalid encoding"_s);                      return JSC::JSValue::encode(jsUndefined());                  } @@ -950,7 +950,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JS          JSC::JSValue arg1 = callFrame->uncheckedArgument(0);          std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, arg1);          if (!encoded) { -            throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"); +            throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"_s);              return JSC::JSValue::encode(jsUndefined());          } @@ -963,7 +963,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JS          JSC::JSValue arg2 = callFrame->uncheckedArgument(1);          int32_t ioffset = arg2.toInt32(lexicalGlobalObject);          if (ioffset < 0) { -            throwTypeError(lexicalGlobalObject, scope, "Offset must be a positive integer"); +            throwTypeError(lexicalGlobalObject, scope, "Offset must be a positive integer"_s);              return JSC::JSValue::encode(jsUndefined());          }          offset = static_cast<uint32_t>(ioffset); @@ -1020,7 +1020,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JS          break;      }      default: { -        throwTypeError(lexicalGlobalObject, scope, "Unsupported encoding? This shouldn't happen"); +        throwTypeError(lexicalGlobalObject, scope, "Unsupported encoding? This shouldn't happen"_s);          break;      }      } @@ -1043,14 +1043,14 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlo      auto scope = DECLARE_THROW_SCOPE(vm);      if (UNLIKELY(callFrame->argumentCount() == 0)) { -        throwTypeError(lexicalGlobalObject, scope, "Not enough arguments"); +        throwTypeError(lexicalGlobalObject, scope, "Not enough arguments"_s);          return JSC::JSValue::encode(jsUndefined());      }      EnsureStillAliveScope arg0 = callFrame->argument(0);      auto* str = arg0.value().toStringOrNull(lexicalGlobalObject);      if (!str) { -        throwTypeError(lexicalGlobalObject, scope, "write() expects a string"); +        throwTypeError(lexicalGlobalObject, scope, "write() expects a string"_s);          return JSC::JSValue::encode(jsUndefined());      } @@ -1063,14 +1063,14 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlo          if (arg1.value().isAnyInt()) {              int32_t ioffset = arg1.value().toInt32(lexicalGlobalObject);              if (ioffset < 0) { -                throwTypeError(lexicalGlobalObject, scope, "Offset must be a positive integer"); +                throwTypeError(lexicalGlobalObject, scope, "Offset must be a positive integer"_s);                  return JSC::JSValue::encode(jsUndefined());              }              offset = static_cast<uint32_t>(ioffset);          } else if (arg1.value().isString()) {              std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, arg1.value());              if (!encoded) { -                throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"); +                throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"_s);                  return JSC::JSValue::encode(jsUndefined());              } @@ -1091,7 +1091,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_writeBody(JSC::JSGlo      if (callFrame->argumentCount() > 2) {          std::optional<BufferEncodingType> encoded = parseEnumeration<BufferEncodingType>(*lexicalGlobalObject, callFrame->argument(3));          if (!encoded) { -            throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"); +            throwTypeError(lexicalGlobalObject, scope, "Invalid encoding"_s);              return JSC::JSValue::encode(jsUndefined());          } @@ -1464,7 +1464,7 @@ JSBuffer::JSBuffer(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Bu  void JSBuffer::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, DOMURL>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -1540,7 +1540,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  Buffer* JSBuffer::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSBuffer*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSBuffer*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h index f071164d5..6b9ee6fa2 100644 --- a/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h +++ b/src/javascript/jsc/bindings/JSBufferConstructorBuiltins.h @@ -54,7 +54,7 @@ extern const JSC::ConstructorKind s_jsBufferConstructorFromCodeConstructorKind;  #define WEBCORE_BUILTIN_JSBUFFERCONSTRUCTOR_FROM 1  #define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(macro) \ -    macro(jsBufferConstructorFromCode, from, static_cast<const char*>(nullptr), s_jsBufferConstructorFromCodeLength) \ +    macro(jsBufferConstructorFromCode, from, ASCIILiteral(), s_jsBufferConstructorFromCodeLength) \  #define WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(macro) \      macro(from) \ @@ -70,7 +70,7 @@ public:      explicit JSBufferConstructorBuiltinsWrapper(JSC::VM& vm)          : m_vm(vm)          WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) -#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length), { })) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))          WEBCORE_FOREACH_JSBUFFERCONSTRUCTOR_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)  #undef INITIALIZE_BUILTIN_SOURCE_MEMBERS      { diff --git a/src/javascript/jsc/bindings/JSBufferEncodingType.cpp b/src/javascript/jsc/bindings/JSBufferEncodingType.cpp index 5d972a419..d88429d48 100644 --- a/src/javascript/jsc/bindings/JSBufferEncodingType.cpp +++ b/src/javascript/jsc/bindings/JSBufferEncodingType.cpp @@ -72,7 +72,7 @@ template<> std::optional<BufferEncodingType> parseEnumeration<BufferEncodingType              const size_t skip = encoding[3] == '-' ? 4 : 3;              if (encoding[skip] == '8' && encoding[skip + 1] == '\0')                  return BufferEncodingType::utf8; -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(skip, 5), "16le")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(skip, 5), "16le"_s))                  return BufferEncodingType::ucs2;              // ucs2          } else if (encoding[1] == 'c' && encoding[2] == 's') { @@ -80,17 +80,17 @@ template<> std::optional<BufferEncodingType> parseEnumeration<BufferEncodingType              if (encoding[skip] == '2' && encoding[skip + 1] == '\0')                  return BufferEncodingType::ucs2;          } -        if (WTF::equalIgnoringASCIICase(encoding, "utf8")) +        if (WTF::equalIgnoringASCIICase(encoding, "utf8"_s))              return BufferEncodingType::utf8; -        if (WTF::equalIgnoringASCIICase(encoding, "utf-8")) +        if (WTF::equalIgnoringASCIICase(encoding, "utf-8"_s))              return BufferEncodingType::utf8; -        if (WTF::equalIgnoringASCIICase(encoding, "ucs2")) +        if (WTF::equalIgnoringASCIICase(encoding, "ucs2"_s))              return BufferEncodingType::ucs2; -        if (WTF::equalIgnoringASCIICase(encoding, "ucs-2")) +        if (WTF::equalIgnoringASCIICase(encoding, "ucs-2"_s))              return BufferEncodingType::ucs2; -        if (WTF::equalIgnoringASCIICase(encoding, "utf16le")) +        if (WTF::equalIgnoringASCIICase(encoding, "utf16le"_s))              return BufferEncodingType::ucs2; -        if (WTF::equalIgnoringASCIICase(encoding, "utf-16le")) +        if (WTF::equalIgnoringASCIICase(encoding, "utf-16le"_s))              return BufferEncodingType::ucs2;          break; @@ -98,10 +98,10 @@ template<> std::optional<BufferEncodingType> parseEnumeration<BufferEncodingType      case 'L':          // latin1          if (encoding[1] == 'a') { -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 4), "tin1")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 4), "tin1"_s))                  return BufferEncodingType::latin1;          } -        if (WTF::equalIgnoringASCIICase(encoding, "latin1")) +        if (WTF::equalIgnoringASCIICase(encoding, "latin1"_s))              return BufferEncodingType::latin1;          break; @@ -109,26 +109,26 @@ template<> std::optional<BufferEncodingType> parseEnumeration<BufferEncodingType      case 'B':          // binary is a deprecated alias of latin1          if (encoding[1] == 'i') { -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "nary")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "nary"_s))                  return BufferEncodingType::latin1;              // buffer          } else if (encoding[1] == 'u') { -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "ffer")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "ffer"_s))                  return BufferEncodingType::buffer;              // base64          } else if (encoding[1] == 'a') { -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "se64")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 5), "se64"_s))                  return BufferEncodingType::base64; -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 8), "se64url")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 8), "se64url"_s))                  return BufferEncodingType::base64url;          } -        if (WTF::equalIgnoringASCIICase(encoding, "binary")) +        if (WTF::equalIgnoringASCIICase(encoding, "binary"_s))              return BufferEncodingType::latin1; // BINARY is a deprecated alias of LATIN1. -        if (WTF::equalIgnoringASCIICase(encoding, "buffer")) +        if (WTF::equalIgnoringASCIICase(encoding, "buffer"_s))              return BufferEncodingType::buffer; -        if (WTF::equalIgnoringASCIICase(encoding, "base64")) +        if (WTF::equalIgnoringASCIICase(encoding, "base64"_s))              return BufferEncodingType::base64; -        if (WTF::equalIgnoringASCIICase(encoding, "base64url")) +        if (WTF::equalIgnoringASCIICase(encoding, "base64url"_s))              return BufferEncodingType::base64url;          break; @@ -136,10 +136,10 @@ template<> std::optional<BufferEncodingType> parseEnumeration<BufferEncodingType      case 'A':          // ascii          if (encoding[1] == 's') { -            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 3), "cii")) +            if (WTF::equalIgnoringASCIICase(encoding.substringSharingImpl(2, 3), "cii"_s))                  return BufferEncodingType::ascii;          } -        if (WTF::equalIgnoringASCIICase(encoding, "ascii")) +        if (WTF::equalIgnoringASCIICase(encoding, "ascii"_s))              return BufferEncodingType::ascii;          break; @@ -149,7 +149,7 @@ template<> std::optional<BufferEncodingType> parseEnumeration<BufferEncodingType          if (encoding[1] == 'e')              if (encoding[2] == 'x' && encoding[3] == '\0')                  return BufferEncodingType::hex; -        if (WTF::equalIgnoringASCIICase(encoding, "hex")) +        if (WTF::equalIgnoringASCIICase(encoding, "hex"_s))              return BufferEncodingType::hex;          break;      } diff --git a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h index beff50d66..08fb50197 100644 --- a/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h +++ b/src/javascript/jsc/bindings/JSBufferPrototypeBuiltins.h @@ -390,63 +390,63 @@ extern const JSC::ConstructorKind s_jsBufferPrototypeInitializeBunBufferCodeCons  #define WEBCORE_BUILTIN_JSBUFFERPROTOTYPE_INITIALIZEBUNBUFFER 1  #define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(macro) \ -    macro(jsBufferPrototypeSetBigUint64Code, setBigUint64, static_cast<const char*>(nullptr), s_jsBufferPrototypeSetBigUint64CodeLength) \ -    macro(jsBufferPrototypeReadInt8Code, readInt8, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadInt8CodeLength) \ -    macro(jsBufferPrototypeReadUInt8Code, readUInt8, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadUInt8CodeLength) \ -    macro(jsBufferPrototypeReadInt16LECode, readInt16LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadInt16LECodeLength) \ -    macro(jsBufferPrototypeReadInt16BECode, readInt16BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadInt16BECodeLength) \ -    macro(jsBufferPrototypeReadUInt16LECode, readUInt16LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadUInt16LECodeLength) \ -    macro(jsBufferPrototypeReadUInt16BECode, readUInt16BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadUInt16BECodeLength) \ -    macro(jsBufferPrototypeReadInt32LECode, readInt32LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadInt32LECodeLength) \ -    macro(jsBufferPrototypeReadInt32BECode, readInt32BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadInt32BECodeLength) \ -    macro(jsBufferPrototypeReadUInt32LECode, readUInt32LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadUInt32LECodeLength) \ -    macro(jsBufferPrototypeReadUInt32BECode, readUInt32BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadUInt32BECodeLength) \ -    macro(jsBufferPrototypeReadFloatLECode, readFloatLE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadFloatLECodeLength) \ -    macro(jsBufferPrototypeReadFloatBECode, readFloatBE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadFloatBECodeLength) \ -    macro(jsBufferPrototypeReadDoubleLECode, readDoubleLE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadDoubleLECodeLength) \ -    macro(jsBufferPrototypeReadDoubleBECode, readDoubleBE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadDoubleBECodeLength) \ -    macro(jsBufferPrototypeReadBigInt64LECode, readBigInt64LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadBigInt64LECodeLength) \ -    macro(jsBufferPrototypeReadBigInt64BECode, readBigInt64BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadBigInt64BECodeLength) \ -    macro(jsBufferPrototypeReadBigUInt64LECode, readBigUInt64LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadBigUInt64LECodeLength) \ -    macro(jsBufferPrototypeReadBigUInt64BECode, readBigUInt64BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeReadBigUInt64BECodeLength) \ -    macro(jsBufferPrototypeWriteInt8Code, writeInt8, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteInt8CodeLength) \ -    macro(jsBufferPrototypeWriteUInt8Code, writeUInt8, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteUInt8CodeLength) \ -    macro(jsBufferPrototypeWriteInt16LECode, writeInt16LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteInt16LECodeLength) \ -    macro(jsBufferPrototypeWriteInt16BECode, writeInt16BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteInt16BECodeLength) \ -    macro(jsBufferPrototypeWriteUInt16LECode, writeUInt16LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteUInt16LECodeLength) \ -    macro(jsBufferPrototypeWriteUInt16BECode, writeUInt16BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteUInt16BECodeLength) \ -    macro(jsBufferPrototypeWriteInt32LECode, writeInt32LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteInt32LECodeLength) \ -    macro(jsBufferPrototypeWriteInt32BECode, writeInt32BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteInt32BECodeLength) \ -    macro(jsBufferPrototypeWriteUInt32LECode, writeUInt32LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteUInt32LECodeLength) \ -    macro(jsBufferPrototypeWriteUInt32BECode, writeUInt32BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteUInt32BECodeLength) \ -    macro(jsBufferPrototypeWriteFloatLECode, writeFloatLE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteFloatLECodeLength) \ -    macro(jsBufferPrototypeWriteFloatBECode, writeFloatBE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteFloatBECodeLength) \ -    macro(jsBufferPrototypeWriteDoubleLECode, writeDoubleLE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteDoubleLECodeLength) \ -    macro(jsBufferPrototypeWriteDoubleBECode, writeDoubleBE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteDoubleBECodeLength) \ -    macro(jsBufferPrototypeWriteBigInt64LECode, writeBigInt64LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteBigInt64LECodeLength) \ -    macro(jsBufferPrototypeWriteBigInt64BECode, writeBigInt64BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteBigInt64BECodeLength) \ -    macro(jsBufferPrototypeWriteBigUInt64LECode, writeBigUInt64LE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteBigUInt64LECodeLength) \ -    macro(jsBufferPrototypeWriteBigUInt64BECode, writeBigUInt64BE, static_cast<const char*>(nullptr), s_jsBufferPrototypeWriteBigUInt64BECodeLength) \ -    macro(jsBufferPrototypeSliceCode, slice, static_cast<const char*>(nullptr), s_jsBufferPrototypeSliceCodeLength) \ -    macro(jsBufferPrototypeUtf8WriteCode, utf8Write, static_cast<const char*>(nullptr), s_jsBufferPrototypeUtf8WriteCodeLength) \ -    macro(jsBufferPrototypeUcs2WriteCode, ucs2Write, static_cast<const char*>(nullptr), s_jsBufferPrototypeUcs2WriteCodeLength) \ -    macro(jsBufferPrototypeUtf16leWriteCode, utf16leWrite, static_cast<const char*>(nullptr), s_jsBufferPrototypeUtf16leWriteCodeLength) \ -    macro(jsBufferPrototypeLatin1WriteCode, latin1Write, static_cast<const char*>(nullptr), s_jsBufferPrototypeLatin1WriteCodeLength) \ -    macro(jsBufferPrototypeAsciiWriteCode, asciiWrite, static_cast<const char*>(nullptr), s_jsBufferPrototypeAsciiWriteCodeLength) \ -    macro(jsBufferPrototypeBase64WriteCode, base64Write, static_cast<const char*>(nullptr), s_jsBufferPrototypeBase64WriteCodeLength) \ -    macro(jsBufferPrototypeBase64urlWriteCode, base64urlWrite, static_cast<const char*>(nullptr), s_jsBufferPrototypeBase64urlWriteCodeLength) \ -    macro(jsBufferPrototypeHexWriteCode, hexWrite, static_cast<const char*>(nullptr), s_jsBufferPrototypeHexWriteCodeLength) \ -    macro(jsBufferPrototypeUtf8SliceCode, utf8Slice, static_cast<const char*>(nullptr), s_jsBufferPrototypeUtf8SliceCodeLength) \ -    macro(jsBufferPrototypeUcs2SliceCode, ucs2Slice, static_cast<const char*>(nullptr), s_jsBufferPrototypeUcs2SliceCodeLength) \ -    macro(jsBufferPrototypeUtf16leSliceCode, utf16leSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeUtf16leSliceCodeLength) \ -    macro(jsBufferPrototypeLatin1SliceCode, latin1Slice, static_cast<const char*>(nullptr), s_jsBufferPrototypeLatin1SliceCodeLength) \ -    macro(jsBufferPrototypeAsciiSliceCode, asciiSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeAsciiSliceCodeLength) \ -    macro(jsBufferPrototypeBase64SliceCode, base64Slice, static_cast<const char*>(nullptr), s_jsBufferPrototypeBase64SliceCodeLength) \ -    macro(jsBufferPrototypeBase64urlSliceCode, base64urlSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeBase64urlSliceCodeLength) \ -    macro(jsBufferPrototypeHexSliceCode, hexSlice, static_cast<const char*>(nullptr), s_jsBufferPrototypeHexSliceCodeLength) \ -    macro(jsBufferPrototypeToJSONCode, toJSON, static_cast<const char*>(nullptr), s_jsBufferPrototypeToJSONCodeLength) \ -    macro(jsBufferPrototypeSubarrayCode, subarray, static_cast<const char*>(nullptr), s_jsBufferPrototypeSubarrayCodeLength) \ -    macro(jsBufferPrototypeInitializeBunBufferCode, initializeBunBuffer, static_cast<const char*>(nullptr), s_jsBufferPrototypeInitializeBunBufferCodeLength) \ +    macro(jsBufferPrototypeSetBigUint64Code, setBigUint64, ASCIILiteral(), s_jsBufferPrototypeSetBigUint64CodeLength) \ +    macro(jsBufferPrototypeReadInt8Code, readInt8, ASCIILiteral(), s_jsBufferPrototypeReadInt8CodeLength) \ +    macro(jsBufferPrototypeReadUInt8Code, readUInt8, ASCIILiteral(), s_jsBufferPrototypeReadUInt8CodeLength) \ +    macro(jsBufferPrototypeReadInt16LECode, readInt16LE, ASCIILiteral(), s_jsBufferPrototypeReadInt16LECodeLength) \ +    macro(jsBufferPrototypeReadInt16BECode, readInt16BE, ASCIILiteral(), s_jsBufferPrototypeReadInt16BECodeLength) \ +    macro(jsBufferPrototypeReadUInt16LECode, readUInt16LE, ASCIILiteral(), s_jsBufferPrototypeReadUInt16LECodeLength) \ +    macro(jsBufferPrototypeReadUInt16BECode, readUInt16BE, ASCIILiteral(), s_jsBufferPrototypeReadUInt16BECodeLength) \ +    macro(jsBufferPrototypeReadInt32LECode, readInt32LE, ASCIILiteral(), s_jsBufferPrototypeReadInt32LECodeLength) \ +    macro(jsBufferPrototypeReadInt32BECode, readInt32BE, ASCIILiteral(), s_jsBufferPrototypeReadInt32BECodeLength) \ +    macro(jsBufferPrototypeReadUInt32LECode, readUInt32LE, ASCIILiteral(), s_jsBufferPrototypeReadUInt32LECodeLength) \ +    macro(jsBufferPrototypeReadUInt32BECode, readUInt32BE, ASCIILiteral(), s_jsBufferPrototypeReadUInt32BECodeLength) \ +    macro(jsBufferPrototypeReadFloatLECode, readFloatLE, ASCIILiteral(), s_jsBufferPrototypeReadFloatLECodeLength) \ +    macro(jsBufferPrototypeReadFloatBECode, readFloatBE, ASCIILiteral(), s_jsBufferPrototypeReadFloatBECodeLength) \ +    macro(jsBufferPrototypeReadDoubleLECode, readDoubleLE, ASCIILiteral(), s_jsBufferPrototypeReadDoubleLECodeLength) \ +    macro(jsBufferPrototypeReadDoubleBECode, readDoubleBE, ASCIILiteral(), s_jsBufferPrototypeReadDoubleBECodeLength) \ +    macro(jsBufferPrototypeReadBigInt64LECode, readBigInt64LE, ASCIILiteral(), s_jsBufferPrototypeReadBigInt64LECodeLength) \ +    macro(jsBufferPrototypeReadBigInt64BECode, readBigInt64BE, ASCIILiteral(), s_jsBufferPrototypeReadBigInt64BECodeLength) \ +    macro(jsBufferPrototypeReadBigUInt64LECode, readBigUInt64LE, ASCIILiteral(), s_jsBufferPrototypeReadBigUInt64LECodeLength) \ +    macro(jsBufferPrototypeReadBigUInt64BECode, readBigUInt64BE, ASCIILiteral(), s_jsBufferPrototypeReadBigUInt64BECodeLength) \ +    macro(jsBufferPrototypeWriteInt8Code, writeInt8, ASCIILiteral(), s_jsBufferPrototypeWriteInt8CodeLength) \ +    macro(jsBufferPrototypeWriteUInt8Code, writeUInt8, ASCIILiteral(), s_jsBufferPrototypeWriteUInt8CodeLength) \ +    macro(jsBufferPrototypeWriteInt16LECode, writeInt16LE, ASCIILiteral(), s_jsBufferPrototypeWriteInt16LECodeLength) \ +    macro(jsBufferPrototypeWriteInt16BECode, writeInt16BE, ASCIILiteral(), s_jsBufferPrototypeWriteInt16BECodeLength) \ +    macro(jsBufferPrototypeWriteUInt16LECode, writeUInt16LE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt16LECodeLength) \ +    macro(jsBufferPrototypeWriteUInt16BECode, writeUInt16BE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt16BECodeLength) \ +    macro(jsBufferPrototypeWriteInt32LECode, writeInt32LE, ASCIILiteral(), s_jsBufferPrototypeWriteInt32LECodeLength) \ +    macro(jsBufferPrototypeWriteInt32BECode, writeInt32BE, ASCIILiteral(), s_jsBufferPrototypeWriteInt32BECodeLength) \ +    macro(jsBufferPrototypeWriteUInt32LECode, writeUInt32LE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt32LECodeLength) \ +    macro(jsBufferPrototypeWriteUInt32BECode, writeUInt32BE, ASCIILiteral(), s_jsBufferPrototypeWriteUInt32BECodeLength) \ +    macro(jsBufferPrototypeWriteFloatLECode, writeFloatLE, ASCIILiteral(), s_jsBufferPrototypeWriteFloatLECodeLength) \ +    macro(jsBufferPrototypeWriteFloatBECode, writeFloatBE, ASCIILiteral(), s_jsBufferPrototypeWriteFloatBECodeLength) \ +    macro(jsBufferPrototypeWriteDoubleLECode, writeDoubleLE, ASCIILiteral(), s_jsBufferPrototypeWriteDoubleLECodeLength) \ +    macro(jsBufferPrototypeWriteDoubleBECode, writeDoubleBE, ASCIILiteral(), s_jsBufferPrototypeWriteDoubleBECodeLength) \ +    macro(jsBufferPrototypeWriteBigInt64LECode, writeBigInt64LE, ASCIILiteral(), s_jsBufferPrototypeWriteBigInt64LECodeLength) \ +    macro(jsBufferPrototypeWriteBigInt64BECode, writeBigInt64BE, ASCIILiteral(), s_jsBufferPrototypeWriteBigInt64BECodeLength) \ +    macro(jsBufferPrototypeWriteBigUInt64LECode, writeBigUInt64LE, ASCIILiteral(), s_jsBufferPrototypeWriteBigUInt64LECodeLength) \ +    macro(jsBufferPrototypeWriteBigUInt64BECode, writeBigUInt64BE, ASCIILiteral(), s_jsBufferPrototypeWriteBigUInt64BECodeLength) \ +    macro(jsBufferPrototypeSliceCode, slice, ASCIILiteral(), s_jsBufferPrototypeSliceCodeLength) \ +    macro(jsBufferPrototypeUtf8WriteCode, utf8Write, ASCIILiteral(), s_jsBufferPrototypeUtf8WriteCodeLength) \ +    macro(jsBufferPrototypeUcs2WriteCode, ucs2Write, ASCIILiteral(), s_jsBufferPrototypeUcs2WriteCodeLength) \ +    macro(jsBufferPrototypeUtf16leWriteCode, utf16leWrite, ASCIILiteral(), s_jsBufferPrototypeUtf16leWriteCodeLength) \ +    macro(jsBufferPrototypeLatin1WriteCode, latin1Write, ASCIILiteral(), s_jsBufferPrototypeLatin1WriteCodeLength) \ +    macro(jsBufferPrototypeAsciiWriteCode, asciiWrite, ASCIILiteral(), s_jsBufferPrototypeAsciiWriteCodeLength) \ +    macro(jsBufferPrototypeBase64WriteCode, base64Write, ASCIILiteral(), s_jsBufferPrototypeBase64WriteCodeLength) \ +    macro(jsBufferPrototypeBase64urlWriteCode, base64urlWrite, ASCIILiteral(), s_jsBufferPrototypeBase64urlWriteCodeLength) \ +    macro(jsBufferPrototypeHexWriteCode, hexWrite, ASCIILiteral(), s_jsBufferPrototypeHexWriteCodeLength) \ +    macro(jsBufferPrototypeUtf8SliceCode, utf8Slice, ASCIILiteral(), s_jsBufferPrototypeUtf8SliceCodeLength) \ +    macro(jsBufferPrototypeUcs2SliceCode, ucs2Slice, ASCIILiteral(), s_jsBufferPrototypeUcs2SliceCodeLength) \ +    macro(jsBufferPrototypeUtf16leSliceCode, utf16leSlice, ASCIILiteral(), s_jsBufferPrototypeUtf16leSliceCodeLength) \ +    macro(jsBufferPrototypeLatin1SliceCode, latin1Slice, ASCIILiteral(), s_jsBufferPrototypeLatin1SliceCodeLength) \ +    macro(jsBufferPrototypeAsciiSliceCode, asciiSlice, ASCIILiteral(), s_jsBufferPrototypeAsciiSliceCodeLength) \ +    macro(jsBufferPrototypeBase64SliceCode, base64Slice, ASCIILiteral(), s_jsBufferPrototypeBase64SliceCodeLength) \ +    macro(jsBufferPrototypeBase64urlSliceCode, base64urlSlice, ASCIILiteral(), s_jsBufferPrototypeBase64urlSliceCodeLength) \ +    macro(jsBufferPrototypeHexSliceCode, hexSlice, ASCIILiteral(), s_jsBufferPrototypeHexSliceCodeLength) \ +    macro(jsBufferPrototypeToJSONCode, toJSON, ASCIILiteral(), s_jsBufferPrototypeToJSONCodeLength) \ +    macro(jsBufferPrototypeSubarrayCode, subarray, ASCIILiteral(), s_jsBufferPrototypeSubarrayCodeLength) \ +    macro(jsBufferPrototypeInitializeBunBufferCode, initializeBunBuffer, ASCIILiteral(), s_jsBufferPrototypeInitializeBunBufferCodeLength) \  #define WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(macro) \      macro(asciiSlice) \ @@ -518,7 +518,7 @@ public:      explicit JSBufferPrototypeBuiltinsWrapper(JSC::VM& vm)          : m_vm(vm)          WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) -#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length), { })) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { }))          WEBCORE_FOREACH_JSBUFFERPROTOTYPE_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)  #undef INITIALIZE_BUILTIN_SOURCE_MEMBERS      { diff --git a/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp b/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp index 494bf9e3a..473196641 100644 --- a/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp +++ b/src/javascript/jsc/bindings/JSDOMExceptionHandling.cpp @@ -56,7 +56,7 @@ void reportException(JSGlobalObject* lexicalGlobalObject, JSC::Exception* except      vm.clearLastException();      auto* globalObject = jsCast<JSDOMGlobalObject*>(lexicalGlobalObject); -    // if (auto* window = jsDynamicCast<JSDOMWindow*>(vm, globalObject)) { +    // if (auto* window = jsDynamicCast<JSDOMWindow*>( globalObject)) {      //     if (!window->wrapped().isCurrentlyDisplayedInFrame())      //         return;      // } @@ -85,7 +85,7 @@ void reportException(JSGlobalObject* lexicalGlobalObject, JSValue exceptionValue  {      VM& vm = lexicalGlobalObject->vm();      RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock()); -    auto* exception = jsDynamicCast<JSC::Exception*>(vm, exceptionValue); +    auto* exception = jsDynamicCast<JSC::Exception*>(exceptionValue);      if (!exception) {          exception = vm.lastException();          if (!exception) @@ -100,9 +100,9 @@ String retrieveErrorMessageWithoutName(JSGlobalObject& lexicalGlobalObject, VM&      // FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions      // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception.      String errorMessage; -    if (auto* error = jsDynamicCast<ErrorInstance*>(vm, exception)) +    if (auto* error = jsDynamicCast<ErrorInstance*>(exception))          errorMessage = error->sanitizedMessageString(&lexicalGlobalObject); -    else if (auto* error = jsDynamicCast<JSDOMException*>(vm, exception)) +    else if (auto* error = jsDynamicCast<JSDOMException*>(exception))          errorMessage = error->wrapped().message();      else          errorMessage = exception.toWTFString(&lexicalGlobalObject); @@ -119,7 +119,7 @@ String retrieveErrorMessage(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue      // FIXME: <http://webkit.org/b/115087> Web Inspector: WebCore::reportException should not evaluate JavaScript handling exceptions      // If this is a custom exception object, call toString on it to try and get a nice string representation for the exception.      String errorMessage; -    if (auto* error = jsDynamicCast<ErrorInstance*>(vm, exception)) +    if (auto* error = jsDynamicCast<ErrorInstance*>(exception))          errorMessage = error->sanitizedToString(&lexicalGlobalObject);      else          errorMessage = exception.toWTFString(&lexicalGlobalObject); diff --git a/src/javascript/jsc/bindings/JSDOMGlobalObject.h b/src/javascript/jsc/bindings/JSDOMGlobalObject.h index fe5344aeb..b22700d7d 100644 --- a/src/javascript/jsc/bindings/JSDOMGlobalObject.h +++ b/src/javascript/jsc/bindings/JSDOMGlobalObject.h @@ -23,8 +23,8 @@ JSClass* toJSDOMGlobalObject(JSC::VM& vm, JSC::JSValue value)      if (auto* object = value.getObject()) {          if (object->type() == JSC::PureForwardingProxyType) -            return JSC::jsDynamicCast<JSClass*>(vm, JSC::jsCast<JSC::JSProxy*>(object)->target()); -        if (object->inherits<JSClass>(vm)) +            return JSC::jsDynamicCast<JSClass*>(JSC::jsCast<JSC::JSProxy*>(object)->target()); +        if (object->inherits<JSClass>())              return JSC::jsCast<JSClass*>(object);      } diff --git a/src/javascript/jsc/bindings/JSFFIFunction.cpp b/src/javascript/jsc/bindings/JSFFIFunction.cpp index 1f146350e..5c4ad3ed6 100644 --- a/src/javascript/jsc/bindings/JSFFIFunction.cpp +++ b/src/javascript/jsc/bindings/JSFFIFunction.cpp @@ -64,7 +64,7 @@ DEFINE_VISIT_CHILDREN(JSFFIFunction);  void JSFFIFunction::finishCreation(VM& vm, NativeExecutable* executable, unsigned length, const String& name)  {      Base::finishCreation(vm, executable, length, name); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));  }  JSFFIFunction* JSFFIFunction::create(VM& vm, Zig::GlobalObject* globalObject, unsigned length, const String& name, FFIFunction FFIFunction, Intrinsic intrinsic, NativeFunction nativeConstructor) diff --git a/src/javascript/jsc/bindings/Path.cpp b/src/javascript/jsc/bindings/Path.cpp index ed155141c..6e3e27b0e 100644 --- a/src/javascript/jsc/bindings/Path.cpp +++ b/src/javascript/jsc/bindings/Path.cpp @@ -27,7 +27,7 @@ namespace JSCastingHelpers = JSC::JSCastingHelpers;  // clang-format off  #define DEFINE_CALLBACK_FUNCTION_BODY(ZigFunction) JSC::VM& vm = globalObject->vm(); \ -    auto* thisObject = JSC::jsDynamicCast<JSC::JSFinalObject*>(vm, callFrame->thisValue()); \ +    auto* thisObject = JSC::jsDynamicCast<JSC::JSFinalObject*>( callFrame->thisValue()); \      auto scope = DECLARE_THROW_SCOPE(vm); \      if (!thisObject) \          return throwVMTypeError(globalObject, scope); \ @@ -137,48 +137,48 @@ static JSC::JSObject* createPath(JSGlobalObject* globalThis, bool isWindows)      path->putDirect(vm, clientData->builtinNames().basenamePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("basename"), Path_functionBasename), +            "basename"_s, Path_functionBasename),          0);      path->putDirect(vm, clientData->builtinNames().dirnamePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("dirname"), Path_functionDirname), +            "dirname"_s, Path_functionDirname),          0);      path->putDirect(vm, clientData->builtinNames().extnamePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("extname"), Path_functionExtname), +            "extname"_s, Path_functionExtname),          0);      path->putDirect(vm, clientData->builtinNames().formatPublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("format"), Path_functionFormat), +            "format"_s, Path_functionFormat),          0);      path->putDirect(vm, clientData->builtinNames().isAbsolutePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("isAbsolute"), Path_functionIsAbsolute), +            "isAbsolute"_s, Path_functionIsAbsolute),          0);      path->putDirect(vm, clientData->builtinNames().joinPublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("join"), Path_functionJoin), +            "join"_s, Path_functionJoin),          0);      path->putDirect(vm, clientData->builtinNames().normalizePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("normalize"), Path_functionNormalize), +            "normalize"_s, Path_functionNormalize),          0);      path->putDirect(vm, clientData->builtinNames().parsePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("parse"), Path_functionParse), +            "parse"_s, Path_functionParse),          0);      path->putDirect(vm, clientData->builtinNames().relativePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("relative"), Path_functionRelative), +            "relative"_s, Path_functionRelative),          0);      path->putDirect(vm, clientData->builtinNames().resolvePublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("resolve"), Path_functionResolve), +            "resolve"_s, Path_functionResolve),          0);      path->putDirect(vm, clientData->builtinNames().toNamespacedPathPublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0, -            WTF::String("toNamespacedPath"), +            "toNamespacedPath"_s,              Path_functionToNamespacedPath),          0); diff --git a/src/javascript/jsc/bindings/Process.cpp b/src/javascript/jsc/bindings/Process.cpp index a450c8a46..e732b0d54 100644 --- a/src/javascript/jsc/bindings/Process.cpp +++ b/src/javascript/jsc/bindings/Process.cpp @@ -46,7 +46,7 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick,      JSC::JSValue job = callFrame->uncheckedArgument(0); -    if (!job.isObject() || !job.getObject()->isCallable(vm)) { +    if (!job.isObject() || !job.getObject()->isCallable()) {          auto scope = DECLARE_THROW_SCOPE(globalObject->vm());          JSC::throwTypeError(globalObject, scope, "nextTick expects a function"_s);          return JSC::JSValue::encode(JSC::JSValue {}); @@ -94,7 +94,7 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick,          //   vm, globalObject, 0, String(),          //   [job, &argsList](JSC::JSGlobalObject *globalObject, JSC::CallFrame *callFrame) {          //     JSC::VM &vm = globalObject->vm(); -        //     auto callData = getCallData(vm, job); +        //     auto callData = getCallData(job);          //     return JSC::JSValue::encode(JSC::call(globalObject, job, callData, job, argsList));          //   }); @@ -215,66 +215,66 @@ void Process::finishCreation(JSC::VM& vm)      this->putDirect(vm, clientData->builtinNames().nextTickPublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 1, -            WTF::String("nextTick"), Process_functionNextTick), +            MAKE_STATIC_STRING_IMPL("nextTick"), Process_functionNextTick),          0);      this->putDirect(vm, JSC::Identifier::fromString(vm, "dlopen"_s),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 1, -            WTF::String("dlopen"_s), Process_functionDlopen), +            MAKE_STATIC_STRING_IMPL("dlopen"), Process_functionDlopen),          0);      this->putDirect(vm, clientData->builtinNames().cwdPublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0, -            WTF::String("cwd"), Process_functionCwd), +            MAKE_STATIC_STRING_IMPL("cwd"), Process_functionCwd),          0);      this->putDirect(vm, clientData->builtinNames().chdirPublicName(),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0, -            WTF::String("chdir"), Process_functionChdir), +            MAKE_STATIC_STRING_IMPL("chdir"), Process_functionChdir),          0);      this->putDirect(vm, JSC::Identifier::fromString(vm, "exit"_s),          JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0, -            WTF::String("exit"), Process_functionExit), +            MAKE_STATIC_STRING_IMPL("exit"), Process_functionExit),          0);      putDirectCustomAccessor(          vm, clientData->builtinNames().versionsPublicName(),          JSC::CustomGetterSetter::create(vm, Process_getVersionsLazy, Process_setVersionsLazy), 0);      // this should be transpiled out, but just incase -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "browser"), +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "browser"_s),          JSC::JSValue(false)); -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "exitCode"), +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "exitCode"_s),          JSC::JSValue(JSC::jsNumber(0)));      this->putDirect(this->vm(), clientData->builtinNames().versionPublicName(), -        JSC::jsString(this->vm(), WTF::String(Bun__version))); +        JSC::jsString(this->vm(), Bun__version));      // this gives some way of identifying at runtime whether the SSR is happening in node or not.      // this should probably be renamed to what the name of the bundler is, instead of "notNodeJS"      // but it must be something that won't evaluate to truthy in Node.js -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "isBun"), JSC::JSValue(true)); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "isBun"_s), JSC::JSValue(true));  #if defined(__APPLE__) -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"), -        JSC::jsString(this->vm(), WTF::String("darwin"))); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"_s), +        JSC::jsString(this->vm(), makeAtomString("darwin")));  #else -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"), -        JSC::jsString(this->vm(), WTF::String("linux"))); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"_s), +        JSC::jsString(this->vm(), makeAtomString("linux")));  #endif  #if defined(__x86_64__) -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"), -        JSC::jsString(this->vm(), WTF::String("x64"))); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"_s), +        JSC::jsString(this->vm(), makeAtomString("x64")));  #elif defined(__i386__) -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"), -        JSC::jsString(this->vm(), WTF::String("x86"))); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"_s), +        JSC::jsString(this->vm(), makeAtomString("x86")));  #elif defined(__arm__) -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"), -        JSC::jsString(this->vm(), WTF::String("arm"))); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"_s), +        JSC::jsString(this->vm(), makeAtomString("arm")));  #elif defined(__aarch64__) -    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"), -        JSC::jsString(this->vm(), WTF::String("arm64"))); +    this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"_s), +        JSC::jsString(this->vm(), makeAtomString("arm64")));  #endif  } @@ -294,8 +294,8 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setTitle,  {      JSC::VM& vm = globalObject->vm(); -    JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(vm, JSValue::decode(thisValue)); -    JSC::JSString* jsString = JSC::jsDynamicCast<JSC::JSString*>(vm, JSValue::decode(value)); +    JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(JSValue::decode(thisValue)); +    JSC::JSString* jsString = JSC::jsDynamicCast<JSC::JSString*>(JSValue::decode(value));      if (!thisObject || !jsString) {          return false;      } @@ -310,7 +310,7 @@ JSC_DEFINE_CUSTOM_GETTER(Process_getArgv, (JSC::JSGlobalObject * globalObject, J  {      JSC::VM& vm = globalObject->vm(); -    Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(vm, JSValue::decode(thisValue)); +    Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(JSValue::decode(thisValue));      if (!thisObject) {          return JSValue::encode(JSC::jsUndefined());      } @@ -334,7 +334,7 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setArgv,  {      JSC::VM& vm = globalObject->vm(); -    JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(vm, JSValue::decode(thisValue)); +    JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(JSValue::decode(thisValue));      if (!thisObject) {          return false;      } @@ -362,7 +362,7 @@ JSC_DEFINE_CUSTOM_GETTER(Process_getVersionsLazy,      JSC::VM& vm = globalObject->vm();      auto clientData = WebCore::clientData(vm); -    Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(vm, JSValue::decode(thisValue)); +    Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(JSValue::decode(thisValue));      if (!thisObject) {          return JSValue::encode(JSC::jsUndefined());      } @@ -374,28 +374,28 @@ JSC_DEFINE_CUSTOM_GETTER(Process_getVersionsLazy,      JSC::JSObject* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 9); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "node"), -        JSC::JSValue(JSC::jsString(vm, WTF::String("16.14.0")))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "node"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString("16.14.0"))));      object->putDirect( -        vm, JSC::Identifier::fromString(vm, "bun"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__version + 1 /* prefix with v */)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_webkit)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "mimalloc"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_mimalloc)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "libarchive"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_libarchive)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "picohttpparser"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_picohttpparser)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_boringssl)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "zlib"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_zlib)))); -    object->putDirect(vm, JSC::Identifier::fromString(vm, "zig"), -        JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_zig)))); - -    object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"), -        JSC::JSValue(JSC::jsString(vm, WTF::String("67")))); +        vm, JSC::Identifier::fromString(vm, "bun"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__version + 1 /* prefix with v */)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_webkit)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "mimalloc"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_mimalloc)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "libarchive"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_libarchive)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "picohttpparser"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_picohttpparser)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_boringssl)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "zlib"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_zlib)))); +    object->putDirect(vm, JSC::Identifier::fromString(vm, "zig"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString(Bun__versions_zig)))); + +    object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"_s), +        JSC::JSValue(JSC::jsString(vm, makeAtomString("67"))));      thisObject->putDirect(vm, clientData->builtinNames().versionsPrivateName(), object);      return JSC::JSValue::encode(object); @@ -408,7 +408,7 @@ JSC_DEFINE_CUSTOM_SETTER(Process_setVersionsLazy,      JSC::VM& vm = globalObject->vm();      auto clientData = WebCore::clientData(vm); -    Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(vm, JSValue::decode(thisValue)); +    Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(JSValue::decode(thisValue));      if (!thisObject) {          return JSValue::encode(JSC::jsUndefined());      } diff --git a/src/javascript/jsc/bindings/URLDecomposition.cpp b/src/javascript/jsc/bindings/URLDecomposition.cpp index db2bb7f81..eb21e36c8 100644 --- a/src/javascript/jsc/bindings/URLDecomposition.cpp +++ b/src/javascript/jsc/bindings/URLDecomposition.cpp @@ -233,7 +233,7 @@ void URLDecomposition::setSearch(const String& value)      } else {          String newSearch = value;          // Make sure that '#' in the query does not leak to the hash. -        fullURL.setQuery(newSearch.replaceWithLiteral('#', "%23")); +        fullURL.setQuery(makeStringByReplacingAll(value, '#', "%23"_s));      }      setFullURL(fullURL);  } diff --git a/src/javascript/jsc/bindings/bindings.cpp b/src/javascript/jsc/bindings/bindings.cpp index a5a51adbc..ef1d78e27 100644 --- a/src/javascript/jsc/bindings/bindings.cpp +++ b/src/javascript/jsc/bindings/bindings.cpp @@ -77,7 +77,7 @@ template<typename WebCoreType, typename OutType>  OutType* WebCoreCast(JSC__JSValue JSValue0, JSC::VM* vm)  {      // we must use jsDynamicCast here so that we check that the type is correct -    WebCoreType* jsdomURL = JSC::jsDynamicCast<WebCoreType*>(*vm, JSC::JSValue::decode(JSValue0)); +    WebCoreType* jsdomURL = JSC::jsDynamicCast<WebCoreType*>(JSC::JSValue::decode(JSValue0));      if (jsdomURL == nullptr) {          return nullptr;      } @@ -410,7 +410,7 @@ void JSC__JSObject__putRecord(JSC__JSObject* object, JSC__JSGlobalObject* global          descriptor.setValue(array);      } -    object->methodTable(global->vm())->defineOwnProperty(object, global, ident, descriptor, true); +    object->methodTable()->defineOwnProperty(object, global, ident, descriptor, true);      object->putDirect(global->vm(), ident, descriptor.value());      scope.release();  } @@ -454,7 +454,7 @@ void JSC__JSValue__putRecord(JSC__JSValue objectValue, JSC__JSGlobalObject* glob          descriptor.setValue(array);      } -    object->methodTable(global->vm())->defineOwnProperty(object, global, ident, descriptor, true); +    object->methodTable()->defineOwnProperty(object, global, ident, descriptor, true);      object->putDirect(global->vm(), ident, descriptor.value());      scope.release();  } @@ -545,9 +545,9 @@ void JSC__JSValue___then(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObjec              return JSC::JSValue::encode(JSC::jsUndefined());          }); -    if (JSC::JSPromise* promise = JSC::jsDynamicCast<JSC::JSPromise*>(globalObject->vm(), cell)) { +    if (JSC::JSPromise* promise = JSC::jsDynamicCast<JSC::JSPromise*>(cell)) {          promise->performPromiseThen(globalObject, resolverFunction, rejecterFunction, JSC::jsUndefined()); -    } else if (JSC::JSInternalPromise* promise = JSC::jsDynamicCast<JSC::JSInternalPromise*>(globalObject->vm(), cell)) { +    } else if (JSC::JSInternalPromise* promise = JSC::jsDynamicCast<JSC::JSInternalPromise*>(cell)) {          promise->then(globalObject, resolverFunction, rejecterFunction);      }  } @@ -559,7 +559,7 @@ JSC__JSValue JSC__JSValue__parseJSON(JSC__JSValue JSValue0, JSC__JSGlobalObject*      JSC::JSValue result = JSC::JSONParse(arg1, jsValue.toWTFString(arg1));      if (!result) { -        result = JSC::JSValue(JSC::createSyntaxError(arg1->globalObject(), "Failed to parse JSON")); +        result = JSC::JSValue(JSC::createSyntaxError(arg1->globalObject(), "Failed to parse JSON"_s));      }      return JSC::JSValue::encode(result); @@ -587,7 +587,7 @@ JSC__JSValue JSC__JSGlobalObject__putCachedObject(JSC__JSGlobalObject* globalObj  void JSC__JSGlobalObject__deleteModuleRegistryEntry(JSC__JSGlobalObject* global, ZigString* arg1)  {      JSC::JSMap* map = JSC::jsDynamicCast<JSC::JSMap*>( -        global->vm(), global->moduleLoader()->getDirect(global->vm(), JSC::Identifier::fromString(global->vm(), "registry"))); +        global->moduleLoader()->getDirect(global->vm(), JSC::Identifier::fromString(global->vm(), "registry"_s)));      if (!map)          return;      const JSC::Identifier identifier = Zig::toIdentifier(*arg1, global); @@ -602,7 +602,7 @@ JSC__JSInternalPromise* JSC__VM__reloadModule(JSC__VM* vm, JSC__JSGlobalObject*      return nullptr;      // JSC::JSMap *map = JSC::jsDynamicCast<JSC::JSMap *>(      //   arg1->vm(), arg1->moduleLoader()->getDirect( -    //                 arg1->vm(), JSC::Identifier::fromString(arg1->vm(), "registry"))); +    //                 arg1->vm(), JSC::Identifier::fromString(arg1->vm(), "registry"_s)));      // const JSC::Identifier identifier = Zig::toIdentifier(arg2, arg1);      // JSC::JSValue val = JSC::identifierToJSValue(arg1->vm(), identifier); @@ -610,7 +610,7 @@ JSC__JSInternalPromise* JSC__VM__reloadModule(JSC__VM* vm, JSC__JSGlobalObject*      // if (!map->has(arg1, val)) return nullptr;      // if (JSC::JSObject *registryEntry = -    //       JSC::jsDynamicCast<JSC::JSObject *>(arg1->vm(), map->get(arg1, val))) { +    //       JSC::jsDynamicCast<JSC::JSObject *>(arg1-> map->get(arg1, val))) {      //   auto moduleIdent = JSC::Identifier::fromString(arg1->vm(), "module");      //   if (JSC::JSModuleRecord *record = JSC::jsDynamicCast<JSC::JSModuleRecord *>(      //         arg1->vm(), registryEntry->getDirect(arg1->vm(), moduleIdent))) { @@ -657,7 +657,7 @@ JSC__JSValue JSObjectCallAsFunctionReturnValue(JSContextRef ctx, JSObjectRef obj      for (size_t i = 0; i < argumentCount; i++)          argList.append(toJS(globalObject, arguments[i])); -    auto callData = getCallData(vm, jsObject); +    auto callData = getCallData(jsObject);      if (callData.type == JSC::CallData::Type::None)          return JSC::JSValue::encode(JSC::JSValue()); @@ -699,7 +699,7 @@ JSC__JSValue JSObjectCallAsFunctionReturnValueHoldingAPILock(JSContextRef ctx, J      for (size_t i = 0; i < argumentCount; i++)          argList.append(toJS(globalObject, arguments[i])); -    auto callData = getCallData(vm, jsObject); +    auto callData = getCallData(jsObject);      if (callData.type == JSC::CallData::Type::None)          return JSC::JSValue::encode(JSC::JSValue()); @@ -964,7 +964,7 @@ bool JSC__JSValue__asArrayBuffer_(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar      JSC::JSObject* object = value.getObject(); -    if (JSC::JSArrayBufferView* typedArray = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(vm, object)) { +    if (JSC::JSArrayBufferView* typedArray = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(object)) {          if (JSC::ArrayBuffer* buffer = typedArray->possiblySharedBuffer()) {              buffer->pinAndLock();              arg2->ptr = reinterpret_cast<char*>(buffer->data()); @@ -1724,7 +1724,7 @@ JSC__JSValue JSC__JSValue__getPrototype(JSC__JSValue JSValue0, JSC__JSGlobalObje  }  bool JSC__JSValue__isException(JSC__JSValue JSValue0, JSC__VM* arg1)  { -    return JSC::jsDynamicCast<JSC::Exception*>(*arg1, JSC::JSValue::decode(JSValue0)) != nullptr; +    return JSC::jsDynamicCast<JSC::Exception*>(JSC::JSValue::decode(JSValue0)) != nullptr;  }  bool JSC__JSValue__isAnyInt(JSC__JSValue JSValue0)  { @@ -1752,7 +1752,7 @@ void JSC__JSValue__put(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, const Z  bool JSC__JSValue__isClass(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1)  {      JSC::JSValue value = JSC::JSValue::decode(JSValue0); -    return value.isConstructor(arg1->vm()); +    return value.isConstructor();  }  bool JSC__JSValue__isCell(JSC__JSValue JSValue0) { return JSC::JSValue::decode(JSValue0).isCell(); }  bool JSC__JSValue__isCustomGetterSetter(JSC__JSValue JSValue0) @@ -1770,7 +1770,7 @@ bool JSC__JSValue__isAggregateError(JSC__JSValue JSValue0, JSC__JSGlobalObject*      JSC::JSObject* obj = JSC::JSValue::decode(JSValue0).getObject();      if (obj != nullptr) { -        if (JSC::ErrorInstance* err = JSC::jsDynamicCast<JSC::ErrorInstance*>(global->vm(), obj)) { +        if (JSC::ErrorInstance* err = JSC::jsDynamicCast<JSC::ErrorInstance*>(obj)) {              return err->errorType() == JSC::ErrorType::AggregateError;          }      } @@ -1795,7 +1795,7 @@ void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, voi  bool JSC__JSValue__isCallable(JSC__JSValue JSValue0, JSC__VM* arg1)  { -    return JSC::JSValue::decode(JSValue0).isCallable(reinterpret_cast<JSC::VM&>(arg1)); +    return JSC::JSValue::decode(JSValue0).isCallable();  }  bool JSC__JSValue__isGetterSetter(JSC__JSValue JSValue0)  { @@ -1950,9 +1950,9 @@ JSC__JSValue JSC__JSValue__createObject2(JSC__JSGlobalObject* globalObject, cons      descriptor2.setWritable(1);      descriptor2.setValue(JSC::JSValue::decode(JSValue4)); -    object->methodTable(globalObject->vm()) +    object->methodTable()          ->defineOwnProperty(object, globalObject, key2, descriptor2, true); -    object->methodTable(globalObject->vm()) +    object->methodTable()          ->defineOwnProperty(object, globalObject, key1, descriptor1, true);      return JSC::JSValue::encode(object); @@ -2006,7 +2006,7 @@ bool JSC__JSValue__symbolKeyFor(JSC__JSValue symbolValue_, JSC__JSGlobalObject*      if (!uid.symbolRegistry())          return false; -    *arg2 = Zig::toZigString(JSC::jsString(vm, &uid), arg1); +    *arg2 = Zig::toZigString(JSC::jsString(vm, String { uid }), arg1);      return true;  } @@ -2098,8 +2098,10 @@ static void populateStackFrameMetadata(const JSC::StackFrame* stackFrame, ZigSta          return;      JSC::JSObject* callee = JSC::jsCast<JSC::JSObject*>(calleeCell); +    auto& vm = m_codeBlock->vm(); +      // Does the code block have a user-defined name property? -    JSC::JSValue name = callee->getDirect(m_codeBlock->vm(), m_codeBlock->vm().propertyNames->name); +    JSC::JSValue name = callee->getDirect(vm, vm.propertyNames->name);      if (name && name.isString()) {          auto str = name.toWTFString(m_codeBlock->globalObject());          frame->function_name = Zig::toZigString(str); @@ -2109,9 +2111,9 @@ static void populateStackFrameMetadata(const JSC::StackFrame* stackFrame, ZigSta      /* For functions (either JSFunction or InternalFunction), fallback to their "native" name       * property. Based on JSC::getCalculatedDisplayName, "inlining" the       * JSFunction::calculatedDisplayName\InternalFunction::calculatedDisplayName calls */ -    if (JSC::JSFunction* function = JSC::jsDynamicCast<JSC::JSFunction*>(m_codeBlock->vm(), callee)) { +    if (JSC::JSFunction* function = JSC::jsDynamicCast<JSC::JSFunction*>(callee)) { -        WTF::String actualName = function->name(m_codeBlock->vm()); +        WTF::String actualName = function->name(vm);          if (!actualName.isEmpty() || function->isHostOrBuiltinFunction()) {              frame->function_name = Zig::toZigString(actualName);              return; @@ -2121,7 +2123,7 @@ static void populateStackFrameMetadata(const JSC::StackFrame* stackFrame, ZigSta          frame->function_name = Zig::toZigString(inferred_name.string());      } -    if (JSC::InternalFunction* function = JSC::jsDynamicCast<JSC::InternalFunction*>(m_codeBlock->vm(), callee)) { +    if (JSC::InternalFunction* function = JSC::jsDynamicCast<JSC::InternalFunction*>(callee)) {          // Based on JSC::InternalFunction::calculatedDisplayName, skipping the "displayName" property          frame->function_name = Zig::toZigString(function->name());      } @@ -2285,7 +2287,7 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global,      JSC::ErrorInstance* err, const Vector<JSC::StackFrame>* stackTrace,      JSC::JSValue val)  { -    JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(global->vm(), val); +    JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(val);      bool getFromSourceURL = false;      if (stackTrace != nullptr && stackTrace->size() > 0) { @@ -2356,7 +2358,7 @@ void exceptionFromString(ZigException* except, JSC::JSValue value, JSC::JSGlobal  {      // Fallback case for when it's a user-defined ErrorLike-object that doesn't inherit from      // ErrorInstance -    if (JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(global->vm(), value)) { +    if (JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(value)) {          if (obj->hasProperty(global, global->vm().propertyNames->name)) {              auto name_str = obj->getIfPropertyExists(global, global->vm().propertyNames->name).toWTFString(global);              except->name = Zig::toZigString(name_str); @@ -2426,7 +2428,7 @@ void JSC__JSValue__getClassName(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1          return;      } -    const char* ptr = cell->className(arg1->vm()); +    const char* ptr = cell->className();      auto view = WTF::StringView(ptr);      // Fallback to .name if className is empty @@ -2465,7 +2467,7 @@ void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* a          }      } -    if (JSC::JSFunction* function = JSC::jsDynamicCast<JSC::JSFunction*>(vm, obj)) { +    if (JSC::JSFunction* function = JSC::jsDynamicCast<JSC::JSFunction*>(obj)) {          WTF::String actualName = function->name(vm);          if (!actualName.isEmpty() || function->isHostOrBuiltinFunction()) { @@ -2479,7 +2481,7 @@ void JSC__JSValue__getNameProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* a          return;      } -    if (JSC::InternalFunction* function = JSC::jsDynamicCast<JSC::InternalFunction*>(vm, obj)) { +    if (JSC::InternalFunction* function = JSC::jsDynamicCast<JSC::InternalFunction*>(obj)) {          auto view = WTF::StringView(function->name());          *arg2 = Zig::toZigString(view);          return; @@ -2493,14 +2495,14 @@ void JSC__JSValue__toZigException(JSC__JSValue JSValue0, JSC__JSGlobalObject* ar  {      JSC::JSValue value = JSC::JSValue::decode(JSValue0); -    if (JSC::Exception* jscException = JSC::jsDynamicCast<JSC::Exception*>(arg1->vm(), value)) { -        if (JSC::ErrorInstance* error = JSC::jsDynamicCast<JSC::ErrorInstance*>(arg1->vm(), jscException->value())) { +    if (JSC::Exception* jscException = JSC::jsDynamicCast<JSC::Exception*>(value)) { +        if (JSC::ErrorInstance* error = JSC::jsDynamicCast<JSC::ErrorInstance*>(jscException->value())) {              fromErrorInstance(exception, arg1, error, &jscException->stack(), value);              return;          }      } -    if (JSC::ErrorInstance* error = JSC::jsDynamicCast<JSC::ErrorInstance*>(arg1->vm(), value)) { +    if (JSC::ErrorInstance* error = JSC::jsDynamicCast<JSC::ErrorInstance*>(value)) {          fromErrorInstance(exception, arg1, error, nullptr, value);          return;      } @@ -2561,7 +2563,7 @@ void JSC__VM__setExecutionTimeLimit(JSC__VM* vm, double limit)  bool JSC__JSValue__isTerminationException(JSC__JSValue JSValue0, JSC__VM* arg1)  { -    JSC::Exception* exception = JSC::jsDynamicCast<JSC::Exception*>(*arg1, JSC::JSValue::decode(JSValue0)); +    JSC::Exception* exception = JSC::jsDynamicCast<JSC::Exception*>(JSC::JSValue::decode(JSValue0));      return exception != NULL && arg1->isTerminationException(exception);  } @@ -2591,8 +2593,8 @@ void JSC__VM__deleteAllCode(JSC__VM* arg1, JSC__JSGlobalObject* globalObject)      JSC::JSLockHolder locker(globalObject->vm());      arg1->drainMicrotasks(); -    if (JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(globalObject->vm(), globalObject->moduleLoader())) { -        auto id = JSC::Identifier::fromString(globalObject->vm(), "registry"); +    if (JSC::JSObject* obj = JSC::jsDynamicCast<JSC::JSObject*>(globalObject->moduleLoader())) { +        auto id = JSC::Identifier::fromString(globalObject->vm(), "registry"_s);          JSC::JSMap* map = JSC::JSMap::create(globalObject, globalObject->vm(), globalObject->mapStructure());          obj->putDirect(globalObject->vm(), id, map);      } diff --git a/src/javascript/jsc/bindings/headers-cpp.h b/src/javascript/jsc/bindings/headers-cpp.h index 1384e090a..6b4c06ebe 100644 --- a/src/javascript/jsc/bindings/headers-cpp.h +++ b/src/javascript/jsc/bindings/headers-cpp.h @@ -1,4 +1,4 @@ -//-- AUTOGENERATED FILE -- 1651766047 +//-- AUTOGENERATED FILE -- 1651982852  // clang-format off  #pragma once diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h index 0aab07b9e..07a86385f 100644 --- a/src/javascript/jsc/bindings/headers.h +++ b/src/javascript/jsc/bindings/headers.h @@ -1,5 +1,5 @@  // clang-format: off -//-- AUTOGENERATED FILE -- 1651766047 +//-- AUTOGENERATED FILE -- 1651982852  #pragma once  #include <stddef.h> diff --git a/src/javascript/jsc/bindings/helpers.h b/src/javascript/jsc/bindings/helpers.h index e4ceb5696..7b72b3566 100644 --- a/src/javascript/jsc/bindings/helpers.h +++ b/src/javascript/jsc/bindings/helpers.h @@ -200,14 +200,6 @@ static const unsigned char* taggedUTF16Ptr(const UChar* ptr)      return reinterpret_cast<const unsigned char*>(reinterpret_cast<uintptr_t>(ptr) | (static_cast<uint64_t>(1) << 63));  } -static ZigString toZigString(WTF::String str) -{ -    return str.isEmpty() -        ? ZigStringEmpty -        : ZigString { str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()), -              str.length() }; -} -  static ZigString toZigString(WTF::String* str)  {      return str->isEmpty() diff --git a/src/javascript/jsc/bindings/napi.cpp b/src/javascript/jsc/bindings/napi.cpp index 027609ec7..c8a8bb383 100644 --- a/src/javascript/jsc/bindings/napi.cpp +++ b/src/javascript/jsc/bindings/napi.cpp @@ -40,15 +40,184 @@  #include "JavaScriptCore/ArrayBuffer.h"  #include "JavaScriptCore/JSArrayBuffer.h"  #include "JSFFIFunction.h" +#include "JavaScriptCore/JavaScript.h" +#include "JavaScriptCore/JSWeakValue.h" +#include "napi.h" +#include "JavaScriptCore/GetterSetter.h"  #include <iostream>  using namespace JSC; +using namespace Zig; + +class NapiRefWeakHandleOwner final : public JSC::WeakHandleOwner { +public: +    void finalize(JSC::Handle<JSC::Unknown>, void* context) final +    { +        auto* weakValue = reinterpret_cast<NapiRef*>(context); +        weakValue->clear(); +    } +}; + +static NapiRefWeakHandleOwner& weakValueHandleOwner() +{ +    static NeverDestroyed<NapiRefWeakHandleOwner> jscWeakValueHandleOwner; +    return jscWeakValueHandleOwner; +} + +void NapiFinalizer::call(JSC::JSGlobalObject* globalObject, void* data) +{ +    if (finalize_cb) { +        finalize_cb(reinterpret_cast<napi_env>(globalObject), finalize_hint, data); +    } +} + +void NapiRef::ref() +{ +    ++refCount; +    if (refCount == 1 && weakValueRef.isSet()) { +        auto& vm = globalObject.get()->vm(); +        if (weakValueRef.isString()) { +            strongRef.set(vm, JSC::JSValue(weakValueRef.string())); +        } else if (weakValueRef.isObject()) { +            strongRef.set(vm, JSC::JSValue(weakValueRef.object())); +        } else { +            strongRef.set(vm, weakValueRef.primitive()); +        } + +        weakValueRef.clear(); +    } +} + +void NapiRef::unref() +{ +    bool clear = refCount == 1; +    refCount = refCount > 0 ? refCount - 1 : 0; +    if (clear) { +        JSC::JSValue val = strongRef.get(); +        if (val.isString()) { +            weakValueRef.setString(val.toString(globalObject.get()), weakValueHandleOwner(), this); +        } else if (val.isObject()) { +            weakValueRef.setObject(val.getObject(), weakValueHandleOwner(), this); +        } else { +            weakValueRef.setPrimitive(val); +        } +        strongRef.clear(); +    } +} + +void NapiRef::clear() +{ +    this->finalizer.call(this->globalObject.get(), nullptr); +    this->globalObject.clear(); +    this->weakValueRef.clear(); +    this->strongRef.clear(); +}  // namespace Napi {  // class Reference  // } +#define StackAllocatedCallFramePointerTag 62 +typedef struct StackAllocatedCallFrame { +    void* dataPtr; +    JSC::EncodedJSValue thisValue; +    // this is "bar" in: +    //  set foo(bar) +    JSC::EncodedJSValue argument1; +} StackAllocatedCallFrame; + +extern "C" Zig::GlobalObject* +Bun__getDefaultGlobal(); + +static uint32_t getPropertyAttributes(napi_property_attributes attributes) +{ +    uint32_t result = 0; +    if (!(attributes & napi_key_configurable)) { +        result |= JSC::PropertyAttribute::DontDelete; +    } + +    if (!(attributes & napi_key_enumerable)) { +        result |= JSC::PropertyAttribute::DontEnum; +    } + +    if (!(attributes & napi_key_writable)) { +        result |= JSC::PropertyAttribute::ReadOnly; +    } + +    return result; +} + +static uint32_t getPropertyAttributes(napi_property_descriptor prop) +{ +    uint32_t result = getPropertyAttributes(prop.attributes); + +    if (!(prop.getter && !prop.setter)) { +        result |= JSC::PropertyAttribute::ReadOnly; +    } + +    if (prop.method) { +        result |= JSC::PropertyAttribute::Function; +    } + +    return result; +} + +const ClassInfo NapiClass::s_info = { "Function"_s, &NapiClass::Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(NapiClass) }; + +static void defineNapiProperty(Zig::GlobalObject* globalObject, JSC::JSObject* to, napi_property_descriptor property) +{ +    JSC::VM& vm = globalObject->vm(); +    void* dataPtr = property.data; +    auto is_static = !!(property.attributes & napi_static); +    WTF::String nameStr; +    if (property.utf8name != nullptr) { +        nameStr = WTF::String::fromUTF8(property.utf8name); +    } else if (property.name) { +        nameStr = toJS(property.name).toWTFString(globalObject); +    } + +    auto propertyName = JSC::PropertyName(JSC::Identifier::fromString(vm, nameStr)); + +    if (property.method) { +        auto function = Zig::JSFFIFunction::create(vm, globalObject, 1, nameStr, reinterpret_cast<Zig::FFIFunction>(property.method)); +        function->dataPtr = dataPtr; +        JSC::JSValue value = JSC::JSValue(function); + +        to->putDirect(vm, Identifier::fromString(vm, nameStr), value, getPropertyAttributes(property)); +        return; +    } + +    if (property.getter != nullptr || property.setter != nullptr) { +        JSC::JSValue getter = {}; +        JSC::JSValue setter = {}; + +        if (property.getter) { +            auto callGetter = property.getter; +            auto function = Zig::JSFFIFunction::create(vm, globalObject, 0, nameStr, reinterpret_cast<Zig::FFIFunction>(property.getter)); +            function->dataPtr = dataPtr; +            getter = JSC::JSValue(function); +        } + +        if (property.setter) { +            auto callGetter = property.setter; +            auto function = Zig::JSFFIFunction::create(vm, globalObject, 1, nameStr, reinterpret_cast<Zig::FFIFunction>(property.setter)); +            function->dataPtr = dataPtr; +            getter = JSC::JSValue(function); +        } -extern "C" Zig::GlobalObject* Bun__getDefaultGlobal(); +        auto getterSetter = JSC::GetterSetter::create(vm, globalObject, getter, setter); +        to->putDirect(vm, propertyName, getterSetter, getPropertyAttributes(property) | JSC::PropertyAttribute::Accessor); + +    } else { +        // TODO: is dataPtr allowed when given a value? +        JSC::JSValue value = JSC::jsUndefined(); + +        if (property.value) { +            value = toJS(property.value); +        } + +        to->putDirect(vm, propertyName, value, getPropertyAttributes(property)); +    } +}  extern "C" void napi_module_register(napi_module* mod)  { @@ -91,6 +260,55 @@ extern "C" void napi_module_register(napi_module* mod)      promise->result(vm);  } +extern "C" napi_status napi_wrap(napi_env env, +    napi_value js_object, +    void* native_object, +    napi_finalize finalize_cb, +    void* finalize_hint, +    napi_ref* result) +{ +    auto* globalObject = toJS(env); +    auto* object = toJS(js_object).getObject(); +    auto clientData = WebCore::clientData(vm); + +    if (native_object) { +        uintptr_t ref_ptr = reinterpret_cast<uintptr_t>(native_object); +        double ref_double = bitwise_cast<double>(ref_ptr); +        val->putDirect(vm, clientData->builtinNames().passwordPrivateName(), JSC::jsNumber(ref_double), JSC::PropertyAttribute::DontEnum | 0); +    } + +    if (result) { +        auto* ref = new NapiRef(globalObject, object); +        auto clientData = WebCore::clientData(vm); +        if (finalize_cb) { +            ref->finalizer = { finalize_cb, finalize_hint }; +        } +        *result = reinterpret_cast<napi_ref>(ref); +    } +} + +extern "C" napi_status napi_unwrap(napi_env env, napi_value js_object, +    void** result) +{ +    auto* globalObject = toJS(env); +    auto* object = toJS(js_object).getObject(); +    auto clientData = WebCore::clientData(vm); + +    if (native_object) { +        uintptr_t ref_ptr = reinterpret_cast<uintptr_t>(native_object); +        double ref_double = bitwise_cast<double>(ref_ptr); +        val->putDirect(vm, clientData->builtinNames().passwordPrivateName(), JSC::jsNumber(ref_double), JSC::PropertyAttribute::DontEnum | 0); +    } + +    if (result) { +        auto* ref = new NapiRef(globalObject, object); +        if (finalize_cb) { +            ref->finalizer = { finalize_cb, finalize_hint }; +        } +        *result = reinterpret_cast<napi_ref>(ref); +    } +} +  extern "C" napi_status napi_create_function(napi_env env, const char* utf8name,      size_t length, napi_callback cb,      void* data, napi_value* result) @@ -117,16 +335,19 @@ extern "C" napi_status napi_get_cb_info(  {      Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env);      JSC::VM& vm = globalObject->vm(); -    JSC::CallFrame* callFrame = reinterpret_cast<JSC::CallFrame*>(cbinfo); -      auto inputArgsCount = argc == nullptr ? 0 : *argc; +    JSC::CallFrame* callFrame = reinterpret_cast<JSC::CallFrame*>(cbinfo); +    // napi expects arguments to be copied into the argv array.      if (inputArgsCount > 0) {          auto outputArgsCount = callFrame->argumentCount();          auto argsToCopy = inputArgsCount < outputArgsCount ? inputArgsCount : outputArgsCount;          *argc = argsToCopy;          memcpy(argv, callFrame->addressOfArgumentsStart(), argsToCopy * sizeof(JSC::JSValue)); + +        // If the user didn't provide expected number of args, we need to fill the rest with undefined. +        // TODO: can we use memset() here?          auto argv_ptr = argv[outputArgsCount];          for (size_t i = outputArgsCount; i < inputArgsCount; i++) {              argv[i] = reinterpret_cast<napi_value>(JSC::JSValue::encode(JSC::jsUndefined())); @@ -139,8 +360,32 @@ extern "C" napi_status napi_get_cb_info(      }      if (data != nullptr) { -        Zig::JSFFIFunction* ffiFunction = JSC::jsDynamicCast<Zig::JSFFIFunction*>(vm, JSC::JSValue(callFrame->jsCallee())); -        *data = reinterpret_cast<void*>(ffiFunction->dataPtr); +        JSC::JSValue callee = JSC::JSValue(callFrame->jsCallee()); +        if (Zig::JSFFIFunction* ffiFunction = JSC::jsDynamicCast<Zig::JSFFIFunction*>(callee)) { +            *data = reinterpret_cast<void*>(ffiFunction->dataPtr); +        } else { +            *data = nullptr; +        } +    } + +    return napi_ok; +} + +extern "C" napi_status +napi_define_properties(napi_env env, napi_value object, size_t property_count, +    const napi_property_descriptor* properties) +{ +    Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env); +    JSC::VM& vm = globalObject->vm(); + +    JSC::JSValue objectValue = JSC::JSValue(reinterpret_cast<JSC::EncodedJSValue>(object)); +    JSC::JSObject* objectObject = objectValue.getObject(); +    if (!objectObject) { +        return napi_object_expected; +    } + +    for (size_t i = 0; i < property_count; i++) { +        defineNapiProperty(globalObject, objectObject, properties[i]);      }      return napi_ok; @@ -167,8 +412,73 @@ extern "C" napi_status napi_create_reference(napi_env env, napi_value value,  {      Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env); -    JSC::Strong<JSC::Unknown> data = { globalObject->vm(), JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(value)) }; -    *reinterpret_cast<JSC::Strong<JSC::Unknown>*>(result) = data; +    auto* ref = new NapiRef(toJS(env), initial_refcount); +    JSC::JSValue val = toJS(value); +    auto clientData = WebCore::clientData(vm); + +    if (initial_refcount > 0) { +        ref->strongRef.set(globalObject->vm(), val); +    } else { +        if (val.isString()) { +            ref->weakValueRef.setString(val.toString(globalObject), weakValueHandleOwner(), ref); +        } else if (val.isObject()) { +            ref->weakValueRef.setObject(val.getObject(), weakValueHandleOwner(), ref); +        } else { +            ref->weakValueRef.setPrimitive(val); +        } +    } + +    uintptr_t ref_ptr = reinterpret_cast<uintptr_t>(ref); +    double ref_double = bitwise_cast<double>(ref_ptr); +    val->putDirect(vm, clientData->builtinNames().passwordPrivateName(), JSC::jsNumber(ref_double), JSC::PropertyAttribute::DontEnum | 0); + +    *result = toNapi(ref); + +    return napi_ok; +} + +extern "C" napi_status napi_reference_unref(napi_env env, napi_ref ref, +    uint32_t* result) +{ +    NapiRef* napiRef = toJS(ref); +    napiRef->unref(); +    *result = napiRef->refCount; +    return napi_ok; +} + +// Attempts to get a referenced value. If the reference is weak, +// the value might no longer be available, in that case the call +// is still successful but the result is NULL. +extern "C" napi_status napi_get_reference_value(napi_env env, napi_ref ref, +    napi_value* result) +{ +    NapiRef* napiRef = toJS(ref); +    *result = toNapi(napiRef->value()); +    return napi_ok; +} + +extern "C" napi_status napi_reference_ref(napi_env env, napi_ref ref, +    uint32_t* result) +{ +    NapiRef* napiRef = toJS(ref); +    napiRef->ref(); +    *result = napiRef->refCount; +    return napi_ok; +} + +extern "C" napi_status napi_reference_delete(napi_env env, napi_ref ref, +    uint32_t* result) +{ +    NapiRef* napiRef = toJS(ref); +    napiRef->ref(); +    *result = napiRef->refCount(); +    return napi_ok; +} + +extern "C" napi_status napi_delete_reference(napi_env env, napi_ref ref) +{ +    NapiRef* napiRef = toJS(ref); +    ~napiRef();      return napi_ok;  } @@ -185,7 +495,7 @@ extern "C" napi_status napi_is_detached_arraybuffer(napi_env env,          return napi_arraybuffer_expected;      } -    JSC::JSArrayBuffer* jsArrayBuffer = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(vm, value); +    JSC::JSArrayBuffer* jsArrayBuffer = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(value);      if (!jsArrayBuffer) {          return napi_arraybuffer_expected;      } @@ -208,7 +518,7 @@ extern "C" napi_status napi_detach_arraybuffer(napi_env env,          return napi_arraybuffer_expected;      } -    JSC::JSArrayBuffer* jsArrayBuffer = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(vm, value); +    JSC::JSArrayBuffer* jsArrayBuffer = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(value);      if (!jsArrayBuffer) {          return napi_arraybuffer_expected;      } @@ -248,6 +558,25 @@ extern "C" napi_status napi_throw_type_error(napi_env env, const char* code,      JSC::throwException(globalObject, throwScope, error);      return napi_ok;  } + +extern "C" napi_status napi_create_type_error(napi_env env, napi_value code, +    napi_value msg, +    napi_value* result) +{ +    Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env); +    JSC::VM& vm = globalObject->vm(); + +    JSC::JSValue codeValue = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(code)); +    JSC::JSValue messageValue = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(msg)); + +    auto error = JSC::createTypeError(globalObject, messageValue.toWTFString(globalObject)); +    if (codeValue) { +        error->putDirect(vm, Identifier::fromString(vm, "code"_s), codeValue, 0); +    } + +    *result = reinterpret_cast<napi_value>(JSC::JSValue::encode(error)); +    return napi_ok; +}  extern "C" napi_status napi_throw_range_error(napi_env env, const char* code,      const char* msg)  { @@ -290,7 +619,8 @@ extern "C" napi_status napi_object_seal(napi_env env, napi_value object_value)      JSC::EncodedJSValue encodedValue = reinterpret_cast<JSC::EncodedJSValue>(object_value);      JSC::JSValue value = JSC::JSValue::decode(encodedValue); -    if (!value.isObject()) { + +    if (UNLIKELY(!value.isObject())) {          return napi_object_expected;      } @@ -334,6 +664,20 @@ extern "C" napi_status napi_get_new_target(napi_env env,  {      Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env);      JSC::VM& vm = globalObject->vm(); +    // handle: +    // - if they call this function when it was originally a getter/setter call +    // - if they call this function without a result +    if (UNLIKELY(result == nullptr || cbinfo == nullptr)) { +        return napi_invalid_arg; +    } + +    if (reinterpret_cast<size_t>(cbinfo) & (static_cast<size_t>(1) << StackAllocatedCallFramePointerTag)) { +        // This is a stack allocated call frame, so we can't get the new target. +        // We'll just return undefined. +        // TODO: verify this is what napi does too +        *result = reinterpret_cast<napi_value>(JSC::JSValue::encode(JSC::jsUndefined())); +        return napi_ok; +    }      CallFrame* callFrame = reinterpret_cast<JSC::CallFrame*>(cbinfo);      JSC::JSValue newTarget = callFrame->newTarget(); @@ -351,11 +695,174 @@ extern "C" napi_status napi_create_dataview(napi_env env, size_t length,      auto throwScope = DECLARE_THROW_SCOPE(vm);      JSC::EncodedJSValue encodedArraybuffer = reinterpret_cast<JSC::EncodedJSValue>(arraybuffer); -    auto arraybufferValue = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(vm, JSC::JSValue::decode(encodedArraybuffer)); +    auto arraybufferValue = JSC::jsDynamicCast<JSC::JSArrayBuffer*>(JSC::JSValue::decode(encodedArraybuffer));      if (!arraybufferValue) { -        return napi_invalid_arg; +        return napi_arraybuffer_expected;      }      auto dataView = JSC::DataView::create(arraybufferValue->impl(), byte_offset, length); -    *result = reinterpret_cast<napi_value>(dataView->wrap(globalObject, globalObject)); + +    if (result != nullptr) { +        *result = reinterpret_cast<napi_value>(dataView->wrap(globalObject, globalObject)); +    } + +    return napi_ok; +} + +namespace Zig { + +template<typename Visitor> +void NapiClass::visitChildrenImpl(JSCell* cell, Visitor& visitor) +{ +    NapiClass* thisObject = jsCast<NapiClass*>(cell); +    ASSERT_GC_OBJECT_INHERITS(thisObject, info()); +    Base::visitChildren(thisObject, visitor); +} + +DEFINE_VISIT_CHILDREN(NapiClass); + +NapiClass* NapiClass::create(VM& vm, Zig::GlobalObject* globalObject, const char* utf8name, +    size_t length, +    napi_callback constructor, +    void* data, +    size_t property_count, +    const napi_property_descriptor* properties) +{ +    WTF::String name = WTF::String::fromUTF8(utf8name, length); +    NativeExecutable* executable = vm.getHostFunction(reinterpret_cast<FFIFunction>(constructor), JSC::NoIntrinsic, callHostFunctionAsConstructor, nullptr, name); + +    Structure* structure = globalObject->NapiClassStructure(); +    NapiClass* napiClass = new (NotNull, allocateCell<NapiClass>(vm)) NapiClass(vm, executable, globalObject, structure); +    napiClass->finishCreation(vm, executable, length, name, constructor, data, property_count, properties); +    return napiClass; +} + +CallData NapiClass::getConstructData(JSCell* cell) +{ +    auto construct = JSC::jsCast<NapiClass*>(cell)->constructor(); +    if (!construct) { +        return NapiClass::Base::getConstructData(cell); +    } + +    CallData constructData; +    constructData.type = CallData::Type::Native; +    constructData.native.function = construct; +    return constructData; +} + +void NapiClass::finishCreation(VM& vm, NativeExecutable* executable, unsigned length, const String& name, napi_callback constructor, +    void* data, +    size_t property_count, +    const napi_property_descriptor* properties) +{ +    Base::finishCreation(vm, executable, length, name); +    ASSERT(inherits(info())); +    this->m_constructor = reinterpret_cast<FFIFunction>(constructor); +    auto globalObject = reinterpret_cast<Zig::GlobalObject*>(this->globalObject()); + +    // toStringTag + "prototype" +    // size_t staticPropertyCount = 2; +    // prototype always has "constructor", +    size_t prototypePropertyCount = 2; + +    this->putDirect(vm, vm.propertyNames->name, jsString(vm, name), JSC::PropertyAttribute::DontEnum | 0); + +    auto clientData = WebCore::clientData(vm); + +    for (size_t i = 0; i < property_count; i++) { +        const napi_property_descriptor& property = properties[i]; +        // staticPropertyCount += property.attributes & napi_static ? 1 : 0; +        prototypePropertyCount += property.attributes & napi_static ? 0 : 1; +    } + +    JSC::JSObject* prototype = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), prototypePropertyCount); + +    for (size_t i = 0; i < property_count; i++) { +        const napi_property_descriptor& property = properties[i]; + +        if (property.attributes & napi_static) { +            defineNapiProperty(globalObject, this, property); +        } else { +            defineNapiProperty(globalObject, prototype, property); +        } +    } + +    this->putDirect(vm, vm.propertyNames->prototype, prototype, JSC::PropertyAttribute::DontEnum | 0); +    prototype->putDirect(vm, vm.propertyNames->constructor, this, JSC::PropertyAttribute::DontEnum | 0); +    prototype->putDirect(vm, clientData->builtinNames().passwordPrivateName(), JSC::jsNumber(0), JSC::PropertyAttribute::DontEnum | 0); +} +} + +extern "C" napi_status napi_get_all_property_names( +    napi_env env, napi_value objectNapi, napi_key_collection_mode key_mode, +    napi_key_filter key_filter, napi_key_conversion key_conversion, +    napi_value* result) +{ +    DontEnumPropertiesMode jsc_key_mode = key_mode == napi_key_include_prototypes ? DontEnumPropertiesMode::Include : DontEnumPropertiesMode::Exclude; +    PropertyNameMode jsc_property_mode = PropertyNameMode::StringsAndSymbols; +    if (key_filter == napi_key_skip_symbols) { +        jsc_property_mode = PropertyNameMode::Strings; +    } else if (key_filter == napi_key_skip_strings) { +        jsc_property_mode = PropertyNameMode::Symbols; +    } + +    auto globalObject = reinterpret_cast<Zig::GlobalObject*>(env); +    JSC::VM& vm = globalObject->vm(); + +    auto objectValue = JSC::JSValue::decode(reinterpret_cast<EncodedJSValue>(objectNapi)); +    auto* object = objectValue.getObject(); +    if (!object) { +        return napi_object_expected; +    } + +    JSC::JSArray* exportKeys = ownPropertyKeys(globalObject, object, jsc_property_mode, jsc_key_mode, std::nullopt); +    // TODO: filter +    *result = toNapi(JSC::JSValue::encode(exportKeys)); +    return napi_ok; +} + +extern "C" napi_status napi_define_class(napi_env env, +    const char* utf8name, +    size_t length, +    napi_callback constructor, +    void* data, +    size_t property_count, +    const napi_property_descriptor* properties, +    napi_value* result) +{ +    Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env); +    JSC::VM& vm = globalObject->vm(); + +    NapiClass* napiClass = NapiClass::create(vm, globalObject, utf8name, length, constructor, data, property_count, properties); +    JSC::JSValue value = JSC::JSValue(napiClass); +    if (data != nullptr) { +        napiClass->dataPtr = data; +    } + +    *result = reinterpret_cast<napi_value>(JSC::JSValue::encode(value)); +    return napi_ok; +} + +extern "C" napi_status napi_coerce_to_string(napi_env env, napi_value value, +    napi_value* result) +{ +    if (UNLIKELY(result == nullptr)) { +        return napi_invalid_arg; +    } + +    Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(env); +    JSC::VM& vm = globalObject->vm(); + +    auto scope = DECLARE_CATCH_SCOPE(vm); +    JSC::JSValue jsValue = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(value)); + +    // .toString() can throw +    JSC::JSValue resultValue = JSC::JSValue(jsValue.toString(globalObject)); +    *result = reinterpret_cast<napi_value>(JSC::JSValue::encode(resultValue)); + +    if (UNLIKELY(scope.exception())) { +        *result = reinterpret_cast<napi_value>(JSC::JSValue::encode(JSC::jsUndefined())); +        return napi_generic_failure; +    } +    scope.clearException();      return napi_ok;  }
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/napi.h b/src/javascript/jsc/bindings/napi.h new file mode 100644 index 000000000..e547b22fa --- /dev/null +++ b/src/javascript/jsc/bindings/napi.h @@ -0,0 +1,183 @@ +#pragma once + +namespace Zig { +class GlobalObject; +} + +#include "root.h" +#include "JavaScriptCore/JSFunction.h" +#include "JavaScriptCore/VM.h" + +#include "headers-handwritten.h" +#include "BunClientData.h" +#include "WebCoreJSBuiltinInternals.h" +#include "JavaScriptCore/CallFrame.h" +#include "js_native_api_types.h" +#include "JavaScriptCore/JSWeakValue.h" +#include "JSFFIFunction.h" + +namespace JSC { +class JSGlobalObject; +} + +namespace Zig { + +using namespace JSC; + +static inline JSValue toJS(napi_value val) +{ +    return JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(val)); +} + +static inline Zig::GlobalObject* toJS(napi_env val) +{ +    return reinterpret_cast<Zig::GlobalObject*>(val); +} + +static inline napi_value toNapi(JSC::EncodedJSValue val) +{ +    return reinterpret_cast<napi_value>(val); +} + +static inline napi_value toNapi(JSC::JSValue val) +{ +    return toNapi(JSC::JSValue::encode(val)); +} + +static inline napi_env toNapi(JSC::JSGlobalObject* val) +{ +    return reinterpret_cast<napi_env>(val); +} + +class NapiFinalizer { +public: +    void* finalize_hint = nullptr; +    napi_finalize finalize_cb; + +    void call(JSC::JSGlobalObject* globalObject, void* data); +}; + +class NapiRef : public RefCounted<NapiRef>, public CanMakeWeakPtr<NapiRef> { +    WTF_MAKE_FAST_ALLOCATED; + +public: +    void ref(); +    void unref(); +    void clear(); + +    NapiRef(JSC::JSGlobalObject* global, uint32_t count) +    { +        globalObject = JSC::Weak<JSC::JSGlobalObject>(global); +        strongRef = {}; +        weakValueRef.clear(); +        refCount = count; +    } + +    JSC::JSValue value() const +    { +        if (refCount == 0) { +            if (!weakValueRef.isSet()) { +                return JSC::JSValue {}; +            } + +            if (weakValue.isString()) { +                return JSC::JSValue(weakValue.string()); +            } + +            if (weakValue.isObject()) { +                return JSC::JSValue(weakValue.object()); +            } + +            return weakValue.primitive(); +        } + +        return strongRef.get(); +    } + +    ~NapiRef() +    { +        if (this->refCount > 0) { +            this->refCount = 1; +            this->unref(); +        } +    } + +    JSC::Weak<JSC::JSGlobalObject> globalObject; +    JSC::JSWeakValue weakValueRef; +    JSC::Strong<JSC::Unknown> strongRef; +    NapiFinalizer finalizer; +    uint32_t refCount = 0; +}; + +static inline napi_ref toNapi(NapiRef* val) +{ +    return reinterpret_cast<napi_ref>(val); +} + +class NapiClass final : public JSC::JSFunction { +public: +    using Base = JSFunction; + +    static constexpr unsigned StructureFlags = Base::StructureFlags; +    static constexpr bool needsDestruction = false; +    static void destroy(JSCell* cell) +    { +        static_cast<NapiClass*>(cell)->NapiClass::~NapiClass(); +    } + +    template<typename, SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) +    { +        if constexpr (mode == JSC::SubspaceAccess::Concurrently) +            return nullptr; +        return WebCore::subspaceForImpl<NapiClass, WebCore::UseCustomHeapCellType::No>( +            vm, +            [](auto& spaces) { return spaces.m_clientSubspaceForNapiClass.get(); }, +            [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForNapiClass = WTFMove(space); }, +            [](auto& spaces) { return spaces.m_subspaceForNapiClass.get(); }, +            [](auto& spaces, auto&& space) { spaces.m_subspaceForNapiClass = WTFMove(space); }); +    } + +    DECLARE_EXPORT_INFO; + +    JS_EXPORT_PRIVATE static NapiClass* create(VM&, Zig::GlobalObject*, const char* utf8name, +        size_t length, +        napi_callback constructor, +        void* data, +        size_t property_count, +        const napi_property_descriptor* properties); + +    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) +    { +        ASSERT(globalObject); +        return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info()); +    } + +    static CallData getConstructData(JSCell* cell); + +    FFIFunction constructor() +    { +        return m_constructor; +    } + +    void* dataPtr = nullptr; +    FFIFunction m_constructor = nullptr; + +private: +    NapiClass(VM& vm, NativeExecutable* executable, JSC::JSGlobalObject* global, Structure* structure) +        : Base(vm, executable, global, structure) +    { +    } +    void finishCreation(VM&, NativeExecutable*, unsigned length, const String& name, napi_callback constructor, +        void* data, +        size_t property_count, +        const napi_property_descriptor* properties); + +    DECLARE_VISIT_CHILDREN; +}; + +static inline NapiRef* toJS(napi_ref val) +{ +    return reinterpret_cast<NapiRef*>(val); +} + +}
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/napi_external.cpp b/src/javascript/jsc/bindings/napi_external.cpp new file mode 100644 index 000000000..15e46aa97 --- /dev/null +++ b/src/javascript/jsc/bindings/napi_external.cpp @@ -0,0 +1,50 @@ + + +// #pragma once + +// #include "root.h" + +// #include "BunBuiltinNames.h" +// #include "BunClientData.h" + +// namespace Zig { + +// using namespace JSC; + +// class NapiExternal : public JSC::JSNonFinalObject { +//     using Base = JSC::JSNonFinalObject; + +// public: +//     NapiExternal(JSC::VM& vm, JSC::Structure* structure) +//         : Base(vm, structure) +//     { +//     } + +//     DECLARE_INFO; + +//     static constexpr unsigned StructureFlags = Base::StructureFlags; + +//     template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm) +//     { +//         return &vm.plainObjectSpace(); +//     } + +//     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, +//         JSC::JSValue prototype) +//     { +//         return JSC::Structure::create(vm, globalObject, prototype, +//             JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); +//     } + +//     static NapiExternal* create(JSC::VM& vm, JSC::Structure* structure) +//     { +//         NapiExternal* accessor = new (NotNull, JSC::allocateCell<NapiExternal>(vm)) NapiExternal(vm, structure); +//         accessor->finishCreation(vm); +//         return accessor; +//     } + +//     void finishCreation(JSC::VM& vm); +//     void* m_value; +// }; + +// } // namespace Zig
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/napi_external.h b/src/javascript/jsc/bindings/napi_external.h new file mode 100644 index 000000000..edac914f8 --- /dev/null +++ b/src/javascript/jsc/bindings/napi_external.h @@ -0,0 +1,64 @@ + + +#pragma once + +#include "root.h" + +#include "BunBuiltinNames.h" +#include "BunClientData.h" + +namespace Zig { + +using namespace JSC; + +class NapiExternal : public JSC::JSNonFinalObject { +    using Base = JSC::JSNonFinalObject; + +public: +    NapiExternal(JSC::VM& vm, JSC::Structure* structure) +        : Base(vm, structure) +    { +    } + +    DECLARE_INFO; + +    ~NapiExternal() +    { +        if (m_value) { +            delete m_value; +        } + +        static constexpr unsigned StructureFlags = Base::StructureFlags; + +        template<typename, SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM & vm) +        { +            if constexpr (mode == JSC::SubspaceAccess::Concurrently) +                return nullptr; +            return WebCore::subspaceForImpl<JSNapiExternal, WebCore::UseCustomHeapCellType::No>( +                vm, +                [](auto& spaces) { return spaces.m_clientSubspaceForNapiExternal.get(); }, +                [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForNapiExternal = WTFMove(space); }, +                [](auto& spaces) { return spaces.m_subspaceForNapiExternal.get(); }, +                [](auto& spaces, auto&& space) { spaces.m_subspaceForNapiExternal = WTFMove(space); }); +        } + +        static JSC::Structure* createStructure(JSC::VM & vm, JSC::JSGlobalObject * globalObject, +            JSC::JSValue prototype) +        { +            return JSC::Structure::create(vm, globalObject, prototype, +                JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); +        } + +        static NapiExternal* create(JSC::VM & vm, JSC::Structure * structure) +        { +            NapiExternal* accessor = new (NotNull, JSC::allocateCell<NapiExternal>(vm)) NapiExternal(vm, structure); +            accessor->finishCreation(vm); +            return accessor; +        } + +        void finishCreation(JSC::VM & vm); +        void* m_value; +        void* finalizer_context; +    }; + +} // namespace Zig
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/CommonAtomStrings.cpp b/src/javascript/jsc/bindings/webcore/CommonAtomStrings.cpp new file mode 100644 index 000000000..57cdc3d24 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/CommonAtomStrings.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *    notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *    notice, this list of conditions and the following disclaimer in the + *    documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "CommonAtomStrings.h" + +namespace WebCore { + +#define DEFINE_COMMON_ATOM(atomName, atomValue) \ +    MainThreadLazyNeverDestroyed<const AtomString> atomName ## AtomData; +#define INITIALIZE_COMMON_ATOM(atomName, atomValue) \ +    atomName ## AtomData.constructWithoutAccessCheck(atomValue ## _s); + +WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(DEFINE_COMMON_ATOM) + +void initializeCommonAtomStrings() +{ +    // Initialization is not thread safe, so this function must be called from the main thread first. +    ASSERT(isUIThread()); + +    static std::once_flag initializeKey; +    std::call_once(initializeKey, [] { +        WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(INITIALIZE_COMMON_ATOM) +    }); +} + +#undef DEFINE_COMMON_ATOM +#undef INITIALIZE_COMMON_ATOM + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/CommonAtomStrings.h b/src/javascript/jsc/bindings/webcore/CommonAtomStrings.h new file mode 100644 index 000000000..0385f8222 --- /dev/null +++ b/src/javascript/jsc/bindings/webcore/CommonAtomStrings.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *    notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *    notice, this list of conditions and the following disclaimer in the + *    documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include <wtf/NeverDestroyed.h> +#include <wtf/text/AtomString.h> + +namespace WebCore { + +#define WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(macro) \ +    macro(alternative, "alternative") \ +    macro(auto, "auto") \ +    macro(captions, "captions") \ +    macro(commentary, "commentary") \ +    macro(cssContentType, "text/css") \ +    macro(eager, "eager") \ +    macro(email, "email") \ +    macro(false, "false") \ +    macro(lazy, "lazy") \ +    macro(main, "main") \ +    macro(none, "none") \ +    macro(off, "off") \ +    macro(on, "on") \ +    macro(plaintextOnly, "plaintext-only") \ +    macro(reset, "reset") \ +    macro(search, "search") \ +    macro(star, "*") \ +    macro(submit, "submit") \ +    macro(subtitles, "subtitles") \ +    macro(tel, "tel") \ +    macro(text, "text") \ +    macro(textPlainContentType, "text/plain") \ +    macro(true, "true") \ +    macro(url, "url") \ +    macro(xml, "xml") \ +    macro(xmlns, "xmlns") + + +#define DECLARE_COMMON_ATOM(atomName, atomValue) \ +    extern MainThreadLazyNeverDestroyed<const AtomString> atomName ## AtomData; \ +    inline const AtomString& atomName ## Atom() { return atomName ## AtomData.get(); } + +WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(DECLARE_COMMON_ATOM) + +#undef DECLARE_COMMON_ATOM + +WEBCORE_EXPORT void initializeCommonAtomStrings(); + +} // namespace WebCore diff --git a/src/javascript/jsc/bindings/webcore/CustomEvent.h b/src/javascript/jsc/bindings/webcore/CustomEvent.h index 355e2b1cd..53df6d985 100644 --- a/src/javascript/jsc/bindings/webcore/CustomEvent.h +++ b/src/javascript/jsc/bindings/webcore/CustomEvent.h @@ -27,7 +27,6 @@  #pragma once  #include "root.h" -  #include "Event.h"  #include "JSValueInWrappedObject.h"  // #include "SerializedScriptValue.h" @@ -63,4 +62,4 @@ private:      JSValueInWrappedObject m_cachedDetail;  }; -} // namespace WebCore +} // namespace WebCore
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h index 3272f8c8a..3dbb03d00 100644 --- a/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h +++ b/src/javascript/jsc/bindings/webcore/DOMClientIsoSubspaces.h @@ -18,6 +18,7 @@ public:      /* --- bun --- */      std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForBuffer;      std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForFFIFunction; +    std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForNapiClass;      /* --- bun --- */      std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForGlobalObject; diff --git a/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h b/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h index 67c3ead85..d7391f49b 100644 --- a/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h +++ b/src/javascript/jsc/bindings/webcore/DOMIsoSubspaces.h @@ -18,6 +18,7 @@ public:      /*-- BUN --*/      std::unique_ptr<IsoSubspace> m_subspaceForBuffer;      std::unique_ptr<IsoSubspace> m_subspaceForFFIFunction; +    std::unique_ptr<IsoSubspace> m_subspaceForNapiClass;      /*-- BUN --*/      // std::unique_ptr<IsoSubspace> m_subspaceForTouch; diff --git a/src/javascript/jsc/bindings/webcore/EventNames.cpp b/src/javascript/jsc/bindings/webcore/EventNames.cpp index a15b086e2..42c4eb1cf 100644 --- a/src/javascript/jsc/bindings/webcore/EventNames.cpp +++ b/src/javascript/jsc/bindings/webcore/EventNames.cpp @@ -24,7 +24,7 @@  namespace WebCore {  #define INITIALIZE_EVENT_NAME(name) \ -    name##Event(#name, AtomString::ConstructFromLiteral), +    name##Event(makeAtomString(#name)),  EventNames::EventNames()      : DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_EVENT_NAME) dummy(0) diff --git a/src/javascript/jsc/bindings/webcore/HTTPParsers.cpp b/src/javascript/jsc/bindings/webcore/HTTPParsers.cpp index d435cebf4..d49e7d820 100644 --- a/src/javascript/jsc/bindings/webcore/HTTPParsers.cpp +++ b/src/javascript/jsc/bindings/webcore/HTTPParsers.cpp @@ -10,13 +10,13 @@   * are met:   *   * 1.  Redistributions of source code must retain the above copyright - *     notice, this list of conditions and the following disclaimer.  + *     notice, this list of conditions and the following disclaimer.   * 2.  Redistributions in binary form must reproduce the above copyright   *     notice, this list of conditions and the following disclaimer in the - *     documentation and/or other materials provided with the distribution.  + *     documentation and/or other materials provided with the distribution.   * 3.  Neither the name of Apple Inc. ("Apple") nor the names of   *     its contributors may be used to endorse or promote products derived - *     from this software without specific prior written permission.  + *     from this software without specific prior written permission.   *   * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -33,9 +33,11 @@  #include "config.h"  #include "HTTPParsers.h" +#include "CommonAtomStrings.h"  #include "HTTPHeaderField.h"  #include "HTTPHeaderNames.h"  #include "ParsedContentType.h" +#include <wtf/CheckedArithmetic.h>  #include <wtf/DateMath.h>  #include <wtf/NeverDestroyed.h>  #include <wtf/text/StringBuilder.h> @@ -86,7 +88,7 @@ static inline bool skipToken(const String& str, unsigned& pos, const char* token  }  // True if the expected equals sign is seen and there is more to follow. -static inline bool skipEquals(const String& str, unsigned &pos) +static inline bool skipEquals(const String& str, unsigned& pos)  {      return skipWhiteSpace(str, pos) && str[pos++] == '=' && skipWhiteSpace(str, pos);  } @@ -150,7 +152,7 @@ bool isValidAcceptHeaderValue(const String& value)          if (RFC7230::isDelimiter(c))              return false;      } -     +      return true;  } @@ -159,8 +161,7 @@ static bool containsCORSUnsafeRequestHeaderBytes(const String& value)      for (unsigned i = 0; i < value.length(); ++i) {          UChar c = value[i];          // https://fetch.spec.whatwg.org/#cors-unsafe-request-header-byte -        if ((c < 0x20 && c != '\t') || (c == '"' || c == '(' || c == ')' || c == ':' || c == '<' || c == '>' || c == '?' -            || c == '@' || c == '[' || c == '\\' || c == ']' || c == 0x7B || c == '{' || c == '}' || c == 0x7F)) +        if ((c < 0x20 && c != '\t') || (c == '"' || c == '(' || c == ')' || c == ':' || c == '<' || c == '>' || c == '?' || c == '@' || c == '[' || c == '\\' || c == ']' || c == 0x7B || c == '{' || c == '}' || c == 0x7F))              return true;      } @@ -168,6 +169,7 @@ static bool containsCORSUnsafeRequestHeaderBytes(const String& value)  }  // See RFC 7231, Section 5.3.5 and 3.1.3.2. +// https://fetch.spec.whatwg.org/#cors-safelisted-request-header  bool isValidLanguageHeaderValue(const String& value)  {      for (unsigned i = 0; i < value.length(); ++i) { @@ -176,11 +178,6 @@ bool isValidLanguageHeaderValue(const String& value)              continue;          return false;      } -     -    // FIXME: Validate further by splitting into language tags and optional quality -    // values (q=) and then check each language tag. -    // Language tags https://tools.ietf.org/html/rfc7231#section-3.1.3.1 -    // Language tag syntax https://tools.ietf.org/html/bcp47#section-2.1      return true;  } @@ -314,10 +311,9 @@ static const size_t maxInputSampleSize = 128;  template<typename CharType>  static String trimInputSample(CharType* p, size_t length)  { -    String s = String(p, std::min<size_t>(length, maxInputSampleSize)); -    if (length > maxInputSampleSize) -        s.append(horizontalEllipsis); -    return s; +    if (length <= maxInputSampleSize) +        return String(p, length); +    return makeString(StringView(p, length).left(maxInputSampleSize), horizontalEllipsis);  }  std::optional<WallTime> parseHTTPDate(const String& value) @@ -335,7 +331,7 @@ std::optional<WallTime> parseHTTPDate(const String& value)  // that arises from quoted-string, nor does this function properly unquote  // attribute values. Further this function appears to process parameter names  // in a case-sensitive manner. (There are likely other bugs as well.) -String filenameFromHTTPContentDisposition(StringView value) +StringView filenameFromHTTPContentDisposition(StringView value)  {      for (auto keyValuePair : value.split(';')) {          size_t valueStartPos = keyValuePair.find('='); @@ -346,14 +342,14 @@ String filenameFromHTTPContentDisposition(StringView value)          if (key.isEmpty() || key != "filename")              continue; -         +          auto value = keyValuePair.substring(valueStartPos + 1).stripWhiteSpace();          // Remove quotes if there are any          if (value.length() > 1 && value[0] == '\"')              value = value.substring(1, value.length() - 2); -        return value.toString(); +        return value;      }      return String(); @@ -397,7 +393,7 @@ String extractMIMETypeFromMediaType(const String& mediaType)      return mediaType.substring(typeStart, typeEnd - typeStart);  } -String extractCharsetFromMediaType(const String& mediaType) +StringView extractCharsetFromMediaType(StringView mediaType)  {      unsigned charsetPos = 0, charsetLen = 0;      size_t pos = 0; @@ -411,7 +407,7 @@ String extractCharsetFromMediaType(const String& mediaType)          }          // is what we found a beginning of a word? -        if (mediaType[pos-1] > ' ' && mediaType[pos-1] != ';') { +        if (mediaType[pos - 1] > ' ' && mediaType[pos - 1] != ';') {              pos += 7;              continue;          } @@ -419,18 +415,21 @@ String extractCharsetFromMediaType(const String& mediaType)          pos += 7;          // skip whitespace -        while (pos != length && mediaType[pos] <= ' ') +        while (pos < length && mediaType[pos] <= ' ')              ++pos; +        if (pos >= length) +            break; +          if (mediaType[pos++] != '=') // this "charset" substring wasn't a parameter name, but there may be others              continue; -        while (pos != length && (mediaType[pos] <= ' ' || mediaType[pos] == '"' || mediaType[pos] == '\'')) +        while (pos < length && (mediaType[pos] <= ' ' || mediaType[pos] == '"' || mediaType[pos] == '\''))              ++pos;          // we don't handle spaces within quoted parameter values, because charset names cannot have any          unsigned endpos = pos; -        while (pos != length && mediaType[endpos] > ' ' && mediaType[endpos] != '"' && mediaType[endpos] != '\'' && mediaType[endpos] != ';') +        while (endpos < length && mediaType[endpos] > ' ' && mediaType[endpos] != '"' && mediaType[endpos] != '\'' && mediaType[endpos] != ';')              ++endpos;          charsetPos = pos; @@ -532,7 +531,7 @@ XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String&  ContentTypeOptionsDisposition parseContentTypeOptionsHeader(StringView header)  {      StringView leftToken = header.left(header.find(',')); -    if (equalLettersIgnoringASCIICase(stripLeadingAndTrailingHTTPSpaces(leftToken), "nosniff")) +    if (equalLettersIgnoringASCIICase(stripLeadingAndTrailingHTTPSpaces(leftToken), "nosniff"_s))          return ContentTypeOptionsDisposition::Nosniff;      return ContentTypeOptionsDisposition::None;  } @@ -562,11 +561,11 @@ XFrameOptionsDisposition parseXFrameOptionsHeader(StringView header)      for (auto currentHeader : header.split(',')) {          currentHeader = currentHeader.stripWhiteSpace();          XFrameOptionsDisposition currentValue = XFrameOptionsDisposition::None; -        if (equalLettersIgnoringASCIICase(currentHeader, "deny")) +        if (equalLettersIgnoringASCIICase(currentHeader, "deny"_s))              currentValue = XFrameOptionsDisposition::Deny; -        else if (equalLettersIgnoringASCIICase(currentHeader, "sameorigin")) +        else if (equalLettersIgnoringASCIICase(currentHeader, "sameorigin"_s))              currentValue = XFrameOptionsDisposition::SameOrigin; -        else if (equalLettersIgnoringASCIICase(currentHeader, "allowall")) +        else if (equalLettersIgnoringASCIICase(currentHeader, "allowall"_s))              currentValue = XFrameOptionsDisposition::AllowAll;          else              currentValue = XFrameOptionsDisposition::Invalid; @@ -597,7 +596,7 @@ std::optional<std::pair<StringView, HashMap<String, String>>> parseStructuredFie              break;          ++index;      } -    StringView bareItem = header.substring(0, index); +    StringView bareItem = header.left(index);      // Parse parameters (https://datatracker.ietf.org/doc/html/rfc8941#section-4.2.3.2).      HashMap<String, String> parameters; @@ -619,8 +618,8 @@ std::optional<std::pair<StringView, HashMap<String, String>>> parseStructuredFie                  break;              ++index;          } -        String key = header.substring(keyStart, index - keyStart).toString(); -        String value = "true"; +        StringView key = header.substring(keyStart, index - keyStart); +        String value = trueAtom();          if (index < header.length() && header[index] == '=') {              ++index; // Consume '='.              if (isASCIIAlpha(header[index]) || header[index] == '*') { @@ -660,14 +659,14 @@ std::optional<std::pair<StringView, HashMap<String, String>>> parseStructuredFie              } else                  return std::nullopt;          } -        parameters.set(WTFMove(key), WTFMove(value)); +        parameters.set(key.toString(), WTFMove(value));      }      if (index != header.length())          return std::nullopt;      return std::make_pair(bareItem, parameters);  } -bool parseRange(const String& range, long long& rangeOffset, long long& rangeEnd, long long& rangeSuffixLength) +bool parseRange(StringView range, long long& rangeOffset, long long& rangeEnd, long long& rangeSuffixLength)  {      // The format of "Range" header is defined in RFC 2616 Section 14.35.1.      // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 @@ -677,10 +676,10 @@ bool parseRange(const String& range, long long& rangeOffset, long long& rangeEnd      // The "bytes" unit identifier should be present.      static const unsigned bytesLength = 6; -    if (!startsWithLettersIgnoringASCIICase(range, "bytes=")) +    if (!startsWithLettersIgnoringASCIICase(range, "bytes="_s))          return false; -    // FIXME: The rest of this should use StringView. -    String byteRange = range.substring(bytesLength); + +    StringView byteRange = range.substring(bytesLength);      // The '-' character needs to be present.      int index = byteRange.find('-'); @@ -691,7 +690,7 @@ bool parseRange(const String& range, long long& rangeOffset, long long& rangeEnd      // Example:      //     -500      if (!index) { -        if (auto value = parseInteger<long long>(StringView { byteRange }.substring(index + 1))) +        if (auto value = parseInteger<long long>(byteRange.substring(index + 1)))              rangeSuffixLength = *value;          return true;      } @@ -700,11 +699,11 @@ bool parseRange(const String& range, long long& rangeOffset, long long& rangeEnd      // Examples:      //     0-499      //     500- -    auto firstBytePos = parseInteger<long long>(StringView { byteRange }.left(index)); +    auto firstBytePos = parseInteger<long long>(byteRange.left(index));      if (!firstBytePos)          return false; -    auto lastBytePosStr = stripLeadingAndTrailingHTTPSpaces(StringView { byteRange }.substring(index + 1)); +    auto lastBytePosStr = stripLeadingAndTrailingHTTPSpaces(byteRange.substring(index + 1));      long long lastBytePos = -1;      if (!lastBytePosStr.isEmpty()) {          auto value = parseInteger<long long>(lastBytePosStr); @@ -785,7 +784,7 @@ size_t parseHTTPHeader(const uint8_t* start, size_t length, String& failureReaso          default:              if (!isValidHeaderNameCharacter(*p)) {                  if (name.size() < 1) -                    failureReason = "Unexpected start character in header name"; +                    failureReason = "Unexpected start character in header name"_s;                  else                      failureReason = makeString("Unexpected character in header name at ", trimInputSample(name.data(), name.size()));                  return 0; @@ -806,7 +805,8 @@ size_t parseHTTPHeader(const uint8_t* start, size_t length, String& failureReaso      nameSize = name.size();      nameStr = StringView(namePtr, nameSize); -    for (; p < end && *p == 0x20; p++) { } +    for (; p < end && *p == 0x20; p++) { +    }      for (; p < end; p++) {          switch (*p) { @@ -877,7 +877,7 @@ bool isForbiddenHeaderName(const String& name)              break;          }      } -    return startsWithLettersIgnoringASCIICase(name, "sec-") || startsWithLettersIgnoringASCIICase(name, "proxy-"); +    return startsWithLettersIgnoringASCIICase(name, "sec-"_s) || startsWithLettersIgnoringASCIICase(name, "proxy-"_s);  }  // Implements <https://fetch.spec.whatwg.org/#no-cors-safelisted-request-header-name>. @@ -901,19 +901,19 @@ bool isNoCORSSafelistedRequestHeaderName(const String& name)  // Implements <https://fetch.spec.whatwg.org/#privileged-no-cors-request-header-name>.  bool isPriviledgedNoCORSRequestHeaderName(const String& name)  { -    return equalLettersIgnoringASCIICase(name, "range"); +    return equalLettersIgnoringASCIICase(name, "range"_s);  }  // Implements <https://fetch.spec.whatwg.org/#forbidden-response-header-name>.  bool isForbiddenResponseHeaderName(const String& name)  { -    return equalLettersIgnoringASCIICase(name, "set-cookie") || equalLettersIgnoringASCIICase(name, "set-cookie2"); +    return equalLettersIgnoringASCIICase(name, "set-cookie"_s) || equalLettersIgnoringASCIICase(name, "set-cookie2"_s);  }  // Implements <https://fetch.spec.whatwg.org/#forbidden-method>.  bool isForbiddenMethod(const String& name)  { -    return equalLettersIgnoringASCIICase(name, "connect") || equalLettersIgnoringASCIICase(name, "trace") || equalLettersIgnoringASCIICase(name, "track"); +    return equalLettersIgnoringASCIICase(name, "connect"_s) || equalLettersIgnoringASCIICase(name, "trace"_s) || equalLettersIgnoringASCIICase(name, "track"_s);  }  bool isSimpleHeader(const String& name, const String& value) @@ -942,7 +942,7 @@ bool isCrossOriginSafeHeader(HTTPHeaderName name, const HTTPHeaderSet& accessCon      default:          break;      } -    return accessControlExposeHeaderSet.contains(httpHeaderNameString(name).toStringWithoutCopying()); +    return accessControlExposeHeaderSet.contains<ASCIICaseInsensitiveStringViewHashTranslator>(httpHeaderNameString(name));  }  bool isCrossOriginSafeHeader(const String& name, const HTTPHeaderSet& accessControlExposeHeaderSet) @@ -954,9 +954,47 @@ bool isCrossOriginSafeHeader(const String& name, const HTTPHeaderSet& accessCont      return accessControlExposeHeaderSet.contains(name);  } +static bool isSimpleRangeHeaderValue(const String& value) +{ +    if (!value.startsWith("bytes="_s)) +        return false; + +    unsigned start = 0; +    unsigned end = 0; +    bool hasHyphen = false; + +    for (size_t cptr = 6; cptr < value.length(); ++cptr) { +        auto character = value[cptr]; +        if (character >= '0' && character <= '9') { +            if (productOverflows<unsigned>(hasHyphen ? end : start, 10)) +                return false; +            auto newDecimal = (hasHyphen ? end : start) * 10; +            auto sum = Checked<unsigned, RecordOverflow>(newDecimal) + Checked<unsigned, RecordOverflow>(character - '0'); +            if (sum.hasOverflowed()) +                return false; + +            if (hasHyphen) +                end = sum.value(); +            else +                start = sum.value(); +            continue; +        } +        if (character == '-' && !hasHyphen) { +            hasHyphen = true; +            continue; +        } +        return false; +    } + +    return hasHyphen && (!end || start < end); +} +  // Implements https://fetch.spec.whatwg.org/#cors-safelisted-request-header  bool isCrossOriginSafeRequestHeader(HTTPHeaderName name, const String& value)  { +    if (value.length() > 128) +        return false; +      switch (name) {      case HTTPHeaderName::Accept:          if (!isValidAcceptHeaderValue(value)) @@ -975,15 +1013,19 @@ bool isCrossOriginSafeRequestHeader(HTTPHeaderName name, const String& value)          if (!parsedContentType)              return false;          String mimeType = parsedContentType->mimeType(); -        if (!(equalLettersIgnoringASCIICase(mimeType, "application/x-www-form-urlencoded") || equalLettersIgnoringASCIICase(mimeType, "multipart/form-data") || equalLettersIgnoringASCIICase(mimeType, "text/plain"))) +        if (!(equalLettersIgnoringASCIICase(mimeType, "application/x-www-form-urlencoded"_s) || equalLettersIgnoringASCIICase(mimeType, "multipart/form-data"_s) || equalLettersIgnoringASCIICase(mimeType, "text/plain"_s)))              return false;          break;      } +    case HTTPHeaderName::Range: +        if (!isSimpleRangeHeaderValue(value)) +            return false; +        break;      default:          // FIXME: Should we also make safe other headers (DPR, Downlink, Save-Data...)? That would require validating their values.          return false;      } -    return value.length() <= 128; +    return true;  }  // Implements <https://fetch.spec.whatwg.org/#concept-method-normalize>. @@ -991,7 +1033,7 @@ String normalizeHTTPMethod(const String& method)  {      const ASCIILiteral methods[] = { "DELETE"_s, "GET"_s, "HEAD"_s, "OPTIONS"_s, "POST"_s, "PUT"_s };      for (auto value : methods) { -        if (equalIgnoringASCIICase(method, value.characters())) { +        if (equalIgnoringASCIICase(method, value)) {              // Don't bother allocating a new string if it's already all uppercase.              if (method == value)                  break; @@ -1006,7 +1048,7 @@ bool isSafeMethod(const String& method)  {      const ASCIILiteral safeMethods[] = { "GET"_s, "HEAD"_s, "OPTIONS"_s, "TRACE"_s };      for (auto value : safeMethods) { -        if (equalIgnoringASCIICase(method, value.characters())) +        if (equalIgnoringASCIICase(method, value))              return true;      }      return false; @@ -1031,4 +1073,4 @@ CrossOriginResourcePolicy parseCrossOriginResourcePolicyHeader(StringView header      return CrossOriginResourcePolicy::Invalid;  } -} +}
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/HTTPParsers.h b/src/javascript/jsc/bindings/webcore/HTTPParsers.h index 920a5a5b6..917ab2eae 100644 --- a/src/javascript/jsc/bindings/webcore/HTTPParsers.h +++ b/src/javascript/jsc/bindings/webcore/HTTPParsers.h @@ -8,13 +8,13 @@   * are met:   *   * 1.  Redistributions of source code must retain the above copyright - *     notice, this list of conditions and the following disclaimer.  + *     notice, this list of conditions and the following disclaimer.   * 2.  Redistributions in binary form must reproduce the above copyright   *     notice, this list of conditions and the following disclaimer in the - *     documentation and/or other materials provided with the distribution.  + *     documentation and/or other materials provided with the distribution.   * 3.  Neither the name of Apple Inc. ("Apple") nor the names of   *     its contributors may be used to endorse or promote products derived - *     from this software without specific prior written permission.  + *     from this software without specific prior written permission.   *   * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -79,9 +79,9 @@ WEBCORE_EXPORT bool isValidUserAgentHeaderValue(const String&);  bool isValidHTTPToken(const String&);  bool isValidHTTPToken(StringView);  std::optional<WallTime> parseHTTPDate(const String&); -String filenameFromHTTPContentDisposition(StringView); +StringView filenameFromHTTPContentDisposition(StringView);  WEBCORE_EXPORT String extractMIMETypeFromMediaType(const String&); -String extractCharsetFromMediaType(const String&); +StringView extractCharsetFromMediaType(const String&);  XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String& failureReason, unsigned& failurePosition, String& reportURL);  AtomString extractReasonPhraseFromHTTPStatusLine(const String&);  WEBCORE_EXPORT XFrameOptionsDisposition parseXFrameOptionsHeader(StringView); @@ -164,13 +164,13 @@ std::optional<HashSet<String, HashType>> parseAccessControlAllowList(const Strin      while ((end = string.find(',', start)) != notFound) {          if (start != end) {              if (!addToAccessControlAllowList(string, start, end - 1, set)) -                return { }; +                return {};          }          start = end + 1;      }      if (start != string.length()) {          if (!addToAccessControlAllowList(string, start, string.length() - 1, set)) -            return { }; +            return {};      }      return set;  } diff --git a/src/javascript/jsc/bindings/webcore/JSAbortAlgorithm.cpp b/src/javascript/jsc/bindings/webcore/JSAbortAlgorithm.cpp index 0d7765ddf..920b05ee5 100644 --- a/src/javascript/jsc/bindings/webcore/JSAbortAlgorithm.cpp +++ b/src/javascript/jsc/bindings/webcore/JSAbortAlgorithm.cpp @@ -25,12 +25,11 @@  #include "JSDOMExceptionHandling.h"  #include "ScriptExecutionContext.h" -  namespace WebCore {  using namespace JSC;  JSAbortAlgorithm::JSAbortAlgorithm(VM& vm, JSObject* callback) -    : AbortAlgorithm(jsCast<JSDOMGlobalObject*>(callback->globalObject(vm))->scriptExecutionContext()) +    : AbortAlgorithm(jsCast<JSDOMGlobalObject*>(callback->globalObject())->scriptExecutionContext())      , m_data(new JSCallbackDataStrong(vm, callback, this))  {  } @@ -70,9 +69,9 @@ CallbackResult<typename IDLUndefined::ImplementationType> JSAbortAlgorithm::hand      if (returnedException) {          reportException(&lexicalGlobalObject, returnedException);          return CallbackResultType::ExceptionThrown; -     } +    } -    return { }; +    return {};  }  JSC::JSValue toJS(AbortAlgorithm& impl) diff --git a/src/javascript/jsc/bindings/webcore/JSAbortController.cpp b/src/javascript/jsc/bindings/webcore/JSAbortController.cpp index afd63ff5d..4411d07bd 100644 --- a/src/javascript/jsc/bindings/webcore/JSAbortController.cpp +++ b/src/javascript/jsc/bindings/webcore/JSAbortController.cpp @@ -163,7 +163,7 @@ JSAbortController::JSAbortController(Structure* structure, JSDOMGlobalObject& gl  void JSAbortController::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, AbortController>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -193,7 +193,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsAbortControllerConstructor, (JSGlobalObject * lexical  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSAbortControllerPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSAbortControllerPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSAbortController::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -287,7 +287,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  AbortController* JSAbortController::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSAbortController*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSAbortController*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/JSAbortSignal.cpp b/src/javascript/jsc/bindings/webcore/JSAbortSignal.cpp index 5738bcc25..ba7b3c69f 100644 --- a/src/javascript/jsc/bindings/webcore/JSAbortSignal.cpp +++ b/src/javascript/jsc/bindings/webcore/JSAbortSignal.cpp @@ -167,7 +167,7 @@ JSAbortSignal::JSAbortSignal(Structure* structure, JSDOMGlobalObject& globalObje  void JSAbortSignal::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));  }  JSObject* JSAbortSignal::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) @@ -189,7 +189,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsAbortSignalConstructor, (JSGlobalObject * lexicalGlob  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSAbortSignalPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSAbortSignalPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSAbortSignal::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -416,7 +416,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  AbortSignal* JSAbortSignal::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSAbortSignal*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSAbortSignal*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/JSAddEventListenerOptions.cpp b/src/javascript/jsc/bindings/webcore/JSAddEventListenerOptions.cpp index 9eaa310a7..6ef60b2a3 100644 --- a/src/javascript/jsc/bindings/webcore/JSAddEventListenerOptions.cpp +++ b/src/javascript/jsc/bindings/webcore/JSAddEventListenerOptions.cpp @@ -26,7 +26,6 @@  #include "JSDOMConvertInterface.h"  #include <JavaScriptCore/JSCInlines.h> -  namespace WebCore {  using namespace JSC; @@ -38,54 +37,54 @@ template<> AddEventListenerOptions convertDictionary<AddEventListenerOptions>(JS      auto* object = isNullOrUndefined ? nullptr : value.getObject();      if (UNLIKELY(!isNullOrUndefined && !object)) {          throwTypeError(&lexicalGlobalObject, throwScope); -        return { }; +        return {};      }      AddEventListenerOptions result;      JSValue captureValue;      if (isNullOrUndefined)          captureValue = jsUndefined();      else { -        captureValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "capture")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        captureValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "capture"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!captureValue.isUndefined()) {          result.capture = convert<IDLBoolean>(lexicalGlobalObject, captureValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      } else          result.capture = false;      JSValue onceValue;      if (isNullOrUndefined)          onceValue = jsUndefined();      else { -        onceValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "once")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        onceValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "once"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!onceValue.isUndefined()) {          result.once = convert<IDLBoolean>(lexicalGlobalObject, onceValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      } else          result.once = false;      JSValue passiveValue;      if (isNullOrUndefined)          passiveValue = jsUndefined();      else { -        passiveValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "passive")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        passiveValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "passive"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!passiveValue.isUndefined()) {          result.passive = convert<IDLBoolean>(lexicalGlobalObject, passiveValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      }      JSValue signalValue;      if (isNullOrUndefined)          signalValue = jsUndefined();      else { -        signalValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "signal")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        signalValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "signal"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!signalValue.isUndefined()) {          result.signal = convert<IDLInterface<AbortSignal>>(lexicalGlobalObject, signalValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      }      return result;  } diff --git a/src/javascript/jsc/bindings/webcore/JSCallbackData.cpp b/src/javascript/jsc/bindings/webcore/JSCallbackData.cpp index e0cf4a9e9..671f168f7 100644 --- a/src/javascript/jsc/bindings/webcore/JSCallbackData.cpp +++ b/src/javascript/jsc/bindings/webcore/JSCallbackData.cpp @@ -47,7 +47,7 @@ JSValue JSCallbackData::invokeCallback(VM& vm, JSObject* callback, JSValue thisV      // https://webidl.spec.whatwg.org/#ref-for-prepare-to-run-script makes callback's [[Realm]] a running JavaScript execution context,      // which is used for creating TypeError objects: https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist (step 4). -    JSGlobalObject* lexicalGlobalObject = callback->globalObject(vm); +    JSGlobalObject* lexicalGlobalObject = callback->globalObject();      auto scope = DECLARE_CATCH_SCOPE(vm);      JSValue function; @@ -55,7 +55,7 @@ JSValue JSCallbackData::invokeCallback(VM& vm, JSObject* callback, JSValue thisV      if (method != CallbackType::Object) {          function = callback; -        callData = getCallData(vm, callback); +        callData = getCallData(callback);      }      if (callData.type == CallData::Type::None) {          if (method == CallbackType::Function) { @@ -71,7 +71,7 @@ JSValue JSCallbackData::invokeCallback(VM& vm, JSObject* callback, JSValue thisV              return JSValue();          } -        callData = getCallData(vm, function); +        callData = getCallData(function);          if (callData.type == CallData::Type::None) {              returnedException = JSC::Exception::create(vm, createTypeError(lexicalGlobalObject, makeString("'", String(functionName.uid()), "' property of callback interface should be callable")));              return JSValue(); diff --git a/src/javascript/jsc/bindings/webcore/JSCustomEvent.cpp b/src/javascript/jsc/bindings/webcore/JSCustomEvent.cpp index 35f51ba4b..843211d8d 100644 --- a/src/javascript/jsc/bindings/webcore/JSCustomEvent.cpp +++ b/src/javascript/jsc/bindings/webcore/JSCustomEvent.cpp @@ -66,7 +66,7 @@ template<> CustomEvent::Init convertDictionary<CustomEvent::Init>(JSGlobalObject      if (isNullOrUndefined)          bubblesValue = jsUndefined();      else { -        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles")); +        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!bubblesValue.isUndefined()) { @@ -78,7 +78,7 @@ template<> CustomEvent::Init convertDictionary<CustomEvent::Init>(JSGlobalObject      if (isNullOrUndefined)          cancelableValue = jsUndefined();      else { -        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable")); +        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!cancelableValue.isUndefined()) { @@ -90,7 +90,7 @@ template<> CustomEvent::Init convertDictionary<CustomEvent::Init>(JSGlobalObject      if (isNullOrUndefined)          composedValue = jsUndefined();      else { -        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed")); +        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!composedValue.isUndefined()) { @@ -102,7 +102,7 @@ template<> CustomEvent::Init convertDictionary<CustomEvent::Init>(JSGlobalObject      if (isNullOrUndefined)          detailValue = jsUndefined();      else { -        detailValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "detail")); +        detailValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "detail"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!detailValue.isUndefined()) { @@ -165,12 +165,12 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCustomEventDOMConstructor::      if (UNLIKELY(callFrame->argumentCount() < 1))          return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));      EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); -    auto type = convert<IDLDOMString>(*lexicalGlobalObject, argument0.value()); +    auto type = convert<IDLAtomStringAdaptor<IDLDOMString>>(*lexicalGlobalObject, argument0.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue());      EnsureStillAliveScope argument1 = callFrame->argument(1);      auto eventInitDict = convert<IDLDictionary<CustomEvent::Init>>(*lexicalGlobalObject, argument1.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); -    auto object = CustomEvent::create(WTFMove(type), WTFMove(eventInitDict)); +    auto object = CustomEvent::create(type, WTFMove(eventInitDict));      if constexpr (IsExceptionOr<decltype(object)>)          RETURN_IF_EXCEPTION(throwScope, {});      static_assert(TypeOrExceptionOrUnderlyingType<decltype(object)>::isRef); @@ -226,7 +226,7 @@ JSCustomEvent::JSCustomEvent(Structure* structure, JSDOMGlobalObject& globalObje  void JSCustomEvent::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, CustomEvent>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -250,7 +250,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsCustomEventConstructor, (JSGlobalObject * lexicalGlob  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSCustomEventPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSCustomEventPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSCustomEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -277,7 +277,7 @@ static inline JSC::EncodedJSValue jsCustomEventPrototypeFunction_initCustomEvent      if (UNLIKELY(callFrame->argumentCount() < 1))          return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));      EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); -    auto type = convert<IDLDOMString>(*lexicalGlobalObject, argument0.value()); +    auto type = convert<IDLAtomStringAdaptor<IDLDOMString>>(*lexicalGlobalObject, argument0.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue());      EnsureStillAliveScope argument1 = callFrame->argument(1);      auto bubbles = convert<IDLBoolean>(*lexicalGlobalObject, argument1.value()); @@ -288,7 +288,7 @@ static inline JSC::EncodedJSValue jsCustomEventPrototypeFunction_initCustomEvent      EnsureStillAliveScope argument3 = callFrame->argument(3);      auto detail = argument3.value().isUndefined() ? jsNull() : convert<IDLAny>(*lexicalGlobalObject, argument3.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); -    RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.initCustomEvent(WTFMove(type), WTFMove(bubbles), WTFMove(cancelable), WTFMove(detail)); }))); +    RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { return impl.initCustomEvent(type, WTFMove(bubbles), WTFMove(cancelable), WTFMove(detail)); })));  }  JSC_DEFINE_HOST_FUNCTION(jsCustomEventPrototypeFunction_initCustomEvent, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) diff --git a/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h b/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h index ada862b72..d7028c4b5 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMCastThisValue.h @@ -48,7 +48,7 @@ JSClass* castThisValue(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue th      if constexpr (std::is_base_of_v<JSDOMGlobalObject, JSClass>)          return toJSDOMGlobalObject<JSClass>(vm, thisValue.isUndefinedOrNull() ? JSC::JSValue(&lexicalGlobalObject) : thisValue);      else -        return JSC::jsDynamicCast<JSClass*>(vm, thisValue); +        return JSC::jsDynamicCast<JSClass*>(thisValue);  }  } diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h index af969de89..680d71a4e 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructor.h @@ -47,7 +47,7 @@ private:      void finishCreation(JSC::VM&, JSDOMGlobalObject&);      // Usually defined for each specialization class. -    void initializeProperties(JSC::VM&, JSDOMGlobalObject&) { } +    void initializeProperties(JSC::VM&, JSDOMGlobalObject&) {}  };  template<typename JSClass> inline JSDOMConstructor<JSClass>* JSDOMConstructor<JSClass>::create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject& globalObject) @@ -65,7 +65,7 @@ template<typename JSClass> inline JSC::Structure* JSDOMConstructor<JSClass>::cre  template<typename JSClass> inline void JSDOMConstructor<JSClass>::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      initializeProperties(vm, globalObject);  } diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h index da94a3f48..779bf8876 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotCallable.h @@ -78,7 +78,7 @@ template<typename JSClass> inline JSC::Structure* JSDOMConstructorNotCallable<JS  template<typename JSClass> inline void JSDOMConstructorNotCallable<JSClass>::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      initializeProperties(vm, globalObject);  } diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h index 55d4e7792..ac173d0fe 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConstructorNotConstructable.h @@ -62,7 +62,7 @@ template<typename JSClass> inline JSC::Structure* JSDOMConstructorNotConstructab  template<typename JSClass> inline void JSDOMConstructorNotConstructable<JSClass>::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      initializeProperties(vm, globalObject);  } diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h index 928e79b99..8cab2e7d8 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertBase.h @@ -26,9 +26,9 @@  #pragma once  #include "root.h"  #include "ZigGlobalObject.h" - +#include "JSDOMGlobalObject.h"  #include "JSDOMExceptionHandling.h" -#include "JavaScriptCore/Error.h" +#include <JavaScriptCore/Error.h>  namespace WebCore { @@ -265,4 +265,4 @@ template<typename T> struct DefaultConverter {  // Conversion from JSValue -> Implementation for variadic arguments  template<typename IDLType> struct VariadicConverter; -} // namespace WebCore +} // namespace WebCore
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h index 7cc629ab8..bab958a4f 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertBufferSource.h @@ -110,7 +110,7 @@ inline JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSGlobal  inline RefPtr<JSC::ArrayBufferView> toPossiblySharedArrayBufferView(JSC::VM& vm, JSC::JSValue value)  { -    auto* wrapper = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(vm, value); +    auto* wrapper = JSC::jsDynamicCast<JSC::JSArrayBufferView*>(value);      if (!wrapper)          return nullptr;      return wrapper->possiblySharedImpl(); diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h index c8ce13c14..c98ad316b 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertCallbacks.h @@ -41,7 +41,7 @@ template<typename T> struct Converter<IDLCallbackFunction<T>> : DefaultConverter          JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);          auto scope = DECLARE_THROW_SCOPE(vm); -        if (!value.isCallable(vm)) { +        if (!value.isCallable()) {              exceptionThrower(lexicalGlobalObject, scope);              return nullptr;          } @@ -54,7 +54,7 @@ template<typename T> struct JSConverter<IDLCallbackFunction<T>> {      static constexpr bool needsState = false;      static constexpr bool needsGlobalObject = false; -    template <typename U> +    template<typename U>      static JSC::JSValue convert(const U& value)      {          return toJS(Detail::getPtrOrRef(value)); @@ -67,7 +67,6 @@ template<typename T> struct JSConverter<IDLCallbackFunction<T>> {      }  }; -  template<typename T> struct Converter<IDLCallbackInterface<T>> : DefaultConverter<IDLCallbackInterface<T>> {      template<typename ExceptionThrower = DefaultExceptionThrower>      static RefPtr<T> convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower()) @@ -88,7 +87,7 @@ template<typename T> struct JSConverter<IDLCallbackInterface<T>> {      static constexpr bool needsState = false;      static constexpr bool needsGlobalObject = false; -    template <typename U> +    template<typename U>      static JSC::JSValue convert(const U& value)      {          return toJS(Detail::getPtrOrRef(value)); diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp index 739be11ef..c624bd25b 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertDate.cpp @@ -40,7 +40,7 @@ WallTime valueToDate(JSC::JSGlobalObject& lexicalGlobalObject, JSValue value)      double milliseconds = std::numeric_limits<double>::quiet_NaN();      auto& vm = lexicalGlobalObject.vm(); -    if (value.inherits<DateInstance>(vm)) +    if (value.inherits<DateInstance>())          milliseconds = jsCast<DateInstance*>(value)->internalNumber();      else if (value.isNumber())          milliseconds = value.asNumber(); diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h index 399a85ebb..29413d8d9 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertNumbers.h @@ -28,8 +28,8 @@  #include "IDLTypes.h"  #include "JSDOMConvertBase.h"  #include "JSDOMExceptionHandling.h" -#include "JavaScriptCore/JSCJSValueInlines.h" -#include "JavaScriptCore/PureNaN.h" +#include <JavaScriptCore/JSCJSValueInlines.h> +#include <JavaScriptCore/PureNaN.h>  namespace WebCore { @@ -251,6 +251,7 @@ template<typename T> struct JSConverter<IDLClampAdaptor<T>> {      }  }; +  template<typename T> struct Converter<IDLEnforceRangeAdaptor<T>> : DefaultConverter<IDLEnforceRangeAdaptor<T>> {      using ReturnType = typename IDLEnforceRangeAdaptor<T>::ImplementationType; @@ -272,6 +273,7 @@ template<typename T> struct JSConverter<IDLEnforceRangeAdaptor<T>> {      }  }; +  // MARK: -  // MARK: Floating point types @@ -291,7 +293,7 @@ template<> struct Converter<IDLFloat> : DefaultConverter<IDLFloat> {          double number = value.toNumber(&lexicalGlobalObject);          RETURN_IF_EXCEPTION(scope, 0.0);          if (UNLIKELY(number < std::numeric_limits<float>::lowest() || number > std::numeric_limits<float>::max())) -            throwTypeError(&lexicalGlobalObject, scope, "The provided value is outside the range of a float"); +            throwTypeError(&lexicalGlobalObject, scope, "The provided value is outside the range of a float"_s);          if (UNLIKELY(!std::isfinite(number)))              throwNonFiniteTypeError(lexicalGlobalObject, scope);          return static_cast<float>(number); diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h index a0051c383..29324f11b 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertPromise.h @@ -41,7 +41,7 @@ template<typename T> struct Converter<IDLPromise<T>> : DefaultConverter<IDLPromi      {          JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);          auto scope = DECLARE_THROW_SCOPE(vm); -        auto* globalObject = JSC::jsDynamicCast<JSDOMGlobalObject*>(vm, &lexicalGlobalObject); +        auto* globalObject = JSC::jsDynamicCast<JSDOMGlobalObject*>(&lexicalGlobalObject);          if (!globalObject)              return nullptr; diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h index 736fe7303..0f4c84eff 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertRecord.h @@ -100,14 +100,14 @@ private:          // 4. Let keys be ? O.[[OwnPropertyKeys]]().          JSC::PropertyNameArray keys(vm, JSC::PropertyNameMode::StringsAndSymbols, JSC::PrivateSymbolMode::Exclude); -        object->methodTable(vm)->getOwnPropertyNames(object, &lexicalGlobalObject, keys, JSC::DontEnumPropertiesMode::Include); +        object->methodTable()->getOwnPropertyNames(object, &lexicalGlobalObject, keys, JSC::DontEnumPropertiesMode::Include);          RETURN_IF_EXCEPTION(scope, {});          // 5. Repeat, for each element key of keys in List order:          for (auto& key : keys) {              // 1. Let desc be ? O.[[GetOwnProperty]](key).              JSC::PropertySlot slot(object, JSC::PropertySlot::InternalMethodType::GetOwnProperty); -            bool hasProperty = object->methodTable(vm)->getOwnPropertySlot(object, &lexicalGlobalObject, key, slot); +            bool hasProperty = object->methodTable()->getOwnPropertySlot(object, &lexicalGlobalObject, key, slot);              RETURN_IF_EXCEPTION(scope, {});              // 2. If desc is not undefined and desc.[[Enumerable]] is true: diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h index 85a7fd6ab..72fb8450d 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertScheduledAction.h @@ -38,7 +38,7 @@ template<> struct Converter<IDLScheduledAction> : DefaultConverter<IDLScheduledA          JSC::VM& vm = JSC::getVM(&lexicalGlobalObject);          auto scope = DECLARE_THROW_SCOPE(vm); -        if (!value.isCallable(vm)) { +        if (!value.isCallable()) {              auto code = Converter<IDLDOMString>::convert(lexicalGlobalObject, value);              RETURN_IF_EXCEPTION(scope, nullptr);              return ScheduledAction::create(globalObject.world(), WTFMove(code)); @@ -51,4 +51,3 @@ template<> struct Converter<IDLScheduledAction> : DefaultConverter<IDLScheduledA  };  } - diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp index 6c0a208d8..00f385e07 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.cpp @@ -23,10 +23,10 @@  #include "JSDOMConvertStrings.h"  #include "JSDOMExceptionHandling.h" -#include "JavaScriptCore/HeapInlines.h" -#include "JavaScriptCore/JSCJSValueInlines.h" -#include "wtf/text/StringBuilder.h" -#include "wtf/unicode/CharacterNames.h" +#include <JavaScriptCore/HeapInlines.h> +#include <JavaScriptCore/JSCJSValueInlines.h> +#include <wtf/text/StringBuilder.h> +#include <wtf/unicode/CharacterNames.h>  namespace WebCore {  using namespace JSC; @@ -42,14 +42,13 @@ String identifierToString(JSGlobalObject& lexicalGlobalObject, const Identifier&      return identifier.string();  } -static inline String stringToByteString(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, String&& string) +static inline bool throwIfInvalidByteString(JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, const String& string)  { -    if (!string.isAllLatin1()) { +    if (UNLIKELY(!string.isAllLatin1())) {          throwTypeError(&lexicalGlobalObject, scope); -        return {}; +        return true;      } - -    return WTFMove(string); +    return false;  }  String identifierToByteString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) @@ -59,7 +58,9 @@ String identifierToByteString(JSGlobalObject& lexicalGlobalObject, const Identif      auto string = identifierToString(lexicalGlobalObject, identifier);      RETURN_IF_EXCEPTION(scope, {}); -    return stringToByteString(lexicalGlobalObject, scope, WTFMove(string)); +    if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string))) +        return {}; +    return string;  }  String valueToByteString(JSGlobalObject& lexicalGlobalObject, JSValue value) @@ -70,7 +71,23 @@ String valueToByteString(JSGlobalObject& lexicalGlobalObject, JSValue value)      auto string = value.toWTFString(&lexicalGlobalObject);      RETURN_IF_EXCEPTION(scope, {}); -    return stringToByteString(lexicalGlobalObject, scope, WTFMove(string)); +    if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string))) +        return {}; +    return string; +} + +AtomString valueToByteAtomString(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +{ +    VM& vm = lexicalGlobalObject.vm(); +    auto scope = DECLARE_THROW_SCOPE(vm); + +    auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); +    RETURN_IF_EXCEPTION(scope, {}); + +    if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string.string()))) +        return nullAtom(); + +    return string;  }  String identifierToUSVString(JSGlobalObject& lexicalGlobalObject, const Identifier& identifier) @@ -89,4 +106,15 @@ String valueToUSVString(JSGlobalObject& lexicalGlobalObject, JSValue value)      return replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string));  } -} // namespace WebCore +AtomString valueToUSVAtomString(JSGlobalObject& lexicalGlobalObject, JSValue value) +{ +    VM& vm = lexicalGlobalObject.vm(); +    auto scope = DECLARE_THROW_SCOPE(vm); + +    auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); +    RETURN_IF_EXCEPTION(scope, {}); + +    return replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string)); +} + +} // namespace WebCore
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h index 29fa7259a..450caf7e9 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertStrings.h @@ -34,10 +34,12 @@ namespace WebCore {  WEBCORE_EXPORT String identifierToString(JSC::JSGlobalObject&, const JSC::Identifier&);  WEBCORE_EXPORT String identifierToByteString(JSC::JSGlobalObject&, const JSC::Identifier&);  WEBCORE_EXPORT String valueToByteString(JSC::JSGlobalObject&, JSC::JSValue); +WEBCORE_EXPORT AtomString valueToByteAtomString(JSC::JSGlobalObject&, JSC::JSValue);  WEBCORE_EXPORT String identifierToUSVString(JSC::JSGlobalObject&, const JSC::Identifier&);  WEBCORE_EXPORT String valueToUSVString(JSC::JSGlobalObject&, JSC::JSValue); +WEBCORE_EXPORT AtomString valueToUSVAtomString(JSC::JSGlobalObject&, JSC::JSValue); -inline String propertyNameToString(JSC::PropertyName propertyName) +inline AtomString propertyNameToString(JSC::PropertyName propertyName)  {      ASSERT(!propertyName.isSymbol());      return propertyName.uid() ? propertyName.uid() : propertyName.publicName(); @@ -158,7 +160,7 @@ template<typename T> struct Converter<IDLLegacyNullToEmptyStringAdaptor<T>> : De      }  }; -template<typename T>  struct JSConverter<IDLLegacyNullToEmptyStringAdaptor<T>> { +template<typename T> struct JSConverter<IDLLegacyNullToEmptyStringAdaptor<T>> {      static constexpr bool needsState = true;      static constexpr bool needsGlobalObject = false; @@ -168,6 +170,25 @@ template<typename T>  struct JSConverter<IDLLegacyNullToEmptyStringAdaptor<T>> {      }  }; +template<typename T> struct Converter<IDLLegacyNullToEmptyAtomStringAdaptor<T>> : DefaultConverter<IDLLegacyNullToEmptyAtomStringAdaptor<T>> { +    static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +    { +        if (value.isNull()) +            return emptyAtom(); +        return Converter<IDLAtomStringAdaptor<T>>::convert(lexicalGlobalObject, value); +    } +}; + +template<typename T> struct JSConverter<IDLLegacyNullToEmptyAtomStringAdaptor<T>> { +    static constexpr bool needsState = true; +    static constexpr bool needsGlobalObject = false; + +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) +    { +        return JSConverter<T>::convert(lexicalGlobalObject, value); +    } +}; +  template<typename T> struct Converter<IDLAtomStringAdaptor<T>> : DefaultConverter<IDLAtomStringAdaptor<T>> {      static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)      { @@ -177,28 +198,80 @@ template<typename T> struct Converter<IDLAtomStringAdaptor<T>> : DefaultConverte      }  }; -template<typename T>  struct JSConverter<IDLAtomStringAdaptor<T>> { +template<> struct Converter<IDLAtomStringAdaptor<IDLUSVString>> : DefaultConverter<IDLAtomStringAdaptor<IDLUSVString>> { +    static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +    { +        return valueToUSVAtomString(lexicalGlobalObject, value); +    } +}; + +template<> struct Converter<IDLAtomStringAdaptor<IDLByteString>> : DefaultConverter<IDLAtomStringAdaptor<IDLByteString>> { +    static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) +    { +        return valueToByteAtomString(lexicalGlobalObject, value); +    } +}; + +template<typename T> struct JSConverter<IDLAtomStringAdaptor<T>> {      static constexpr bool needsState = true;      static constexpr bool needsGlobalObject = false;      static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value)      { -        static_assert(std::is_same<T, IDLDOMString>::value, "This adaptor is only supported for IDLDOMString at the moment."); +        return JSConverter<T>::convert(lexicalGlobalObject, value); +    } +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) +    {          return JSConverter<T>::convert(lexicalGlobalObject, value);      } + +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const URL& value) +    { +        return JSConverter<T>::convert(lexicalGlobalObject, value.string()); +    } +}; + +template<> struct JSConverter<IDLAtomStringAdaptor<IDLUSVString>> { +    static constexpr bool needsState = true; +    static constexpr bool needsGlobalObject = false; + +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) +    { +        return JSConverter<IDLUSVString>::convert(lexicalGlobalObject, value.string()); +    } + +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const String& value) +    { +        return JSConverter<IDLUSVString>::convert(lexicalGlobalObject, value); +    } + +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const URL& value) +    { +        return JSConverter<IDLUSVString>::convert(lexicalGlobalObject, value.string()); +    } +}; + +template<> struct JSConverter<IDLAtomStringAdaptor<IDLByteString>> { +    static constexpr bool needsState = true; +    static constexpr bool needsGlobalObject = false; + +    static JSC::JSValue convert(JSC::JSGlobalObject& lexicalGlobalObject, const AtomString& value) +    { +        return JSConverter<IDLByteString>::convert(lexicalGlobalObject, value.string()); +    }  };  template<typename T> struct Converter<IDLRequiresExistingAtomStringAdaptor<T>> : DefaultConverter<IDLRequiresExistingAtomStringAdaptor<T>> {      static AtomString convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value)      {          static_assert(std::is_same<T, IDLDOMString>::value, "This adaptor is only supported for IDLDOMString at the moment."); -     -        return AtomString(value.toString(&lexicalGlobalObject)->toExistingAtomString(&lexicalGlobalObject)); + +        return value.toString(&lexicalGlobalObject)->toExistingAtomString(&lexicalGlobalObject);      }  }; -template<typename T>  struct JSConverter<IDLRequiresExistingAtomStringAdaptor<T>> { +template<typename T> struct JSConverter<IDLRequiresExistingAtomStringAdaptor<T>> {      static constexpr bool needsState = true;      static constexpr bool needsGlobalObject = false; @@ -210,5 +283,4 @@ template<typename T>  struct JSConverter<IDLRequiresExistingAtomStringAdaptor<T>      }  }; - -} // namespace WebCore +} // namespace WebCore
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h b/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h index eed7d1980..6c48a072a 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMConvertXPathNSResolver.h @@ -45,7 +45,7 @@ template<> struct Converter<IDLInterface<XPathNSResolver>> : DefaultConverter<ID          }          auto object = asObject(value); -        if (object->inherits<JSXPathNSResolver>(vm)) +        if (object->inherits<JSXPathNSResolver>())              return &JSC::jsCast<JSXPathNSResolver*>(object)->wrapped();          return JSCustomXPathNSResolver::create(vm, object); diff --git a/src/javascript/jsc/bindings/webcore/JSDOMException.cpp b/src/javascript/jsc/bindings/webcore/JSDOMException.cpp index bf8bcd9f9..9847b3d51 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMException.cpp +++ b/src/javascript/jsc/bindings/webcore/JSDOMException.cpp @@ -216,7 +216,7 @@ JSDOMException::JSDOMException(Structure* structure, JSDOMGlobalObject& globalOb  void JSDOMException::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, DOMException>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -246,7 +246,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMExceptionConstructor, (JSGlobalObject * lexicalGlo  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSDOMExceptionPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSDOMExceptionPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSDOMException::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -367,7 +367,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  DOMException* JSDOMException::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSDOMException*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSDOMException*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp b/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp index 205e1c80a..0bc957e17 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp +++ b/src/javascript/jsc/bindings/webcore/JSDOMIterator.cpp @@ -26,8 +26,8 @@  #include "config.h"  #include "JSDOMIterator.h" -#include "JavaScriptCore/ArrayPrototype.h" -#include "JavaScriptCore/BuiltinNames.h" +#include <JavaScriptCore/ArrayPrototype.h> +#include <JavaScriptCore/BuiltinNames.h>  namespace WebCore { @@ -52,4 +52,4 @@ void addValueIterableMethods(JSC::JSGlobalObject& globalObject, JSC::JSObject& p      copyProperty(vm.propertyNames->builtinNames().valuesPrivateName(), vm.propertyNames->builtinNames().valuesPublicName());  } -} +}
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/JSDOMIterator.h b/src/javascript/jsc/bindings/webcore/JSDOMIterator.h index 04b4c001b..b9740d4f9 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMIterator.h +++ b/src/javascript/jsc/bindings/webcore/JSDOMIterator.h @@ -27,8 +27,8 @@  #pragma once  #include "JSDOMConvert.h" -#include "JavaScriptCore/IteratorPrototype.h" -#include "JavaScriptCore/PropertySlot.h" +#include <JavaScriptCore/IteratorPrototype.h> +#include <JavaScriptCore/PropertySlot.h>  #include <type_traits>  namespace WebCore { @@ -210,7 +210,7 @@ template<typename JSIterator> JSC::JSValue iteratorForEach(JSC::JSGlobalObject&      JSC::JSValue callback = callFrame.argument(0);      JSC::JSValue thisValue = callFrame.argument(1); -    auto callData = JSC::getCallData(JSC::getVM(&lexicalGlobalObject), callback); +    auto callData = JSC::getCallData(callback);      if (callData.type == JSC::CallData::Type::None)          return throwTypeError(&lexicalGlobalObject, scope, "Cannot call callback"_s); @@ -255,7 +255,7 @@ JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMIteratorPrototype<JSWrapper, I      JSC::VM& vm = globalObject->vm();      auto scope = DECLARE_THROW_SCOPE(vm); -    auto iterator = JSC::jsDynamicCast<JSDOMIteratorBase<JSWrapper, IteratorTraits>*>(vm, callFrame->thisValue()); +    auto iterator = JSC::jsDynamicCast<JSDOMIteratorBase<JSWrapper, IteratorTraits>*>(callFrame->thisValue());      if (!iterator)          return JSC::JSValue::encode(throwTypeError(globalObject, scope, "Cannot call next() on a non-Iterator object"_s)); @@ -266,10 +266,10 @@ template<typename JSWrapper, typename IteratorTraits>  void JSDOMIteratorPrototype<JSWrapper, IteratorTraits>::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->next, next, 0, 0, JSC::NoIntrinsic);      JSC_TO_STRING_TAG_WITHOUT_TRANSITION();  } -} +}
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp b/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp index 898622279..fcf6d5b72 100644 --- a/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp +++ b/src/javascript/jsc/bindings/webcore/JSDOMURL.cpp @@ -194,7 +194,7 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSDOMURLDOMConstructor::const          JSValue distinguishingArg = callFrame->uncheckedArgument(1);          if (distinguishingArg.isUndefined())              RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame))); -        if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSDOMURL>(vm)) +        if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSDOMURL>())              RELEASE_AND_RETURN(throwScope, (constructJSDOMURL2(lexicalGlobalObject, callFrame)));          RELEASE_AND_RETURN(throwScope, (constructJSDOMURL1(lexicalGlobalObject, callFrame)));      } @@ -259,7 +259,7 @@ JSDOMURL::JSDOMURL(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DO  void JSDOMURL::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, DOMURL>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -289,7 +289,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsDOMURLConstructor, (JSGlobalObject * lexicalGlobalObj  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSDOMURLPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSDOMURLPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSDOMURL::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -717,10 +717,10 @@ static inline JSC::EncodedJSValue jsDOMURLConstructorFunction_createObjectURLOve      //     size_t argsCount = std::min<size_t>(1, callFrame->argumentCount());      //     if (argsCount == 1) {      //         JSValue distinguishingArg = callFrame->uncheckedArgument(0); -    //         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSBlob>(vm)) +    //         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSBlob>())      //             RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL1Body(lexicalGlobalObject, callFrame)));      // #if ENABLE(MEDIA_SOURCE) -    //         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSMediaSource>(vm)) +    //         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSMediaSource>())      //             RELEASE_AND_RETURN(throwScope, (jsDOMURLConstructorFunction_createObjectURL2Body(lexicalGlobalObject, callFrame)));      // #endif      //     } @@ -838,7 +838,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  DOMURL* JSDOMURL::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSDOMURL*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSDOMURL*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/JSErrorCallback.cpp b/src/javascript/jsc/bindings/webcore/JSErrorCallback.cpp index a227058a3..987d4d74a 100644 --- a/src/javascript/jsc/bindings/webcore/JSErrorCallback.cpp +++ b/src/javascript/jsc/bindings/webcore/JSErrorCallback.cpp @@ -28,12 +28,11 @@  #include "JSDOMGlobalObject.h"  #include "ScriptExecutionContext.h" -  namespace WebCore {  using namespace JSC;  JSErrorCallback::JSErrorCallback(VM& vm, JSObject* callback) -    : ErrorCallback(jsCast<JSDOMGlobalObject*>(callback->globalObject(vm))->scriptExecutionContext()) +    : ErrorCallback(jsCast<JSDOMGlobalObject*>(callback->globalObject())->scriptExecutionContext())      , m_data(new JSCallbackDataStrong(vm, callback, this))  {  } @@ -74,9 +73,9 @@ CallbackResult<typename IDLUndefined::ImplementationType> JSErrorCallback::handl      if (returnedException) {          reportException(&lexicalGlobalObject, returnedException);          return CallbackResultType::ExceptionThrown; -     } +    } -    return { }; +    return {};  }  JSC::JSValue toJS(ErrorCallback& impl) diff --git a/src/javascript/jsc/bindings/webcore/JSErrorEvent.cpp b/src/javascript/jsc/bindings/webcore/JSErrorEvent.cpp index 4f6db111f..be909421c 100644 --- a/src/javascript/jsc/bindings/webcore/JSErrorEvent.cpp +++ b/src/javascript/jsc/bindings/webcore/JSErrorEvent.cpp @@ -66,7 +66,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          bubblesValue = jsUndefined();      else { -        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles")); +        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!bubblesValue.isUndefined()) { @@ -78,7 +78,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          cancelableValue = jsUndefined();      else { -        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable")); +        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!cancelableValue.isUndefined()) { @@ -90,7 +90,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          composedValue = jsUndefined();      else { -        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed")); +        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!composedValue.isUndefined()) { @@ -102,7 +102,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          colnoValue = jsUndefined();      else { -        colnoValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "colno")); +        colnoValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "colno"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!colnoValue.isUndefined()) { @@ -114,7 +114,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          errorValue = jsUndefined();      else { -        errorValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "error")); +        errorValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "error"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!errorValue.isUndefined()) { @@ -126,7 +126,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          filenameValue = jsUndefined();      else { -        filenameValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "filename")); +        filenameValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "filename"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!filenameValue.isUndefined()) { @@ -138,7 +138,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          linenoValue = jsUndefined();      else { -        linenoValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "lineno")); +        linenoValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "lineno"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!linenoValue.isUndefined()) { @@ -150,7 +150,7 @@ template<> ErrorEvent::Init convertDictionary<ErrorEvent::Init>(JSGlobalObject&      if (isNullOrUndefined)          messageValue = jsUndefined();      else { -        messageValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "message")); +        messageValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "message"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!messageValue.isUndefined()) { @@ -213,12 +213,12 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSErrorEventDOMConstructor::c      if (UNLIKELY(callFrame->argumentCount() < 1))          return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));      EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); -    auto type = convert<IDLDOMString>(*lexicalGlobalObject, argument0.value()); +    auto type = convert<IDLAtomStringAdaptor<IDLDOMString>>(*lexicalGlobalObject, argument0.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue());      EnsureStillAliveScope argument1 = callFrame->argument(1);      auto eventInitDict = convert<IDLDictionary<ErrorEvent::Init>>(*lexicalGlobalObject, argument1.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); -    auto object = ErrorEvent::create(WTFMove(type), WTFMove(eventInitDict)); +    auto object = ErrorEvent::create(type, WTFMove(eventInitDict));      if constexpr (IsExceptionOr<decltype(object)>)          RETURN_IF_EXCEPTION(throwScope, {});      static_assert(TypeOrExceptionOrUnderlyingType<decltype(object)>::isRef); @@ -277,7 +277,7 @@ JSErrorEvent::JSErrorEvent(Structure* structure, JSDOMGlobalObject& globalObject  void JSErrorEvent::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, ErrorEvent>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -301,7 +301,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsErrorEventConstructor, (JSGlobalObject * lexicalGloba  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSErrorEventPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSErrorEventPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSErrorEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); diff --git a/src/javascript/jsc/bindings/webcore/JSErrorHandler.cpp b/src/javascript/jsc/bindings/webcore/JSErrorHandler.cpp index 228f247ce..ee5df32b5 100644 --- a/src/javascript/jsc/bindings/webcore/JSErrorHandler.cpp +++ b/src/javascript/jsc/bindings/webcore/JSErrorHandler.cpp @@ -76,12 +76,12 @@ void JSErrorHandler::handleEvent(ScriptExecutionContext& scriptExecutionContext,      if (!globalObject)          return; -    auto callData = getCallData(vm, jsFunction); +    auto callData = getCallData(jsFunction);      if (callData.type != CallData::Type::None) {          Ref<JSErrorHandler> protectedThis(*this);          RefPtr<Event> savedEvent; -        // auto* jsFunctionWindow = jsDynamicCast<JSDOMWindow*>(vm, jsFunction->globalObject()); +        // auto* jsFunctionWindow = jsDynamicCast<JSDOMWindow*>( jsFunction->globalObject());          // if (jsFunctionWindow) {          //     savedEvent = jsFunctionWindow->currentEvent(); diff --git a/src/javascript/jsc/bindings/webcore/JSEvent.cpp b/src/javascript/jsc/bindings/webcore/JSEvent.cpp index 28eb8c389..058298923 100644 --- a/src/javascript/jsc/bindings/webcore/JSEvent.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEvent.cpp @@ -155,7 +155,7 @@ template<> EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSEventDOMConstructor::constr      if (UNLIKELY(callFrame->argumentCount() < 1))          return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));      EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); -    auto type = convert<IDLDOMString>(*lexicalGlobalObject, argument0.value()); +    auto type = convert<IDLAtomStringAdaptor<IDLDOMString>>(*lexicalGlobalObject, argument0.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue());      EnsureStillAliveScope argument1 = callFrame->argument(1);      auto eventInitDict = convert<IDLDictionary<EventInit>>(*lexicalGlobalObject, argument1.value()); @@ -246,7 +246,7 @@ JSEvent::JSEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<Even  void JSEvent::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, Event>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -276,7 +276,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsEventConstructor, (JSGlobalObject * lexicalGlobalObje  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSEventPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSEventPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSEvent::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -560,7 +560,7 @@ static inline JSC::EncodedJSValue jsEventPrototypeFunction_initEventBody(JSC::JS      if (UNLIKELY(callFrame->argumentCount() < 1))          return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));      EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); -    auto type = convert<IDLDOMString>(*lexicalGlobalObject, argument0.value()); +    auto type = convert<IDLAtomStringAdaptor<IDLDOMString>>(*lexicalGlobalObject, argument0.value());      RETURN_IF_EXCEPTION(throwScope, encodedJSValue());      EnsureStillAliveScope argument1 = callFrame->argument(1);      auto bubbles = convert<IDLBoolean>(*lexicalGlobalObject, argument1.value()); @@ -612,7 +612,7 @@ void JSEventOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)  Event* JSEvent::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSEvent*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSEvent*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/JSEventCustom.h b/src/javascript/jsc/bindings/webcore/JSEventCustom.h index 8271b933d..c910848f6 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventCustom.h +++ b/src/javascript/jsc/bindings/webcore/JSEventCustom.h @@ -36,9 +36,9 @@ template<>  struct InheritsTraits<WebCore::JSEvent> {      static constexpr std::optional<JSTypeRange> typeRange { { static_cast<JSType>(WebCore::JSEventType), static_cast<JSType>(WebCore::JSEventType) } };      template<typename From> -    static inline bool inherits(VM& vm, From* from) +    static inline bool inherits(From* from)      { -        return inheritsJSTypeImpl<WebCore::JSEvent>(vm, from, *typeRange); +        return inheritsJSTypeImpl<WebCore::JSEvent>(from, *typeRange);      }  }; diff --git a/src/javascript/jsc/bindings/webcore/JSEventInit.cpp b/src/javascript/jsc/bindings/webcore/JSEventInit.cpp index f7ef28f92..5ec28613e 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventInit.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEventInit.cpp @@ -24,7 +24,6 @@  #include "JSDOMConvertBoolean.h"  #include <JavaScriptCore/JSCInlines.h> -  namespace WebCore {  using namespace JSC; @@ -36,43 +35,43 @@ template<> EventInit convertDictionary<EventInit>(JSGlobalObject& lexicalGlobalO      auto* object = isNullOrUndefined ? nullptr : value.getObject();      if (UNLIKELY(!isNullOrUndefined && !object)) {          throwTypeError(&lexicalGlobalObject, throwScope); -        return { }; +        return {};      }      EventInit result;      JSValue bubblesValue;      if (isNullOrUndefined)          bubblesValue = jsUndefined();      else { -        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!bubblesValue.isUndefined()) {          result.bubbles = convert<IDLBoolean>(lexicalGlobalObject, bubblesValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      } else          result.bubbles = false;      JSValue cancelableValue;      if (isNullOrUndefined)          cancelableValue = jsUndefined();      else { -        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!cancelableValue.isUndefined()) {          result.cancelable = convert<IDLBoolean>(lexicalGlobalObject, cancelableValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      } else          result.cancelable = false;      JSValue composedValue;      if (isNullOrUndefined)          composedValue = jsUndefined();      else { -        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!composedValue.isUndefined()) {          result.composed = convert<IDLBoolean>(lexicalGlobalObject, composedValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      } else          result.composed = false;      return result; diff --git a/src/javascript/jsc/bindings/webcore/JSEventListener.cpp b/src/javascript/jsc/bindings/webcore/JSEventListener.cpp index 244ee934f..3d6be9cd0 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventListener.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEventListener.cpp @@ -179,14 +179,14 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext      JSValue handleEventFunction = jsFunction; -    auto callData = getCallData(vm, handleEventFunction); +    auto callData = getCallData(handleEventFunction);      // If jsFunction is not actually a function and this is an EventListener, see if it implements callback interface.      if (callData.type == CallData::Type::None) {          if (m_isAttribute)              return; -        handleEventFunction = jsFunction->get(lexicalGlobalObject, Identifier::fromString(vm, "handleEvent")); +        handleEventFunction = jsFunction->get(lexicalGlobalObject, Identifier::fromString(vm, "handleEvent"_s));          if (UNLIKELY(scope.exception())) {              auto* exception = scope.exception();              scope.clearException(); @@ -194,7 +194,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext              reportException(lexicalGlobalObject, exception);              return;          } -        callData = getCallData(vm, handleEventFunction); +        callData = getCallData(handleEventFunction);          if (callData.type == CallData::Type::None) {              event.target()->uncaughtExceptionInEventHandler();              reportException(lexicalGlobalObject, createTypeError(lexicalGlobalObject, "'handleEvent' property of event listener should be callable"_s)); @@ -277,7 +277,7 @@ String JSEventListener::functionName() const      auto& vm = isolatedWorld().vm();      JSC::JSLockHolder lock(vm); -    auto* handlerFunction = JSC::jsDynamicCast<JSC::JSFunction*>(vm, m_jsFunction.get()); +    auto* handlerFunction = JSC::jsDynamicCast<JSC::JSFunction*>(m_jsFunction.get());      if (!handlerFunction)          return {}; diff --git a/src/javascript/jsc/bindings/webcore/JSEventListenerOptions.cpp b/src/javascript/jsc/bindings/webcore/JSEventListenerOptions.cpp index 72c01abd0..a1e6fb69f 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventListenerOptions.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEventListenerOptions.cpp @@ -24,7 +24,6 @@  #include "JSDOMConvertBoolean.h"  #include <JavaScriptCore/JSCInlines.h> -  namespace WebCore {  using namespace JSC; @@ -36,19 +35,19 @@ template<> EventListenerOptions convertDictionary<EventListenerOptions>(JSGlobal      auto* object = isNullOrUndefined ? nullptr : value.getObject();      if (UNLIKELY(!isNullOrUndefined && !object)) {          throwTypeError(&lexicalGlobalObject, throwScope); -        return { }; +        return {};      }      EventListenerOptions result;      JSValue captureValue;      if (isNullOrUndefined)          captureValue = jsUndefined();      else { -        captureValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "capture")); -        RETURN_IF_EXCEPTION(throwScope, { }); +        captureValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "capture"_s)); +        RETURN_IF_EXCEPTION(throwScope, {});      }      if (!captureValue.isUndefined()) {          result.capture = convert<IDLBoolean>(lexicalGlobalObject, captureValue); -        RETURN_IF_EXCEPTION(throwScope, { }); +        RETURN_IF_EXCEPTION(throwScope, {});      } else          result.capture = false;      return result; diff --git a/src/javascript/jsc/bindings/webcore/JSEventModifierInit.cpp b/src/javascript/jsc/bindings/webcore/JSEventModifierInit.cpp index 53fd87c95..0e9d2c804 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventModifierInit.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEventModifierInit.cpp @@ -46,7 +46,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          bubblesValue = jsUndefined();      else { -        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles")); +        bubblesValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "bubbles"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!bubblesValue.isUndefined()) { @@ -58,7 +58,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          cancelableValue = jsUndefined();      else { -        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable")); +        cancelableValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "cancelable"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!cancelableValue.isUndefined()) { @@ -70,7 +70,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          composedValue = jsUndefined();      else { -        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed")); +        composedValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "composed"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!composedValue.isUndefined()) { @@ -82,7 +82,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          detailValue = jsUndefined();      else { -        detailValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "detail")); +        detailValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "detail"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!detailValue.isUndefined()) { @@ -94,7 +94,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          viewValue = jsUndefined();      else { -        viewValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "view")); +        viewValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "view"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      // if (!viewValue.isUndefined()) { @@ -106,7 +106,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          altKeyValue = jsUndefined();      else { -        altKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "altKey")); +        altKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "altKey"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!altKeyValue.isUndefined()) { @@ -118,7 +118,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          ctrlKeyValue = jsUndefined();      else { -        ctrlKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "ctrlKey")); +        ctrlKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "ctrlKey"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!ctrlKeyValue.isUndefined()) { @@ -130,7 +130,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          metaKeyValue = jsUndefined();      else { -        metaKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "metaKey")); +        metaKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "metaKey"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!metaKeyValue.isUndefined()) { @@ -142,7 +142,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          modifierAltGraphValue = jsUndefined();      else { -        modifierAltGraphValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "modifierAltGraph")); +        modifierAltGraphValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "modifierAltGraph"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!modifierAltGraphValue.isUndefined()) { @@ -154,7 +154,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          modifierCapsLockValue = jsUndefined();      else { -        modifierCapsLockValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "modifierCapsLock")); +        modifierCapsLockValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "modifierCapsLock"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!modifierCapsLockValue.isUndefined()) { @@ -166,7 +166,7 @@ template<> EventModifierInit convertDictionary<EventModifierInit>(JSGlobalObject      if (isNullOrUndefined)          shiftKeyValue = jsUndefined();      else { -        shiftKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "shiftKey")); +        shiftKeyValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "shiftKey"_s));          RETURN_IF_EXCEPTION(throwScope, {});      }      if (!shiftKeyValue.isUndefined()) { diff --git a/src/javascript/jsc/bindings/webcore/JSEventTarget.cpp b/src/javascript/jsc/bindings/webcore/JSEventTarget.cpp index 705e020c3..fb5a35a48 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventTarget.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEventTarget.cpp @@ -173,7 +173,7 @@ JSEventTarget::JSEventTarget(Structure* structure, JSDOMGlobalObject& globalObje  void JSEventTarget::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, EventTarget>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -203,7 +203,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsEventTargetConstructor, (JSGlobalObject * lexicalGlob  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSEventTargetPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSEventTargetPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSEventTarget::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); diff --git a/src/javascript/jsc/bindings/webcore/JSEventTargetCustom.cpp b/src/javascript/jsc/bindings/webcore/JSEventTargetCustom.cpp index cc63b0c0c..3b24d0a8a 100644 --- a/src/javascript/jsc/bindings/webcore/JSEventTargetCustom.cpp +++ b/src/javascript/jsc/bindings/webcore/JSEventTargetCustom.cpp @@ -51,20 +51,20 @@ JSValue toJSNewlyCreated(JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<E  EventTarget* JSEventTarget::toWrapped(VM& vm, JSValue value)  { -    // if (value.inherits<JSWindowProxy>(vm)) +    // if (value.inherits<JSWindowProxy>())      //     return &jsCast<JSWindowProxy*>(asObject(value))->wrapped(); -    // if (value.inherits<JSDOMWindow>(vm)) +    // if (value.inherits<JSDOMWindow>())      //     return &jsCast<JSDOMWindow*>(asObject(value))->wrapped(); -    // if (value.inherits<JSWorkerGlobalScope>(vm)) +    // if (value.inherits<JSWorkerGlobalScope>())      //     return &jsCast<JSWorkerGlobalScope*>(asObject(value))->wrapped(); -    if (value.inherits<JSEventTarget>(vm)) +    if (value.inherits<JSEventTarget>())          return &jsCast<JSEventTarget*>(asObject(value))->wrapped();      return nullptr;  }  std::unique_ptr<JSEventTargetWrapper> jsEventTargetCast(VM& vm, JSValue thisValue)  { -    if (auto* target = jsDynamicCast<JSEventTarget*>(vm, thisValue)) +    if (auto* target = jsDynamicCast<JSEventTarget*>(thisValue))          return makeUnique<JSEventTargetWrapper>(target->wrapped(), *target);      // if (auto* window = toJSDOMGlobalObject<JSDOMWindow>(vm, thisValue))      //     return makeUnique<JSEventTargetWrapper>(window->wrapped(), *window); diff --git a/src/javascript/jsc/bindings/webcore/JSFetchHeaders.cpp b/src/javascript/jsc/bindings/webcore/JSFetchHeaders.cpp index 91d79388b..9ac6cd9f8 100644 --- a/src/javascript/jsc/bindings/webcore/JSFetchHeaders.cpp +++ b/src/javascript/jsc/bindings/webcore/JSFetchHeaders.cpp @@ -183,7 +183,7 @@ JSFetchHeaders::JSFetchHeaders(Structure* structure, JSDOMGlobalObject& globalOb  void JSFetchHeaders::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, FetchHeaders>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -213,7 +213,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsFetchHeadersConstructor, (JSGlobalObject * lexicalGlo  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSFetchHeadersPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSFetchHeadersPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSFetchHeaders::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -494,7 +494,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  FetchHeaders* JSFetchHeaders::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSFetchHeaders*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSFetchHeaders*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp index 29aea6d1b..038731371 100644 --- a/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp +++ b/src/javascript/jsc/bindings/webcore/JSURLSearchParams.cpp @@ -190,7 +190,7 @@ JSURLSearchParams::JSURLSearchParams(Structure* structure, JSDOMGlobalObject& gl  void JSURLSearchParams::finishCreation(VM& vm)  {      Base::finishCreation(vm); -    ASSERT(inherits(vm, info())); +    ASSERT(inherits(info()));      // static_assert(!std::is_base_of<ActiveDOMObject, URLSearchParams>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");  } @@ -220,7 +220,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsURLSearchParamsConstructor, (JSGlobalObject * lexical  {      VM& vm = JSC::getVM(lexicalGlobalObject);      auto throwScope = DECLARE_THROW_SCOPE(vm); -    auto* prototype = jsDynamicCast<JSURLSearchParamsPrototype*>(vm, JSValue::decode(thisValue)); +    auto* prototype = jsDynamicCast<JSURLSearchParamsPrototype*>(JSValue::decode(thisValue));      if (UNLIKELY(!prototype))          return throwVMTypeError(lexicalGlobalObject, throwScope);      return JSValue::encode(JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), prototype->globalObject())); @@ -551,7 +551,7 @@ JSC::JSValue toJS(JSC::JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* g  URLSearchParams* JSURLSearchParams::toWrapped(JSC::VM& vm, JSC::JSValue value)  { -    if (auto* wrapper = jsDynamicCast<JSURLSearchParams*>(vm, value)) +    if (auto* wrapper = jsDynamicCast<JSURLSearchParams*>(value))          return &wrapper->wrapped();      return nullptr;  } diff --git a/src/javascript/jsc/bindings/webcore/ParsedContentType.cpp b/src/javascript/jsc/bindings/webcore/ParsedContentType.cpp index 9ef2a1720..04b30cf9b 100644 --- a/src/javascript/jsc/bindings/webcore/ParsedContentType.cpp +++ b/src/javascript/jsc/bindings/webcore/ParsedContentType.cpp @@ -1,4 +1,4 @@ - /* +/*   * Copyright (C) 2011 Google Inc. All rights reserved.   * Copyright (C) 2012 Intel Corporation. All rights reserved.   * @@ -114,7 +114,6 @@ static String collectHTTPQuotedString(StringView input, unsigned& startIndex)              ASSERT(quoteOrBackslash == '"');              break;          } -      }      return builder.toString();  } @@ -232,7 +231,7 @@ bool ParsedContentType::parseContentType(Mode mode)      unsigned index = 0;      unsigned contentTypeLength = m_contentType.length();      skipSpaces(m_contentType, index); -    if (index >= contentTypeLength)  { +    if (index >= contentTypeLength) {          LOG_ERROR("Invalid Content-Type string '%s'", m_contentType.ascii().data());          return false;      } @@ -347,7 +346,7 @@ ParsedContentType::ParsedContentType(const String& contentType)  String ParsedContentType::charset() const  { -    return parameterValueForName("charset"); +    return parameterValueForName("charset"_s);  }  void ParsedContentType::setCharset(String&& charset) @@ -365,11 +364,11 @@ size_t ParsedContentType::parameterCount() const      return m_parameterValues.size();  } -void ParsedContentType::setContentType(StringView contentRange, Mode mode) +void ParsedContentType::setContentType(String&& contentRange, Mode mode)  { -    m_mimeType = contentRange.toString(); +    m_mimeType = WTFMove(contentRange);      if (mode == Mode::MimeSniff) -        m_mimeType = stripLeadingAndTrailingHTTPSpaces(m_mimeType).convertToASCIILowercase(); +        m_mimeType = stripLeadingAndTrailingHTTPSpaces(StringView(m_mimeType)).convertToASCIILowercase();      else          m_mimeType = m_mimeType.stripWhiteSpace();  } @@ -408,7 +407,7 @@ String ParsedContentType::serialize() const              builder.append('"');              for (unsigned index = 0; index < value.length(); ++index) {                  auto ch = value[index]; -                if (ch == '\\' || ch =='"') +                if (ch == '\\' || ch == '"')                      builder.append('\\');                  builder.append(ch);              } @@ -419,4 +418,4 @@ String ParsedContentType::serialize() const      return builder.toString();  } -} +}
\ No newline at end of file diff --git a/src/javascript/jsc/bindings/webcore/ParsedContentType.h b/src/javascript/jsc/bindings/webcore/ParsedContentType.h index d22b97252..03837e6d9 100644 --- a/src/javascript/jsc/bindings/webcore/ParsedContentType.h +++ b/src/javascript/jsc/bindings/webcore/ParsedContentType.h @@ -63,7 +63,7 @@ private:      ParsedContentType(const ParsedContentType&) = delete;      ParsedContentType& operator=(ParsedContentType const&) = delete;      bool parseContentType(Mode); -    void setContentType(StringView, Mode); +    void setContentType(String&&, Mode);      void setContentTypeParameter(const String&, const String&, Mode);      typedef HashMap<String, String> KeyValuePairs; @@ -73,4 +73,4 @@ private:      String m_mimeType;  }; -} +}
\ No newline at end of file | 
