@@ -2137,14 +2137,22 @@ static void CRC32(const FunctionCallbackInfo<Value>& args) { |
2137 | 2137 | args.GetReturnValue().Set(CRC32Impl(args.GetIsolate(), args[0], value)); |
2138 | 2138 | } |
2139 | 2139 |
|
| 2140 | +// Strings use CRC32 above: the fast API path must not flatten them. |
| 2141 | +static void CRC32Buffer(const FunctionCallbackInfo<Value>& args) { |
| 2142 | + CHECK(args[0]->IsArrayBufferView()); |
| 2143 | + CHECK(args[1]->IsUint32()); |
| 2144 | + uint32_t value = args[1].As<v8::Uint32>()->Value(); |
| 2145 | + args.GetReturnValue().Set(CRC32Impl(args.GetIsolate(), args[0], value)); |
| 2146 | +} |
| 2147 | + |
2140 | 2148 | static uint32_t FastCRC32(v8::Local<v8::Value> receiver, |
2141 | 2149 | v8::Local<v8::Value> data, |
2142 | 2150 | uint32_t value, |
2143 | 2151 | // NOLINTNEXTLINE(runtime/references) |
2144 | 2152 | v8::FastApiCallbackOptions& options) { |
2145 | 2153 | TRACK_V8_FAST_API_CALL("zlib.crc32"); |
2146 | 2154 | v8::HandleScope handle_scope(options.isolate); |
2147 | | - CHECK(data->IsArrayBufferView() || data->IsString()); |
| 2155 | + CHECK(data->IsArrayBufferView()); |
2148 | 2156 | return CRC32Impl(options.isolate, data, value); |
2149 | 2157 | } |
2150 | 2158 |
|
@@ -2167,14 +2175,21 @@ static void CRC32C(const FunctionCallbackInfo<Value>& args) { |
2167 | 2175 | args.GetReturnValue().Set(CRC32CImpl(args.GetIsolate(), args[0], value)); |
2168 | 2176 | } |
2169 | 2177 |
|
| 2178 | +static void CRC32CBuffer(const FunctionCallbackInfo<Value>& args) { |
| 2179 | + CHECK(args[0]->IsArrayBufferView()); |
| 2180 | + CHECK(args[1]->IsUint32()); |
| 2181 | + uint32_t value = args[1].As<v8::Uint32>()->Value(); |
| 2182 | + args.GetReturnValue().Set(CRC32CImpl(args.GetIsolate(), args[0], value)); |
| 2183 | +} |
| 2184 | + |
2170 | 2185 | static uint32_t FastCRC32C(v8::Local<v8::Value> receiver, |
2171 | 2186 | v8::Local<v8::Value> data, |
2172 | 2187 | uint32_t value, |
2173 | 2188 | // NOLINTNEXTLINE(runtime/references) |
2174 | 2189 | v8::FastApiCallbackOptions& options) { |
2175 | 2190 | TRACK_V8_FAST_API_CALL("zlib.crc32c"); |
2176 | 2191 | v8::HandleScope handle_scope(options.isolate); |
2177 | | - CHECK(data->IsArrayBufferView() || data->IsString()); |
| 2192 | + CHECK(data->IsArrayBufferView()); |
2178 | 2193 | return CRC32CImpl(options.isolate, data, value); |
2179 | 2194 | } |
2180 | 2195 |
|
@@ -2192,8 +2207,12 @@ void Initialize(Local<Object> target, |
2192 | 2207 | MakeClass<ZstdCompressStream>::Make(env, target, "ZstdCompress"); |
2193 | 2208 | MakeClass<ZstdDecompressStream>::Make(env, target, "ZstdDecompress"); |
2194 | 2209 |
|
2195 | | - SetFastMethodNoSideEffect(context, target, "crc32", CRC32, &fast_crc32_); |
2196 | | - SetFastMethodNoSideEffect(context, target, "crc32c", CRC32C, &fast_crc32c_); |
| 2210 | + SetMethodNoSideEffect(context, target, "crc32", CRC32); |
| 2211 | + SetMethodNoSideEffect(context, target, "crc32c", CRC32C); |
| 2212 | + SetFastMethodNoSideEffect( |
| 2213 | + context, target, "crc32Buffer", CRC32Buffer, &fast_crc32_); |
| 2214 | + SetFastMethodNoSideEffect( |
| 2215 | + context, target, "crc32cBuffer", CRC32CBuffer, &fast_crc32c_); |
2197 | 2216 | target->Set(env->context(), |
2198 | 2217 | FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"), |
2199 | 2218 | FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION)).Check(); |
@@ -2206,8 +2225,10 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { |
2206 | 2225 | MakeClass<ZstdCompressStream>::Make(registry); |
2207 | 2226 | MakeClass<ZstdDecompressStream>::Make(registry); |
2208 | 2227 | registry->Register(CRC32); |
| 2228 | + registry->Register(CRC32Buffer); |
2209 | 2229 | registry->Register(fast_crc32_); |
2210 | 2230 | registry->Register(CRC32C); |
| 2231 | + registry->Register(CRC32CBuffer); |
2211 | 2232 | registry->Register(fast_crc32c_); |
2212 | 2233 | } |
2213 | 2234 |
|
|