예제 #1
0
파일: db.cpp 프로젝트: lx6317648/fibjs
void _appendValue(exlib::string& str, v8::Local<v8::Value>& v, bool mysql)
{
    bool bNumber = v->IsNumber() || v->IsNumberObject();

    if (bNumber) {
        v8::String::Utf8Value s1(v);
        str.append(*s1, s1.length());
    } else {
        exlib::string s;
        str += '\'';

        if (v->IsDate()) {
            date_t d = v;
            d.sqlString(s);
        } else {
            v8::String::Utf8Value s1(v);
            _escape(*s1, s1.length(), mysql, s);
        }
        str.append(s);

        str += '\'';
    }
}
예제 #2
0
void V8BiquadFilterNode::typeAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
{
    BiquadFilterNode* imp = V8BiquadFilterNode::toNative(info.Holder());

    if (value->IsNumber()) {
        bool ok = false;
        uint32_t type = toUInt32(value, ok);
        ASSERT(ok);
        if (!imp->setType(type))
            throwTypeError("Illegal BiquadFilterNode type", info.GetIsolate());
        return;
    }

    if (value->IsString()) {
        String type = toWebCoreString(value.As<v8::String>());
        if (type == "lowpass" || type == "highpass" || type == "bandpass" || type == "lowshelf" || type == "highshelf" || type == "peaking" || type == "notch" || type == "allpass") {
            imp->setType(type);
            return;
        }
    }

    throwTypeError("Illegal BiquadFilterNode type", info.GetIsolate());
}
예제 #3
0
void V8SVGLength::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.SVGLength.value._set");
    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder());
    if (wrapper->isReadOnly()) {
        V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR, info.GetIsolate());
        return;
    }

    if (!isUndefinedOrNull(value) && !value->IsNumber() && !value->IsBoolean()) {
        V8Proxy::throwTypeError(0, info.GetIsolate());
        return;
    }

    SVGLength& imp = wrapper->propertyReference();
    ExceptionCode ec = 0;
    SVGLengthContext lengthContext(wrapper->contextElement());
    imp.setValue(static_cast<float>(value->NumberValue()), lengthContext, ec);
    if (UNLIKELY(ec))
        V8Proxy::setDOMException(ec, info.GetIsolate());
    else
        wrapper->commitChange();
}
예제 #4
0
static void installV8TestIntegerIndexedPrimaryGlobalTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
{
    functionTemplate->ReadOnlyPrototype();

    v8::Local<v8::Signature> defaultSignature;
    defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "TestIntegerIndexedPrimaryGlobal", V8TestIntegerIndexedPrimaryGlobal::domTemplateForNamedPropertiesObject(isolate), V8TestIntegerIndexedPrimaryGlobal::internalFieldCount,
        0, 0,
        V8TestIntegerIndexedPrimaryGlobalAccessors, WTF_ARRAY_LENGTH(V8TestIntegerIndexedPrimaryGlobalAccessors),
        V8TestIntegerIndexedPrimaryGlobalMethods, WTF_ARRAY_LENGTH(V8TestIntegerIndexedPrimaryGlobalMethods));
    v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
    ALLOW_UNUSED_LOCAL(instanceTemplate);
    v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate();
    ALLOW_UNUSED_LOCAL(prototypeTemplate);
    if (RuntimeEnabledFeatures::iterableCollectionsEnabled()) {
        instanceTemplate->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate), v8::kArrayProto_values, v8::DontEnum);
    }
    v8::IndexedPropertyHandlerConfiguration indexedPropertyHandlerConfig(TestIntegerIndexedPrimaryGlobalV8Internal::indexedPropertyGetterCallback, TestIntegerIndexedPrimaryGlobalV8Internal::indexedPropertySetterCallback, 0, TestIntegerIndexedPrimaryGlobalV8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestIntegerIndexedPrimaryGlobal>, v8::Local<v8::Value>(), v8::PropertyHandlerFlags::kNone);
    instanceTemplate->SetHandler(indexedPropertyHandlerConfig);
    functionTemplate->SetHiddenPrototype(true);

    // Custom toString template
    functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
}
bool ScriptCustomElementDefinitionBuilder::valueForName(
    const v8::Local<v8::Object>& object,
    const StringView& name,
    v8::Local<v8::Value>& value) const {
  v8::Isolate* isolate = m_scriptState->isolate();
  v8::Local<v8::Context> context = m_scriptState->context();
  v8::Local<v8::String> nameString = v8AtomicString(isolate, name);
  v8::TryCatch tryCatch(isolate);
  if (!v8Call(object->Get(context, nameString), value, tryCatch)) {
    m_exceptionState.rethrowV8Exception(tryCatch.Exception());
    return false;
  }
  return true;
}
예제 #6
0
void transferHiddenDependency(v8::Handle<v8::Object> object, EventListener* oldValue, v8::Local<v8::Value> newValue, int cacheIndex, v8::Isolate* isolate)
{
    if (oldValue) {
        V8AbstractEventListener* oldListener = V8AbstractEventListener::cast(oldValue);
        if (oldListener) {
            v8::Local<v8::Object> oldListenerObject = oldListener->getExistingListenerObject();
            if (!oldListenerObject.IsEmpty())
                removeHiddenDependency(object, oldListenerObject, cacheIndex, isolate);
        }
    }
    // Non-callable input is treated as null and ignored
    if (newValue->IsFunction())
        createHiddenDependency(object, newValue, cacheIndex, isolate);
}
예제 #7
0
bool extractTransferables(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState, v8::Isolate* isolate)
{
    if (isUndefinedOrNull(value)) {
        ports.resize(0);
        arrayBuffers.resize(0);
        return true;
    }

    uint32_t length = 0;
    if (value->IsArray()) {
        v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value);
        length = array->Length();
    } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
        exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex + 1));
        return false;
    }

    v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value);

    // Validate the passed array of transferrables.
    for (unsigned int i = 0; i < length; ++i) {
        v8::Local<v8::Value> transferrable = transferrables->Get(i);
        // Validation of non-null objects, per HTML5 spec 10.3.3.
        if (isUndefinedOrNull(transferrable)) {
            exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " is an untransferable " + (transferrable->IsUndefined() ? "'undefined'" : "'null'") + " value.");
            return false;
        }
        // Validation of Objects implementing an interface, per WebIDL spec 4.1.15.
        if (V8MessagePort::hasInstance(transferrable, isolate)) {
            RefPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Object>::Cast(transferrable));
            // Check for duplicate MessagePorts.
            if (ports.contains(port)) {
                exceptionState.throwDOMException(DataCloneError, "Message port at index " + String::number(i) + " is a duplicate of an earlier port.");
                return false;
            }
            ports.append(port.release());
        } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) {
            RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(transferrable));
            if (arrayBuffers.contains(arrayBuffer)) {
                exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer.");
                return false;
            }
            arrayBuffers.append(arrayBuffer.release());
        } else {
            exceptionState.throwDOMException(DataCloneError, "Value at index " + String::number(i) + " does not have a transferable type.");
            return false;
        }
    }
    return true;
}
예제 #8
0
bool getMessagePortArray(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, v8::Isolate* isolate)
{
    if (isUndefinedOrNull(value)) {
        ports.resize(0);
        return true;
    }
    if (!value->IsArray()) {
        throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex), isolate);
        return false;
    }
    bool success = false;
    ports = toRefPtrNativeArray<MessagePort, V8MessagePort>(value, argumentIndex, isolate, &success);
    return success;
}
예제 #9
0
bool getMessagePortArray(v8::Local<v8::Value> value, const String& propertyName, MessagePortArray& ports, v8::Isolate* isolate)
{
    if (isUndefinedOrNull(value)) {
        ports.resize(0);
        return true;
    }
    if (!value->IsArray()) {
        throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName), isolate);
        return false;
    }
    bool success = false;
    ports = toRefPtrNativeArray<MessagePort, V8MessagePort>(value, propertyName, isolate, &success);
    return success;
}
예제 #10
0
result_t HttpCollection::_named_enumerator(v8::Local<v8::Array>& retVal)
{
    int32_t i, n;
    std::set<exlib::string> name_set;
    Isolate* isolate = holder();

    retVal = v8::Array::New(isolate->m_isolate);
    for (i = 0, n = 0; i < m_count; i++) {
        exlib::string& name = m_map[i].first;
        if (name_set.insert(name).second)
            retVal->Set(n++, isolate->NewString(name));
    }

    return 0;
}
예제 #11
0
void MainThreadDebugger::runMessageLoopOnPause(v8::Local<v8::Context> context)
{
    v8::HandleScope scope(context->GetIsolate());
    LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context);
    m_pausedFrame = frame->localFrameRoot();

    // Wait for continue or step command.
    m_clientMessageLoop->run(m_pausedFrame);

    // The listener may have been removed in the nested loop.
    if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedFrame))
        listener->didContinue();

    m_pausedFrame = 0;
}
예제 #12
0
static void namedPropertyQuery(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
{
    if (!name->IsString())
        return;
    TestInterface2* impl = V8TestInterface2::toImpl(info.Holder());
    AtomicString propertyName = toCoreAtomicString(name.As<v8::String>());
    v8::String::Utf8Value namedProperty(name);
    ExceptionState exceptionState(ExceptionState::GetterContext, *namedProperty, "TestInterface2", info.Holder(), info.GetIsolate());
    bool result = impl->namedPropertyQuery(propertyName, exceptionState);
    if (exceptionState.throwIfNeeded())
        return;
    if (!result)
        return;
    v8SetReturnValueInt(info, v8::None);
}
예제 #13
0
CUInt128 CJSKadID::FromValue(v8::Local<v8::Value> value)
{
    v8::HandleScope HandleScope(v8::Isolate::GetCurrent());

	CUInt128 Value;
	if(value->IsString())
		Value.FromHex(CJSEngine::GetWStr(value));
	else if(value->IsObject())
	{
		if(CKadIDObj* pVariant = GetCObject<CKadIDObj>(value->ToObject()))
			Value = pVariant->m_Value;
		else if(CVariantPrx* pVariant = GetCObject<CVariantPrx>(value->ToObject()))
			Value = pVariant->GetCopy();
	}
	else	
	{
		sint64 iValue = value->IntegerValue();
		if(iValue < 0)
			Value = CUInt128(true);
		else
			Value = CUInt128((sint32)iValue);
	}
	return Value;
}
예제 #14
0
// static
std::unique_ptr<SourceLocation> SourceLocation::fromMessage(
    v8::Isolate* isolate,
    v8::Local<v8::Message> message,
    ExecutionContext* executionContext) {
  v8::Local<v8::StackTrace> stack = message->GetStackTrace();
  std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = nullptr;
  V8PerIsolateData* data = V8PerIsolateData::from(isolate);
  if (data && data->threadDebugger())
    stackTrace = data->threadDebugger()->v8Inspector()->createStackTrace(stack);

  int scriptId = message->GetScriptOrigin().ScriptID()->Value();
  if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
    int topScriptId = stack->GetFrame(0)->GetScriptId();
    if (topScriptId == scriptId)
      scriptId = 0;
  }

  int lineNumber = 0;
  int columnNumber = 0;
  if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()),
             lineNumber) &&
      v8Call(message->GetStartColumn(isolate->GetCurrentContext()),
             columnNumber))
    ++columnNumber;

  if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty())
    return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTrace),
                                                          0);

  String url = toCoreStringWithUndefinedOrNullCheck(
      message->GetScriptOrigin().ResourceName());
  if (url.isNull())
    url = executionContext->url();
  return SourceLocation::create(url, lineNumber, columnNumber,
                                std::move(stackTrace), scriptId);
}
예제 #15
0
void V8TestInterfaceEventInit::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, TestInterfaceEventInit& impl, ExceptionState& exceptionState)
{
    if (isUndefinedOrNull(v8Value))
        return;
    if (!v8Value->IsObject()) {
        exceptionState.throwTypeError("cannot convert to dictionary.");
        return;
    }

    V8EventInit::toImpl(isolate, v8Value, impl, exceptionState);
    if (exceptionState.hadException())
        return;

    v8::TryCatch block;
    v8::Local<v8::Object> v8Object;
    if (!v8Call(v8Value->ToObject(isolate->GetCurrentContext()), v8Object, block)) {
        exceptionState.rethrowV8Exception(block.Exception());
        return;
    }
    {
        v8::Local<v8::Value> stringMemberValue;
        if (!v8Object->Get(isolate->GetCurrentContext(), v8String(isolate, "stringMember")).ToLocal(&stringMemberValue)) {
            exceptionState.rethrowV8Exception(block.Exception());
            return;
        }
        if (stringMemberValue.IsEmpty() || stringMemberValue->IsUndefined()) {
            // Do nothing.
        } else {
            V8StringResource<> stringMember = stringMemberValue;
            if (!stringMember.prepare(exceptionState))
                return;
            impl.setStringMember(stringMember);
        }
    }

}
예제 #16
0
파일: coroutine.cpp 프로젝트: AsamQi/fibjs
inline result_t _parallel(std::vector<v8::Local<v8::Function> > &funs,
                          v8::Local<v8::Array> &retVal)
{
    std::vector<obj_ptr<JSFiber> > fibers;
    int i;

    fibers.resize(funs.size());
    for (i = 1; i < (int) funs.size(); i++)
        JSFiber::New(funs[i], NULL, 0, fibers[i]);

    v8::Local<v8::Value> r;
    JSFiber::call(funs[0], NULL, 0, r);
    bool bError = r.IsEmpty();

    if (!bError)
    {
        retVal = v8::Array::New(isolate, (int) funs.size());
        retVal->Set(0, r);
    }

    for (i = 1; i < (int) funs.size(); i++)
    {
        JSFiber *fb = fibers[i];
        fb->join();

        if (fb->isError())
            bError = true;
        else if (!bError && fb->get_result(r) != CALL_RETURN_NULL)
            retVal->Set(i, r);
    }

    if (bError)
        return CHECK_ERROR(CALL_E_INTERNAL);

    return 0;
}
예제 #17
0
// The read-eval-execute loop of the shell.
void Fragment::Script::ScriptEngine::RunShell(v8::Local<v8::Context> context, v8::Platform *platform) {
    fprintf(stderr, "V8 version %s [sample shell]\n", v8::V8::GetVersion());
    static const int kBufferSize = 256;
    // Enter the execution environment before evaluating any code.
    v8::Context::Scope context_scope(context);
    v8::Local<v8::String> name(
            v8::String::NewFromUtf8(context->GetIsolate(), "(shell)",
                                    v8::NewStringType::kNormal).ToLocalChecked());
    while (true) {
        char buffer[kBufferSize];
        fprintf(stderr, "> ");
        char *str = fgets(buffer, kBufferSize, stdin);
        if (str == NULL) break;
        v8::HandleScope handle_scope(context->GetIsolate());
        ExecuteString(
                context->GetIsolate(),
                v8::String::NewFromUtf8(context->GetIsolate(), str,
                                        v8::NewStringType::kNormal).ToLocalChecked(),
                name, true, true);
        while (v8::platform::PumpMessageLoop(platform, context->GetIsolate()))
            continue;
    }
    fprintf(stderr, "\n");
}
예제 #18
0
파일: Stats.cpp 프로젝트: CheneyWong/fibjs
result_t Stats::_named_enumerator(v8::Local<v8::Array> &retVal)
{
    int i;
    Isolate &isolate = Isolate::now();

    retVal = v8::Array::New(isolate.isolate);

    for (i = 0; i < m_size; i++)
        retVal->Set(i,
                    v8::String::NewFromUtf8(isolate.isolate, m_keys[i].c_str(),
                                            v8::String::kNormalString,
                                            (int) m_keys[i].length()));

    return 0;
}
예제 #19
0
파일: unicode.hpp 프로젝트: AMDmi3/osmium
 /**
 * Sends v8::String to output stream. This will first convert it to a UTF-8 string.
 *
 * @exception UTF16_to_UTF8_Conversion_Error Thrown if the conversion failed.
 * @param string A v8::String.
 * @param os A reference to an output stream.
 */
 inline void v8_String_to_ostream(v8::Local<v8::String> string, std::ostream& os) {
     UErrorCode error_code = U_ZERO_ERROR;
     int length = 4 * (string->Length() + 1);
     uint16_t* src = static_cast<uint16_t*>(malloc(length));
     if (!src) {
         throw std::bad_alloc();
     }
     char* buffer = static_cast<char*>(malloc(length));
     if (!buffer) {
         free(src);
         throw std::bad_alloc();
     }
     int32_t buffer_length;
     string->Write(src);
     u_strToUTF8(buffer, length, &buffer_length, src, string->Length(), &error_code);
     if (error_code != U_ZERO_ERROR) {
         free(buffer);
         free(src);
         throw UTF16_to_UTF8_Conversion_Error(error_code);
     }
     os << buffer;
     free(buffer);
     free(src);
 }
