本文整理汇总了C++中JSObjectGetProperty函数的典型用法代码示例。如果您正苦于以下问题:C++ JSObjectGetProperty函数的具体用法?C++ JSObjectGetProperty怎么用?C++ JSObjectGetProperty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSObjectGetProperty函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT_ARG
void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message)
{
ASSERT_ARG(message, message);
JSStringRef messageConstructorString = JSStringCreateWithUTF8CString("ConsoleMessage");
JSObjectRef messageConstructor = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, messageConstructorString, 0), 0);
JSStringRelease(messageConstructorString);
JSStringRef addMessageString = JSStringCreateWithUTF8CString("addMessageToConsole");
JSObjectRef addMessage = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, addMessageString, 0), 0);
JSStringRelease(addMessageString);
JSValueRef sourceValue = JSValueMakeNumber(m_scriptContext, message->source);
JSValueRef levelValue = JSValueMakeNumber(m_scriptContext, message->level);
JSStringRef messageString = JSStringCreateWithCharacters(message->message.characters(), message->message.length());
JSValueRef messageValue = JSValueMakeString(m_scriptContext, messageString);
JSValueRef lineValue = JSValueMakeNumber(m_scriptContext, message->line);
JSStringRef urlString = JSStringCreateWithCharacters(message->url.characters(), message->url.length());
JSValueRef urlValue = JSValueMakeString(m_scriptContext, urlString);
JSValueRef args[] = { sourceValue, levelValue, messageValue, lineValue, urlValue };
JSObjectRef messageObject = JSObjectCallAsConstructor(m_scriptContext, messageConstructor, 5, args, 0);
JSStringRelease(messageString);
JSStringRelease(urlString);
JSObjectCallAsFunction(m_scriptContext, addMessage, m_scriptObject, 1, &messageObject, 0);
}
示例2: HyperloopJSValueIsArray
/*
* Tests whether a JavaScript value is an array object
*
* This invokes Array.isArray(value) and returns its result
*/
EXPORTAPI bool HyperloopJSValueIsArray(JSContextRef ctx, JSValueRef value)
{
if (JSValueIsObject(ctx, value))
{
JSObjectRef global = JSContextGetGlobalObject(ctx);
JSValueRef exception = JSValueMakeNull(ctx);
JSStringRef string = JSStringCreateWithUTF8CString("Array");
JSObjectRef array = JSValueToObject(ctx, JSObjectGetProperty(ctx, global, string, &exception), &exception);
JSStringRelease(string);
if (!JSValueIsNull(ctx, exception))
{
return false;
}
string = JSStringCreateWithUTF8CString("isArray");
JSObjectRef isArray = JSValueToObject(ctx, JSObjectGetProperty(ctx, array, string, &exception), &exception);
JSStringRelease(string);
if (!JSValueIsNull(ctx, exception))
{
return false;
}
JSValueRef result = JSObjectCallAsFunction(ctx, isArray, global, 1, &value, &exception);
if (JSValueIsNull(ctx, exception) && JSValueIsBoolean(ctx, result))
{
return JSValueToBoolean(ctx, result);
}
}
return false;
}
示例3: search
static JSValueRef search(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
if (argumentCount < 2 || !JSValueIsString(ctx, arguments[1]))
return JSValueMakeUndefined(ctx);
Node* node = toNode(toJS(arguments[0]));
if (!node)
return JSValueMakeUndefined(ctx);
JSStringRef string = JSValueToStringCopy(ctx, arguments[1], 0);
String target(JSStringGetCharactersPtr(string), JSStringGetLength(string));
JSStringRelease(string);
JSObjectRef globalObject = JSContextGetGlobalObject(ctx);
JSStringRef constructorString = JSStringCreateWithUTF8CString("Array");
JSObjectRef arrayConstructor = JSValueToObject(ctx, JSObjectGetProperty(ctx, globalObject, constructorString, 0), 0);
JSStringRelease(constructorString);
JSObjectRef array = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, 0);
JSStringRef pushString = JSStringCreateWithUTF8CString("push");
JSValueRef pushValue = JSObjectGetProperty(ctx, array, pushString, 0);
JSStringRelease(pushString);
JSObjectRef push = JSValueToObject(ctx, pushValue, 0);
RefPtr<Range> searchRange(rangeOfContents(node));
int exception = 0;
do {
RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false));
if (resultRange->collapsed(exception))
break;
// A non-collapsed result range can in some funky whitespace cases still not
// advance the range's start position (4509328). Break to avoid infinite loop.
VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM);
if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM))
break;
KJS::JSLock lock;
JSValueRef arg0 = toRef(toJS(toJS(ctx), resultRange.get()));
JSObjectCallAsFunction(ctx, push, array, 1, &arg0, 0);
setStart(searchRange.get(), newStart);
} while (true);
return array;
}
示例4: lengthPropertyName
bool TestRunner::findString(JSContextRef context, JSStringRef string, JSObjectRef optionsArray)
{
JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
if (!JSValueIsNumber(context, lengthValue))
return false;
QWebPage::FindFlags findFlags = QWebPage::FindCaseSensitively;
int length = static_cast<int>(JSValueToNumber(context, lengthValue, 0));
for (int i = 0; i < length; ++i) {
JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
if (!JSValueIsString(context, value))
continue;
JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
findFlags &= ~QWebPage::FindCaseSensitively;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
findFlags |= QWebPage::FindAtWordBeginningsOnly;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
findFlags |= QWebPage::TreatMedialCapitalAsWordBeginning;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
findFlags |= QWebPage::FindBackward;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
findFlags |= QWebPage::FindWrapsAroundDocument;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection"))
findFlags |= QWebPage::FindBeginsInSelection;
}
DumpRenderTree* drt = DumpRenderTree::instance();
return drt->webPage()->findText(JSStringCopyQString(string), findFlags);
}
示例5: EvilExceptionObject_convertToType
static JSValueRef EvilExceptionObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
{
UNUSED_PARAM(object);
UNUSED_PARAM(exception);
JSStringRef funcName;
switch (type) {
case kJSTypeNumber:
funcName = JSStringCreateWithUTF8CString("toNumber");
break;
case kJSTypeString:
funcName = JSStringCreateWithUTF8CString("toStringExplicit");
break;
default:
return NULL;
break;
}
JSValueRef func = JSObjectGetProperty(context, object, funcName, exception);
JSStringRelease(funcName);
JSObjectRef function = JSValueToObject(context, func, exception);
if (!function)
return NULL;
JSValueRef value = JSObjectCallAsFunction(context, function, object, 0, NULL, exception);
if (!value)
return (JSValueRef)JSStringCreateWithUTF8CString("convertToType failed");
return value;
}
示例6: JSObjectGetProperty
unsigned JSArray::length() {
JSValueRef val = JSObjectGetProperty(ctx_, instance_, JSString("length"), nullptr);
if (JSValueIsNumber(ctx_, val))
return static_cast<unsigned>(JSValueToNumber(ctx_, val, nullptr));
return 0;
}
示例7: JSObjectGetProperty
VJSValue VJSObject::GetProperty( const VString& inPropertyName, JS4D::ExceptionRef *outException) const
{
JSStringRef jsName = JS4D::VStringToString( inPropertyName);
JSValueRef valueRef = JSObjectGetProperty( fContext, fObject, jsName, outException);
JSStringRelease( jsName);
return VJSValue( fContext, valueRef);
}
示例8: JSStringCreateWithUTF8CString
bool JS4D::DateObjectToVTime( ContextRef inContext, ObjectRef inObject, VTime& outTime, ExceptionRef *outException)
{
// it's caller responsibility to check inObject is really a Date using ValueIsInstanceOf
// call getTime()
bool ok = false;
JSStringRef jsString = JSStringCreateWithUTF8CString( "getTime");
JSValueRef getTime = JSObjectGetProperty( inContext, inObject, jsString, outException);
JSObjectRef getTimeFunction = JSValueToObject( inContext, getTime, outException);
JSStringRelease( jsString);
JSValueRef result = (getTime != NULL) ? JSObjectCallAsFunction( inContext, getTimeFunction, inObject, 0, NULL, outException) : NULL;
if (result != NULL)
{
// The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
double r = JSValueToNumber( inContext, result, outException);
sLONG8 n = (sLONG8) r;
if (n == r)
{
outTime.FromUTCTime( 1970, 1, 1, 0, 0, 0, 0);
outTime.AddMilliseconds( n);
ok = true;
}
else
{
outTime.SetNull( true);
}
}
else
{
outTime.SetNull( true);
}
return ok;
}
示例9: JSValueMakeNumber
JS4D::ObjectRef JS4D::VTimeToObject( ContextRef inContext, const VTime& inTime, ExceptionRef *outException)
{
if (inTime.IsNull())
return NULL; // can't return JSValueMakeNull as an object
sWORD year, month, day, hour, minute, second, millisecond;
inTime.GetLocalTime( year, month, day, hour, minute, second, millisecond);
JSValueRef args[6];
args[0] = JSValueMakeNumber( inContext, year);
args[1] = JSValueMakeNumber( inContext, month-1);
args[2] = JSValueMakeNumber( inContext, day);
args[3] = JSValueMakeNumber( inContext, hour);
args[4] = JSValueMakeNumber( inContext, minute);
args[5] = JSValueMakeNumber( inContext, second);
#if NEW_WEBKIT
JSObjectRef date = JSObjectMakeDate( inContext, 6, args, outException);
#else
JSStringRef jsClassName = JSStringCreateWithUTF8CString("Date");
JSObjectRef constructor = JSValueToObject( inContext, JSObjectGetProperty( inContext, JSContextGetGlobalObject( inContext), jsClassName, NULL), NULL);
JSStringRelease( jsClassName);
JSObjectRef date = JSObjectCallAsConstructor( inContext, constructor, 6, args, outException);
#endif
return date;
}
示例10: ASSERT
void InspectorController::scriptObjectReady()
{
ASSERT(m_scriptContext);
if (!m_scriptContext)
return;
JSObjectRef global = JSContextGetGlobalObject(m_scriptContext);
ASSERT(global);
JSStringRef inspectorString = JSStringCreateWithUTF8CString("WebInspector");
JSValueRef inspectorValue = JSObjectGetProperty(m_scriptContext, global, inspectorString, 0);
JSStringRelease(inspectorString);
ASSERT(inspectorValue);
if (!inspectorValue)
return;
m_scriptObject = JSValueToObject(m_scriptContext, inspectorValue, 0);
ASSERT(m_scriptObject);
JSValueProtect(m_scriptContext, m_scriptObject);
// Make sure our window is visible now that the page loaded
m_client->showWindow();
}
示例11: JSContextGetGlobalObject
JNIEXPORT void JNICALL
Java_com_appcelerator_hyperloop_HyperloopJNI_HyperloopCallActivityOnCreate
(JNIEnv *env, jobject thiz, jlong jsContextRef, jobject activity, jobject savedInstanceState)
{
JSContextRef context = (JSContextRef)jsContextRef;
JSObjectRef globalObject = JSContextGetGlobalObject(context);
JSStringRef onCreate = JSStringCreateWithUTF8CString("onCreate");
JSObjectRef onCreateFunc = JSValueToObject(context,
JSObjectGetProperty(context, globalObject, onCreate, NULL), NULL);
JSStringRelease(onCreate);
// save current Activity
JSObjectRef activityObj = MakeObjectForJava_android_app_Activity(context, activity);
// save parameter
JSValueRef args[1];
args[0] = MakeObjectForJava_android_os_Bundle(context, savedInstanceState);
JSValueRef exception = JSValueMakeNull(context);
// Call onCreate function
if (JSObjectIsFunction(context, onCreateFunc)) {
JSObjectCallAsFunction(context, onCreateFunc, activityObj, 1, args, &exception);
}
if (!JSValueIsNull(context, exception)) {
JSStringRef string = JSValueToStringCopy(context, exception, NULL);
CCHAR_FROM_JSSTRINGREF(string, cstring);
LOGD("Java_com_appcelerator_hyperloop_HyperloopJNI_HyperloopCallActivityOnCreate '%s'", cstring);
free(cstring);
JSStringRelease(string);
}
}
示例12: arrayLength
static unsigned arrayLength(JSContextRef context, JSObjectRef array)
{
JSRetainPtr<JSStringRef> lengthString(Adopt, JSStringCreateWithUTF8CString("length"));
JSValueRef lengthValue = JSObjectGetProperty(context, array, lengthString.get(), 0);
if (!lengthValue)
return 0;
return static_cast<unsigned>(JSValueToNumber(context, lengthValue, 0));
}
示例13: JSStringCreateWithUTF8CString
JSValueRef ObjectWrapper::GetValue(const KeyType key)
{
JSStringRef strKey = JSStringCreateWithUTF8CString(key.c_str());
JSValueRef value = JSObjectGetProperty(g_ctx, m_obj, strKey, NULL);
JSStringRelease(strKey);
return value;
}
示例14: getChildren
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
KJS::JSLock lock(false);
if (!JSValueIsObjectOfClass(ctx, thisObject, ProfileNodeClass()))
return JSValueMakeUndefined(ctx);
ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
const Vector<RefPtr<ProfileNode> >& children = profileNode->children();
JSObjectRef global = JSContextGetGlobalObject(ctx);
JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array"));
JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push"));
JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) {
JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() ));
JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
}
return result;
}
示例15: JSObjectGetProperty
Value Object::getProperty(const String& propName) const {
JSValueRef exn;
JSValueRef property = JSObjectGetProperty(m_context, m_obj, propName, &exn);
if (!property) {
std::string exceptionText = Value(m_context, exn).toString().str();
throwJSExecutionException("Failed to get property: %s", exceptionText.c_str());
}
return Value(m_context, property);
}