32
32
#include "PlatformString.h"
33
33
#include "StringSourceProvider.h"
34
34
#include "c_utility.h"
35
#include "c_instance.h"
36
#include "IdentifierRep.h"
35
37
#include "npruntime_impl.h"
36
38
#include "npruntime_priv.h"
37
39
#include "runtime_root.h"
43
45
#include <runtime/Completion.h>
44
46
#include <runtime/Completion.h>
46
using WebCore::String;
47
using WebCore::StringSourceProvider;
48
48
using namespace JSC;
49
49
using namespace JSC::Bindings;
50
using namespace WebCore;
51
static void getListFromVariantArgs(ExecState* exec, const NPVariant* args, unsigned argCount, RootObject* rootObject, ArgList& aList)
52
static void getListFromVariantArgs(ExecState* exec, const NPVariant* args, unsigned argCount, RootObject* rootObject, MarkedArgumentBuffer& aList)
53
54
for (unsigned i = 0; i < argCount; ++i)
54
55
aList.append(convertNPVariantToValue(exec, &args[i], rootObject));
111
112
ExecState* exec = rootObject->globalObject()->globalExec();
113
JSLock lock(SilenceAssertionsOnly);
114
115
// Call the function object.
115
JSValuePtr function = obj->imp;
116
JSValue function = obj->imp;
116
117
CallData callData;
117
CallType callType = function->getCallData(callData);
118
CallType callType = function.getCallData(callData);
118
119
if (callType == CallTypeNone)
122
MarkedArgumentBuffer argList;
122
123
getListFromVariantArgs(exec, args, argCount, rootObject, argList);
123
124
ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject();
124
globalObject->startTimeoutCheck();
125
JSValuePtr resultV = call(exec, function, callType, callData, function, argList);
126
globalObject->stopTimeoutCheck();
125
globalObject->globalData()->timeoutChecker.start();
126
JSValue resultV = call(exec, function, callType, callData, function, argList);
127
globalObject->globalData()->timeoutChecker.stop();
128
129
// Convert and return the result of the function call.
129
130
convertValueToNPVariant(exec, resultV, result);
142
143
if (o->_class == NPScriptObjectClass) {
143
144
JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o);
145
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(methodName);
146
IdentifierRep* i = static_cast<IdentifierRep*>(methodName);
149
150
// Special case the "eval" method.
160
161
if (!rootObject || !rootObject->isValid())
162
163
ExecState* exec = rootObject->globalObject()->globalExec();
164
JSValuePtr function = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string));
164
JSLock lock(SilenceAssertionsOnly);
165
JSValue function = obj->imp->get(exec, identifierFromNPIdentifier(i->string()));
165
166
CallData callData;
166
CallType callType = function->getCallData(callData);
167
CallType callType = function.getCallData(callData);
167
168
if (callType == CallTypeNone)
170
171
// Call the function object.
172
MarkedArgumentBuffer argList;
172
173
getListFromVariantArgs(exec, args, argCount, rootObject, argList);
173
174
ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject();
174
globalObject->startTimeoutCheck();
175
JSValuePtr resultV = call(exec, function, callType, callData, obj->imp, argList);
176
globalObject->stopTimeoutCheck();
175
globalObject->globalData()->timeoutChecker.start();
176
JSValue resultV = call(exec, function, callType, callData, obj->imp, argList);
177
globalObject->globalData()->timeoutChecker.stop();
178
179
// Convert and return the result of the function call.
179
180
convertValueToNPVariant(exec, resultV, result);
200
201
ExecState* exec = rootObject->globalObject()->globalExec();
202
JSLock lock(SilenceAssertionsOnly);
202
203
String scriptString = convertNPStringToUTF16(s);
203
204
ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject();
204
globalObject->startTimeoutCheck();
205
globalObject->globalData()->timeoutChecker.start();
205
206
Completion completion = JSC::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(scriptString));
206
globalObject->stopTimeoutCheck();
207
globalObject->globalData()->timeoutChecker.stop();
207
208
ComplType type = completion.complType();
210
211
if (type == Normal) {
211
212
result = completion.value();
235
236
ExecState* exec = rootObject->globalObject()->globalExec();
236
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName);
237
IdentifierRep* i = static_cast<IdentifierRep*>(propertyName);
241
result = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string));
239
JSLock lock(SilenceAssertionsOnly);
242
result = obj->imp->get(exec, identifierFromNPIdentifier(i->string()));
243
result = obj->imp->get(exec, i->value.number);
244
result = obj->imp->get(exec, i->number());
245
246
convertValueToNPVariant(exec, result, variant);
246
247
exec->clearException();
269
270
ExecState* exec = rootObject->globalObject()->globalExec();
271
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName);
271
JSLock lock(SilenceAssertionsOnly);
272
IdentifierRep* i = static_cast<IdentifierRep*>(propertyName);
274
275
PutPropertySlot slot;
275
obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant, rootObject), slot);
276
obj->imp->put(exec, identifierFromNPIdentifier(i->string()), convertNPVariantToValue(exec, variant, rootObject), slot);
277
obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant, rootObject));
278
obj->imp->put(exec, i->number(), convertNPVariantToValue(exec, variant, rootObject));
278
279
exec->clearException();
297
298
ExecState* exec = rootObject->globalObject()->globalExec();
298
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName);
300
if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string))) {
299
IdentifierRep* i = static_cast<IdentifierRep*>(propertyName);
301
if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string()))) {
301
302
exec->clearException();
305
if (!obj->imp->hasProperty(exec, i->value.number)) {
306
if (!obj->imp->hasProperty(exec, i->number())) {
306
307
exec->clearException();
313
obj->imp->deleteProperty(exec, identifierFromNPIdentifier(i->value.string));
312
JSLock lock(SilenceAssertionsOnly);
314
obj->imp->deleteProperty(exec, identifierFromNPIdentifier(i->string()));
315
obj->imp->deleteProperty(exec, i->value.number);
316
obj->imp->deleteProperty(exec, i->number());
317
318
exec->clearException();
332
333
ExecState* exec = rootObject->globalObject()->globalExec();
333
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName);
336
bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string));
334
IdentifierRep* i = static_cast<IdentifierRep*>(propertyName);
335
JSLock lock(SilenceAssertionsOnly);
337
bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string()));
337
338
exec->clearException();
341
bool result = obj->imp->hasProperty(exec, i->value.number);
342
bool result = obj->imp->hasProperty(exec, i->number());
342
343
exec->clearException();
354
355
if (o->_class == NPScriptObjectClass) {
355
356
JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o);
357
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(methodName);
358
IdentifierRep* i = static_cast<IdentifierRep*>(methodName);
361
362
RootObject* rootObject = obj->rootObject;
365
366
ExecState* exec = rootObject->globalObject()->globalExec();
367
JSValuePtr func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string));
367
JSLock lock(SilenceAssertionsOnly);
368
JSValue func = obj->imp->get(exec, identifierFromNPIdentifier(i->string()));
368
369
exec->clearException();
369
return !func->isUndefined();
370
return !func.isUndefined();
372
373
if (o->_class->hasMethod)
378
void _NPN_SetException(NPObject*, const NPUTF8*)
379
void _NPN_SetException(NPObject*, const NPUTF8* message)
381
// Bug 19888: Implement _NPN_SetException() correctly
382
// <https://bugs.webkit.org/show_bug.cgi?id=19888>
381
// Ignorning the NPObject param is consistent with the Mozilla implementation.
382
UString exception(message);
383
CInstance::setGlobalException(exception);
385
386
bool _NPN_Enumerate(NPP, NPObject* o, NPIdentifier** identifier, uint32_t* count)
394
395
ExecState* exec = rootObject->globalObject()->globalExec();
396
JSLock lock(SilenceAssertionsOnly);
396
397
PropertyNameArray propertyNames(exec);
398
399
obj->imp->getPropertyNames(exec, propertyNames);
431
432
ExecState* exec = rootObject->globalObject()->globalExec();
433
JSLock lock(SilenceAssertionsOnly);
434
435
// Call the constructor object.
435
JSValuePtr constructor = obj->imp;
436
JSValue constructor = obj->imp;
436
437
ConstructData constructData;
437
ConstructType constructType = constructor->getConstructData(constructData);
438
ConstructType constructType = constructor.getConstructData(constructData);
438
439
if (constructType == ConstructTypeNone)
442
MarkedArgumentBuffer argList;
442
443
getListFromVariantArgs(exec, args, argCount, rootObject, argList);
443
444
ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject();
444
globalObject->startTimeoutCheck();
445
JSValuePtr resultV = construct(exec, constructor, constructType, constructData, argList);
446
globalObject->stopTimeoutCheck();
445
globalObject->globalData()->timeoutChecker.start();
446
JSValue resultV = construct(exec, constructor, constructType, constructData, argList);
447
globalObject->globalData()->timeoutChecker.stop();
448
449
// Convert and return the result.
449
450
convertValueToNPVariant(exec, resultV, result);