예제 #20
0
파일: test.cpp 프로젝트: Andrew-Zhang/fibjs
result_t test_base::describe(const char *name, v8::Local<v8::Function> block)
{
    _case::init();

    _case *last = s_now;

    result_t hr = _case::enter(name);
    if (hr < 0)
        return hr;

    block->Call(v8::Undefined(isolate), 0, NULL);

    s_now = last;
    return 0;
}
예제 #21
0
static void messageHandlerInWorker(v8::Local<v8::Message> message, v8::Local<v8::Value> data)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    V8PerIsolateData* perIsolateData = V8PerIsolateData::from(isolate);
    // Exceptions that occur in error handler should be ignored since in that case
    // WorkerGlobalScope::reportException will send the exception to the worker object.
    if (perIsolateData->isReportingException())
        return;
    perIsolateData->setReportingException(true);

    ScriptState* scriptState = ScriptState::current(isolate);
    // During the frame teardown, there may not be a valid context.
    if (ExecutionContext* context = scriptState->executionContext()) {
        String errorMessage = toCoreStringWithNullCheck(message->Get());
        TOSTRING_VOID(V8StringResource<>, sourceURL, message->GetScriptOrigin().ResourceName());
        int scriptId = 0;
        RefPtrWillBeRawPtr<ScriptCallStack> callStack = extractCallStack(isolate, message, &scriptId);

        int lineNumber = 0;
        int columnNumber = 0;
        if (v8Call(message->GetLineNumber(scriptState->context()), lineNumber)
            && v8Call(message->GetStartColumn(scriptState->context()), columnNumber))
            ++columnNumber;
        RefPtrWillBeRawPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, &DOMWrapperWorld::current(isolate));
        AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;

        // If execution termination has been triggered as part of constructing
        // the error event from the v8::Message, quietly leave.
        if (!v8::V8::IsExecutionTerminating(isolate)) {
            V8ErrorHandler::storeExceptionOnErrorEventWrapper(isolate, event.get(), data, scriptState->context()->Global());
            context->reportException(event.release(), scriptId, callStack, corsStatus);
        }
    }

    perIsolateData->setReportingException(false);
}
예제 #22
0
파일: Image.cpp 프로젝트: 540513310/fibjs
result_t getPoints(v8::Local<v8::Array> &points, std::vector<gdPoint> &pts)
{
    int32_t i, len = points->Length();

    pts.resize(len);

    for (i = 0; i < len; i++)
    {
        v8::Local<v8::Value> v = points->Get(i);

        if (!v->IsArray())
            return CHECK_ERROR(CALL_E_TYPEMISMATCH);

        v8::Local<v8::Array> pt = v8::Local<v8::Array>::Cast(v);

        if (pt->Length() != 2)
            return CHECK_ERROR(CALL_E_TYPEMISMATCH);

        pts[i].x = pt->Get(0)->Int32Value();
        pts[i].y = pt->Get(1)->Int32Value();
    }

    return 0;
}
예제 #23
0
void resetInternalsObject(v8::Local<v8::Context> context)
{
    // This can happen if JavaScript is disabled in the main frame.
    if (context.IsEmpty())
        return;

    v8::Context::Scope contextScope(context);
    v8::HandleScope scope;

    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    ASSERT(scriptContext->isDocument());
    Page* page = static_cast<Document*>(scriptContext)->frame()->page();
    Internals::resetToConsistentState(page);
    InternalSettings::from(page)->resetToConsistentState();
}
예제 #24
0
static void bAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.SVGMatrix.b._set");
    SVGPropertyTearOff<SVGMatrix>* wrapper = V8SVGMatrix::toNative(info.Holder());
    if (wrapper->role() == AnimValRole) {
        V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& impInstance = wrapper->propertyReference();
    SVGMatrix* imp = &impInstance;
    double v = static_cast<double>(value->NumberValue());
    imp->setB(v);
    wrapper->commitChange();
    return;
}
예제 #25
0
bool OptionsObject::getKey(const String& key, v8::Local<v8::Value>& value) const
{
    if (isUndefinedOrNull())
        return false;
    v8::Local<v8::Object> options = m_options->ToObject();
    ASSERT(!options.IsEmpty());

    v8::Handle<v8::String> v8Key = v8String(key);
    if (!options->Has(v8Key))
        return false;
    value = options->Get(v8Key);
    if (value.IsEmpty())
        return false;
    return true;
}
예제 #26
0
void V8Element::scrollTopAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
{
    ExceptionState exceptionState(ExceptionState::SetterContext, "scrollTop", "Element", info.Holder(), info.GetIsolate());
    Element* imp = V8Element::toNative(info.Holder());

    if (RuntimeEnabledFeatures::cssomSmoothScrollEnabled() && value->IsObject()) {
        V8TRYCATCH_VOID(Dictionary, scrollOptionsVertical, Dictionary(value, info.GetIsolate()));
        imp->setScrollTop(scrollOptionsVertical, exceptionState);
        exceptionState.throwIfNeeded();
        return;
    }

    V8TRYCATCH_EXCEPTION_VOID(int, position, toInt32(value, exceptionState), exceptionState);
    imp->setScrollTop(position);
}
예제 #27
0
void MSRect::Initialize(v8::Local<v8::Object> target) {
  v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(MSRect::New);
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->SetClassName(Nan::New("Rect").ToLocalChecked());

  RW_ATTR(tpl, "minx", PropertyGetter, PropertySetter);
  RW_ATTR(tpl, "miny", PropertyGetter, PropertySetter);
  RW_ATTR(tpl, "maxx", PropertyGetter, PropertySetter);
  RW_ATTR(tpl, "maxy", PropertyGetter, PropertySetter);

  Nan::SetPrototypeMethod(tpl, "project", Project);

  target->Set(Nan::New("Rect").ToLocalChecked(), tpl->GetFunction());
  constructor.Reset(tpl);
}
예제 #28
0
result_t Redis::_map(v8::Local<v8::Object> &map, int32_t cmd)
{
    m_subMode = 1;

    Isolate* isolate = holder();
    v8::Local<v8::Array> channels = map->GetPropertyNames();
    int32_t sz = channels->Length();
    int32_t i;
    v8::Local<v8::Array> subs = v8::Array::New(isolate->m_isolate);
    int32_t count = 0;

    for (i = 0; i < sz; i ++)
    {
        v8::Local<v8::Value> channel = channels->Get(i);
        std::string s;

        GetArgumentValue(channel, s);
        s = s_cmd[cmd][1] + s;

        v8::Local<v8::Value> value = map->Get(channel);

        if (!value->IsFunction())
            return CHECK_ERROR(CALL_E_TYPEMISMATCH);

        v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(value);

        if ((cmd & 1) ? unregsub(s, func) : regsub(s, func))
            subs->Set(count ++, channel);
    }

    if (!count)
        return 0;

    Variant v;
    return doCommand(s_cmd[cmd][0], subs, v);
}
예제 #29
0
void V8StringOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, StringOrDouble& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState)
{
    if (v8Value.IsEmpty())
        return;

    if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull(v8Value))
        return;

    if (v8Value->IsNumber()) {
        double cppValue = toRestrictedDouble(isolate, v8Value, exceptionState);
        if (exceptionState.hadException())
            return;
        impl.setDouble(cppValue);
        return;
    }

    {
        V8StringResource<> cppValue = v8Value;
        if (!cppValue.prepare(exceptionState))
            return;
        impl.setString(cppValue);
        return;
    }
}
예제 #30
0
파일: os_osx.cpp 프로젝트: CYCOK/fibjs
result_t os_base::loadavg(v8::Local<v8::Array> &retVal)
{
    double avg[3] =
    { 0, 0, 0 };

    struct loadavg info;
    size_t size = sizeof(info);
    int which[] =
    { CTL_VM, VM_LOADAVG };

    if (sysctl(which, 2, &info, &size, NULL, 0) < 0)
        return CHECK_ERROR(LastError());

    avg[0] = (double) info.ldavg[0] / info.fscale;
    avg[1] = (double) info.ldavg[1] / info.fscale;
    avg[2] = (double) info.ldavg[2] / info.fscale;

    retVal = v8::Array::New(isolate, 3);
    retVal->Set(0, v8::Number::New(isolate, avg[0]));
    retVal->Set(1, v8::Number::New(isolate, avg[1]));
    retVal->Set(2, v8::Number::New(isolate, avg[2]));

    return 0;
}