| 1 | /* |
| 2 | * Copyright (C) 2014-2016 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "ConsoleObject.h" |
| 28 | |
| 29 | #include "ConsoleClient.h" |
| 30 | #include "Error.h" |
| 31 | #include "JSCInlines.h" |
| 32 | #include "ScriptArguments.h" |
| 33 | #include "ScriptCallStackFactory.h" |
| 34 | |
| 35 | namespace JSC { |
| 36 | |
| 37 | static String valueOrDefaultLabelString(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 38 | { |
| 39 | if (callFrame->argumentCount() < 1) |
| 40 | return "default"_s ; |
| 41 | |
| 42 | auto value = callFrame->argument(0); |
| 43 | if (value.isUndefined()) |
| 44 | return "default"_s ; |
| 45 | |
| 46 | return value.toWTFString(globalObject); |
| 47 | } |
| 48 | |
| 49 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ConsoleObject); |
| 50 | |
| 51 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncDebug(JSGlobalObject*, CallFrame*); |
| 52 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncError(JSGlobalObject*, CallFrame*); |
| 53 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncLog(JSGlobalObject*, CallFrame*); |
| 54 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncInfo(JSGlobalObject*, CallFrame*); |
| 55 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncWarn(JSGlobalObject*, CallFrame*); |
| 56 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncClear(JSGlobalObject*, CallFrame*); |
| 57 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncDir(JSGlobalObject*, CallFrame*); |
| 58 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncDirXML(JSGlobalObject*, CallFrame*); |
| 59 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTable(JSGlobalObject*, CallFrame*); |
| 60 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTrace(JSGlobalObject*, CallFrame*); |
| 61 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncAssert(JSGlobalObject*, CallFrame*); |
| 62 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCount(JSGlobalObject*, CallFrame*); |
| 63 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCountReset(JSGlobalObject*, CallFrame*); |
| 64 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfile(JSGlobalObject*, CallFrame*); |
| 65 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfileEnd(JSGlobalObject*, CallFrame*); |
| 66 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTakeHeapSnapshot(JSGlobalObject*, CallFrame*); |
| 67 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTime(JSGlobalObject*, CallFrame*); |
| 68 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeLog(JSGlobalObject*, CallFrame*); |
| 69 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeEnd(JSGlobalObject*, CallFrame*); |
| 70 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeStamp(JSGlobalObject*, CallFrame*); |
| 71 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroup(JSGlobalObject*, CallFrame*); |
| 72 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroupCollapsed(JSGlobalObject*, CallFrame*); |
| 73 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroupEnd(JSGlobalObject*, CallFrame*); |
| 74 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncRecord(JSGlobalObject*, CallFrame*); |
| 75 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncRecordEnd(JSGlobalObject*, CallFrame*); |
| 76 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncScreenshot(JSGlobalObject*, CallFrame*); |
| 77 | |
| 78 | const ClassInfo ConsoleObject::s_info = { "Console" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(ConsoleObject) }; |
| 79 | |
| 80 | ConsoleObject::ConsoleObject(VM& vm, Structure* structure) |
| 81 | : JSNonFinalObject(vm, structure) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | void ConsoleObject::finishCreation(VM& vm, JSGlobalObject* globalObject) |
| 86 | { |
| 87 | Base::finishCreation(vm); |
| 88 | ASSERT(inherits(vm, info())); |
| 89 | |
| 90 | // For legacy reasons, console properties are enumerable, writable, deleteable, |
| 91 | // and all have a length of 0. This may change if Console is standardized. |
| 92 | |
| 93 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("debug" , consoleProtoFuncDebug, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 94 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("error" , consoleProtoFuncError, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 95 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("log" , consoleProtoFuncLog, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 96 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("info" , consoleProtoFuncInfo, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 97 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("warn" , consoleProtoFuncWarn, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 98 | |
| 99 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->clear, consoleProtoFuncClear, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 100 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("dir" , consoleProtoFuncDir, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 101 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("dirxml" , consoleProtoFuncDirXML, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 102 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("table" , consoleProtoFuncTable, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 103 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("trace" , consoleProtoFuncTrace, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 104 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("assert" , consoleProtoFuncAssert, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 105 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->count, consoleProtoFuncCount, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 106 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("countReset" , consoleProtoFuncCountReset, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 107 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("profile" , consoleProtoFuncProfile, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 108 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("profileEnd" , consoleProtoFuncProfileEnd, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 109 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("time" , consoleProtoFuncTime, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 110 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("timeLog" , consoleProtoFuncTimeLog, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 111 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("timeEnd" , consoleProtoFuncTimeEnd, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 112 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("timeStamp" , consoleProtoFuncTimeStamp, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 113 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("takeHeapSnapshot" , consoleProtoFuncTakeHeapSnapshot, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 114 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("group" , consoleProtoFuncGroup, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 115 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("groupCollapsed" , consoleProtoFuncGroupCollapsed, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 116 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("groupEnd" , consoleProtoFuncGroupEnd, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 117 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("record" , consoleProtoFuncRecord, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 118 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("recordEnd" , consoleProtoFuncRecordEnd, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 119 | JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("screenshot" , consoleProtoFuncScreenshot, static_cast<unsigned>(PropertyAttribute::None), 0); |
| 120 | } |
| 121 | |
| 122 | static String valueToStringWithUndefinedOrNullCheck(JSGlobalObject* globalObject, JSValue value) |
| 123 | { |
| 124 | if (value.isUndefinedOrNull()) |
| 125 | return String(); |
| 126 | return value.toWTFString(globalObject); |
| 127 | } |
| 128 | |
| 129 | static EncodedJSValue consoleLogWithLevel(JSGlobalObject* globalObject, CallFrame* callFrame, MessageLevel level) |
| 130 | { |
| 131 | ConsoleClient* client = globalObject->consoleClient(); |
| 132 | if (!client) |
| 133 | return JSValue::encode(jsUndefined()); |
| 134 | |
| 135 | client->logWithLevel(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0), level); |
| 136 | return JSValue::encode(jsUndefined()); |
| 137 | } |
| 138 | |
| 139 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncDebug(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 140 | { |
| 141 | return consoleLogWithLevel(globalObject, callFrame, MessageLevel::Debug); |
| 142 | } |
| 143 | |
| 144 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncError(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 145 | { |
| 146 | return consoleLogWithLevel(globalObject, callFrame, MessageLevel::Error); |
| 147 | } |
| 148 | |
| 149 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncLog(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 150 | { |
| 151 | return consoleLogWithLevel(globalObject, callFrame, MessageLevel::Log); |
| 152 | } |
| 153 | |
| 154 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncInfo(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 155 | { |
| 156 | return consoleLogWithLevel(globalObject, callFrame, MessageLevel::Info); |
| 157 | } |
| 158 | |
| 159 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncWarn(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 160 | { |
| 161 | return consoleLogWithLevel(globalObject, callFrame, MessageLevel::Warning); |
| 162 | } |
| 163 | |
| 164 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncClear(JSGlobalObject* globalObject, CallFrame*) |
| 165 | { |
| 166 | ConsoleClient* client = globalObject->consoleClient(); |
| 167 | if (!client) |
| 168 | return JSValue::encode(jsUndefined()); |
| 169 | |
| 170 | client->clear(globalObject); |
| 171 | return JSValue::encode(jsUndefined()); |
| 172 | } |
| 173 | |
| 174 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncDir(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 175 | { |
| 176 | ConsoleClient* client = globalObject->consoleClient(); |
| 177 | if (!client) |
| 178 | return JSValue::encode(jsUndefined()); |
| 179 | |
| 180 | client->dir(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 181 | return JSValue::encode(jsUndefined()); |
| 182 | } |
| 183 | |
| 184 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncDirXML(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 185 | { |
| 186 | ConsoleClient* client = globalObject->consoleClient(); |
| 187 | if (!client) |
| 188 | return JSValue::encode(jsUndefined()); |
| 189 | |
| 190 | client->dirXML(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 191 | return JSValue::encode(jsUndefined()); |
| 192 | } |
| 193 | |
| 194 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTable(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 195 | { |
| 196 | ConsoleClient* client = globalObject->consoleClient(); |
| 197 | if (!client) |
| 198 | return JSValue::encode(jsUndefined()); |
| 199 | |
| 200 | client->table(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 201 | return JSValue::encode(jsUndefined()); |
| 202 | } |
| 203 | |
| 204 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTrace(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 205 | { |
| 206 | ConsoleClient* client = globalObject->consoleClient(); |
| 207 | if (!client) |
| 208 | return JSValue::encode(jsUndefined()); |
| 209 | |
| 210 | client->trace(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 211 | return JSValue::encode(jsUndefined()); |
| 212 | } |
| 213 | |
| 214 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncAssert(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 215 | { |
| 216 | VM& vm = globalObject->vm(); |
| 217 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 218 | ConsoleClient* client = globalObject->consoleClient(); |
| 219 | if (!client) |
| 220 | return JSValue::encode(jsUndefined()); |
| 221 | |
| 222 | bool condition = callFrame->argument(0).toBoolean(globalObject); |
| 223 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 224 | |
| 225 | if (condition) |
| 226 | return JSValue::encode(jsUndefined()); |
| 227 | |
| 228 | client->assertion(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 1)); |
| 229 | return JSValue::encode(jsUndefined()); |
| 230 | } |
| 231 | |
| 232 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCount(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 233 | { |
| 234 | auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); |
| 235 | auto* client = globalObject->consoleClient(); |
| 236 | if (!client) |
| 237 | return JSValue::encode(jsUndefined()); |
| 238 | |
| 239 | auto label = valueOrDefaultLabelString(globalObject, callFrame); |
| 240 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 241 | |
| 242 | client->count(globalObject, label); |
| 243 | return JSValue::encode(jsUndefined()); |
| 244 | } |
| 245 | |
| 246 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncCountReset(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 247 | { |
| 248 | auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); |
| 249 | auto* client = globalObject->consoleClient(); |
| 250 | if (!client) |
| 251 | return JSValue::encode(jsUndefined()); |
| 252 | |
| 253 | auto label = valueOrDefaultLabelString(globalObject, callFrame); |
| 254 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 255 | |
| 256 | client->countReset(globalObject, label); |
| 257 | return JSValue::encode(jsUndefined()); |
| 258 | } |
| 259 | |
| 260 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfile(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 261 | { |
| 262 | VM& vm = globalObject->vm(); |
| 263 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 264 | ConsoleClient* client = globalObject->consoleClient(); |
| 265 | if (!client) |
| 266 | return JSValue::encode(jsUndefined()); |
| 267 | |
| 268 | size_t argsCount = callFrame->argumentCount(); |
| 269 | if (!argsCount) { |
| 270 | client->profile(globalObject, String()); |
| 271 | return JSValue::encode(jsUndefined()); |
| 272 | } |
| 273 | |
| 274 | const String& title(valueToStringWithUndefinedOrNullCheck(globalObject, callFrame->argument(0))); |
| 275 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 276 | |
| 277 | client->profile(globalObject, title); |
| 278 | return JSValue::encode(jsUndefined()); |
| 279 | } |
| 280 | |
| 281 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncProfileEnd(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 282 | { |
| 283 | VM& vm = globalObject->vm(); |
| 284 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 285 | ConsoleClient* client = globalObject->consoleClient(); |
| 286 | if (!client) |
| 287 | return JSValue::encode(jsUndefined()); |
| 288 | |
| 289 | size_t argsCount = callFrame->argumentCount(); |
| 290 | if (!argsCount) { |
| 291 | client->profileEnd(globalObject, String()); |
| 292 | return JSValue::encode(jsUndefined()); |
| 293 | } |
| 294 | |
| 295 | const String& title(valueToStringWithUndefinedOrNullCheck(globalObject, callFrame->argument(0))); |
| 296 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 297 | |
| 298 | client->profileEnd(globalObject, title); |
| 299 | return JSValue::encode(jsUndefined()); |
| 300 | } |
| 301 | |
| 302 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTakeHeapSnapshot(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 303 | { |
| 304 | VM& vm = globalObject->vm(); |
| 305 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 306 | ConsoleClient* client = globalObject->consoleClient(); |
| 307 | if (!client) |
| 308 | return JSValue::encode(jsUndefined()); |
| 309 | |
| 310 | size_t argsCount = callFrame->argumentCount(); |
| 311 | if (!argsCount) { |
| 312 | client->takeHeapSnapshot(globalObject, String()); |
| 313 | return JSValue::encode(jsUndefined()); |
| 314 | } |
| 315 | |
| 316 | const String& title(valueToStringWithUndefinedOrNullCheck(globalObject, callFrame->argument(0))); |
| 317 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 318 | |
| 319 | client->takeHeapSnapshot(globalObject, title); |
| 320 | return JSValue::encode(jsUndefined()); |
| 321 | } |
| 322 | |
| 323 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTime(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 324 | { |
| 325 | auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); |
| 326 | auto* client = globalObject->consoleClient(); |
| 327 | if (!client) |
| 328 | return JSValue::encode(jsUndefined()); |
| 329 | |
| 330 | auto label = valueOrDefaultLabelString(globalObject, callFrame); |
| 331 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 332 | |
| 333 | client->time(globalObject, label); |
| 334 | return JSValue::encode(jsUndefined()); |
| 335 | } |
| 336 | |
| 337 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeLog(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 338 | { |
| 339 | auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); |
| 340 | auto* client = globalObject->consoleClient(); |
| 341 | if (!client) |
| 342 | return JSValue::encode(jsUndefined()); |
| 343 | |
| 344 | auto label = valueOrDefaultLabelString(globalObject, callFrame); |
| 345 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 346 | |
| 347 | client->timeLog(globalObject, label, Inspector::createScriptArguments(globalObject, callFrame, 1)); |
| 348 | return JSValue::encode(jsUndefined()); |
| 349 | } |
| 350 | |
| 351 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeEnd(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 352 | { |
| 353 | auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); |
| 354 | auto* client = globalObject->consoleClient(); |
| 355 | if (!client) |
| 356 | return JSValue::encode(jsUndefined()); |
| 357 | |
| 358 | auto label = valueOrDefaultLabelString(globalObject, callFrame); |
| 359 | RETURN_IF_EXCEPTION(scope, encodedJSValue()); |
| 360 | |
| 361 | client->timeEnd(globalObject, label); |
| 362 | return JSValue::encode(jsUndefined()); |
| 363 | } |
| 364 | |
| 365 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncTimeStamp(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 366 | { |
| 367 | ConsoleClient* client = globalObject->consoleClient(); |
| 368 | if (!client) |
| 369 | return JSValue::encode(jsUndefined()); |
| 370 | |
| 371 | client->timeStamp(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 372 | return JSValue::encode(jsUndefined()); |
| 373 | } |
| 374 | |
| 375 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroup(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 376 | { |
| 377 | ConsoleClient* client = globalObject->consoleClient(); |
| 378 | if (!client) |
| 379 | return JSValue::encode(jsUndefined()); |
| 380 | |
| 381 | client->group(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 382 | return JSValue::encode(jsUndefined()); |
| 383 | } |
| 384 | |
| 385 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroupCollapsed(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 386 | { |
| 387 | ConsoleClient* client = globalObject->consoleClient(); |
| 388 | if (!client) |
| 389 | return JSValue::encode(jsUndefined()); |
| 390 | |
| 391 | client->groupCollapsed(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 392 | return JSValue::encode(jsUndefined()); |
| 393 | } |
| 394 | |
| 395 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncGroupEnd(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 396 | { |
| 397 | ConsoleClient* client = globalObject->consoleClient(); |
| 398 | if (!client) |
| 399 | return JSValue::encode(jsUndefined()); |
| 400 | |
| 401 | client->groupEnd(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 402 | return JSValue::encode(jsUndefined()); |
| 403 | } |
| 404 | |
| 405 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncRecord(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 406 | { |
| 407 | ConsoleClient* client = globalObject->consoleClient(); |
| 408 | if (!client) |
| 409 | return JSValue::encode(jsUndefined()); |
| 410 | |
| 411 | client->record(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 412 | return JSValue::encode(jsUndefined()); |
| 413 | } |
| 414 | |
| 415 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncRecordEnd(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 416 | { |
| 417 | ConsoleClient* client = globalObject->consoleClient(); |
| 418 | if (!client) |
| 419 | return JSValue::encode(jsUndefined()); |
| 420 | |
| 421 | client->recordEnd(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 422 | return JSValue::encode(jsUndefined()); |
| 423 | } |
| 424 | |
| 425 | static EncodedJSValue JSC_HOST_CALL consoleProtoFuncScreenshot(JSGlobalObject* globalObject, CallFrame* callFrame) |
| 426 | { |
| 427 | ConsoleClient* client = globalObject->consoleClient(); |
| 428 | if (!client) |
| 429 | return JSValue::encode(jsUndefined()); |
| 430 | |
| 431 | client->screenshot(globalObject, Inspector::createScriptArguments(globalObject, callFrame, 0)); |
| 432 | return JSValue::encode(jsUndefined()); |
| 433 | } |
| 434 | |
| 435 | } // namespace JSC |
| 436 | |