|
35 | 35 | #include "builtins/compression-stream.h"
|
36 | 36 | #include "builtins/console.h"
|
37 | 37 | #include "builtins/decompression-stream.h"
|
| 38 | +#include "builtins/dictionary.h" |
38 | 39 | #include "builtins/env.h"
|
39 | 40 | #include "builtins/fastly.h"
|
40 | 41 | #include "builtins/logger.h"
|
@@ -2491,73 +2492,6 @@ JSObject *create(JSContext *cx, HandleObject response, ResponseHandle response_h
|
2491 | 2492 | }
|
2492 | 2493 | } // namespace Response
|
2493 | 2494 |
|
2494 |
| -namespace Dictionary { |
2495 |
| -namespace Slots { |
2496 |
| -enum { Dictionary, Count }; |
2497 |
| -}; |
2498 |
| - |
2499 |
| -DictionaryHandle dictionary_handle(JSObject *obj) { |
2500 |
| - JS::Value val = JS::GetReservedSlot(obj, Slots::Dictionary); |
2501 |
| - return DictionaryHandle{static_cast<uint32_t>(val.toInt32())}; |
2502 |
| -} |
2503 |
| - |
2504 |
| -const unsigned ctor_length = 1; |
2505 |
| - |
2506 |
| -bool check_receiver(JSContext *cx, HandleValue receiver, const char *method_name); |
2507 |
| - |
2508 |
| -bool get(JSContext *cx, unsigned argc, Value *vp) { |
2509 |
| - METHOD_HEADER(1) |
2510 |
| - |
2511 |
| - size_t name_len; |
2512 |
| - UniqueChars name = encode(cx, args[0], &name_len); |
2513 |
| - |
2514 |
| - OwnedHostCallBuffer buffer; |
2515 |
| - size_t nwritten = 0; |
2516 |
| - int status = xqd_dictionary_get(dictionary_handle(self), name.get(), name_len, buffer.get(), |
2517 |
| - DICTIONARY_ENTRY_MAX_LEN, &nwritten); |
2518 |
| - // Status code 10 indicates the key wasn't found, so we return null. |
2519 |
| - if (status == 10) { |
2520 |
| - args.rval().setNull(); |
2521 |
| - return true; |
2522 |
| - } |
2523 |
| - |
2524 |
| - // Ensure that we throw an exception for all unexpected host errors. |
2525 |
| - if (!HANDLE_RESULT(cx, status)) |
2526 |
| - return false; |
2527 |
| - |
2528 |
| - RootedString text(cx, JS_NewStringCopyUTF8N(cx, JS::UTF8Chars(buffer.get(), nwritten))); |
2529 |
| - if (!text) |
2530 |
| - return false; |
2531 |
| - |
2532 |
| - args.rval().setString(text); |
2533 |
| - return true; |
2534 |
| -} |
2535 |
| - |
2536 |
| -const JSFunctionSpec methods[] = {JS_FN("get", get, 1, JSPROP_ENUMERATE), JS_FS_END}; |
2537 |
| - |
2538 |
| -const JSPropertySpec properties[] = {JS_PS_END}; |
2539 |
| -bool constructor(JSContext *cx, unsigned argc, Value *vp); |
2540 |
| -CLASS_BOILERPLATE(Dictionary) |
2541 |
| - |
2542 |
| -bool constructor(JSContext *cx, unsigned argc, Value *vp) { |
2543 |
| - REQUEST_HANDLER_ONLY("The Dictionary builtin"); |
2544 |
| - CTOR_HEADER("Dictionary", 1); |
2545 |
| - |
2546 |
| - size_t name_len; |
2547 |
| - UniqueChars name = encode(cx, args[0], &name_len); |
2548 |
| - RootedObject dictionary(cx, JS_NewObjectForConstructor(cx, &class_, args)); |
2549 |
| - DictionaryHandle dict_handle = {INVALID_HANDLE}; |
2550 |
| - if (!HANDLE_RESULT(cx, xqd_dictionary_open(name.get(), name_len, &dict_handle))) |
2551 |
| - return false; |
2552 |
| - |
2553 |
| - JS::SetReservedSlot(dictionary, Slots::Dictionary, JS::Int32Value((int)dict_handle.handle)); |
2554 |
| - if (!dictionary) |
2555 |
| - return false; |
2556 |
| - args.rval().setObject(*dictionary); |
2557 |
| - return true; |
2558 |
| -} |
2559 |
| -} // namespace Dictionary |
2560 |
| - |
2561 | 2495 | namespace TextEncoder {
|
2562 | 2496 | namespace Slots {
|
2563 | 2497 | enum { Count };
|
@@ -5032,7 +4966,7 @@ bool define_fastly_sys(JSContext *cx, HandleObject global) {
|
5032 | 4966 | return false;
|
5033 | 4967 | if (!Response::init_class(cx, global))
|
5034 | 4968 | return false;
|
5035 |
| - if (!Dictionary::init_class(cx, global)) |
| 4969 | + if (!builtins::Dictionary::init_class(cx, global)) |
5036 | 4970 | return false;
|
5037 | 4971 | if (!Headers::init_class(cx, global))
|
5038 | 4972 | return false;
|
|
0 commit comments